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
=== modified file 'src/MainWindow.vala'
--- src/MainWindow.vala 2014-10-29 21:19:58 +0000
+++ src/MainWindow.vala 2014-10-30 19:07:02 +0000
@@ -32,6 +32,9 @@
32namespace Scratch {32namespace Scratch {
3333
34 public class MainWindow : Gtk.Window {34 public class MainWindow : Gtk.Window {
35 public int FONT_SIZE_MAX = 72;
36 public int FONT_SIZE_MIN = 7;
37
35 public weak ScratchApp app;38 public weak ScratchApp app;
3639
37 // Widgets40 // Widgets
@@ -195,13 +198,13 @@
195 toolbar_title = "(%s)".printf (doc.get_basename ());198 toolbar_title = "(%s)".printf (doc.get_basename ());
196199
197 this.toolbar.title = toolbar_title;200 this.toolbar.title = toolbar_title;
198 }201 } else {
199 else {
200 this.toolbar.title = this.app.app_cmd_name;202 this.toolbar.title = this.app.app_cmd_name;
201 }203 }
202 // Set actions sensitive property204 // Set actions sensitive property
203 main_actions.get_action ("SaveFile").visible = (!settings.autosave || doc.file == null);205 main_actions.get_action ("SaveFile").visible = (!settings.autosave || doc.file == null);
204 main_actions.get_action ("SaveFileAs").visible = (doc.file != null);206 main_actions.get_action ("SaveFileAs").visible = (doc.file != null);
207 main_actions.get_action ("Zoom").visible = get_current_font_size () != get_default_font_size ();
205 doc.check_undoable_actions ();208 doc.check_undoable_actions ();
206 });209 });
207210
@@ -516,7 +519,76 @@
516 update_opened_files ();519 update_opened_files ();
517 }520 }
518521
522 public void set_default_zoom () {
523 Scratch.settings.font = get_current_font () + " " + get_default_font_size ().to_string ();
524 }
525
526 // Ctrl + scroll
527 public void zoom_in () {
528 zooming (ScrollDirection.UP);
529 }
530
531 // Ctrl + scroll
532 public void zoom_out () {
533 zooming (ScrollDirection.DOWN);
534 }
535
536 void zooming (ScrollDirection direction) {
537
538 string font = get_current_font ();
539 int font_size = (int) get_current_font_size ();
540
541 if (Scratch.settings.use_system_font) {
542
543 Scratch.settings.use_system_font = false;
544
545 font = get_default_font ();
546 font_size = (int) get_default_font_size ();
547 }
548
549
550 if (direction == ScrollDirection.DOWN) {
551 font_size --;
552 if (font_size < FONT_SIZE_MIN)
553 return;
554 } else if (direction == ScrollDirection.UP) {
555 font_size ++;
556 if (font_size > FONT_SIZE_MAX)
557 return;
558 }
559
560 string new_font = font + " " + font_size.to_string ();
561 Scratch.settings.font = new_font;
562 }
563
564 public string get_current_font () {
565 string font = Scratch.settings.font;
566 string font_family = font.substring (0, font.last_index_of (" "));
567 return font_family;
568 }
569
570 public double get_current_font_size () {
571 string font = Scratch.settings.font;
572 string font_size = font.substring (font.last_index_of (" ") + 1);
573 return double.parse (font_size);
574 }
575
576 public string get_default_font () {
577 string font = app.default_font;
578 string font_family = font.substring (0, font.last_index_of (" "));
579 return font_family;
580 }
581
582 public double get_default_font_size () {
583 string font = app.default_font;
584 string font_size = font.substring (font.last_index_of (" ") + 1);
585 return double.parse (font_size);
586 }
587
519 // Actions functions588 // Actions functions
589 void action_set_default_zoom () {
590 set_default_zoom ();
591 }
520 void action_preferences () {592 void action_preferences () {
521 var dialog = new Scratch.Dialogs.Preferences (this, plugins);593 var dialog = new Scratch.Dialogs.Preferences (this, plugins);
522 dialog.show_all ();594 dialog.show_all ();
@@ -773,6 +845,10 @@
773 /* label, accelerator */ N_("Clipboard"), null,845 /* label, accelerator */ N_("Clipboard"), null,
774 /* tooltip */ N_("New file from Clipboard"),846 /* tooltip */ N_("New file from Clipboard"),
775 action_new_tab_from_clipboard },847 action_new_tab_from_clipboard },
848 { "Zoom", "zoom-original",
849 /* label, accelerator */ N_("Zoom"), "<Control>0",
850 /* tooltip */ N_("Zoom 1:1"),
851 action_set_default_zoom },
776 { "SaveFile", "document-save",852 { "SaveFile", "document-save",
777 /* label, accelerator */ N_("Save"), "<Control>s",853 /* label, accelerator */ N_("Save"), "<Control>s",
778 /* tooltip */ N_("Save this file"),854 /* tooltip */ N_("Save this file"),
779855
=== modified file 'src/Scratch.vala'
--- src/Scratch.vala 2014-10-11 22:32:35 +0000
+++ src/Scratch.vala 2014-10-30 19:07:02 +0000
@@ -35,6 +35,7 @@
3535
36 public string app_cmd_name { get { return _app_cmd_name; } }36 public string app_cmd_name { get { return _app_cmd_name; } }
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; } }
38 public string default_font { get; set; }
38 private static string _app_cmd_name;39 private static string _app_cmd_name;
39 private static string _data_home_folder_unsaved;40 private static string _data_home_folder_unsaved;
40 private static string _cwd;41 private static string _cwd;
@@ -87,6 +88,7 @@
87 Logger.DisplayLevel = LogLevel.DEBUG;88 Logger.DisplayLevel = LogLevel.DEBUG;
8889
89 // Init settings90 // Init settings
91 default_font = new GLib.Settings ("org.gnome.desktop.interface").get_string ("monospace-font-name");
90 saved_state = new SavedState ();92 saved_state = new SavedState ();
91 settings = new Settings ();93 settings = new Settings ();
92 services = new ServicesSettings ();94 services = new ServicesSettings ();
9395
=== modified file 'src/Widgets/SourceView.vala'
--- src/Widgets/SourceView.vala 2014-08-05 12:33:36 +0000
+++ src/Widgets/SourceView.vala 2014-10-30 19:07:02 +0000
@@ -40,13 +40,13 @@
40 private uint selection_changed_timer = 0;40 private uint selection_changed_timer = 0;
41 private TextIter last_select_start_iter;41 private TextIter last_select_start_iter;
42 private TextIter last_select_end_iter;42 private TextIter last_select_end_iter;
43 43
44 44
45 // Consts 45 // Consts
46 // Pause after end user highlighting to confirm select,in ms46 // Pause after end user highlighting to confirm select,in ms
47 private const uint SELECTION_CHANGED_PAUSE = 400; 47 private const uint SELECTION_CHANGED_PAUSE = 400;
48 48
49 49
50 // Signals50 // Signals
51 public signal void style_changed (SourceStyleScheme style);51 public signal void style_changed (SourceStyleScheme style);
52 public signal void language_changed (SourceLanguage language);52 public signal void language_changed (SourceLanguage language);
@@ -84,6 +84,43 @@
84 // Settings84 // Settings
85 restore_settings ();85 restore_settings ();
86 settings.changed.connect (restore_settings);86 settings.changed.connect (restore_settings);
87
88 this.scroll_event.connect ((key_event) => {
89 if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y < 0) {
90 Scratch.ScratchApp.instance.get_last_window ().zoom_in ();
91 return true;
92 } else if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y > 0) {
93 Scratch.ScratchApp.instance.get_last_window ().zoom_out ();
94 return true;
95 }
96
97 return false;
98 });
99
100 this.key_press_event.connect ((key_event) => {
101 switch (key_event.keyval) {
102 case Gdk.Key.plus:
103 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
104 Scratch.ScratchApp.instance.get_last_window ().zoom_in ();
105 return true;
106 }
107 break;
108 case Gdk.Key.minus:
109 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
110 Scratch.ScratchApp.instance.get_last_window ().zoom_out ();
111 return true;
112 }
113 break;
114 case 0x30:
115 if (Gdk.ModifierType.CONTROL_MASK in key_event.state) {
116 Scratch.ScratchApp.instance.get_last_window ().set_default_zoom ();
117 return true;
118 }
119 break;
120 }
121
122 return false;
123 });
87 }124 }
88125
89 ~SourceView () {126 ~SourceView () {
@@ -143,9 +180,7 @@
143 if (!value) // if false, simply return null180 if (!value) // if false, simply return null
144 return;181 return;
145182
146 var settings = new GLib.Settings ("org.gnome.desktop.interface");183 this.font = ScratchApp.instance.default_font;
147 this.font = settings.get_string ("monospace-font-name");
148
149 }184 }
150185
151 public void change_syntax_highlight_from_file (File file) {186 public void change_syntax_highlight_from_file (File file) {
@@ -197,7 +232,7 @@
197 override_font (Pango.FontDescription.from_string (this.font));232 override_font (Pango.FontDescription.from_string (this.font));
198233
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);
200 235
201 this.style_changed (buffer.style_scheme);236 this.style_changed (buffer.style_scheme);
202 }237 }
203238
@@ -211,7 +246,7 @@
211 Scratch.settings.indent_width = (int) tab_width;246 Scratch.settings.indent_width = (int) tab_width;
212 Scratch.settings.font = this.font;247 Scratch.settings.font = this.font;
213 Scratch.settings.style_scheme = buffer.style_scheme.id;248 Scratch.settings.style_scheme = buffer.style_scheme.id;
214 249
215 this.style_changed (buffer.style_scheme);250 this.style_changed (buffer.style_scheme);
216 }251 }
217252
@@ -270,44 +305,44 @@
270 buffer.get_start_iter (out start);305 buffer.get_start_iter (out start);
271 buffer.place_cursor (start);306 buffer.place_cursor (start);
272 }307 }
273 308
274 public void set_language (SourceLanguage lang) {309 public void set_language (SourceLanguage lang) {
275 this.buffer.set_language (lang);310 this.buffer.set_language (lang);
276 this.language_changed (lang);311 this.language_changed (lang);
277 }312 }
278 313
279 314
280 void on_mark_set (TextIter loc,TextMark mar) {315 void on_mark_set (TextIter loc,TextMark mar) {
281 // Weed out user movement for text selection changes316 // Weed out user movement for text selection changes
282 TextIter start, end;317 TextIter start, end;
283 this.buffer.get_selection_bounds (out start,out end);318 this.buffer.get_selection_bounds (out start,out end);
284 319
285 if (start == last_select_start_iter && end == last_select_end_iter)320 if (start == last_select_start_iter && end == last_select_end_iter)
286 return;321 return;
287 322
288 if (selection_changed_timer !=0 &&323 if (selection_changed_timer !=0 &&
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)
290 Source.remove (selection_changed_timer);325 Source.remove (selection_changed_timer);
291 326
292 // Fire deselected immediatly327 // Fire deselected immediatly
293 if (!this.buffer.get_has_selection ())328 if (!this.buffer.get_has_selection ())
294 deselected ();329 deselected ();
295 // Don't fire signal till we think select movement is done330 // Don't fire signal till we think select movement is done
296 else331 else
297 selection_changed_timer = Timeout.add (SELECTION_CHANGED_PAUSE, selection_changed_event);332 selection_changed_timer = Timeout.add (SELECTION_CHANGED_PAUSE, selection_changed_event);
298 333
299 }334 }
300 335
301 bool selection_changed_event () {336 bool selection_changed_event () {
302 TextIter start, end;337 TextIter start, end;
303 bool selected = this.buffer.get_selection_bounds (out start,out end);338 bool selected = this.buffer.get_selection_bounds (out start,out end);
304 if (selected)339 if (selected)
305 selection_changed (start,end); 340 selection_changed (start,end);
306 else341 else
307 deselected (); 342 deselected ();
308 return false;343 return false;
309 }344 }
310345
311 }346 }
312347
313}348}
314\ No newline at end of file349\ No newline at end of file
315350
=== modified file 'src/Widgets/ToolBar.vala'
--- src/Widgets/ToolBar.vala 2014-10-11 22:32:35 +0000
+++ src/Widgets/ToolBar.vala 2014-10-30 19:07:02 +0000
@@ -31,6 +31,7 @@
31 public ToolButton save_as_button;31 public ToolButton save_as_button;
32 public ToolButton revert_button;32 public ToolButton revert_button;
33 public ToolButton find_button;33 public ToolButton find_button;
34 public ToolButton zoom_default;
3435
35 public Gtk.Menu share_menu;36 public Gtk.Menu share_menu;
36 public Gtk.Menu menu;37 public Gtk.Menu menu;
@@ -50,6 +51,7 @@
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;
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;
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;
54 zoom_default = main_actions.get_action ("Zoom").create_tool_item () as Gtk.ToolButton;
5355
54 // Create Share and AppMenu56 // Create Share and AppMenu
55 share_menu = new Gtk.Menu ();57 share_menu = new Gtk.Menu ();
@@ -89,8 +91,9 @@
89 pack_start (revert_button);91 pack_start (revert_button);
90 pack_start (new SeparatorToolItem ());92 pack_start (new SeparatorToolItem ());
91 pack_start (find_button);93 pack_start (find_button);
9294
93 pack_end (share_app_menu);95 pack_end (share_app_menu);
96 pack_end (zoom_default);
9497
95 // Show/Hide widgets98 // Show/Hide widgets
96 show_all ();99 show_all ();
@@ -98,6 +101,7 @@
98 // Some signals...101 // Some signals...
99 settings.changed.connect (() => {102 settings.changed.connect (() => {
100 save_button.visible = !settings.autosave;103 save_button.visible = !settings.autosave;
104 zoom_default.visible = ScratchApp.instance.get_last_window ().get_default_font_size () != ScratchApp.instance.get_last_window ().get_current_font_size ();
101 });105 });
102106
103 }107 }

Subscribers

People subscribed via source and target branches