Revision: 3517
http://geany.svn.sourceforge.net/geany/?rev=3517&view=rev
Author: eht16
Date: 2009-01-27 20:19:43 +0000 (Tue, 27 Jan 2009)
Log Message:
-----------
Add a progressbar widget to the statusbar and use it to show progress when building with the Make commands, when printing and when using Find in Files.
Add progressbar convenience functions and ui_entry_add_clear_icon() to the plugin API.
Modified Paths:
--------------
trunk/ChangeLog
trunk/plugins/geanyfunctions.h
trunk/src/build.c
trunk/src/plugindata.h
trunk/src/plugins.c
trunk/src/printing.c
trunk/src/search.c
trunk/src/ui_utils.c
trunk/src/ui_utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/ChangeLog 2009-01-27 20:19:43 UTC (rev 3517)
@@ -5,6 +5,14 @@
* src/geanyentryaction.c, src/ui_utils.c, src/ui_utils.h:
Add a clear icon to the toolbar search and goto text fields
(will be available with GTK >= 2.16).
+ * plugins/geanyfunctions.h, src/build.c, src/plugindata.h,
+ src/plugins.c, src/printing.c, src/search.c, src/ui_utils.c,
+ src/ui_utils.h:
+ Add a progressbar widget to the statusbar and use it to show progress
+ when building with the Make commands, when printing and when using
+ Find in Files.
+ Add progressbar convenience functions and ui_entry_add_clear_icon()
+ to the plugin API.
2009-01-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/plugins/geanyfunctions.h
===================================================================
--- trunk/plugins/geanyfunctions.h 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/plugins/geanyfunctions.h 2009-01-27 20:19:43 UTC (rev 3517)
@@ -184,6 +184,12 @@
geany_functions->p_ui->image_menu_item_new
#define ui_lookup_widget \
geany_functions->p_ui->lookup_widget
+#define ui_progress_bar_start \
+ geany_functions->p_ui->progress_bar_start
+#define ui_progress_bar_stop \
+ geany_functions->p_ui->progress_bar_stop
+#define ui_entry_add_clear_icon \
+ geany_functions->p_ui->entry_add_clear_icon
#define dialogs_show_question \
geany_functions->p_dialogs->show_question
#define dialogs_show_msgbox \
Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/build.c 2009-01-27 20:19:43 UTC (rev 3517)
@@ -518,6 +518,7 @@
{
g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL);
build_menu_update(doc);
+ ui_progress_bar_start(NULL);
}
/* use GIOChannels to monitor stdout and stderr */
@@ -912,6 +913,7 @@
build_info.pid = 0;
/* enable build items again */
build_menu_update(NULL);
+ ui_progress_bar_stop();
}
Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/plugindata.h 2009-01-27 20:19:43 UTC (rev 3517)
@@ -45,7 +45,7 @@
enum {
/** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */
- GEANY_API_VERSION = 128,
+ GEANY_API_VERSION = 129,
/** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */
@@ -383,6 +383,9 @@
void (*widget_set_tooltip_text) (GtkWidget *widget, const gchar *text);
GtkWidget* (*image_menu_item_new) (const gchar *stock_id, const gchar *label);
GtkWidget* (*lookup_widget) (GtkWidget *widget, const gchar *widget_name);
+ void (*progress_bar_start) (const gchar *text);
+ void (*progress_bar_stop) (void);
+ void (*entry_add_clear_icon) (GtkWidget *entry);
}
UIUtilsFuncs;
Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/plugins.c 2009-01-27 20:19:43 UTC (rev 3517)
@@ -225,7 +225,10 @@
&ui_add_document_sensitive,
&ui_widget_set_tooltip_text,
&ui_image_menu_item_new,
- &ui_lookup_widget
+ &ui_lookup_widget,
+ &ui_progress_bar_start,
+ &ui_progress_bar_stop,
+ &ui_entry_add_clear_icon
};
static DialogFuncs dialog_funcs = {
Modified: trunk/src/printing.c
===================================================================
--- trunk/src/printing.c 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/printing.c 2009-01-27 20:19:43 UTC (rev 3517)
@@ -396,6 +396,7 @@
if (dinfo == NULL)
return;
+ gtk_widget_hide(main_widgets.progressbar);
g_object_unref(dinfo->layout);
}
@@ -410,6 +411,8 @@
if (dinfo == NULL)
return;
+ gtk_widget_show(main_widgets.progressbar);
+
desc = pango_font_description_from_string(interface_prefs.editor_font);
/* init dinfo fields */
@@ -478,6 +481,14 @@
editor = dinfo->doc->editor;
+ if (dinfo->n_pages > 0)
+ {
+ gdouble fraction = (page_nr + 1) / (gdouble) dinfo->n_pages;
+ gchar *text = g_strdup_printf(_("Page %d of %d"), page_nr, dinfo->n_pages);
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), fraction);
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text);
+ }
+
#ifdef GEANY_PRINT_DEBUG
geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d",
page_nr, dinfo->n_pages, dinfo->lines_per_page);
Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/search.c 2009-01-27 20:19:43 UTC (rev 3517)
@@ -1378,6 +1378,8 @@
{
gchar *str, *utf8_str;
+ ui_progress_bar_start(_("Searching..."));
+
g_free(msgwindow.find_in_files_dir);
msgwindow.find_in_files_dir = g_strdup(dir);
/* we can pass 'enc' without strdup'ing it here because it's a global const string and
@@ -1562,6 +1564,7 @@
utils_beep();
g_spawn_close_pid(child_pid);
+ ui_progress_bar_stop();
}
Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/ui_utils.c 2009-01-27 20:19:43 UTC (rev 3517)
@@ -75,6 +75,7 @@
static void update_recent_menu(void);
static void recent_file_loaded(const gchar *utf8_filename);
static void recent_file_activate_cb(GtkMenuItem *menuitem, gpointer user_data);
+static GtkWidget *progress_bar_create(void);
/* simple wrapper for gtk_widget_set_sensitive() to allow widget being NULL */
@@ -1656,6 +1657,8 @@
ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar");
ui_widgets.print_page_setup = ui_lookup_widget(main_widgets.window, "page_setup1");
+ main_widgets.progressbar = progress_bar_create();
+
widgets.popup_goto_items[0] = ui_lookup_widget(main_widgets.editor_menu, "goto_tag_definition1");
widgets.popup_goto_items[1] = ui_lookup_widget(main_widgets.editor_menu, "goto_tag_declaration1");
widgets.popup_goto_items[2] = ui_lookup_widget(main_widgets.editor_menu, "find_usage1");
@@ -1792,3 +1795,73 @@
g_warning("Widget not found: %s", widget_name);
return found_widget;
}
+
+
+
+/* Progress Bar */
+static guint progress_bar_timer_id = (guint) -1;
+
+
+static GtkWidget *progress_bar_create(void)
+{
+ GtkWidget *bar = gtk_progress_bar_new();
+
+ /* Set the progressbar's height to 1 to fit it in the statusbar */
+ gtk_widget_set_size_request(bar, -1, 1);
+ gtk_box_pack_start (GTK_BOX(ui_widgets.statusbar), bar, FALSE, FALSE, 3);
+
+ return bar;
+}
+
+
+static gboolean progress_bar_pulse(gpointer data)
+{
+ gtk_progress_bar_pulse(GTK_PROGRESS_BAR(main_widgets.progressbar));
+
+ return TRUE;
+}
+
+
+/**
+ * Starts a constantly pulsing progressbar in the right corner of the statusbar
+ * (if the statusbar is visible). This is a convenience function which adds a timer to
+ * pulse the progressbar constantly until ui_progress_bar_stop() is called.
+ * You can use this function when you have time consuming asynchronous operation and want to
+ * display some activity in the GUI and when you don't know about detailed progress steps.
+ * The progressbar widget is hidden by default when it is not active. This function and
+ * ui_progress_bar_stop() will show and hide it automatically for you.
+ *
+ * You can also access the progressbar widget directly using @c geany->main_widgets->progressbar
+ * and use the GtkProgressBar API to set discrete fractions to display better progress information.
+ * In this case, you need to show and hide the widget yourself. You can find some example code
+ * in @c src/printing.c.
+ *
+ * @param text The text to be shown as the progress bar label or NULL to leave it empty.
+ */
+void ui_progress_bar_start(const gchar *text)
+{
+ g_return_if_fail(progress_bar_timer_id == (guint) -1);
+
+ if (! interface_prefs.statusbar_visible)
+ return;
+
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text);
+
+ progress_bar_timer_id = g_timeout_add(200, progress_bar_pulse, NULL);
+
+ gtk_widget_show(GTK_WIDGET(main_widgets.progressbar));
+}
+
+
+/** Stops a running progress bar and hides the widget again. */
+void ui_progress_bar_stop(void)
+{
+ gtk_widget_hide(GTK_WIDGET(main_widgets.progressbar));
+
+ if (progress_bar_timer_id != (guint) -1)
+ {
+ g_source_remove(progress_bar_timer_id);
+ progress_bar_timer_id = (guint) -1;
+ }
+}
+
Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h 2009-01-27 19:31:45 UTC (rev 3516)
+++ trunk/src/ui_utils.h 2009-01-27 20:19:43 UTC (rev 3517)
@@ -64,6 +64,9 @@
GtkWidget *notebook; /**< Document notebook. */
GtkWidget *editor_menu; /**< Popup editor menu. */
GtkWidget *tools_menu; /**< Most plugins add menu items to the Tools menu. */
+ GtkWidget *progressbar; /**< Progress bar widget in the status bar to show
+ progress of various actions.
+ See ui_progress_bar_start() for details. */
}
GeanyMainWidgets;
@@ -267,4 +270,8 @@
void ui_update_view_editor_menu_items(void);
+void ui_progress_bar_start(const gchar *text);
+
+void ui_progress_bar_stop(void);
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3516
http://geany.svn.sourceforge.net/geany/?rev=3516&view=rev
Author: eht16
Date: 2009-01-27 19:31:45 +0000 (Tue, 27 Jan 2009)
Log Message:
-----------
Add a clear icon to the toolbar search and goto text fields (will be available with GTK >= 2.16).
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/geanyentryaction.c
trunk/src/ui_utils.c
trunk/src/ui_utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/ChangeLog 2009-01-27 19:31:45 UTC (rev 3516)
@@ -2,6 +2,9 @@
* src/document.c:
Fix legacy file monitoring since I broke once more.
+ * src/geanyentryaction.c, src/ui_utils.c, src/ui_utils.h:
+ Add a clear icon to the toolbar search and goto text fields
+ (will be available with GTK >= 2.16).
2009-01-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/geanyentryaction.c
===================================================================
--- trunk/src/geanyentryaction.c 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/geanyentryaction.c 2009-01-27 19:31:45 UTC (rev 3516)
@@ -26,6 +26,7 @@
#include "geany.h"
#include "support.h"
+#include "ui_utils.h"
#include "geanyentryaction.h"
#include <ctype.h>
@@ -88,7 +89,10 @@
priv->entry = gtk_entry_new();
if (priv->numeric)
- gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 8);
+ gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 9);
+
+ ui_entry_add_clear_icon(priv->entry);
+
gtk_widget_show(priv->entry);
toolitem = g_object_new(GTK_TYPE_TOOL_ITEM, NULL);
Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/ui_utils.c 2009-01-27 19:31:45 UTC (rev 3516)
@@ -1178,6 +1178,34 @@
}
+static void entry_clear_icon_press_cb(GtkEntry *entry, gint icon_pos, GdkEvent *event, gpointer data)
+{
+ if (event->button.button == 1 && icon_pos == 1)
+ {
+ gtk_entry_set_text(entry, "");
+ }
+}
+
+
+/** Convenience function to add a small clear icon to the right end of the passed @a entry.
+ * A callback to clear the contents of the GtkEntry is automatically added.
+ *
+ * This feature is only available with GTK 2.16 but implemented as a runtime check,
+ * so it is safe to just use this function, if the code is ran with older versions,
+ * nothing happens. If ran with GTK 2.16 or newer, the icon is displayed.
+ *
+ * @param entry The GtkEntry object to which the icon should be attached.
+ */
+void ui_entry_add_clear_icon(GtkWidget *entry)
+{
+ if (gtk_check_version(2, 15, 2) == NULL)
+ {
+ g_object_set(entry, "secondary-icon-stock", "gtk-clear", NULL);
+ g_signal_connect(entry, "icon-press", G_CALLBACK(entry_clear_icon_press_cb), NULL);
+ }
+}
+
+
static void add_to_size_group(GtkWidget *widget, gpointer size_group)
{
g_return_if_fail(GTK_IS_SIZE_GROUP(size_group));
Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/ui_utils.h 2009-01-27 19:31:45 UTC (rev 3516)
@@ -185,6 +185,8 @@
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
+void ui_entry_add_clear_icon(GtkWidget *entry);
+
/* End of 'generic' functions */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.