Merge lp:~artem-anufrij/scratch/improve-split-view into lp:~elementary-apps/scratch/scratch

Proposed by Artem Anufrij
Status: Superseded
Proposed branch: lp:~artem-anufrij/scratch/improve-split-view
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 431 lines (+135/-97)
7 files modified
plugins/terminal/terminal.vala (+3/-1)
src/MainWindow.vala (+15/-23)
src/Services/Document.vala (+1/-1)
src/Widgets/SourceView.vala (+4/-7)
src/Widgets/SplitView.vala (+102/-63)
src/Widgets/ToolBar.vala (+10/-0)
src/scratch-ui.xml (+0/-2)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/improve-split-view
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+243913@code.launchpad.net

This proposal has been superseded by a proposal from 2014-12-07.

Description of the change

#1: Change two MenuItems "Add View" and "Remove View" to a ToggleButton "Split View"

#2: Fixed the saving bug.

#3: on deactivating "Split View", both views will be merged.

To post a comment you must log in.
1426. By artem-anufrij

ready for test

Revision history for this message
Danielle Foré (danrabbit) wrote :

* We typically don't remove menu items inside the same context. The "Split View" item should be made insensitive, not removed.

* Open a file, split the view, type some stuff in the new document, combine the view, crash

review: Needs Fixing
1427. By artem-anufrij

ToggleButton: change sensetive instead visibility. Crash after 'open doc' -> 'slit view' ON/OFF

1428. By artem-anufrij

toggle off after closing last document in the split view

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

> * We typically don't remove menu items inside the same context. The "Split
> View" item should be made insensitive, not removed.

done

> * Open a file, split the view, type some stuff in the new document, combine
> the view, crash

fixed

1429. By artem-anufrij

only merge lp:scratch

Unmerged revisions

1429. By artem-anufrij

only merge lp:scratch

1428. By artem-anufrij

toggle off after closing last document in the split view

1427. By artem-anufrij

ToggleButton: change sensetive instead visibility. Crash after 'open doc' -> 'slit view' ON/OFF

1426. By artem-anufrij

ready for test

1425. By artem-anufrij

ready for test

1424. By artem-anufrij

dev

1423. By artem-anufrij

dev version

1422. By artem-anufrij

Improve split view behavior and fix the saving bug

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/terminal/terminal.vala'
2--- plugins/terminal/terminal.vala 2014-12-05 20:58:48 +0000
3+++ plugins/terminal/terminal.vala 2014-12-07 19:14:14 +0000
4@@ -150,13 +150,15 @@
5 tool_button.tooltip_text = _("Show Terminal");
6 tool_button.toggled.connect (() => {
7 if (this.tool_button.active) {
8- tool_button.tooltip_text = _("Hide Terminal");
9+ debug ("Show Terminal");
10+ tool_button.tooltip_text = _("Hide Terminal");
11 if (on_bottom) {
12 bottombar.set_current_page (bottombar.append_page (grid, new Gtk.Label (_("Terminal"))));
13 } else {
14 contextbar.set_current_page (contextbar.append_page (grid, new Gtk.Label (_("Terminal"))));
15 }
16 } else {
17+ debug ("Hide Terminal");
18 tool_button.tooltip_text = _("Show Terminal");
19 if (on_bottom) {
20 bottombar.remove_page (bottombar.page_num (grid));
21
22=== modified file 'src/MainWindow.vala'
23--- src/MainWindow.vala 2014-11-24 19:59:52 +0000
24+++ src/MainWindow.vala 2014-12-07 19:14:14 +0000
25@@ -156,9 +156,6 @@
26 this.toolbar.title = this.title;
27 this.toolbar.show_close_button = true;
28 this.set_titlebar (this.toolbar);
29- toolbar.menu = ui.get_widget ("ui/AppMenu") as Gtk.Menu;
30- var app_menu = (app as Granite.Application).create_appmenu (toolbar.menu);
31- toolbar.pack_end (app_menu);
32
33 // SearchManager
34 this.search_revealer = new Gtk.Revealer ();
35@@ -179,6 +176,9 @@
36 this.split_view.welcome_hidden.connect (() => {
37 set_widgets_sensitive (true);
38 });
39+ this.split_view.split_view_state_change.connect ((state) => {
40+ this.toolbar.split_view.active = state;
41+ });
42 this.split_view.document_change.connect ((doc) => {
43 this.search_manager.set_text_view (doc.source_view);
44 // Update MainWindow title
45@@ -323,6 +323,7 @@
46 main_actions.get_action ("Redo").sensitive = val;
47 main_actions.get_action ("Revert").sensitive = val;
48 this.toolbar.share_app_menu.sensitive = val;
49+ this.toolbar.split_view.sensitive = val;
50
51 // Zoom button
52 main_actions.get_action ("Zoom").visible = get_current_font_size () != get_default_font_size () && val;
53@@ -397,7 +398,7 @@
54 else {
55 view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
56 if (view == null)
57- view = this.split_view.current_view;
58+ view = this.split_view.get_current_view ();
59 view.open_document (doc);
60 }
61 }
62@@ -412,7 +413,7 @@
63 else {
64 view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
65 if (view == null)
66- view = this.split_view.current_view;
67+ view = this.split_view.get_current_view ();
68 view.close_document (doc);
69 }
70 }
71@@ -703,22 +704,21 @@
72 Scratch.Widgets.DocumentView? view = null;
73 if (this.split_view.is_empty ()) {
74 view = split_view.add_view ();
75- }
76- else {
77+ } else {
78 view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
79 }
80 string text_from_clipboard = clipboard.wait_for_text ();
81 view.new_document_from_clipboard (text_from_clipboard);
82 }
83
84- void action_new_view () {
85- var view = split_view.add_view ();
86- if (view != null)
87- view.new_document ();
88- }
89-
90- void action_remove_view () {
91- split_view.remove_view ();
92+ public void action_toggle_split_view (bool show_split_view) {
93+ if (show_split_view) {
94+ var view = split_view.add_view ();
95+ if (view != null)
96+ view.new_document ();
97+ } else if (split_view.views.length () > 1) {
98+ split_view.remove_view ();
99+ }
100 }
101
102 void action_fullscreen () {
103@@ -837,14 +837,6 @@
104 /* label, accelerator */ N_("Add New Tab"), "<Control>n",
105 /* tooltip */ N_("Add a new tab"),
106 action_new_tab },
107- { "NewView", "add",
108- /* label, accelerator */ N_("Add New View"), "F3",
109- /* tooltip */ N_("Add a new view"),
110- action_new_view },
111- { "RemoveView", "window-close",
112- /* label, accelerator */ N_("Remove Current View"), null,
113- /* tooltip */ N_("Remove this view"),
114- action_remove_view },
115 { "Undo", "edit-undo",
116 /* label, accelerator */ N_("Undo"), "<Control>z",
117 /* tooltip */ N_("Undo the last action"),
118
119=== modified file 'src/Services/Document.vala'
120--- src/Services/Document.vala 2014-11-03 21:19:56 +0000
121+++ src/Services/Document.vala 2014-12-07 19:14:14 +0000
122@@ -671,7 +671,7 @@
123 }
124 }
125
126- private bool delete_temporary_file (bool force = false) {
127+ public bool delete_temporary_file (bool force = false) {
128 if (!is_file_temporary || (get_text ().length > 0 && !force))
129 return false;
130 try {
131
132=== modified file 'src/Widgets/SourceView.vala'
133--- src/Widgets/SourceView.vala 2014-11-12 23:55:34 +0000
134+++ src/Widgets/SourceView.vala 2014-12-07 19:14:14 +0000
135@@ -176,11 +176,8 @@
136 }
137
138 public void use_default_font (bool value) {
139-
140- if (!value) // if false, simply return null
141- return;
142-
143- this.font = ScratchApp.instance.default_font;
144+ if (value)
145+ this.font = ScratchApp.instance.default_font;
146 }
147
148 public void change_syntax_highlight_from_file (File file) {
149@@ -310,7 +307,7 @@
150 public void set_language (SourceLanguage? lang) {
151 if (lang == null)
152 return;
153-
154+
155 this.buffer.set_language (lang);
156 this.language_changed (lang);
157 }
158@@ -349,4 +346,4 @@
159
160 }
161
162-}
163\ No newline at end of file
164+}
165
166=== modified file 'src/Widgets/SplitView.vala'
167--- src/Widgets/SplitView.vala 2014-11-30 23:20:55 +0000
168+++ src/Widgets/SplitView.vala 2014-12-07 19:14:14 +0000
169@@ -26,16 +26,17 @@
170
171 // Widgets
172 public Granite.Widgets.Welcome welcome_screen;
173- public Scratch.Widgets.DocumentView? current_view = null;
174+ public Scratch.Services.Document? current_document = null;
175
176- public GLib.List<Scratch.Widgets.DocumentView> views;
177- private GLib.List<Scratch.Widgets.DocumentView> hidden_views;
178+ public Scratch.Widgets.DocumentView view1 = null;
179+ public Scratch.Widgets.DocumentView view2 = null;
180+ public GLib.List<Scratch.Widgets.DocumentView> views = new GLib.List<Scratch.Widgets.DocumentView>();
181
182 // Signals
183 public signal void welcome_shown ();
184 public signal void welcome_hidden ();
185 public signal void document_change (Scratch.Services.Document document);
186- public signal void views_changed (uint count);
187+ public signal void split_view_state_change (bool splitview);
188
189 private weak MainWindow window;
190
191@@ -84,56 +85,47 @@
192 Gtk.drag_finish (ctx, true, false, time);
193 }
194 });
195-
196- this.views = new GLib.List<Scratch.Widgets.DocumentView> ();
197- this.hidden_views = new GLib.List<Scratch.Widgets.DocumentView> ();
198 }
199
200- public Scratch.Widgets.DocumentView? add_view () {
201- if (views.length () >= 2) {
202- warning ("Maximum view number was already reached!");
203- return null;
204- }
205-
206- // Hide welcome screen
207- if (get_children ().length () > 0)
208- hide_welcome ();
209-
210- Scratch.Widgets.DocumentView view;
211- if (hidden_views.length () == 0) {
212- view = new Scratch.Widgets.DocumentView (window);
213-
214- view.empty.connect (() => {
215- remove_view (view);
216- });
217- } else {
218- view = hidden_views.nth_data (0);
219- hidden_views.remove (view);
220- }
221-
222+ private Scratch.Widgets.DocumentView crate_new_view () {
223+ Scratch.Widgets.DocumentView view = new Scratch.Widgets.DocumentView (window);
224+ view.empty.connect (view_on_empty);
225 view.document_change.connect (on_document_changed);
226- view.vexpand = true;
227-
228- if (views.length () < 1)
229- this.pack1 (view, true, true);
230- else
231- this.pack2 (view, true, true);
232-
233- view.show_all ();
234-
235- views.append (view);
236- this.current_view = view;
237- debug ("View added succefully");
238-
239- // Enbale/Disable useless GtkActions about views
240- check_actions ();
241+ this.views.append (view);
242+ this.add (view);
243 return view;
244 }
245
246- public void remove_view (Scratch.Widgets.DocumentView? view = null) {
247+ public Scratch.Widgets.DocumentView? add_view () {
248+ hide_welcome ();
249+
250+ if (view1 == null) {
251+ view1 = crate_new_view ();
252+ this.pack1 (view1, true, true);
253+ check_actions ();
254+ return view1;
255+
256+ } else if (view2 == null) {
257+ view2 = crate_new_view ();
258+ this.pack2 (view2, true, true);
259+ check_actions ();
260+ return view2;
261+ }
262+
263+ check_actions ();
264+
265+ return get_current_view ();
266+ }
267+
268+ private void view_on_empty (Scratch.Widgets.DocumentView empty_view) {
269+ remove_view (empty_view);
270+ }
271+
272+ public void remove_view (Scratch.Widgets.DocumentView? remove_view = null) {
273 // If no specific view is required to be removed, just remove the current one
274+ Scratch.Widgets.DocumentView? view = remove_view;
275 if (view == null)
276- view = get_focus_child () as Scratch.Widgets.DocumentView;
277+ view = get_unfocused_view ();
278 if (view == null) {
279 warning ("The is no focused view to remove!");
280 return;
281@@ -141,12 +133,21 @@
282
283 this.remove (view);
284 this.views.remove (view);
285+
286+ merge_views (view);
287+
288 view.document_change.disconnect (on_document_changed);
289- view.visible = false;
290- this.hidden_views.append (view);
291- debug ("View removed succefully");
292-
293- // Enbale/Disable useless GtkActions about views
294+
295+ if(view1 == view) {
296+ view1.destroy ();
297+ view1 = null;
298+ }
299+
300+ if(view2 == view) {
301+ view2.destroy ();
302+ view2 = null;
303+ }
304+
305 check_actions ();
306
307 // Move the focus on the other view
308@@ -155,15 +156,53 @@
309 }
310
311 // Show/Hide welcome screen
312- if (this.views.length () == 0)
313+ if (this.view1 == null && this.view2 == null)
314 show_welcome ();
315+
316+ debug ("View removed succefully");
317+ }
318+
319+ private void merge_views (Scratch.Widgets.DocumentView source) {
320+ debug ("Merge Views");
321+ Scratch.Widgets.DocumentView target = null;
322+
323+ if (source == view1 && view2 != null)
324+ target = view2;
325+ else if (source == view2 && view1 != null)
326+ target = view1;
327+
328+ if (target == null)
329+ return;
330+
331+ source.empty.disconnect (view_on_empty);
332+
333+ foreach (Granite.Widgets.Tab? tab in source.notebook.tabs) {
334+ if (tab == null)
335+ continue;
336+ // Check if the tab is not a temporery and empty file
337+ if (!(tab as Scratch.Services.Document).delete_temporary_file ()) {
338+ source.notebook.remove_tab (tab);
339+ target.notebook.insert_tab (tab, target.notebook.n_tabs);
340+ }
341+ }
342 }
343
344 public Scratch.Widgets.DocumentView? get_current_view () {
345- views.foreach ((v) => {
346- if (v.has_focus)
347- current_view = v;
348- });
349+ Scratch.Widgets.DocumentView? return_value = get_focus_child () as Scratch.Widgets.DocumentView;
350+
351+ if (return_value != null)
352+ return return_value;
353+
354+ return view1 ?? view2;
355+ }
356+
357+ private Scratch.Widgets.DocumentView? get_unfocused_view () {
358+ Scratch.Widgets.DocumentView? current_view = get_current_view();
359+ debug ("Current view is null: %s", (current_view == null).to_string ());
360+ if (current_view == view1 && view2 != null)
361+ return view2;
362+ else if (current_view == view2 && view1 != null)
363+ return view1;
364
365 return current_view;
366 }
367@@ -191,16 +230,16 @@
368
369 // Detect the last focused Document throw a signal
370 private void on_document_changed (Scratch.Services.Document? document) {
371- if (document != null)
372- document_change (document);
373+ current_document = document;
374+
375+ if (current_document != null)
376+ document_change (current_document);
377+
378 }
379
380 // Check the possibility to add or not a new view
381- private void check_actions () {
382- window.main_actions.get_action ("NewView").sensitive = (views.length () < 2);
383- window.main_actions.get_action ("RemoveView").sensitive = (views.length () > 1);
384-
385- views_changed (views.length ());
386+ private void check_actions (){
387+ split_view_state_change (view1 != null && view2 != null);
388 }
389 }
390 }
391
392=== modified file 'src/Widgets/ToolBar.vala'
393--- src/Widgets/ToolBar.vala 2014-11-12 20:19:40 +0000
394+++ src/Widgets/ToolBar.vala 2014-12-07 19:14:14 +0000
395@@ -32,6 +32,7 @@
396 public ToolButton revert_button;
397 public ToolButton find_button;
398 public ToolButton zoom_default;
399+ public Gtk.CheckMenuItem split_view;
400
401 public Gtk.Menu share_menu;
402 public Gtk.Menu menu;
403@@ -82,6 +83,15 @@
404 });
405 share_app_menu.no_show_all = true;
406
407+ // Create AppMenu
408+ this.menu = ScratchApp.instance.get_last_window ().ui.get_widget ("ui/AppMenu") as Gtk.Menu;
409+
410+ split_view = new Gtk.CheckMenuItem.with_label ("Split View");
411+
412+ split_view.activate.connect (() => { ScratchApp.instance.get_last_window ().action_toggle_split_view (split_view.get_active ()); });
413+ this.menu.insert (split_view, 0);
414+ pack_end (ScratchApp.instance.create_appmenu (this.menu));
415+
416 // Add everything to the toolbar
417 pack_start (open_button);
418 pack_start (templates_button);
419
420=== modified file 'src/scratch-ui.xml'
421--- src/scratch-ui.xml 2014-08-11 17:35:47 +0000
422+++ src/scratch-ui.xml 2014-12-07 19:14:14 +0000
423@@ -23,8 +23,6 @@
424 </popup>
425
426 <popup name="AppMenu">
427- <menuitem action="NewView" />
428- <menuitem action="RemoveView" />
429 <separator />
430 <menuitem action="Preferences" />
431 </popup>

Subscribers

People subscribed via source and target branches