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
1=== modified file 'src/Widgets/sourceview.vala'
2--- src/Widgets/sourceview.vala 2011-08-19 10:42:12 +0000
3+++ src/Widgets/sourceview.vala 2011-08-20 10:49:23 +0000
4@@ -36,6 +36,7 @@
5
6 public SourceView (MainWindow window) {
7
8+ Gtk.drag_dest_add_uri_targets (this);
9 this.window = window;
10
11 manager = new LanguageManager ();
12@@ -65,6 +66,13 @@
13
14 }
15
16+ public override void drag_data_received (Gdk.DragContext context, int x, int y, SelectionData selection_data, uint info, uint time_) {
17+ foreach (string s in selection_data.get_uris ()){
18+ window.open (Filename.from_uri (s));
19+ window.set_undo_redo ();
20+ }
21+ }
22+
23 public void use_default_font (bool value) {
24
25 if (!value) // if false, simply return null
26
27=== modified file 'src/main_window.vala'
28--- src/main_window.vala 2011-08-19 14:30:49 +0000
29+++ src/main_window.vala 2011-08-20 10:49:23 +0000
30@@ -217,51 +217,43 @@
31
32 // filech.response.connect (on_response);
33
34- if (filech.run () == ResponseType.ACCEPT) {
35- string filename = filech.get_filename ();
36-
37- if (filename != null) {
38-
39- // check if file is already opened
40- int target_page = -1;
41-
42- try {
43- set_combobox_language (filename);
44- } catch (Error e) {
45- warning ("Cannont set the combobox id");
46- }
47-
48- if (!current_notebook.welcome_screen.active) {
49-
50- int tot_pages = current_notebook.get_n_pages ();
51- for (int i = 0; i < tot_pages; i++) {
52- if (current_tab.filename == filename) {
53- target_page = i;
54- }
55- }
56-
57- }
58-
59-
60- if (target_page >= 0) {
61- message ("file already opened: %s\n", filename);
62- current_notebook.set_current_page (target_page);
63- } else {
64- message ("Opening: %s\n", filename);
65- current_notebook.show_tabs_view ();
66- load_file (filename);
67- //set the name of the file, not all the path, in the tab label
68- var name = filename.split("/");
69- current_tab.label.label.set_text (name[name.length-1]);
70-
71- }
72- }
73-
74- }
75-
76+ if (filech.run () == ResponseType.ACCEPT)
77+ open (filech.get_filename ());
78+
79 filech.close ();
80 set_undo_redo ();
81-
82+
83+ }
84+
85+ public void open (string filename) {
86+ if (filename != null) {
87+ // check if file is already opened
88+ int target_page = -1;
89+
90+ try {
91+ set_combobox_language (filename);
92+ } catch (Error e) {
93+ warning ("Cannont set the combobox id");
94+ }
95+
96+ if (!current_notebook.welcome_screen.active) {
97+
98+ int tot_pages = current_notebook.get_n_pages ();
99+ for (int i = 0; i < tot_pages; i++)
100+ if (current_tab.filename == filename)
101+ target_page = i;
102+
103+ }
104+ if (target_page >= 0) {
105+ message ("file already opened: %s\n", filename);
106+ current_notebook.set_current_page (target_page);
107+ } else {
108+ message ("Opening: %s\n", filename);
109+ current_notebook.show_tabs_view ();
110+ var name = filename.split("/");
111+ load_file (filename,name[name.length-1]);
112+ }
113+ }
114 }
115
116 public void on_save_clicked() {
117@@ -305,7 +297,7 @@
118 }
119
120 //generic functions
121- public void load_file (string filename) {
122+ public void load_file (string filename, string? title=null) {
123
124 if (filename != "") {
125 try {
126@@ -337,9 +329,11 @@
127 //set values for label
128 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());
129 var label = tab.label.label;
130- if (label.get_text().substring (0, 1) == "*"){
131+
132+ if (title != null)
133+ label.set_text (title);
134+ else
135 label.set_text (filename);
136- }
137 set_window_title (filename);
138
139 } catch (Error e) {
140@@ -348,7 +342,10 @@
141 }
142 var tab = (Tab) current_notebook.get_nth_page (current_notebook.get_current_page());
143 var label = tab.label.label;
144- if (label.get_text().substring (0, 1) == "*"){
145+
146+ if (title != null)
147+ label.set_text (title);
148+ else if (label.get_text().substring (0, 1) == "*"){
149 label.set_text (filename);
150 }
151

Subscribers

People subscribed via source and target branches