Merge lp:~artem-anufrij/scratch/Bugfix-1193676 into lp:~elementary-apps/scratch/scratch
- Bugfix-1193676
- Merge into scratch
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 | ||||
Related bugs: |
|
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 +/-)
Corentin Noël (tintou) wrote : | # |
Working fine here
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
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"
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
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
Danielle Foré (danrabbit) wrote : | # |
Works as expected :) Needs another code review since changes were made
Robert Roth (evfool) wrote : | # |
Clean code, two minor issues noted inline.
- 1416. By artem-anufrij
-
space between conversion and method name added
Artem Anufrij (artem-anufrij) wrote : | # |
@Robert:
done...
Preview Diff
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 | 32 | namespace Scratch { | 32 | namespace Scratch { |
6 | 33 | 33 | ||
7 | 34 | public class MainWindow : Gtk.Window { | 34 | public class MainWindow : Gtk.Window { |
8 | 35 | public int FONT_SIZE_MAX = 72; | ||
9 | 36 | public int FONT_SIZE_MIN = 7; | ||
10 | 37 | |||
11 | 35 | public weak ScratchApp app; | 38 | public weak ScratchApp app; |
12 | 36 | 39 | ||
13 | 37 | // Widgets | 40 | // Widgets |
14 | @@ -195,13 +198,13 @@ | |||
15 | 195 | toolbar_title = "(%s)".printf (doc.get_basename ()); | 198 | toolbar_title = "(%s)".printf (doc.get_basename ()); |
16 | 196 | 199 | ||
17 | 197 | this.toolbar.title = toolbar_title; | 200 | this.toolbar.title = toolbar_title; |
20 | 198 | } | 201 | } else { |
19 | 199 | else { | ||
21 | 200 | this.toolbar.title = this.app.app_cmd_name; | 202 | this.toolbar.title = this.app.app_cmd_name; |
22 | 201 | } | 203 | } |
23 | 202 | // Set actions sensitive property | 204 | // Set actions sensitive property |
24 | 203 | main_actions.get_action ("SaveFile").visible = (!settings.autosave || doc.file == null); | 205 | main_actions.get_action ("SaveFile").visible = (!settings.autosave || doc.file == null); |
25 | 204 | main_actions.get_action ("SaveFileAs").visible = (doc.file != null); | 206 | main_actions.get_action ("SaveFileAs").visible = (doc.file != null); |
26 | 207 | main_actions.get_action ("Zoom").visible = get_current_font_size () != get_default_font_size (); | ||
27 | 205 | doc.check_undoable_actions (); | 208 | doc.check_undoable_actions (); |
28 | 206 | }); | 209 | }); |
29 | 207 | 210 | ||
30 | @@ -516,7 +519,76 @@ | |||
31 | 516 | update_opened_files (); | 519 | update_opened_files (); |
32 | 517 | } | 520 | } |
33 | 518 | 521 | ||
34 | 522 | public void set_default_zoom () { | ||
35 | 523 | Scratch.settings.font = get_current_font () + " " + get_default_font_size ().to_string (); | ||
36 | 524 | } | ||
37 | 525 | |||
38 | 526 | // Ctrl + scroll | ||
39 | 527 | public void zoom_in () { | ||
40 | 528 | zooming (ScrollDirection.UP); | ||
41 | 529 | } | ||
42 | 530 | |||
43 | 531 | // Ctrl + scroll | ||
44 | 532 | public void zoom_out () { | ||
45 | 533 | zooming (ScrollDirection.DOWN); | ||
46 | 534 | } | ||
47 | 535 | |||
48 | 536 | void zooming (ScrollDirection direction) { | ||
49 | 537 | |||
50 | 538 | string font = get_current_font (); | ||
51 | 539 | int font_size = (int) get_current_font_size (); | ||
52 | 540 | |||
53 | 541 | if (Scratch.settings.use_system_font) { | ||
54 | 542 | |||
55 | 543 | Scratch.settings.use_system_font = false; | ||
56 | 544 | |||
57 | 545 | font = get_default_font (); | ||
58 | 546 | font_size = (int) get_default_font_size (); | ||
59 | 547 | } | ||
60 | 548 | |||
61 | 549 | |||
62 | 550 | if (direction == ScrollDirection.DOWN) { | ||
63 | 551 | font_size --; | ||
64 | 552 | if (font_size < FONT_SIZE_MIN) | ||
65 | 553 | return; | ||
66 | 554 | } else if (direction == ScrollDirection.UP) { | ||
67 | 555 | font_size ++; | ||
68 | 556 | if (font_size > FONT_SIZE_MAX) | ||
69 | 557 | return; | ||
70 | 558 | } | ||
71 | 559 | |||
72 | 560 | string new_font = font + " " + font_size.to_string (); | ||
73 | 561 | Scratch.settings.font = new_font; | ||
74 | 562 | } | ||
75 | 563 | |||
76 | 564 | public string get_current_font () { | ||
77 | 565 | string font = Scratch.settings.font; | ||
78 | 566 | string font_family = font.substring (0, font.last_index_of (" ")); | ||
79 | 567 | return font_family; | ||
80 | 568 | } | ||
81 | 569 | |||
82 | 570 | public double get_current_font_size () { | ||
83 | 571 | string font = Scratch.settings.font; | ||
84 | 572 | string font_size = font.substring (font.last_index_of (" ") + 1); | ||
85 | 573 | return double.parse (font_size); | ||
86 | 574 | } | ||
87 | 575 | |||
88 | 576 | public string get_default_font () { | ||
89 | 577 | string font = app.default_font; | ||
90 | 578 | string font_family = font.substring (0, font.last_index_of (" ")); | ||
91 | 579 | return font_family; | ||
92 | 580 | } | ||
93 | 581 | |||
94 | 582 | public double get_default_font_size () { | ||
95 | 583 | string font = app.default_font; | ||
96 | 584 | string font_size = font.substring (font.last_index_of (" ") + 1); | ||
97 | 585 | return double.parse (font_size); | ||
98 | 586 | } | ||
99 | 587 | |||
100 | 519 | // Actions functions | 588 | // Actions functions |
101 | 589 | void action_set_default_zoom () { | ||
102 | 590 | set_default_zoom (); | ||
103 | 591 | } | ||
104 | 520 | void action_preferences () { | 592 | void action_preferences () { |
105 | 521 | var dialog = new Scratch.Dialogs.Preferences (this, plugins); | 593 | var dialog = new Scratch.Dialogs.Preferences (this, plugins); |
106 | 522 | dialog.show_all (); | 594 | dialog.show_all (); |
107 | @@ -773,6 +845,10 @@ | |||
108 | 773 | /* label, accelerator */ N_("Clipboard"), null, | 845 | /* label, accelerator */ N_("Clipboard"), null, |
109 | 774 | /* tooltip */ N_("New file from Clipboard"), | 846 | /* tooltip */ N_("New file from Clipboard"), |
110 | 775 | action_new_tab_from_clipboard }, | 847 | action_new_tab_from_clipboard }, |
111 | 848 | { "Zoom", "zoom-original", | ||
112 | 849 | /* label, accelerator */ N_("Zoom"), "<Control>0", | ||
113 | 850 | /* tooltip */ N_("Zoom 1:1"), | ||
114 | 851 | action_set_default_zoom }, | ||
115 | 776 | { "SaveFile", "document-save", | 852 | { "SaveFile", "document-save", |
116 | 777 | /* label, accelerator */ N_("Save"), "<Control>s", | 853 | /* label, accelerator */ N_("Save"), "<Control>s", |
117 | 778 | /* tooltip */ N_("Save this file"), | 854 | /* tooltip */ N_("Save this file"), |
118 | 779 | 855 | ||
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 | 35 | 35 | ||
124 | 36 | public string app_cmd_name { get { return _app_cmd_name; } } | 36 | public string app_cmd_name { get { return _app_cmd_name; } } |
125 | 37 | public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } } | 37 | public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } } |
126 | 38 | public string default_font { get; set; } | ||
127 | 38 | private static string _app_cmd_name; | 39 | private static string _app_cmd_name; |
128 | 39 | private static string _data_home_folder_unsaved; | 40 | private static string _data_home_folder_unsaved; |
129 | 40 | private static string _cwd; | 41 | private static string _cwd; |
130 | @@ -87,6 +88,7 @@ | |||
131 | 87 | Logger.DisplayLevel = LogLevel.DEBUG; | 88 | Logger.DisplayLevel = LogLevel.DEBUG; |
132 | 88 | 89 | ||
133 | 89 | // Init settings | 90 | // Init settings |
134 | 91 | default_font = new GLib.Settings ("org.gnome.desktop.interface").get_string ("monospace-font-name"); | ||
135 | 90 | saved_state = new SavedState (); | 92 | saved_state = new SavedState (); |
136 | 91 | settings = new Settings (); | 93 | settings = new Settings (); |
137 | 92 | services = new ServicesSettings (); | 94 | services = new ServicesSettings (); |
138 | 93 | 95 | ||
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 | 40 | private uint selection_changed_timer = 0; | 40 | private uint selection_changed_timer = 0; |
144 | 41 | private TextIter last_select_start_iter; | 41 | private TextIter last_select_start_iter; |
145 | 42 | private TextIter last_select_end_iter; | 42 | private TextIter last_select_end_iter; |
149 | 43 | 43 | ||
150 | 44 | 44 | ||
151 | 45 | // Consts | 45 | // Consts |
152 | 46 | // Pause after end user highlighting to confirm select,in ms | 46 | // Pause after end user highlighting to confirm select,in ms |
156 | 47 | private const uint SELECTION_CHANGED_PAUSE = 400; | 47 | private const uint SELECTION_CHANGED_PAUSE = 400; |
157 | 48 | 48 | ||
158 | 49 | 49 | ||
159 | 50 | // Signals | 50 | // Signals |
160 | 51 | public signal void style_changed (SourceStyleScheme style); | 51 | public signal void style_changed (SourceStyleScheme style); |
161 | 52 | public signal void language_changed (SourceLanguage language); | 52 | public signal void language_changed (SourceLanguage language); |
162 | @@ -84,6 +84,43 @@ | |||
163 | 84 | // Settings | 84 | // Settings |
164 | 85 | restore_settings (); | 85 | restore_settings (); |
165 | 86 | settings.changed.connect (restore_settings); | 86 | settings.changed.connect (restore_settings); |
166 | 87 | |||
167 | 88 | this.scroll_event.connect ((key_event) => { | ||
168 | 89 | if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y < 0) { | ||
169 | 90 | Scratch.ScratchApp.instance.get_last_window ().zoom_in (); | ||
170 | 91 | return true; | ||
171 | 92 | } else if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y > 0) { | ||
172 | 93 | Scratch.ScratchApp.instance.get_last_window ().zoom_out (); | ||
173 | 94 | return true; | ||
174 | 95 | } | ||
175 | 96 | |||
176 | 97 | return false; | ||
177 | 98 | }); | ||
178 | 99 | |||
179 | 100 | this.key_press_event.connect ((key_event) => { | ||
180 | 101 | switch (key_event.keyval) { | ||
181 | 102 | case Gdk.Key.plus: | ||
182 | 103 | if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { | ||
183 | 104 | Scratch.ScratchApp.instance.get_last_window ().zoom_in (); | ||
184 | 105 | return true; | ||
185 | 106 | } | ||
186 | 107 | break; | ||
187 | 108 | case Gdk.Key.minus: | ||
188 | 109 | if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { | ||
189 | 110 | Scratch.ScratchApp.instance.get_last_window ().zoom_out (); | ||
190 | 111 | return true; | ||
191 | 112 | } | ||
192 | 113 | break; | ||
193 | 114 | case 0x30: | ||
194 | 115 | if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { | ||
195 | 116 | Scratch.ScratchApp.instance.get_last_window ().set_default_zoom (); | ||
196 | 117 | return true; | ||
197 | 118 | } | ||
198 | 119 | break; | ||
199 | 120 | } | ||
200 | 121 | |||
201 | 122 | return false; | ||
202 | 123 | }); | ||
203 | 87 | } | 124 | } |
204 | 88 | 125 | ||
205 | 89 | ~SourceView () { | 126 | ~SourceView () { |
206 | @@ -143,9 +180,7 @@ | |||
207 | 143 | if (!value) // if false, simply return null | 180 | if (!value) // if false, simply return null |
208 | 144 | return; | 181 | return; |
209 | 145 | 182 | ||
213 | 146 | var settings = new GLib.Settings ("org.gnome.desktop.interface"); | 183 | this.font = ScratchApp.instance.default_font; |
211 | 147 | this.font = settings.get_string ("monospace-font-name"); | ||
212 | 148 | |||
214 | 149 | } | 184 | } |
215 | 150 | 185 | ||
216 | 151 | public void change_syntax_highlight_from_file (File file) { | 186 | public void change_syntax_highlight_from_file (File file) { |
217 | @@ -197,7 +232,7 @@ | |||
218 | 197 | override_font (Pango.FontDescription.from_string (this.font)); | 232 | override_font (Pango.FontDescription.from_string (this.font)); |
219 | 198 | 233 | ||
220 | 199 | buffer.style_scheme = style_scheme_manager.get_scheme (Scratch.settings.style_scheme); | 234 | buffer.style_scheme = style_scheme_manager.get_scheme (Scratch.settings.style_scheme); |
222 | 200 | 235 | ||
223 | 201 | this.style_changed (buffer.style_scheme); | 236 | this.style_changed (buffer.style_scheme); |
224 | 202 | } | 237 | } |
225 | 203 | 238 | ||
226 | @@ -211,7 +246,7 @@ | |||
227 | 211 | Scratch.settings.indent_width = (int) tab_width; | 246 | Scratch.settings.indent_width = (int) tab_width; |
228 | 212 | Scratch.settings.font = this.font; | 247 | Scratch.settings.font = this.font; |
229 | 213 | Scratch.settings.style_scheme = buffer.style_scheme.id; | 248 | Scratch.settings.style_scheme = buffer.style_scheme.id; |
231 | 214 | 249 | ||
232 | 215 | this.style_changed (buffer.style_scheme); | 250 | this.style_changed (buffer.style_scheme); |
233 | 216 | } | 251 | } |
234 | 217 | 252 | ||
235 | @@ -270,44 +305,44 @@ | |||
236 | 270 | buffer.get_start_iter (out start); | 305 | buffer.get_start_iter (out start); |
237 | 271 | buffer.place_cursor (start); | 306 | buffer.place_cursor (start); |
238 | 272 | } | 307 | } |
240 | 273 | 308 | ||
241 | 274 | public void set_language (SourceLanguage lang) { | 309 | public void set_language (SourceLanguage lang) { |
242 | 275 | this.buffer.set_language (lang); | 310 | this.buffer.set_language (lang); |
243 | 276 | this.language_changed (lang); | 311 | this.language_changed (lang); |
244 | 277 | } | 312 | } |
247 | 278 | 313 | ||
248 | 279 | 314 | ||
249 | 280 | void on_mark_set (TextIter loc,TextMark mar) { | 315 | void on_mark_set (TextIter loc,TextMark mar) { |
250 | 281 | // Weed out user movement for text selection changes | 316 | // Weed out user movement for text selection changes |
251 | 282 | TextIter start, end; | 317 | TextIter start, end; |
252 | 283 | this.buffer.get_selection_bounds (out start,out end); | 318 | this.buffer.get_selection_bounds (out start,out end); |
254 | 284 | 319 | ||
255 | 285 | if (start == last_select_start_iter && end == last_select_end_iter) | 320 | if (start == last_select_start_iter && end == last_select_end_iter) |
256 | 286 | return; | 321 | return; |
258 | 287 | 322 | ||
259 | 288 | if (selection_changed_timer !=0 && | 323 | if (selection_changed_timer !=0 && |
260 | 289 | MainContext.get_thread_default ().find_source_by_id (selection_changed_timer) != null) | 324 | MainContext.get_thread_default ().find_source_by_id (selection_changed_timer) != null) |
261 | 290 | Source.remove (selection_changed_timer); | 325 | Source.remove (selection_changed_timer); |
263 | 291 | 326 | ||
264 | 292 | // Fire deselected immediatly | 327 | // Fire deselected immediatly |
265 | 293 | if (!this.buffer.get_has_selection ()) | 328 | if (!this.buffer.get_has_selection ()) |
266 | 294 | deselected (); | 329 | deselected (); |
267 | 295 | // Don't fire signal till we think select movement is done | 330 | // Don't fire signal till we think select movement is done |
268 | 296 | else | 331 | else |
269 | 297 | selection_changed_timer = Timeout.add (SELECTION_CHANGED_PAUSE, selection_changed_event); | 332 | selection_changed_timer = Timeout.add (SELECTION_CHANGED_PAUSE, selection_changed_event); |
271 | 298 | 333 | ||
272 | 299 | } | 334 | } |
274 | 300 | 335 | ||
275 | 301 | bool selection_changed_event () { | 336 | bool selection_changed_event () { |
276 | 302 | TextIter start, end; | 337 | TextIter start, end; |
277 | 303 | bool selected = this.buffer.get_selection_bounds (out start,out end); | 338 | bool selected = this.buffer.get_selection_bounds (out start,out end); |
278 | 304 | if (selected) | 339 | if (selected) |
280 | 305 | selection_changed (start,end); | 340 | selection_changed (start,end); |
281 | 306 | else | 341 | else |
283 | 307 | deselected (); | 342 | deselected (); |
284 | 308 | return false; | 343 | return false; |
285 | 309 | } | 344 | } |
286 | 310 | 345 | ||
287 | 311 | } | 346 | } |
288 | 312 | 347 | ||
290 | 313 | } | 348 | } |
291 | 314 | \ No newline at end of file | 349 | \ No newline at end of file |
292 | 315 | 350 | ||
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 | 31 | public ToolButton save_as_button; | 31 | public ToolButton save_as_button; |
298 | 32 | public ToolButton revert_button; | 32 | public ToolButton revert_button; |
299 | 33 | public ToolButton find_button; | 33 | public ToolButton find_button; |
300 | 34 | public ToolButton zoom_default; | ||
301 | 34 | 35 | ||
302 | 35 | public Gtk.Menu share_menu; | 36 | public Gtk.Menu share_menu; |
303 | 36 | public Gtk.Menu menu; | 37 | public Gtk.Menu menu; |
304 | @@ -50,6 +51,7 @@ | |||
305 | 50 | save_as_button = main_actions.get_action ("SaveFileAs").create_tool_item () as Gtk.ToolButton; | 51 | save_as_button = main_actions.get_action ("SaveFileAs").create_tool_item () as Gtk.ToolButton; |
306 | 51 | revert_button = main_actions.get_action ("Revert").create_tool_item () as Gtk.ToolButton; | 52 | revert_button = main_actions.get_action ("Revert").create_tool_item () as Gtk.ToolButton; |
307 | 52 | find_button = main_actions.get_action ("Fetch").create_tool_item () as Gtk.ToolButton; | 53 | find_button = main_actions.get_action ("Fetch").create_tool_item () as Gtk.ToolButton; |
308 | 54 | zoom_default = main_actions.get_action ("Zoom").create_tool_item () as Gtk.ToolButton; | ||
309 | 53 | 55 | ||
310 | 54 | // Create Share and AppMenu | 56 | // Create Share and AppMenu |
311 | 55 | share_menu = new Gtk.Menu (); | 57 | share_menu = new Gtk.Menu (); |
312 | @@ -89,8 +91,9 @@ | |||
313 | 89 | pack_start (revert_button); | 91 | pack_start (revert_button); |
314 | 90 | pack_start (new SeparatorToolItem ()); | 92 | pack_start (new SeparatorToolItem ()); |
315 | 91 | pack_start (find_button); | 93 | pack_start (find_button); |
317 | 92 | 94 | ||
318 | 93 | pack_end (share_app_menu); | 95 | pack_end (share_app_menu); |
319 | 96 | pack_end (zoom_default); | ||
320 | 94 | 97 | ||
321 | 95 | // Show/Hide widgets | 98 | // Show/Hide widgets |
322 | 96 | show_all (); | 99 | show_all (); |
323 | @@ -98,6 +101,7 @@ | |||
324 | 98 | // Some signals... | 101 | // Some signals... |
325 | 99 | settings.changed.connect (() => { | 102 | settings.changed.connect (() => { |
326 | 100 | save_button.visible = !settings.autosave; | 103 | save_button.visible = !settings.autosave; |
327 | 104 | zoom_default.visible = ScratchApp.instance.get_last_window ().get_default_font_size () != ScratchApp.instance.get_last_window ().get_current_font_size (); | ||
328 | 101 | }); | 105 | }); |
329 | 102 | 106 | ||
330 | 103 | } | 107 | } |
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.