! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
[PATCH] Enable Ctrl+ / Ctrl- for font increase/decrease
Status:
RESOLVED: MOVED
Severity:
enhancement
Product:
Mousepad
Component:
General

Comments

Description Luca Errani 2020-01-14 14:28:18 CET
Created attachment 9379 
Patch file including the ability to Ctrl+/Ctrl- to increase/decrease font size

Hi everyone,

I use Mousepad everyday as my main text-editor but I found that it lacks the "Zoom in/Zoom out" feature.

I added this patch in order to make it work, I'm sure as hell there are way more elegant ways to achieve the same result, but this is my contribution.

I read on the mailing list that submitting a bug here on Bugzilla is the right way to show you a patch for a XFCE's project. I'm pretty new to working in repositories this big, so I hope I got it right.

Of course, I'm widely open to critics and corrections.
Comment 1 Luca Errani 2020-01-15 18:27:28 CET
Created attachment 9382 
[FIX] This patch fixes the previous one where a silly copy/paste error failed compile

EDIT: The new patch fixes a small copy/paste error I missed when preparing the previous one
Comment 2 Matthew Brush editbugs 2020-01-16 04:13:16 CET
I haven't thoroughly reviewed or tested this yet, but a glance, it looks like it could be made more robust by using the Pango API, like to parse the font description: https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-description-from-string

Also it might be nicer (though a bit more work) to add a "zoom-level" property to the MousepadView rather than embedding the logic in the MousepadWindow code, and then having the action handler just update the new property.

To be honest I'm quite surprised GtkSourceView has no zoom-in/zoom-out functionality itself. It seems a bit odd changing the font preference to achieve zooming.
Comment 3 Luca Errani 2020-01-16 12:05:20 CET
You're completely right, I could implement it using Pango API,  I don't find very suitable the "atoi" implementation too.

Speaking of "how to achieve" the zoom effect, I just copied the way that the IntelliJ-suite follow so, if you think we should find another way, let's close this bug and go on, otherwise I could upload a new patch using pango library which will increase the font size in the preferences and see how to deal with it!

Thank you very much for your commentm I'll work on that!
Comment 4 Luca Errani 2020-01-16 20:07:12 CET
Created attachment 9387 
[PATCH] Use of Pango API to retrieve and set font size

I modified my patch on Matthew's suggestions, now it uses Pango API; all the logic is still in mousepad-window.c though
Comment 5 Theo Linkspfeifer editbugs 2020-01-17 15:36:48 CET
Thunar, Geany and others have an option to reset back to normal size (Ctrl+0). Maybe this should be added also.
Comment 6 Luca Errani 2020-01-17 16:15:26 CET
Hi Theo! 
This shouldn't be hard to implement, so I'll do it. Is there a default value stored in mousepad's settings? I only saw the "USE_DEFAULT_FONT" macro but I don't think we should reset the selected font to default; do you think we should set a "default font size" value somewhere?
Comment 7 Theo Linkspfeifer editbugs 2020-01-17 18:18:44 CET
It is defined here:
https://git.xfce.org/apps/mousepad/tree/mousepad/mousepad-view.c#n44
Comment 8 Luca Errani 2020-01-18 12:53:29 CET
Created attachment 9393 
[PATCH] Moved zoom_level in MousepadView as a property, added Ctrl+0 to reset font size

Hi everyone!
I followed your suggestions, now MousepadWindow simply updates the corresponding MousepadView's zoom_level property, so that Ctrl++ and Ctrl+- set its value to the previous +2 or the previous -2.

As Theo suggested, I also added the ability to reset to default font size by pressing Ctrl+0.

Let me know if it's better than before and if we have to work more on it!
Comment 9 Matthew Brush editbugs 2020-01-18 17:50:54 CET
Nice work!

The only thing I don't like is that the zoom setting affects the font setting, though I'm not sure there's a better way.
Comment 10 Luca Errani 2020-01-18 18:07:42 CET
Hi Matthew!

Thank you! I understand that manually interacting with the font setting could become messy if not treated the right way, but I saw that even Gedit uses the TextSize plugin to achieve the same result, and it increases/decreases the font size too! 

Anyway, let me know if any other modification is needed!
Comment 11 Matthew Brush editbugs 2020-01-18 20:57:41 CET
I tested this out a bit, a few comments:

If you build with `-Wignored-qualifiers` (default on with my compiler/environment), there are warnings about returning `const gint` instead of `gint`, since it's already returned by value, I suppose.

Also with `-Wreturn-type` (again default with my compiler/environment), it warns about a `g_return_if_fail` use in `mousepad_view_set_default_zoom_level()` since it returns a value. It should use `g_return_val_if_fail` instead with a sensible 2nd argument to be returned in case of failure.

As for using it, the only glitch I noticed is that when you zoom in and out and reset the zoom, it doesn't seem to update the GtkFontButton font size in the preferences dialog. Here it ends up showing 0 for the font size that is part of the GtkFontButton label.
Comment 12 Matthew Brush editbugs 2020-01-18 21:41:50 CET
(In reply to Matthew Brush from comment #11)
> I tested this out a bit, a few comments:
> 
> If you build with `-Wignored-qualifiers` (default on with my
> compiler/environment), there are warnings about returning `const gint`
> instead of `gint`, since it's already returned by value, I suppose.
> 
> Also with `-Wreturn-type` (again default with my compiler/environment), it
> warns about a `g_return_if_fail` use in
> `mousepad_view_set_default_zoom_level()` since it returns a value. It should
> use `g_return_val_if_fail` instead with a sensible 2nd argument to be
> returned in case of failure.
> 
> As for using it, the only glitch I noticed is that when you zoom in and out
> and reset the zoom, it doesn't seem to update the GtkFontButton font size in
> the preferences dialog. Here it ends up showing 0 for the font size that is
> part of the GtkFontButton label.

Also one subjective thing which can be ignored, but IMO there should be a menu separator between the "Select Font" and the new "Zoom In/Out/Default" menu items in the View menu in `mousepad-window-ui.xml`. Even though they are technically related, I don't think they should be related in the UI.
Comment 13 Luca Errani 2020-01-19 14:24:27 CET
Created attachment 9396 
[PATCH] Updates preferences on zoom in/out, View menu separator

Hi Matthew!

I fixed the warnings you suggested, added a separator between "Select font" and the "Zoom in/out/default" block and fixed the missing update in the settings panel.

Though I have to say that it behaves a little bit strangely, everytime I try to zoom in/out, the mousepad_view_update_font gets called twice: one from the propery binding, one from the explicit call in mousepad_view_set_zoom_level, but removing the latter will result in no update at all.
Do you know why? I've tried to fix it but I didn't manage to find a solution.
Comment 14 Luca Errani 2020-01-19 14:55:08 CET
Created attachment 9397 
[PATCH] fix for multiple "update font" calls when zooming

I found the problem!
Basically I was calling "mousepad_view_set_zoom_level", then setting to false the USE_DEFAULT_FONT setting and set the ZOOM_LEVEL property to its new value. All these three functions were calling "mousepad_view_update_font", which resulted in a silly overhead. 
Now it doesn't call the "mousepad_view_set_zoom_level" and sets to fasle the USE_DEFAULT_FONT only if needed.

The instruction MOUSEPAD_SETTING_SET_BOOLEAN(ZOOM_LEVEL, zoom_level) will do the trick and update the view
Comment 15 Luca Errani 2020-01-28 18:48:54 CET
Hi!
Can I have an update about this thread? Does it need to be reviewed or edited? What can I do to make it better?
Comment 16 Theo Linkspfeifer editbugs 2020-01-29 12:10:59 CET
I applied your patch and did a quick test. It seems to work.

However, you should change the menu entry labels to Title Case and maybe move the entries to the bottom of the View menu (see Geany).
Comment 17 Theo Linkspfeifer editbugs 2020-01-29 12:15:09 CET
Furthermore, I noticed that both Geany and Thunar use "Normal Size" as label. This could be adapted also.
Comment 18 Luca Errani 2020-01-29 19:21:06 CET
Created attachment 9408 
[PATCH] Label refactor

Hi! 
I added a patch based on Theo's suggestion! Hope it's good!
Comment 19 Git Bot editbugs 2020-05-24 01:34:04 CEST
-- GitLab Migration Automatic Message --

This bug has been migrated to xfce.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.xfce.org/apps/mousepad/-/issues/46.

Please create an account or use an existing account on one of our supported OAuth providers. 

If you want to fork to submit patches and merge requests please continue reading here: https://docs.xfce.org/contribute/dev/git/start#gitlab_forks_and_merge_requests

Also feel free to reach out to us on the mailing list https://mail.xfce.org/mailman/listinfo/xfce4-dev

Bug #16376

Reported by:
Luca Errani
Reported on: 2020-01-14
Last modified on: 2020-05-24

People

Assignee:
Matthew Brush
CC List:
1 user

Version

Target Milestone:
Mousepad 0.4.x

Attachments

Additional information