Merge lp:~spinatelli/scratch/scratch-dnd into lp:~registry/scratch/scratch

Proposed by Sergio Spinatelli
Status: Merged
Approved by: Mario Guerriero
Approved revision: 105
Merged at revision: 104
Proposed branch: lp:~spinatelli/scratch/scratch-dnd
Merge into: lp:~registry/scratch/scratch
Diff against target: 150 lines (+52/-47)
2 files modified
src/Widgets/sourceview.vala (+8/-0)
src/main_window.vala (+44/-47)
To merge this branch: bzr merge lp:~spinatelli/scratch/scratch-dnd
Reviewer Review Type Date Requested Status
Mario Guerriero (community) Approve
Review via email: mp+72290@code.launchpad.net

Description of the change

Add basic drag and drop to open a file

To post a comment you must log in.
Revision history for this message
Mario Guerriero (mefrio-g) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Widgets/sourceview.vala'
--- src/Widgets/sourceview.vala 2011-08-19 10:42:12 +0000
+++ src/Widgets/sourceview.vala 2011-08-20 10:49:23 +0000
@@ -36,6 +36,7 @@
36 36
37 public SourceView (MainWindow window) {37 public SourceView (MainWindow window) {
3838
39 Gtk.drag_dest_add_uri_targets (this);
39 this.window = window;40 this.window = window;
40 41
41 manager = new LanguageManager ();42 manager = new LanguageManager ();
@@ -65,6 +66,13 @@
6566
66 }67 }
6768
69 public override void drag_data_received (Gdk.DragContext context, int x, int y, SelectionData selection_data, uint info, uint time_) {
70 foreach (string s in selection_data.get_uris ()){
71 window.open (Filename.from_uri (s));
72 window.set_undo_redo ();
73 }
74 }
75
68 public void use_default_font (bool value) {76 public void use_default_font (bool value) {
69 77
70 if (!value) // if false, simply return null78 if (!value) // if false, simply return null
7179
=== modified file 'src/main_window.vala'
--- src/main_window.vala 2011-08-19 14:30:49 +0000
+++ src/main_window.vala 2011-08-20 10:49:23 +0000
@@ -217,51 +217,43 @@
217 217
218 // filech.response.connect (on_response);218 // filech.response.connect (on_response);
219 219
220 if (filech.run () == ResponseType.ACCEPT) {220 if (filech.run () == ResponseType.ACCEPT)
221 string filename = filech.get_filename ();221 open (filech.get_filename ());
222 222
223 if (filename != null) {
224
225 // check if file is already opened
226 int target_page = -1;
227
228 try {
229 set_combobox_language (filename);
230 } catch (Error e) {
231 warning ("Cannont set the combobox id");
232 }
233
234 if (!current_notebook.welcome_screen.active) {
235
236 int tot_pages = current_notebook.get_n_pages ();
237 for (int i = 0; i < tot_pages; i++) {
238 if (current_tab.filename == filename) {
239 target_page = i;
240 }
241 }
242
243 }
244
245
246 if (target_page >= 0) {
247 message ("file already opened: %s\n", filename);
248 current_notebook.set_current_page (target_page);
249 } else {
250 message ("Opening: %s\n", filename);
251 current_notebook.show_tabs_view ();
252 load_file (filename);
253 //set the name of the file, not all the path, in the tab label
254 var name = filename.split("/");
255 current_tab.label.label.set_text (name[name.length-1]);
256
257 }
258 }
259
260 }
261
262 filech.close ();223 filech.close ();
263 set_undo_redo ();224 set_undo_redo ();
264 225
226 }
227
228 public void open (string filename) {
229 if (filename != null) {
230 // check if file is already opened
231 int target_page = -1;
232
233 try {
234 set_combobox_language (filename);
235 } catch (Error e) {
236 warning ("Cannont set the combobox id");
237 }
238
239 if (!current_notebook.welcome_screen.active) {
240
241 int tot_pages = current_notebook.get_n_pages ();
242 for (int i = 0; i < tot_pages; i++)
243 if (current_tab.filename == filename)
244 target_page = i;
245
246 }
247 if (target_page >= 0) {
248 message ("file already opened: %s\n", filename);
249 current_notebook.set_current_page (target_page);
250 } else {
251 message ("Opening: %s\n", filename);
252 current_notebook.show_tabs_view ();
253 var name = filename.split("/");
254 load_file (filename,name[name.length-1]);
255 }
256 }
265 }257 }
266 258
267 public void on_save_clicked() {259 public void on_save_clicked() {
@@ -305,7 +297,7 @@
305 }297 }
306298
307 //generic functions299 //generic functions
308 public void load_file (string filename) {300 public void load_file (string filename, string? title=null) {
309 301
310 if (filename != "") { 302 if (filename != "") {
311 try {303 try {
@@ -337,9 +329,11 @@
337 //set values for label329 //set values for label
338 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());330 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());
339 var label = tab.label.label;331 var label = tab.label.label;
340 if (label.get_text().substring (0, 1) == "*"){332
333 if (title != null)
334 label.set_text (title);
335 else
341 label.set_text (filename);336 label.set_text (filename);
342 }
343 set_window_title (filename);337 set_window_title (filename);
344 338
345 } catch (Error e) {339 } catch (Error e) {
@@ -348,7 +342,10 @@
348 }342 }
349 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());343 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());
350 var label = tab.label.label;344 var label = tab.label.label;
351 if (label.get_text().substring (0, 1) == "*"){345
346 if (title != null)
347 label.set_text (title);
348 else if (label.get_text().substring (0, 1) == "*"){
352 label.set_text (filename);349 label.set_text (filename);
353 }350 }
354 351

Subscribers

People subscribed via source and target branches