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
=== modified file 'src/MainWindow.vala'
--- src/MainWindow.vala 2015-03-19 21:34:20 +0000
+++ src/MainWindow.vala 2015-03-30 21:07:33 +0000
@@ -214,20 +214,20 @@
214 this.contextbar = new Gtk.Notebook ();214 this.contextbar = new Gtk.Notebook ();
215 this.contextbar.no_show_all = true;215 this.contextbar.no_show_all = true;
216 this.contextbar.page_removed.connect (() => { on_plugin_toggled (contextbar); });216 this.contextbar.page_removed.connect (() => { on_plugin_toggled (contextbar); });
217 this.contextbar.page_added.connect (() => { 217 this.contextbar.page_added.connect (() => {
218 if (!this.split_view.is_empty ())218 if (!this.split_view.is_empty ())
219 on_plugin_toggled (contextbar); 219 on_plugin_toggled (contextbar);
220 });220 });
221 221
222222
223223
224 this.bottombar = new Gtk.Notebook ();224 this.bottombar = new Gtk.Notebook ();
225 this.bottombar.no_show_all = true;225 this.bottombar.no_show_all = true;
226 this.bottombar.page_removed.connect (() => { on_plugin_toggled (bottombar); });226 this.bottombar.page_removed.connect (() => { on_plugin_toggled (bottombar); });
227 this.bottombar.page_added.connect (() => { 227 this.bottombar.page_added.connect (() => {
228 if (!this.split_view.is_empty ())228 if (!this.split_view.is_empty ())
229 on_plugin_toggled (bottombar); 229 on_plugin_toggled (bottombar);
230 }); 230 });
231231
232 hp1 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);232 hp1 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
233 hp2 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);233 hp2 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
@@ -612,7 +612,9 @@
612 }612 }
613613
614 void action_close_tab () {614 void action_close_tab () {
615615 var view = get_current_view ();
616 if (view != null)
617 view.close_current_document ();
616 }618 }
617619
618 void action_quit () {620 void action_quit () {
619621
=== modified file 'src/Widgets/DocumentView.vala'
--- src/Widgets/DocumentView.vala 2015-03-19 21:34:20 +0000
+++ src/Widgets/DocumentView.vala 2015-03-30 21:07:33 +0000
@@ -24,23 +24,23 @@
24using Granite.Widgets;24using Granite.Widgets;
2525
26namespace Scratch.Widgets {26namespace Scratch.Widgets {
27 27
28 public class DocumentView : Gtk.Box {28 public class DocumentView : Gtk.Box {
2929
30 // Parent window30 // Parent window
31 private weak MainWindow window;31 private weak MainWindow window;
32 32
33 // Widgets33 // Widgets
34 public DynamicNotebook notebook;34 public DynamicNotebook notebook;
35 35
36 public GLib.List<Document> docs;36 public GLib.List<Document> docs;
37 37
38 public Scratch.Services.Document current {38 public Scratch.Services.Document current {
39 set {39 set {
40 notebook.current = value;40 notebook.current = value;
41 }41 }
42 }42 }
43 43
44 // Signals44 // Signals
45 public signal void document_change (Document? document);45 public signal void document_change (Document? document);
46 public signal void empty ();46 public signal void empty ();
@@ -48,9 +48,9 @@
48 public DocumentView (MainWindow window) {48 public DocumentView (MainWindow window) {
49 orientation = Orientation.VERTICAL;49 orientation = Orientation.VERTICAL;
50 this.window = window;50 this.window = window;
51 51
52 docs = new GLib.List<Document> ();52 docs = new GLib.List<Document> ();
53 53
54 // Layout54 // Layout
55 this.notebook = new DynamicNotebook ();55 this.notebook = new DynamicNotebook ();
56 this.notebook.allow_restoring = true;56 this.notebook.allow_restoring = true;
@@ -87,7 +87,7 @@
87 });87 });
8888
89 this.pack_start (notebook, true, true, 0);89 this.pack_start (notebook, true, true, 0);
90 90
91 show_all ();91 show_all ();
92 }92 }
9393
@@ -97,17 +97,17 @@
9797
98 return ScratchApp.instance.data_home_folder_unsaved + new_text_file;98 return ScratchApp.instance.data_home_folder_unsaved + new_text_file;
99 }99 }
100 100
101 public void new_document () {101 public void new_document () {
102 File file = File.new_for_path (unsaved_file_path_builder ());102 File file = File.new_for_path (unsaved_file_path_builder ());
103 file.create (FileCreateFlags.PRIVATE);103 file.create (FileCreateFlags.PRIVATE);
104104
105 var doc = new Document (window.main_actions, file);105 var doc = new Document (window.main_actions, file);
106 doc.create_page ();106 doc.create_page ();
107 107
108 this.notebook.insert_tab (doc, -1);108 this.notebook.insert_tab (doc, -1);
109 this.notebook.current = doc;109 this.notebook.current = doc;
110 110
111 doc.focus ();111 doc.focus ();
112 }112 }
113113
@@ -117,7 +117,7 @@
117117
118 var doc = new Document (window.main_actions, file);118 var doc = new Document (window.main_actions, file);
119 doc.create_page ();119 doc.create_page ();
120 120
121 // Set clipboard content121 // Set clipboard content
122 try {122 try {
123 string s;123 string s;
@@ -131,24 +131,24 @@
131131
132 doc.focus ();132 doc.focus ();
133 }133 }
134 134
135 public void open_document (Document doc) {135 public void open_document (Document doc) {
136 for (int n = 0; n <= docs.length (); n++) {136 for (int n = 0; n <= docs.length (); n++) {
137 if (docs.nth_data (n) == null)137 if (docs.nth_data (n) == null)
138 continue;138 continue;
139 if (docs.nth_data (n).file != null 139 if (docs.nth_data (n).file != null
140 && docs.nth_data (n).file.get_uri () == doc.file.get_uri ()) {140 && docs.nth_data (n).file.get_uri () == doc.file.get_uri ()) {
141 this.notebook.current = docs.nth_data (n);141 this.notebook.current = docs.nth_data (n);
142 warning ("This Document was already opened! Not opening a duplicate!");142 warning ("This Document was already opened! Not opening a duplicate!");
143 return;143 return;
144 }144 }
145 }145 }
146 146
147 doc.create_page ();147 doc.create_page ();
148 148
149 this.notebook.insert_tab (doc, -1);149 this.notebook.insert_tab (doc, -1);
150 this.notebook.current = doc;150 this.notebook.current = doc;
151 151
152 doc.focus ();152 doc.focus ();
153 }153 }
154154
@@ -158,7 +158,7 @@
158158
159 var doc = new Document (window.main_actions, file);159 var doc = new Document (window.main_actions, file);
160 doc.create_page ();160 doc.create_page ();
161 161
162 // Set a copy of content162 // Set a copy of content
163 try {163 try {
164 string s;164 string s;
@@ -172,16 +172,16 @@
172172
173 doc.focus ();173 doc.focus ();
174 }174 }
175 175
176 public void next_document () {176 public void next_document () {
177 uint current_index = docs.index (get_current_document ()) + 1;177 uint current_index = docs.index (get_current_document ()) + 1;
178 if (current_index < docs.length ()) {178 if (current_index < docs.length ()) {
179 Document? next_doc = docs.nth_data (current_index++);179 Document? next_doc = docs.nth_data (current_index++);
180 this.notebook.current = next_doc;180 this.notebook.current = next_doc;
181 next_doc.focus();181 next_doc.focus();
182 } 182 }
183 }183 }
184 184
185 public void previous_document () {185 public void previous_document () {
186 uint current_index = docs.index (get_current_document ());186 uint current_index = docs.index (get_current_document ());
187 if (current_index > 0) {187 if (current_index > 0) {
@@ -190,28 +190,36 @@
190 previous_doc.focus ();190 previous_doc.focus ();
191 }191 }
192 }192 }
193 193
194 public void close_document (Document doc) {194 public void close_document (Document doc) {
195 this.notebook.remove_tab (doc);195 this.notebook.remove_tab (doc);
196 doc.close ();196 doc.close ();
197 }197 }
198 198
199 public void close_current_document () {
200 var doc = get_current_document ();
201 if (doc != null) {
202 if(this.notebook.close_tab_requested (doc))
203 this.notebook.remove_tab (doc);
204 }
205 }
206
199 public Document? get_current_document () {207 public Document? get_current_document () {
200 return this.notebook.current as Document;208 return this.notebook.current as Document;
201 }209 }
202 210
203 public void set_current_document (Document doc) {211 public void set_current_document (Document doc) {
204 this.notebook.current = doc;212 this.notebook.current = doc;
205 }213 }
206 214
207 public bool is_empty () {215 public bool is_empty () {
208 return this.docs.length () == 0;216 return this.docs.length () == 0;
209 }217 }
210 218
211 public new void focus () {219 public new void focus () {
212 get_current_document ().focus ();220 get_current_document ().focus ();
213 }221 }
214 222
215 private void on_doc_added (Granite.Widgets.Tab tab) {223 private void on_doc_added (Granite.Widgets.Tab tab) {
216 var doc = tab as Document;224 var doc = tab as Document;
217 doc.main_actions = window.main_actions;225 doc.main_actions = window.main_actions;
@@ -261,13 +269,13 @@
261 document_change (doc);269 document_change (doc);
262 }270 }
263271
264 return true; 272 return true;
265 }273 }
266 274
267 private bool drag_motion (Gdk.DragContext ctx, int x, int y, uint time){275 private bool drag_motion (Gdk.DragContext ctx, int x, int y, uint time){
268 return true;276 return true;
269 }277 }
270 278
271 private void drag_received(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData sel, uint info, uint time){279 private void drag_received(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData sel, uint info, uint time){
272 var uris = sel.get_uris ();280 var uris = sel.get_uris ();
273 if (uris.length > 0) {281 if (uris.length > 0) {
@@ -277,7 +285,7 @@
277 Document doc = new Document (window.main_actions, file);285 Document doc = new Document (window.main_actions, file);
278 this.open_document (doc);286 this.open_document (doc);
279 }287 }
280 288
281 Gtk.drag_finish (ctx, true, false, time);289 Gtk.drag_finish (ctx, true, false, time);
282 }290 }
283 }291 }
284292
=== modified file 'src/Widgets/SourceView.vala'
--- src/Widgets/SourceView.vala 2015-03-19 21:34:20 +0000
+++ src/Widgets/SourceView.vala 2015-03-30 21:07:33 +0000
@@ -97,6 +97,7 @@
97 });97 });
9898
99 this.key_press_event.connect ((key_event) => {99 this.key_press_event.connect ((key_event) => {
100
100 switch (key_event.keyval) {101 switch (key_event.keyval) {
101 case Gdk.Key.plus:102 case Gdk.Key.plus:
102 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {103 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
@@ -309,7 +310,7 @@
309 public void set_language (SourceLanguage? lang) {310 public void set_language (SourceLanguage? lang) {
310 if (lang == null)311 if (lang == null)
311 return;312 return;
312 313
313 this.buffer.set_language (lang);314 this.buffer.set_language (lang);
314 this.language_changed (lang);315 this.language_changed (lang);
315 }316 }
@@ -345,7 +346,5 @@
345 deselected ();346 deselected ();
346 return false;347 return false;
347 }348 }
348
349 }349 }
350
351}
352\ No newline at end of file350\ No newline at end of file
351}

Subscribers

People subscribed via source and target branches