Merge lp:~kjtehprogrammer/scratch/drag-n-drop into lp:~elementary-apps/scratch/scratch

Proposed by KJ Lawrence
Status: Merged
Approved by: Mario Guerriero
Approved revision: 1274
Merged at revision: 1280
Proposed branch: lp:~kjtehprogrammer/scratch/drag-n-drop
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 83 lines (+43/-2)
2 files modified
src/Widgets/DocumentView.vala (+23/-1)
src/Widgets/SplitView.vala (+20/-1)
To merge this branch: bzr merge lp:~kjtehprogrammer/scratch/drag-n-drop
Reviewer Review Type Date Requested Status
Mario Guerriero (community) Approve
Review via email: mp+215251@code.launchpad.net

Commit message

Drag n Drop enabled for welcome screen and SourceView

Description of the change

Adds the capability to accept drag-and-drops on the welcome screen and on individual documents. Dragging a new document in to sourceview will open it up in another tab automatically.

Should handle multiple files without any issues - I dragged a whole group in through files and it loaded them all in. My only problem is that, for whatever reason, the sourceview drag-and-drop happens twice. It doesn't affect anything because Scratch checks for duplicate files, but its still a pain (and a brief waste of memory).

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/DocumentView.vala'
--- src/Widgets/DocumentView.vala 2013-11-23 15:01:37 +0000
+++ src/Widgets/DocumentView.vala 2014-04-10 16:53:42 +0000
@@ -164,6 +164,12 @@
164 files += doc.file.get_uri ();164 files += doc.file.get_uri ();
165 settings.schema.set_strv ("opened-files", files);165 settings.schema.set_strv ("opened-files", files);
166 }166 }
167
168 // Handle Drag-and-drop functionality on source-view
169 Gtk.TargetEntry uris = {"text/uri-list", 0, 0};
170 Gtk.TargetEntry text = {"text/plain", 0, 0};
171 Gtk.drag_dest_set (doc.source_view, Gtk.DestDefaults.ALL, {uris, text}, Gdk.DragAction.COPY);
172 doc.source_view.drag_data_received.connect (this.drag_received);
167 }173 }
168 174
169 private void remove_document (Document doc) {175 private void remove_document (Document doc) {
@@ -178,6 +184,22 @@
178 }184 }
179 settings.schema.set_strv ("opened-files", opened);185 settings.schema.set_strv ("opened-files", opened);
180 }186 }
187
188 doc.source_view.drag_data_received.disconnect (this.drag_received);
189 }
190
191 private void drag_received(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData sel, uint info, uint time){
192 var uris = sel.get_uris ();
193 if (uris.length > 0){
194 for (var i = 0; i < uris.length; i++){
195 string filename = uris[i];
196 File file = File.new_for_uri(filename);
197 Document doc = new Document(file);
198 this.open_document(doc);
199 }
200
201 Gtk.drag_finish (ctx, true, false, time);
202 }
181 }203 }
182 204
183 public Document? get_current_document () {205 public Document? get_current_document () {
@@ -198,4 +220,4 @@
198 220
199 }221 }
200 222
201}223}
202\ No newline at end of file224\ No newline at end of file
203225
=== modified file 'src/Widgets/SplitView.vala'
--- src/Widgets/SplitView.vala 2013-07-22 06:11:19 +0000
+++ src/Widgets/SplitView.vala 2014-04-10 16:53:42 +0000
@@ -55,6 +55,25 @@
55 main_actions.get_action ("Open").activate ();55 main_actions.get_action ("Open").activate ();
56 });56 });
57 57
58 // Handle Drag-and-drop functionality on source-view
59 Gtk.TargetEntry target = {"text/uri-list", 0, 0};
60 Gtk.drag_dest_set (this.welcome_screen, Gtk.DestDefaults.ALL, {target}, Gdk.DragAction.COPY);
61 this.welcome_screen.drag_data_received.connect ((ctx, x, y, sel, info, time) => {
62 var uris = sel.get_uris ();
63 if (uris.length > 0){
64 var view = this.current_view ?? this.add_view ();
65
66 for (var i = 0; i < uris.length; i++){
67 string filename = uris[i];
68 File file = File.new_for_uri(filename);
69 Scratch.Services.Document doc = new Scratch.Services.Document(file);
70 view.open_document(doc);
71 }
72
73 Gtk.drag_finish (ctx, true, false, time);
74 }
75 });
76
58 this.views = new GLib.List<Scratch.Widgets.DocumentView> ();77 this.views = new GLib.List<Scratch.Widgets.DocumentView> ();
59 }78 }
60 79
@@ -162,4 +181,4 @@
162 main_actions.get_action ("RemoveView").sensitive = (views.length () > 1);181 main_actions.get_action ("RemoveView").sensitive = (views.length () > 1);
163 }182 }
164 }183 }
165}184}
166\ No newline at end of file185\ No newline at end of file

Subscribers

People subscribed via source and target branches