Merge lp:~artem-anufrij/scratch/Bugfix-1193676 into lp:~elementary-apps/scratch/scratch

Proposed by Artem Anufrij
Status: Merged
Approved by: Robert Roth
Approved revision: 1416
Merged at revision: 1400
Proposed branch: lp:~artem-anufrij/scratch/Bugfix-1193676
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 330 lines (+142/-25)
4 files modified
src/MainWindow.vala (+78/-2)
src/Scratch.vala (+2/-0)
src/Widgets/SourceView.vala (+57/-22)
src/Widgets/ToolBar.vala (+5/-1)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/Bugfix-1193676
Reviewer Review Type Date Requested Status
Artem Anufrij (community) Approve
Robert Roth (community) code style Approve
Danielle Foré ux Approve
Corentin Noël code Approve
elementary Apps team code Pending
Review via email: mp+239765@code.launchpad.net

Commit message

Zooming (ctrl + scroll, or ctrl +/-) implemented.

Description of the change

Zooming (ctrl + scroll, or ctrl +/-)

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

There's no easy way to get back to the default zoom level. I would suggest a tool item with the icon "zoom-original" be added to the right side of the header bar whenever the zoom level is not the default.

If I open preferences, turn off "custom font" and then try to zoom, Scratch will freeze.

review: Needs Fixing
Revision history for this message
Corentin Noël (tintou) wrote :

Working fine here

review: Approve (code)
Revision history for this message
Shawn McTear (syst3mfailur3) wrote :

For reseting to default zoom, why not add ctrl+0, as thats already the keyboard shortcut in browsers.

Note: Haven't tested code.

1409. By artem-anufrij

add zoom-original button

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

Crash fixed and zoom button present.

If I have a custom font set, hitting the zoom button also resets the font family. It should only reset the font size.

I'm not sure "Default font" is a great tooltip. How about just "Zoom 1:1"

1410. By artem-anufrij

ctrl+0 added

1411. By artem-anufrij

Tooltip changed

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

Tooltip: "Zoom 1:1"

added Ctrl+0 for reset zoom

1412. By artem-anufrij

font familiy will not be reset on zoom 1:1

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

font familiy will not be reset on zoom 1:1

1413. By artem-anufrij

compare only font size for visiblity of zoom 1:1 button

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

Works as expected :) Needs another code review since changes were made

review: Approve (ux)
1414. By artem-anufrij

break;

1415. By artem-anufrij

solved conflict

Revision history for this message
Robert Roth (evfool) wrote :

Clean code, two minor issues noted inline.

review: Approve (code style)
1416. By artem-anufrij

space between conversion and method name added

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

@Robert:

done...

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 2014-10-29 21:19:58 +0000
3+++ src/MainWindow.vala 2014-10-30 19:07:02 +0000
4@@ -32,6 +32,9 @@
5 namespace Scratch {
6
7 public class MainWindow : Gtk.Window {
8+ public int FONT_SIZE_MAX = 72;
9+ public int FONT_SIZE_MIN = 7;
10+
11 public weak ScratchApp app;
12
13 // Widgets
14@@ -195,13 +198,13 @@
15 toolbar_title = "(%s)".printf (doc.get_basename ());
16
17 this.toolbar.title = toolbar_title;
18- }
19- else {
20+ } else {
21 this.toolbar.title = this.app.app_cmd_name;
22 }
23 // Set actions sensitive property
24 main_actions.get_action ("SaveFile").visible = (!settings.autosave || doc.file == null);
25 main_actions.get_action ("SaveFileAs").visible = (doc.file != null);
26+ main_actions.get_action ("Zoom").visible = get_current_font_size () != get_default_font_size ();
27 doc.check_undoable_actions ();
28 });
29
30@@ -516,7 +519,76 @@
31 update_opened_files ();
32 }
33
34+ public void set_default_zoom () {
35+ Scratch.settings.font = get_current_font () + " " + get_default_font_size ().to_string ();
36+ }
37+
38+ // Ctrl + scroll
39+ public void zoom_in () {
40+ zooming (ScrollDirection.UP);
41+ }
42+
43+ // Ctrl + scroll
44+ public void zoom_out () {
45+ zooming (ScrollDirection.DOWN);
46+ }
47+
48+ void zooming (ScrollDirection direction) {
49+
50+ string font = get_current_font ();
51+ int font_size = (int) get_current_font_size ();
52+
53+ if (Scratch.settings.use_system_font) {
54+
55+ Scratch.settings.use_system_font = false;
56+
57+ font = get_default_font ();
58+ font_size = (int) get_default_font_size ();
59+ }
60+
61+
62+ if (direction == ScrollDirection.DOWN) {
63+ font_size --;
64+ if (font_size < FONT_SIZE_MIN)
65+ return;
66+ } else if (direction == ScrollDirection.UP) {
67+ font_size ++;
68+ if (font_size > FONT_SIZE_MAX)
69+ return;
70+ }
71+
72+ string new_font = font + " " + font_size.to_string ();
73+ Scratch.settings.font = new_font;
74+ }
75+
76+ public string get_current_font () {
77+ string font = Scratch.settings.font;
78+ string font_family = font.substring (0, font.last_index_of (" "));
79+ return font_family;
80+ }
81+
82+ public double get_current_font_size () {
83+ string font = Scratch.settings.font;
84+ string font_size = font.substring (font.last_index_of (" ") + 1);
85+ return double.parse (font_size);
86+ }
87+
88+ public string get_default_font () {
89+ string font = app.default_font;
90+ string font_family = font.substring (0, font.last_index_of (" "));
91+ return font_family;
92+ }
93+
94+ public double get_default_font_size () {
95+ string font = app.default_font;
96+ string font_size = font.substring (font.last_index_of (" ") + 1);
97+ return double.parse (font_size);
98+ }
99+
100 // Actions functions
101+ void action_set_default_zoom () {
102+ set_default_zoom ();
103+ }
104 void action_preferences () {
105 var dialog = new Scratch.Dialogs.Preferences (this, plugins);
106 dialog.show_all ();
107@@ -773,6 +845,10 @@
108 /* label, accelerator */ N_("Clipboard"), null,
109 /* tooltip */ N_("New file from Clipboard"),
110 action_new_tab_from_clipboard },
111+ { "Zoom", "zoom-original",
112+ /* label, accelerator */ N_("Zoom"), "<Control>0",
113+ /* tooltip */ N_("Zoom 1:1"),
114+ action_set_default_zoom },
115 { "SaveFile", "document-save",
116 /* label, accelerator */ N_("Save"), "<Control>s",
117 /* tooltip */ N_("Save this file"),
118
119=== modified file 'src/Scratch.vala'
120--- src/Scratch.vala 2014-10-11 22:32:35 +0000
121+++ src/Scratch.vala 2014-10-30 19:07:02 +0000
122@@ -35,6 +35,7 @@
123
124 public string app_cmd_name { get { return _app_cmd_name; } }
125 public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } }
126+ public string default_font { get; set; }
127 private static string _app_cmd_name;
128 private static string _data_home_folder_unsaved;
129 private static string _cwd;
130@@ -87,6 +88,7 @@
131 Logger.DisplayLevel = LogLevel.DEBUG;
132
133 // Init settings
134+ default_font = new GLib.Settings ("org.gnome.desktop.interface").get_string ("monospace-font-name");
135 saved_state = new SavedState ();
136 settings = new Settings ();
137 services = new ServicesSettings ();
138
139=== modified file 'src/Widgets/SourceView.vala'
140--- src/Widgets/SourceView.vala 2014-08-05 12:33:36 +0000
141+++ src/Widgets/SourceView.vala 2014-10-30 19:07:02 +0000
142@@ -40,13 +40,13 @@
143 private uint selection_changed_timer = 0;
144 private TextIter last_select_start_iter;
145 private TextIter last_select_end_iter;
146-
147-
148- // Consts
149+
150+
151+ // Consts
152 // Pause after end user highlighting to confirm select,in ms
153- private const uint SELECTION_CHANGED_PAUSE = 400;
154-
155-
156+ private const uint SELECTION_CHANGED_PAUSE = 400;
157+
158+
159 // Signals
160 public signal void style_changed (SourceStyleScheme style);
161 public signal void language_changed (SourceLanguage language);
162@@ -84,6 +84,43 @@
163 // Settings
164 restore_settings ();
165 settings.changed.connect (restore_settings);
166+
167+ this.scroll_event.connect ((key_event) => {
168+ if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y < 0) {
169+ Scratch.ScratchApp.instance.get_last_window ().zoom_in ();
170+ return true;
171+ } else if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y > 0) {
172+ Scratch.ScratchApp.instance.get_last_window ().zoom_out ();
173+ return true;
174+ }
175+
176+ return false;
177+ });
178+
179+ this.key_press_event.connect ((key_event) => {
180+ switch (key_event.keyval) {
181+ case Gdk.Key.plus:
182+ if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
183+ Scratch.ScratchApp.instance.get_last_window ().zoom_in ();
184+ return true;
185+ }
186+ break;
187+ case Gdk.Key.minus:
188+ if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
189+ Scratch.ScratchApp.instance.get_last_window ().zoom_out ();
190+ return true;
191+ }
192+ break;
193+ case 0x30:
194+ if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
195+ Scratch.ScratchApp.instance.get_last_window ().set_default_zoom ();
196+ return true;
197+ }
198+ break;
199+ }
200+
201+ return false;
202+ });
203 }
204
205 ~SourceView () {
206@@ -143,9 +180,7 @@
207 if (!value) // if false, simply return null
208 return;
209
210- var settings = new GLib.Settings ("org.gnome.desktop.interface");
211- this.font = settings.get_string ("monospace-font-name");
212-
213+ this.font = ScratchApp.instance.default_font;
214 }
215
216 public void change_syntax_highlight_from_file (File file) {
217@@ -197,7 +232,7 @@
218 override_font (Pango.FontDescription.from_string (this.font));
219
220 buffer.style_scheme = style_scheme_manager.get_scheme (Scratch.settings.style_scheme);
221-
222+
223 this.style_changed (buffer.style_scheme);
224 }
225
226@@ -211,7 +246,7 @@
227 Scratch.settings.indent_width = (int) tab_width;
228 Scratch.settings.font = this.font;
229 Scratch.settings.style_scheme = buffer.style_scheme.id;
230-
231+
232 this.style_changed (buffer.style_scheme);
233 }
234
235@@ -270,44 +305,44 @@
236 buffer.get_start_iter (out start);
237 buffer.place_cursor (start);
238 }
239-
240+
241 public void set_language (SourceLanguage lang) {
242 this.buffer.set_language (lang);
243 this.language_changed (lang);
244 }
245-
246-
247+
248+
249 void on_mark_set (TextIter loc,TextMark mar) {
250 // Weed out user movement for text selection changes
251 TextIter start, end;
252 this.buffer.get_selection_bounds (out start,out end);
253-
254+
255 if (start == last_select_start_iter && end == last_select_end_iter)
256 return;
257-
258+
259 if (selection_changed_timer !=0 &&
260 MainContext.get_thread_default ().find_source_by_id (selection_changed_timer) != null)
261 Source.remove (selection_changed_timer);
262-
263+
264 // Fire deselected immediatly
265 if (!this.buffer.get_has_selection ())
266 deselected ();
267 // Don't fire signal till we think select movement is done
268 else
269 selection_changed_timer = Timeout.add (SELECTION_CHANGED_PAUSE, selection_changed_event);
270-
271+
272 }
273-
274+
275 bool selection_changed_event () {
276 TextIter start, end;
277 bool selected = this.buffer.get_selection_bounds (out start,out end);
278 if (selected)
279- selection_changed (start,end);
280+ selection_changed (start,end);
281 else
282- deselected ();
283+ deselected ();
284 return false;
285 }
286
287 }
288
289-}
290+}
291\ No newline at end of file
292
293=== modified file 'src/Widgets/ToolBar.vala'
294--- src/Widgets/ToolBar.vala 2014-10-11 22:32:35 +0000
295+++ src/Widgets/ToolBar.vala 2014-10-30 19:07:02 +0000
296@@ -31,6 +31,7 @@
297 public ToolButton save_as_button;
298 public ToolButton revert_button;
299 public ToolButton find_button;
300+ public ToolButton zoom_default;
301
302 public Gtk.Menu share_menu;
303 public Gtk.Menu menu;
304@@ -50,6 +51,7 @@
305 save_as_button = main_actions.get_action ("SaveFileAs").create_tool_item () as Gtk.ToolButton;
306 revert_button = main_actions.get_action ("Revert").create_tool_item () as Gtk.ToolButton;
307 find_button = main_actions.get_action ("Fetch").create_tool_item () as Gtk.ToolButton;
308+ zoom_default = main_actions.get_action ("Zoom").create_tool_item () as Gtk.ToolButton;
309
310 // Create Share and AppMenu
311 share_menu = new Gtk.Menu ();
312@@ -89,8 +91,9 @@
313 pack_start (revert_button);
314 pack_start (new SeparatorToolItem ());
315 pack_start (find_button);
316-
317+
318 pack_end (share_app_menu);
319+ pack_end (zoom_default);
320
321 // Show/Hide widgets
322 show_all ();
323@@ -98,6 +101,7 @@
324 // Some signals...
325 settings.changed.connect (() => {
326 save_button.visible = !settings.autosave;
327+ zoom_default.visible = ScratchApp.instance.get_last_window ().get_default_font_size () != ScratchApp.instance.get_last_window ().get_current_font_size ();
328 });
329
330 }

Subscribers

People subscribed via source and target branches