From aac75de16be1ac7ce7fe469fe04208bf754271cd Mon Sep 17 00:00:00 2001 From: Luca Errani Date: Wed, 15 Jan 2020 18:24:18 +0100 Subject: [PATCH] Ctrl++/Ctrl+- can increase/decrease font size --- mousepad/mousepad-window-ui.xml | 2 + mousepad/mousepad-window.c | 84 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/mousepad/mousepad-window-ui.xml b/mousepad/mousepad-window-ui.xml index 4eef0b3..28e5413 100644 --- a/mousepad/mousepad-window-ui.xml +++ b/mousepad/mousepad-window-ui.xml @@ -93,6 +93,8 @@ + + diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index 9f33844..152ca62 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -325,6 +325,10 @@ static void mousepad_window_action_go_to_position (GtkAction MousepadWindow *window); static void mousepad_window_action_select_font (GtkAction *action, MousepadWindow *window); +static void mousepad_window_action_zoom_in (GtkAction *action, + MousepadWindow *window); +static void mousepad_window_action_zoom_out (GtkAction *action, + MousepadWindow *window); static void mousepad_window_action_line_numbers (GtkToggleAction *action, MousepadWindow *window); static void mousepad_window_action_menubar (GtkToggleAction *action, @@ -465,6 +469,8 @@ static const GtkActionEntry action_entries[] = { "view-menu", NULL, N_("_View"), NULL, NULL, NULL, }, { "font", GTK_STOCK_SELECT_FONT, N_("Select F_ont..."), NULL, N_("Change the editor font"), G_CALLBACK (mousepad_window_action_select_font), }, + { "zoom-in", GTK_STOCK_ZOOM_IN, N_("Zoom in"), "plus", N_("Increase font size"), G_CALLBACK (mousepad_window_action_zoom_in), }, + { "zoom-out", GTK_STOCK_ZOOM_OUT, N_("Zoom out"), "minus", N_("Decrease font size"), G_CALLBACK (mousepad_window_action_zoom_out), }, { "color-scheme-menu", NULL, N_("_Color Scheme"), NULL, NULL, NULL, }, { "document-menu", NULL, N_("_Document"), NULL, NULL, NULL, }, @@ -5016,6 +5022,84 @@ mousepad_window_action_select_font (GtkAction *action, gtk_widget_destroy (dialog); } +static void +mousepad_window_action_zoom_in (GtkAction *action, + MousepadWindow *window) +{ + gchar *font_name; + gchar tmp_buffer[3]; + int len, font_size; + + g_return_if_fail (MOUSEPAD_IS_WINDOW (window)); + g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); + + /* set the current font name */ + font_name = MOUSEPAD_SETTING_GET_STRING (FONT_NAME); + + /* extract last 2 chars (font size) */ + len = strlen(font_name); + font_size = atoi(font_name + len - 2); + + /* set 72 as maximum size */ + if (font_size + 2 > 72) { + g_free (font_name); + return; + } + + /* remove font size, 1 digit if lesser than 10, 2 otherwise */ + font_name[len - (font_size < 10 ? 1 : 2)] = '\0'; + + g_snprintf(tmp_buffer, 3, "%d", font_size + 2); + strcat(font_name, tmp_buffer); + + /* store the font in the preferences */ + MOUSEPAD_SETTING_SET_STRING (FONT_NAME, font_name); + /* stop using default font */ + MOUSEPAD_SETTING_SET_BOOLEAN (USE_DEFAULT_FONT, FALSE); + + /* cleanup */ + g_free (font_name); +} + +static void +mousepad_window_action_zoom_out (GtkAction *action, + MousepadWindow *window) +{ + gchar *font_name; + gchar tmp_buffer[3]; + int len, font_size; + + g_return_if_fail (MOUSEPAD_IS_WINDOW (window)); + g_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); + + /* set the current font name */ + font_name = MOUSEPAD_SETTING_GET_STRING (FONT_NAME); + + /* extract last 2 chars (font size) */ + len = strlen(font_name); + font_size = atoi(font_name + len - 2); + + /* set 6 as minimum size */ + if (font_size - 2 < 6){ + g_free (font_name); + return; + } + + /* remove font size, 1 digit if lesser than 10, 2 otherwise */ + font_name[len - (font_size < 10 ? 1 : 2)] = '\0'; + + g_snprintf(tmp_buffer, 3, "%d", font_size - 2); + strcat(font_name, tmp_buffer); + + + /* store the font in the preferences */ + MOUSEPAD_SETTING_SET_STRING (FONT_NAME, font_name); + /* stop using default font */ + MOUSEPAD_SETTING_SET_BOOLEAN (USE_DEFAULT_FONT, FALSE); + + /* cleanup */ + g_free (font_name); +} static void -- 2.20.1