Skip to content

Commit

Permalink
Show zoom in status bar (use specifier %z)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpaulsen93 authored and b4n committed Oct 6, 2019
1 parent 66823da commit 2f0d622
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/geany.txt
Expand Up @@ -2693,6 +2693,9 @@ Placeholder Description
``%r`` Shows whether the document is read-only (RO) or nothing.
``%Y`` The Scintilla style number at the caret position. This is
useful if you're debugging color schemes or related code.
``%z`` Shows ``Zoom: (zoomlevel)%`` if the document's current zoom
level is not 100%. If the zoom level gets back to 100%
then nothing will be displayed for ``%z``.
============ ===========================================================

Terminal (VTE) preferences
Expand Down
1 change: 1 addition & 0 deletions src/editor.c
Expand Up @@ -1187,6 +1187,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi
case SCN_ZOOM:
/* recalculate line margin width */
sci_set_line_numbers(sci, editor_prefs.show_linenumber_margin);
ui_update_statusbar(doc, -1);
break;
}
/* we always return FALSE here to let plugins handle the event too */
Expand Down
10 changes: 10 additions & 0 deletions src/sciwrappers.c
Expand Up @@ -321,6 +321,10 @@ void sci_zoom_off(ScintillaObject *sci)
SSM(sci, SCI_SETZOOM, 0, 0);
}

gint sci_get_zoom(ScintillaObject *sci)
{
return SSM(sci, SCI_GETZOOM, 0, 0);
}

/** Sets a line marker.
* @param sci Scintilla widget.
Expand Down Expand Up @@ -964,6 +968,12 @@ void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size
}


gdouble sci_get_font_size(ScintillaObject *sci, gint style)
{
return SSM(sci, SCI_STYLEGETSIZEFRACTIONAL, (uptr_t) style, 0) / (gdouble) SC_FONT_SIZE_MULTIPLIER;
}


/** Jumps to the specified line in the document.
* If @a unfold is set and @a line is hidden by a fold, it is unfolded
* first to ensure it is visible.
Expand Down
3 changes: 3 additions & 0 deletions src/sciwrappers.h
Expand Up @@ -132,6 +132,7 @@ void sci_set_eol_mode (ScintillaObject *sci, gint eolmode);
void sci_zoom_in (ScintillaObject *sci);
void sci_zoom_out (ScintillaObject *sci);
void sci_zoom_off (ScintillaObject *sci);
gint sci_get_zoom (ScintillaObject *sci);
void sci_toggle_marker_at_line (ScintillaObject *sci, gint line, gint marker);
gint sci_marker_next (ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap);
gint sci_marker_previous (ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap);
Expand Down Expand Up @@ -218,6 +219,8 @@ void sci_move_selected_lines_up (ScintillaObject *sci);

void sci_set_font_fractional (ScintillaObject *sci, gint style, const gchar *font, gdouble size);

gdouble sci_get_font_size (ScintillaObject *sci, gint style);

#endif /* GEANY_PRIVATE */

G_END_DECLS
Expand Down
16 changes: 16 additions & 0 deletions src/ui_utils.c
Expand Up @@ -195,6 +195,7 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
const gchar sp[] = " ";
GString *stats_str;
ScintillaObject *sci = doc->editor->sci;
gint zoom;

if (!EMPTY(ui_prefs.statusbar_template))
fmt = ui_prefs.statusbar_template;
Expand Down Expand Up @@ -304,6 +305,21 @@ static gchar *create_statusbar_statistics(GeanyDocument *doc,
g_string_append_printf(stats_str, "%d",
sci_get_style_at(doc->editor->sci, pos));
break;
case 'z':
zoom = sci_get_zoom(doc->editor->sci);
if (zoom != 0)
{
gdouble size, percent;

size = sci_get_font_size(doc->editor->sci, STYLE_DEFAULT);
if (size > 0.0)
{
percent = (size + zoom) * 100 / size;
g_string_append_printf(stats_str, _("Zoom: %.0f%%"), percent);
g_string_append(stats_str, sp);
}
}
break;
default:
g_string_append_len(stats_str, expos, 1);
}
Expand Down

0 comments on commit 2f0d622

Please sign in to comment.