Merge lp:~artem-anufrij/scratch/close-current-document-ctrl-w into lp:~elementary-apps/scratch/scratch

Proposed by Artem Anufrij
Status: Merged
Approved by: Fabio Zaramella
Approved revision: 1484
Merged at revision: 1484
Proposed branch: lp:~artem-anufrij/scratch/close-current-document-ctrl-w
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 284 lines (+51/-42)
3 files modified
src/MainWindow.vala (+9/-7)
src/Widgets/DocumentView.vala (+39/-31)
src/Widgets/SourceView.vala (+3/-4)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/close-current-document-ctrl-w
Reviewer Review Type Date Requested Status
Fabio Zaramella (community) Approve
Review via email: mp+254653@code.launchpad.net

Commit message

Close current tab with ctrl+w

Description of the change

Close current tab with ctrl+w

To post a comment you must log in.
Revision history for this message
Robert Roth (evfool) wrote :

Patch would be relatively short if it wouldn't include trailing spaces removal. After finding the code to review I've found and commented a small whitespace issue, other than that, it looks OK code-wise, can't test right now, but if it works, it can be approved.

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

It works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/MainWindow.vala'
2--- src/MainWindow.vala 2015-03-19 21:34:20 +0000
3+++ src/MainWindow.vala 2015-03-30 21:07:33 +0000
4@@ -214,20 +214,20 @@
5 this.contextbar = new Gtk.Notebook ();
6 this.contextbar.no_show_all = true;
7 this.contextbar.page_removed.connect (() => { on_plugin_toggled (contextbar); });
8- this.contextbar.page_added.connect (() => {
9+ this.contextbar.page_added.connect (() => {
10 if (!this.split_view.is_empty ())
11- on_plugin_toggled (contextbar);
12+ on_plugin_toggled (contextbar);
13 });
14-
15+
16
17
18 this.bottombar = new Gtk.Notebook ();
19 this.bottombar.no_show_all = true;
20 this.bottombar.page_removed.connect (() => { on_plugin_toggled (bottombar); });
21- this.bottombar.page_added.connect (() => {
22+ this.bottombar.page_added.connect (() => {
23 if (!this.split_view.is_empty ())
24- on_plugin_toggled (bottombar);
25- });
26+ on_plugin_toggled (bottombar);
27+ });
28
29 hp1 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
30 hp2 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
31@@ -612,7 +612,9 @@
32 }
33
34 void action_close_tab () {
35-
36+ var view = get_current_view ();
37+ if (view != null)
38+ view.close_current_document ();
39 }
40
41 void action_quit () {
42
43=== modified file 'src/Widgets/DocumentView.vala'
44--- src/Widgets/DocumentView.vala 2015-03-19 21:34:20 +0000
45+++ src/Widgets/DocumentView.vala 2015-03-30 21:07:33 +0000
46@@ -24,23 +24,23 @@
47 using Granite.Widgets;
48
49 namespace Scratch.Widgets {
50-
51+
52 public class DocumentView : Gtk.Box {
53
54 // Parent window
55 private weak MainWindow window;
56-
57+
58 // Widgets
59 public DynamicNotebook notebook;
60-
61+
62 public GLib.List<Document> docs;
63-
64+
65 public Scratch.Services.Document current {
66 set {
67 notebook.current = value;
68 }
69 }
70-
71+
72 // Signals
73 public signal void document_change (Document? document);
74 public signal void empty ();
75@@ -48,9 +48,9 @@
76 public DocumentView (MainWindow window) {
77 orientation = Orientation.VERTICAL;
78 this.window = window;
79-
80+
81 docs = new GLib.List<Document> ();
82-
83+
84 // Layout
85 this.notebook = new DynamicNotebook ();
86 this.notebook.allow_restoring = true;
87@@ -87,7 +87,7 @@
88 });
89
90 this.pack_start (notebook, true, true, 0);
91-
92+
93 show_all ();
94 }
95
96@@ -97,17 +97,17 @@
97
98 return ScratchApp.instance.data_home_folder_unsaved + new_text_file;
99 }
100-
101+
102 public void new_document () {
103 File file = File.new_for_path (unsaved_file_path_builder ());
104 file.create (FileCreateFlags.PRIVATE);
105
106 var doc = new Document (window.main_actions, file);
107 doc.create_page ();
108-
109+
110 this.notebook.insert_tab (doc, -1);
111 this.notebook.current = doc;
112-
113+
114 doc.focus ();
115 }
116
117@@ -117,7 +117,7 @@
118
119 var doc = new Document (window.main_actions, file);
120 doc.create_page ();
121-
122+
123 // Set clipboard content
124 try {
125 string s;
126@@ -131,24 +131,24 @@
127
128 doc.focus ();
129 }
130-
131+
132 public void open_document (Document doc) {
133 for (int n = 0; n <= docs.length (); n++) {
134 if (docs.nth_data (n) == null)
135 continue;
136- if (docs.nth_data (n).file != null
137+ if (docs.nth_data (n).file != null
138 && docs.nth_data (n).file.get_uri () == doc.file.get_uri ()) {
139 this.notebook.current = docs.nth_data (n);
140 warning ("This Document was already opened! Not opening a duplicate!");
141 return;
142 }
143 }
144-
145+
146 doc.create_page ();
147-
148+
149 this.notebook.insert_tab (doc, -1);
150 this.notebook.current = doc;
151-
152+
153 doc.focus ();
154 }
155
156@@ -158,7 +158,7 @@
157
158 var doc = new Document (window.main_actions, file);
159 doc.create_page ();
160-
161+
162 // Set a copy of content
163 try {
164 string s;
165@@ -172,16 +172,16 @@
166
167 doc.focus ();
168 }
169-
170+
171 public void next_document () {
172 uint current_index = docs.index (get_current_document ()) + 1;
173 if (current_index < docs.length ()) {
174 Document? next_doc = docs.nth_data (current_index++);
175 this.notebook.current = next_doc;
176 next_doc.focus();
177- }
178+ }
179 }
180-
181+
182 public void previous_document () {
183 uint current_index = docs.index (get_current_document ());
184 if (current_index > 0) {
185@@ -190,28 +190,36 @@
186 previous_doc.focus ();
187 }
188 }
189-
190+
191 public void close_document (Document doc) {
192 this.notebook.remove_tab (doc);
193 doc.close ();
194 }
195-
196+
197+ public void close_current_document () {
198+ var doc = get_current_document ();
199+ if (doc != null) {
200+ if(this.notebook.close_tab_requested (doc))
201+ this.notebook.remove_tab (doc);
202+ }
203+ }
204+
205 public Document? get_current_document () {
206 return this.notebook.current as Document;
207 }
208-
209+
210 public void set_current_document (Document doc) {
211 this.notebook.current = doc;
212 }
213-
214+
215 public bool is_empty () {
216 return this.docs.length () == 0;
217 }
218-
219+
220 public new void focus () {
221 get_current_document ().focus ();
222 }
223-
224+
225 private void on_doc_added (Granite.Widgets.Tab tab) {
226 var doc = tab as Document;
227 doc.main_actions = window.main_actions;
228@@ -261,13 +269,13 @@
229 document_change (doc);
230 }
231
232- return true;
233+ return true;
234 }
235-
236+
237 private bool drag_motion (Gdk.DragContext ctx, int x, int y, uint time){
238 return true;
239 }
240-
241+
242 private void drag_received(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData sel, uint info, uint time){
243 var uris = sel.get_uris ();
244 if (uris.length > 0) {
245@@ -277,7 +285,7 @@
246 Document doc = new Document (window.main_actions, file);
247 this.open_document (doc);
248 }
249-
250+
251 Gtk.drag_finish (ctx, true, false, time);
252 }
253 }
254
255=== modified file 'src/Widgets/SourceView.vala'
256--- src/Widgets/SourceView.vala 2015-03-19 21:34:20 +0000
257+++ src/Widgets/SourceView.vala 2015-03-30 21:07:33 +0000
258@@ -97,6 +97,7 @@
259 });
260
261 this.key_press_event.connect ((key_event) => {
262+
263 switch (key_event.keyval) {
264 case Gdk.Key.plus:
265 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
266@@ -309,7 +310,7 @@
267 public void set_language (SourceLanguage? lang) {
268 if (lang == null)
269 return;
270-
271+
272 this.buffer.set_language (lang);
273 this.language_changed (lang);
274 }
275@@ -345,7 +346,5 @@
276 deselected ();
277 return false;
278 }
279-
280 }
281-
282-}
283\ No newline at end of file
284+}

Subscribers

People subscribed via source and target branches