Branch: refs/heads/master Author: Matthew Brush matt@geany.org Committer: Matthew Brush matt@geany.org Date: Mon, 15 Apr 2013 02:03:58 UTC Commit: d452d0b737dd38843b887542b04a806e1bdcb56e https://github.com/geany/geany/commit/d452d0b737dd38843b887542b04a806e1bdcb5...
Log Message: ----------- Cleanup statusbar template code a bit
* Unhardcode "pos" and "style" statusbar messages which were only enabled when GEANY_DEBUG is defined and make them real possible format chars.
* Move needless global "statusbar_template" into UIPrefs structure with the other UI preferences, removing (now) pointless ui_finalize() function.
* Rename "add_statusbar_statistics" to "create_statusbar_statistics" and make it return a gchar* instead of passing in a GString argument to update. Fixes a one-time "leak" of the GString and makes the code a little easier to follow.
* Move the default statusbar template string to the top of the file and use it as the default for the various preferences so the user has something to base their customizations off of. TODO: check that the N_() translations stuff works OK.
Modified Paths: -------------- src/main.c src/ui_utils.c src/ui_utils.h
Modified: src/main.c 1 files changed, 0 insertions(+), 1 deletions(-) =================================================================== @@ -1259,7 +1259,6 @@ void main_quit() sidebar_finalize(); configuration_finalize(); filetypes_free_types(); - ui_finalize(); log_finalize();
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
Modified: src/ui_utils.c 67 files changed, 35 insertions(+), 32 deletions(-) =================================================================== @@ -58,6 +58,16 @@ #include "gtkcompat.h"
+#define DEFAULT_STATUSBAR_TEMPLATE N_(\ + "line: %l / %L\t " \ + "col: %c\t " \ + "sel: %s\t " \ + "%w %t %m" \ + "mode: %M " \ + "encoding: %e " \ + "filetype: %f " \ + "scope: %S") + GeanyInterfacePrefs interface_prefs; GeanyMainWidgets main_widgets;
@@ -172,24 +182,24 @@ void ui_set_statusbar(gboolean log, const gchar *format, ...) }
-static gchar *statusbar_template = NULL; - /* note: some comments below are for translators */ -static void add_statusbar_statistics(GString *stats_str, - GeanyDocument *doc, guint line, guint col) +static gchar *create_statusbar_statistics(GeanyDocument *doc, + guint line, guint col, guint pos) { const gchar *cur_tag; const gchar *fmt; const gchar *expos; /* % expansion position */ const gchar sp[] = " "; + GString *stats_str; ScintillaObject *sci = doc->editor->sci;
- fmt = NZV(statusbar_template) ? statusbar_template : - /* Status bar statistics: col = column, sel = selection. */ - _("line: %l / %L\t col: %c\t sel: %s\t %w %t %m" - "mode: %M encoding: %e filetype: %f scope: %S"); + if (NZV(ui_prefs.statusbar_template)) + fmt = ui_prefs.statusbar_template; + else + fmt = _(DEFAULT_STATUSBAR_TEMPLATE); + + stats_str = g_string_sized_new(120);
- g_string_assign(stats_str, ""); while ((expos = strchr(fmt, '%')) != NULL) { /* append leading text before % char */ @@ -210,6 +220,9 @@ static void add_statusbar_statistics(GString *stats_str, case 'C': g_string_append_printf(stats_str, "%d", col + 1); break; + case 'p': + g_string_append_printf(stats_str, "%u", pos); + break; case 's': { gint len = sci_get_selected_text_length(sci) - 1; @@ -279,6 +292,11 @@ static void add_statusbar_statistics(GString *stats_str, symbols_get_current_scope(doc, &cur_tag); g_string_append(stats_str, cur_tag); break; + case 'Y': + g_string_append_c(stats_str, ' '); + g_string_append_printf(stats_str, "%d", + sci_get_style_at(doc->editor->sci, pos)); + break; default: g_string_append_len(stats_str, expos, 1); } @@ -291,6 +309,8 @@ static void add_statusbar_statistics(GString *stats_str, } /* add any remaining text */ g_string_append(stats_str, fmt); + + return g_string_free(stats_str, FALSE); }
@@ -305,11 +325,8 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos)
if (doc != NULL) { - static GString *stats_str = NULL; guint line, col; - - if (G_UNLIKELY(stats_str == NULL)) - stats_str = g_string_sized_new(120); + gchar *stats_str;
if (pos == -1) pos = sci_get_current_position(doc->editor->sci); @@ -323,19 +340,11 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos) else col = 0;
- add_statusbar_statistics(stats_str, doc, line, col); + stats_str = create_statusbar_statistics(doc, line, col, pos);
-#ifdef GEANY_DEBUG - { - const gchar sp[] = " "; - g_string_append(stats_str, sp); - g_string_append_printf(stats_str, _("pos: %d"), pos); - g_string_append(stats_str, sp); - g_string_append_printf(stats_str, _("style: %d"), sci_get_style_at(doc->editor->sci, pos)); - } -#endif /* can be overridden by status messages */ - set_statusbar(stats_str->str, TRUE); + set_statusbar(stats_str, TRUE); + g_free(stats_str); } else /* no documents */ { @@ -2000,8 +2009,8 @@ void ui_init_prefs(void) "compiler_tab_autoscroll", TRUE); stash_group_add_boolean(group, &ui_prefs.allow_always_save, "allow_always_save", FALSE); - stash_group_add_string(group, &statusbar_template, - "statusbar_template", ""); + stash_group_add_string(group, &ui_prefs.statusbar_template, + "statusbar_template", _(DEFAULT_STATUSBAR_TEMPLATE)); stash_group_add_boolean(group, &ui_prefs.new_document_after_close, "new_document_after_close", FALSE); stash_group_add_boolean(group, &interface_prefs.msgwin_status_visible, @@ -2257,12 +2266,6 @@ void ui_finalize_builder(void) }
-void ui_finalize(void) -{ - g_free(statusbar_template); -} - - static void auto_separator_update(GeanyAutoSeparator *autosep) { g_return_if_fail(autosep->item_count >= 0);
Modified: src/ui_utils.h 3 files changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -106,6 +106,7 @@ gint sidebar_page; gboolean msgwindow_visible; gboolean allow_always_save; /* if set, files can always be saved, even if unchanged */ + gchar *statusbar_template; gboolean new_document_after_close;
/* Menu-item related data */ @@ -242,8 +243,6 @@ void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text,
void ui_finalize_builder(void);
-void ui_finalize(void); - void ui_init_toolbar_widgets(void);
void ui_init_stock_items(void);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).