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
1=== modified file 'src/Widgets/DocumentView.vala'
2--- src/Widgets/DocumentView.vala 2013-11-23 15:01:37 +0000
3+++ src/Widgets/DocumentView.vala 2014-04-10 16:53:42 +0000
4@@ -164,6 +164,12 @@
5 files += doc.file.get_uri ();
6 settings.schema.set_strv ("opened-files", files);
7 }
8+
9+ // Handle Drag-and-drop functionality on source-view
10+ Gtk.TargetEntry uris = {"text/uri-list", 0, 0};
11+ Gtk.TargetEntry text = {"text/plain", 0, 0};
12+ Gtk.drag_dest_set (doc.source_view, Gtk.DestDefaults.ALL, {uris, text}, Gdk.DragAction.COPY);
13+ doc.source_view.drag_data_received.connect (this.drag_received);
14 }
15
16 private void remove_document (Document doc) {
17@@ -178,6 +184,22 @@
18 }
19 settings.schema.set_strv ("opened-files", opened);
20 }
21+
22+ doc.source_view.drag_data_received.disconnect (this.drag_received);
23+ }
24+
25+ private void drag_received(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData sel, uint info, uint time){
26+ var uris = sel.get_uris ();
27+ if (uris.length > 0){
28+ for (var i = 0; i < uris.length; i++){
29+ string filename = uris[i];
30+ File file = File.new_for_uri(filename);
31+ Document doc = new Document(file);
32+ this.open_document(doc);
33+ }
34+
35+ Gtk.drag_finish (ctx, true, false, time);
36+ }
37 }
38
39 public Document? get_current_document () {
40@@ -198,4 +220,4 @@
41
42 }
43
44-}
45+}
46\ No newline at end of file
47
48=== modified file 'src/Widgets/SplitView.vala'
49--- src/Widgets/SplitView.vala 2013-07-22 06:11:19 +0000
50+++ src/Widgets/SplitView.vala 2014-04-10 16:53:42 +0000
51@@ -55,6 +55,25 @@
52 main_actions.get_action ("Open").activate ();
53 });
54
55+ // Handle Drag-and-drop functionality on source-view
56+ Gtk.TargetEntry target = {"text/uri-list", 0, 0};
57+ Gtk.drag_dest_set (this.welcome_screen, Gtk.DestDefaults.ALL, {target}, Gdk.DragAction.COPY);
58+ this.welcome_screen.drag_data_received.connect ((ctx, x, y, sel, info, time) => {
59+ var uris = sel.get_uris ();
60+ if (uris.length > 0){
61+ var view = this.current_view ?? this.add_view ();
62+
63+ for (var i = 0; i < uris.length; i++){
64+ string filename = uris[i];
65+ File file = File.new_for_uri(filename);
66+ Scratch.Services.Document doc = new Scratch.Services.Document(file);
67+ view.open_document(doc);
68+ }
69+
70+ Gtk.drag_finish (ctx, true, false, time);
71+ }
72+ });
73+
74 this.views = new GLib.List<Scratch.Widgets.DocumentView> ();
75 }
76
77@@ -162,4 +181,4 @@
78 main_actions.get_action ("RemoveView").sensitive = (views.length () > 1);
79 }
80 }
81-}
82+}
83\ No newline at end of file

Subscribers

People subscribed via source and target branches