Kaydet (Commit) 644a9cfb authored tarafından Enrico Tröger's avatar Enrico Tröger

Add a progressbar widget to the statusbar and use it to show progress when…

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.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3517 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst a20ee7d8
...@@ -5,6 +5,14 @@ ...@@ -5,6 +5,14 @@
* src/geanyentryaction.c, src/ui_utils.c, src/ui_utils.h: * src/geanyentryaction.c, src/ui_utils.c, src/ui_utils.h:
Add a clear icon to the toolbar search and goto text fields Add a clear icon to the toolbar search and goto text fields
(will be available with GTK >= 2.16). (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> 2009-01-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
......
...@@ -184,6 +184,12 @@ ...@@ -184,6 +184,12 @@
geany_functions->p_ui->image_menu_item_new geany_functions->p_ui->image_menu_item_new
#define ui_lookup_widget \ #define ui_lookup_widget \
geany_functions->p_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 \ #define dialogs_show_question \
geany_functions->p_dialogs->show_question geany_functions->p_dialogs->show_question
#define dialogs_show_msgbox \ #define dialogs_show_msgbox \
......
...@@ -518,6 +518,7 @@ static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *d ...@@ -518,6 +518,7 @@ static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *d
{ {
g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL); g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL);
build_menu_update(doc); build_menu_update(doc);
ui_progress_bar_start(NULL);
} }
/* use GIOChannels to monitor stdout and stderr */ /* use GIOChannels to monitor stdout and stderr */
...@@ -912,6 +913,7 @@ static void build_exit_cb(GPid child_pid, gint status, gpointer user_data) ...@@ -912,6 +913,7 @@ static void build_exit_cb(GPid child_pid, gint status, gpointer user_data)
build_info.pid = 0; build_info.pid = 0;
/* enable build items again */ /* enable build items again */
build_menu_update(NULL); build_menu_update(NULL);
ui_progress_bar_stop();
} }
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
enum { enum {
/** The Application Programming Interface (API) version, incremented /** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */ * 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 /** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */ * existing fields in the plugin data types have to be changed or reordered. */
...@@ -383,6 +383,9 @@ typedef struct UIUtilsFuncs ...@@ -383,6 +383,9 @@ typedef struct UIUtilsFuncs
void (*widget_set_tooltip_text) (GtkWidget *widget, const gchar *text); void (*widget_set_tooltip_text) (GtkWidget *widget, const gchar *text);
GtkWidget* (*image_menu_item_new) (const gchar *stock_id, const gchar *label); GtkWidget* (*image_menu_item_new) (const gchar *stock_id, const gchar *label);
GtkWidget* (*lookup_widget) (GtkWidget *widget, const gchar *widget_name); 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; UIUtilsFuncs;
......
...@@ -225,7 +225,10 @@ static UIUtilsFuncs uiutils_funcs = { ...@@ -225,7 +225,10 @@ static UIUtilsFuncs uiutils_funcs = {
&ui_add_document_sensitive, &ui_add_document_sensitive,
&ui_widget_set_tooltip_text, &ui_widget_set_tooltip_text,
&ui_image_menu_item_new, &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 = { static DialogFuncs dialog_funcs = {
......
...@@ -396,6 +396,7 @@ static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gp ...@@ -396,6 +396,7 @@ static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gp
if (dinfo == NULL) if (dinfo == NULL)
return; return;
gtk_widget_hide(main_widgets.progressbar);
g_object_unref(dinfo->layout); g_object_unref(dinfo->layout);
} }
...@@ -410,6 +411,8 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, ...@@ -410,6 +411,8 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
if (dinfo == NULL) if (dinfo == NULL)
return; return;
gtk_widget_show(main_widgets.progressbar);
desc = pango_font_description_from_string(interface_prefs.editor_font); desc = pango_font_description_from_string(interface_prefs.editor_font);
/* init dinfo fields */ /* init dinfo fields */
...@@ -478,6 +481,14 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, ...@@ -478,6 +481,14 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
editor = dinfo->doc->editor; 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 #ifdef GEANY_PRINT_DEBUG
geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d", geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d",
page_nr, dinfo->n_pages, dinfo->lines_per_page); page_nr, dinfo->n_pages, dinfo->lines_per_page);
......
...@@ -1378,6 +1378,8 @@ search_find_in_files(const gchar *utf8_search_text, const gchar *dir, const gcha ...@@ -1378,6 +1378,8 @@ search_find_in_files(const gchar *utf8_search_text, const gchar *dir, const gcha
{ {
gchar *str, *utf8_str; gchar *str, *utf8_str;
ui_progress_bar_start(_("Searching..."));
g_free(msgwindow.find_in_files_dir); g_free(msgwindow.find_in_files_dir);
msgwindow.find_in_files_dir = g_strdup(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 /* we can pass 'enc' without strdup'ing it here because it's a global const string and
...@@ -1562,6 +1564,7 @@ static void search_close_pid(GPid child_pid, gint status, gpointer user_data) ...@@ -1562,6 +1564,7 @@ static void search_close_pid(GPid child_pid, gint status, gpointer user_data)
utils_beep(); utils_beep();
g_spawn_close_pid(child_pid); g_spawn_close_pid(child_pid);
ui_progress_bar_stop();
} }
......
...@@ -75,6 +75,7 @@ widgets; ...@@ -75,6 +75,7 @@ widgets;
static void update_recent_menu(void); static void update_recent_menu(void);
static void recent_file_loaded(const gchar *utf8_filename); static void recent_file_loaded(const gchar *utf8_filename);
static void recent_file_activate_cb(GtkMenuItem *menuitem, gpointer user_data); 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 */ /* simple wrapper for gtk_widget_set_sensitive() to allow widget being NULL */
...@@ -1656,6 +1657,8 @@ void ui_init(void) ...@@ -1656,6 +1657,8 @@ void ui_init(void)
ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar"); ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar");
ui_widgets.print_page_setup = ui_lookup_widget(main_widgets.window, "page_setup1"); 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[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[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"); widgets.popup_goto_items[2] = ui_lookup_widget(main_widgets.editor_menu, "find_usage1");
...@@ -1792,3 +1795,73 @@ GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name) ...@@ -1792,3 +1795,73 @@ GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
g_warning("Widget not found: %s", widget_name); g_warning("Widget not found: %s", widget_name);
return found_widget; 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;
}
}
...@@ -64,6 +64,9 @@ typedef struct GeanyMainWidgets ...@@ -64,6 +64,9 @@ typedef struct GeanyMainWidgets
GtkWidget *notebook; /**< Document notebook. */ GtkWidget *notebook; /**< Document notebook. */
GtkWidget *editor_menu; /**< Popup editor menu. */ GtkWidget *editor_menu; /**< Popup editor menu. */
GtkWidget *tools_menu; /**< Most plugins add menu items to the Tools 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; GeanyMainWidgets;
...@@ -267,4 +270,8 @@ void ui_toggle_editor_features(GeanyUIEditorFeatures feature); ...@@ -267,4 +270,8 @@ void ui_toggle_editor_features(GeanyUIEditorFeatures feature);
void ui_update_view_editor_menu_items(void); void ui_update_view_editor_menu_items(void);
void ui_progress_bar_start(const gchar *text);
void ui_progress_bar_stop(void);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment