Merge lp:~artem-anufrij/scratch/hide-plugins-on-welcome-screen into lp:~elementary-apps/scratch/scratch

Proposed by Artem Anufrij
Status: Merged
Approved by: Robert Roth
Approved revision: 1407
Merged at revision: 1407
Proposed branch: lp:~artem-anufrij/scratch/hide-plugins-on-welcome-screen
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 218 lines (+60/-41)
3 files modified
plugins/browser-preview/browser-preview.vala (+26/-16)
plugins/terminal/terminal.vala (+20/-19)
src/MainWindow.vala (+14/-6)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/hide-plugins-on-welcome-screen
Reviewer Review Type Date Requested Status
Robert Roth (community) Approve
Review via email: mp+241312@code.launchpad.net

Commit message

Hide the bottom and right side plugins on welcome screen (lp:1390895)

Description of the change

Hide the bottom and right side plugins on welcome screen.

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

Branch works as expected, code style is fine, approving.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/browser-preview/browser-preview.vala'
2--- plugins/browser-preview/browser-preview.vala 2014-11-09 16:08:42 +0000
3+++ plugins/browser-preview/browser-preview.vala 2014-11-10 18:12:24 +0000
4@@ -41,12 +41,12 @@
5 public void activate () {
6 plugins = (Scratch.Services.Interface) object;
7
8- plugins.hook_document.connect ((d) => {
9- this.doc = d;
10- this.doc.doc_saved.disconnect (show_preview);
11- this.doc.doc_saved.connect (show_preview);
12+ plugins.hook_window.connect ((w) => {
13+ set_current_document (w.get_current_document ());
14 });
15
16+ plugins.hook_document.connect (set_current_document);
17+
18 plugins.hook_split_view.connect (on_hook_split_view);
19
20 plugins.hook_notebook_context.connect (on_hook_context);
21@@ -60,23 +60,15 @@
22
23 if (plugin_tab != null)
24 plugin_tab.destroy ();
25-
26 }
27
28 void on_hook_split_view (Scratch.Widgets.SplitView view) {
29 this.tool_button.visible = ! view.is_empty ();
30- this.tool_button.no_show_all = view.is_empty ();
31 view.welcome_shown.connect (() => {
32 this.tool_button.visible = false;
33- this.tool_button.no_show_all = true;
34- if (notebook.page_num (plugin_tab) != -1)
35- notebook.remove (plugin_tab);
36 });
37 view.welcome_hidden.connect (() => {
38 this.tool_button.visible = true;
39- this.tool_button.no_show_all = false;
40- if (notebook.page_num (plugin_tab) == -1)
41- notebook.append_page (plugin_tab, new Gtk.Label (_("Web preview")));
42 });
43 }
44
45@@ -86,10 +78,8 @@
46
47 var icon = new Gtk.Image.from_icon_name ("emblem-web", Gtk.IconSize.LARGE_TOOLBAR);
48 tool_button = new Gtk.ToolButton (icon, _("Get preview!"));
49- tool_button.tooltip_text = _("Get preview!");
50- tool_button.clicked.connect (() => {
51- show_preview () ;
52- });
53+ tool_button.tooltip_text = _("Hide preview");
54+ tool_button.clicked.connect (toggle_plugin_visibility);
55
56 icon.show ();
57 tool_button.show ();
58@@ -104,6 +94,7 @@
59 this.notebook = notebook;
60
61 plugin_tab = new Gtk.Paned (Gtk.Orientation.VERTICAL);
62+
63 view = new BrowserPreview.BrowserView (plugin_tab);
64
65 notebook.append_page (plugin_tab, new Gtk.Label (_("Web preview")));
66@@ -111,6 +102,25 @@
67 plugin_tab.show_all ();
68 }
69
70+ void toggle_plugin_visibility () {
71+ if (notebook.page_num (plugin_tab) == -1) {
72+ notebook.append_page (plugin_tab, new Gtk.Label (_("Web preview")));
73+ tool_button.tooltip_text = _("Hide preview");
74+ } else {
75+ notebook.remove (plugin_tab);
76+ tool_button.tooltip_text = _("Show preview");
77+ }
78+ }
79+
80+ void set_current_document (Scratch.Services.Document? d) {
81+ if (d != null) {
82+ this.doc = d;
83+ this.doc.doc_saved.disconnect (show_preview);
84+ this.doc.doc_saved.connect (show_preview);
85+ show_preview ();
86+ }
87+ }
88+
89 void show_preview () {
90 // Get uri
91 if (this.doc.file == null)
92
93=== modified file 'plugins/terminal/terminal.vala'
94--- plugins/terminal/terminal.vala 2014-11-08 20:46:59 +0000
95+++ plugins/terminal/terminal.vala 2014-11-10 18:12:24 +0000
96@@ -29,7 +29,6 @@
97 Gtk.Notebook? bottombar = null;
98 Vte.Terminal terminal;
99 Gtk.Grid grid;
100- ulong? connect_handler;
101
102 Scratch.Services.Interface plugins;
103 public Object object { owned get; construct; }
104@@ -45,22 +44,7 @@
105 return;
106
107 window = w;
108- connect_handler = window.key_press_event.connect ((event) => {
109- if (event.keyval == Gdk.Key.t
110- && Gdk.ModifierType.MOD1_MASK in event.state
111- && Gdk.ModifierType.CONTROL_MASK in event.state) {
112- if (terminal.has_focus && window.get_current_document () != null) {
113- window.get_current_document ().focus ();
114- debug ("Move focus: EDITOR.");
115- return true;
116- } else if (window.get_current_document () != null && window.get_current_document ().source_view.has_focus) {
117- terminal.grab_focus ();
118- debug ("Move focus: TERMINAL.");
119- return true;
120- }
121- }
122- return false;
123- });
124+ window.key_press_event.connect (switch_focus);
125 });
126
127 plugins.hook_notebook_bottom.connect ((n) => {
128@@ -76,8 +60,25 @@
129 public void deactivate () {
130 if (terminal != null)
131 grid.destroy ();
132- if (connect_handler != null)
133- window.disconnect ((ulong)connect_handler);
134+ if (window != null)
135+ window.key_press_event.disconnect (switch_focus);
136+ }
137+
138+ bool switch_focus (Gdk.EventKey event) {
139+ if (event.keyval == Gdk.Key.t
140+ && Gdk.ModifierType.MOD1_MASK in event.state
141+ && Gdk.ModifierType.CONTROL_MASK in event.state) {
142+ if (terminal.has_focus && window.get_current_document () != null) {
143+ window.get_current_document ().focus ();
144+ debug ("Move focus: EDITOR.");
145+ return true;
146+ } else if (window.get_current_document () != null && window.get_current_document ().source_view.has_focus) {
147+ terminal.grab_focus ();
148+ debug ("Move focus: TERMINAL.");
149+ return true;
150+ }
151+ }
152+ return false;
153 }
154
155 void on_hook (Gtk.Notebook notebook) {
156
157=== modified file 'src/MainWindow.vala'
158--- src/MainWindow.vala 2014-11-02 11:16:30 +0000
159+++ src/MainWindow.vala 2014-11-10 18:12:24 +0000
160@@ -175,7 +175,6 @@
161 // Signals
162 this.split_view.welcome_shown.connect (() => {
163 set_widgets_sensitive (false);
164-
165 });
166 this.split_view.welcome_hidden.connect (() => {
167 set_widgets_sensitive (true);
168@@ -278,15 +277,15 @@
169 plugins.hook_notebook_sidebar (this.sidebar);
170 plugins.hook_notebook_context (this.contextbar);
171 plugins.hook_notebook_bottom (this.bottombar);
172- this.split_view.document_change.connect ((doc) => {
173- plugins.hook_document (doc);
174- });
175+ this.split_view.document_change.connect ((doc) => { plugins.hook_document (doc); });
176 plugins.hook_split_view (this.split_view);
177 };
178 plugins.extension_added.connect (() => {
179 hook_func ();
180 });
181 hook_func ();
182+
183+ set_widgets_sensitive (!split_view.is_empty ());
184 }
185
186 private void on_plugin_toggled (Gtk.Notebook notebook) {
187@@ -317,6 +316,15 @@
188 main_actions.get_action ("Redo").sensitive = val;
189 main_actions.get_action ("Revert").sensitive = val;
190 this.toolbar.share_app_menu.sensitive = val;
191+
192+ // PlugIns
193+ if (val) {
194+ on_plugin_toggled (this.contextbar);
195+ on_plugin_toggled (this.bottombar);
196+ } else {
197+ this.contextbar.visible = val;
198+ this.bottombar.visible = val;
199+ }
200 }
201
202 // Get current view
203@@ -335,7 +343,7 @@
204 // Get current document
205 public Scratch.Services.Document? get_current_document () {
206 Scratch.Services.Document? doc = null;
207-
208+
209 var view = this.get_current_view ();
210 if (view != null)
211 doc = view.get_current_document ();
212@@ -897,4 +905,4 @@
213 action_fullscreen }
214 };
215 }
216-}
217\ No newline at end of file
218+}

Subscribers

People subscribed via source and target branches