mirror of https://github.com/GNOME/gimp.git
app: more cleanup in the action history code, mostly general consistency
This commit is contained in:
parent
7149a5ac6c
commit
50ca9068da
|
@ -65,7 +65,7 @@ typedef struct
|
|||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
GimpGuiConfig *config;
|
||||
Gimp *gimp;
|
||||
GtkWidget *keyword_entry;
|
||||
GtkWidget *results_list;
|
||||
GtkWidget *list_view;
|
||||
|
@ -122,16 +122,15 @@ action_search_dialog_create (Gimp *gimp)
|
|||
|
||||
if (! private)
|
||||
{
|
||||
GtkWidget *action_search_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);
|
||||
GtkWidget *main_vbox;
|
||||
GtkWidget *action_search_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget *main_vbox;
|
||||
|
||||
private = g_slice_new0 (SearchDialog);
|
||||
g_object_weak_ref (G_OBJECT (action_search_dialog),
|
||||
(GWeakNotify) search_dialog_free, private);
|
||||
|
||||
private->dialog = action_search_dialog;
|
||||
private->config = config;
|
||||
private->gimp = gimp;
|
||||
|
||||
gtk_window_set_role (GTK_WINDOW (action_search_dialog),
|
||||
"gimp-action-search-dialog");
|
||||
|
@ -537,9 +536,9 @@ action_search_history_and_actions (const gchar *keyword,
|
|||
if (g_strcmp0 (keyword, "") == 0)
|
||||
return;
|
||||
|
||||
history_actions = gimp_action_history_search (keyword,
|
||||
history_actions = gimp_action_history_search (private->gimp,
|
||||
action_search_match_keyword,
|
||||
private->config);
|
||||
keyword);
|
||||
|
||||
/* First put on top of the list any matching action of user history. */
|
||||
for (list = history_actions; list; list = g_list_next (list))
|
||||
|
@ -581,7 +580,7 @@ action_search_history_and_actions (const gchar *keyword,
|
|||
continue;
|
||||
|
||||
if (! gtk_action_is_sensitive (action) &&
|
||||
! private->config->search_show_unavailable)
|
||||
! GIMP_GUI_CONFIG (private->gimp->config)->search_show_unavailable)
|
||||
continue;
|
||||
|
||||
if (action_search_match_keyword (action, keyword, §ion, TRUE))
|
||||
|
|
|
@ -114,8 +114,8 @@ static void prefs_devices_save_callback (GtkWidget *widget,
|
|||
Gimp *gimp);
|
||||
static void prefs_devices_clear_callback (GtkWidget *widget,
|
||||
Gimp *gimp);
|
||||
static void prefs_search_empty_callback (GtkWidget *widget,
|
||||
gpointer user_data);
|
||||
static void prefs_search_clear_callback (GtkWidget *widget,
|
||||
Gimp *gimp);
|
||||
static void prefs_tool_options_save_callback (GtkWidget *widget,
|
||||
Gimp *gimp);
|
||||
static void prefs_tool_options_clear_callback (GtkWidget *widget,
|
||||
|
@ -653,10 +653,10 @@ prefs_devices_clear_callback (GtkWidget *widget,
|
|||
}
|
||||
|
||||
static void
|
||||
prefs_search_empty_callback (GtkWidget *widget,
|
||||
gpointer user_data)
|
||||
prefs_search_clear_callback (GtkWidget *widget,
|
||||
Gimp *gimp)
|
||||
{
|
||||
gimp_action_history_empty ();
|
||||
gimp_action_history_clear (gimp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1647,8 +1647,8 @@ prefs_dialog_new (Gimp *gimp,
|
|||
_("Clear Action History"),
|
||||
GTK_BOX (vbox2));
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (prefs_search_empty_callback),
|
||||
NULL);
|
||||
G_CALLBACK (prefs_search_clear_callback),
|
||||
gimp);
|
||||
|
||||
g_object_unref (size_group);
|
||||
size_group = NULL;
|
||||
|
|
|
@ -520,7 +520,8 @@ gui_restore_after_callback (Gimp *gimp,
|
|||
gimp,
|
||||
gui_config->tearoff_menus);
|
||||
gimp_ui_manager_update (image_ui_manager, gimp);
|
||||
gimp_action_history_init (gui_config);
|
||||
|
||||
gimp_action_history_init (gimp);
|
||||
|
||||
#ifdef GDK_WINDOWING_QUARTZ
|
||||
{
|
||||
|
@ -697,7 +698,7 @@ gui_exit_after_callback (Gimp *gimp,
|
|||
gui_show_tooltips_notify,
|
||||
gimp);
|
||||
|
||||
gimp_action_history_exit (GIMP_GUI_CONFIG (gimp->config));
|
||||
gimp_action_history_exit (gimp);
|
||||
|
||||
g_object_unref (image_ui_manager);
|
||||
image_ui_manager = NULL;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "config/gimpguiconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
|
||||
#include "gimpuimanager.h"
|
||||
#include "gimpaction.h"
|
||||
#include "gimpaction-history.h"
|
||||
|
@ -70,8 +72,9 @@ static gint gimp_action_history_compare_func (GimpActionHistoryItem *a,
|
|||
/* public functions */
|
||||
|
||||
void
|
||||
gimp_action_history_init (GimpGuiConfig *config)
|
||||
gimp_action_history_init (Gimp *gimp)
|
||||
{
|
||||
GimpGuiConfig *config;
|
||||
GimpUIManager *manager;
|
||||
GFile *file;
|
||||
GScanner *scanner;
|
||||
|
@ -79,6 +82,10 @@ gimp_action_history_init (GimpGuiConfig *config)
|
|||
gint count;
|
||||
gint n_items = 0;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
|
||||
config = GIMP_GUI_CONFIG (gimp->config);
|
||||
|
||||
if (history.items != NULL)
|
||||
{
|
||||
g_warning ("%s: must be run only once.", G_STRFUNC);
|
||||
|
@ -179,8 +186,9 @@ gimp_action_history_init (GimpGuiConfig *config)
|
|||
}
|
||||
|
||||
void
|
||||
gimp_action_history_exit (GimpGuiConfig *config)
|
||||
gimp_action_history_exit (Gimp *gimp)
|
||||
{
|
||||
GimpGuiConfig *config;
|
||||
GimpActionHistoryItem *item;
|
||||
GList *actions;
|
||||
GFile *file;
|
||||
|
@ -188,6 +196,10 @@ gimp_action_history_exit (GimpGuiConfig *config)
|
|||
gint min_count = 0;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
|
||||
config = GIMP_GUI_CONFIG (gimp->config);
|
||||
|
||||
/* If we have more items than current history size, trim the history
|
||||
* and move down all count so that 1 is lower.
|
||||
*/
|
||||
|
@ -214,7 +226,56 @@ gimp_action_history_exit (GimpGuiConfig *config)
|
|||
|
||||
gimp_config_writer_finish (writer, "end of action-history", NULL);
|
||||
|
||||
gimp_action_history_empty ();
|
||||
gimp_action_history_clear (gimp);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_history_clear (Gimp *gimp)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
|
||||
g_list_free_full (history.items,
|
||||
(GDestroyNotify) gimp_action_history_item_free);
|
||||
history.items = NULL;
|
||||
}
|
||||
|
||||
/* Search all history actions which match "keyword" with function
|
||||
* match_func(action, keyword).
|
||||
*
|
||||
* @return a list of GtkAction*, to free with:
|
||||
* g_list_free_full (result, (GDestroyNotify) g_object_unref);
|
||||
*/
|
||||
GList *
|
||||
gimp_action_history_search (Gimp *gimp,
|
||||
GimpActionMatchFunc match_func,
|
||||
const gchar *keyword)
|
||||
{
|
||||
GimpGuiConfig *config;
|
||||
GList *actions;
|
||||
GList *result = NULL;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (match_func != NULL, NULL);
|
||||
|
||||
config = GIMP_GUI_CONFIG (gimp->config);
|
||||
|
||||
for (actions = history.items, i = 0;
|
||||
actions && i < config->action_history_size;
|
||||
actions = g_list_next (actions), i++)
|
||||
{
|
||||
GimpActionHistoryItem *item = actions->data;
|
||||
GtkAction *action = item->action;
|
||||
|
||||
if (! gtk_action_is_sensitive (action) &&
|
||||
! config->search_show_unavailable)
|
||||
continue;
|
||||
|
||||
if (match_func (action, keyword, NULL, FALSE))
|
||||
result = g_list_prepend (result, g_object_ref (action));
|
||||
}
|
||||
|
||||
return g_list_reverse (result);
|
||||
}
|
||||
|
||||
/* gimp_action_history_excluded_action:
|
||||
|
@ -310,47 +371,6 @@ gimp_action_history_activate_callback (GtkAction *action,
|
|||
(GCompareFunc) gimp_action_history_compare_func);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_history_empty (void)
|
||||
{
|
||||
g_list_free_full (history.items,
|
||||
(GDestroyNotify) gimp_action_history_item_free);
|
||||
history.items = NULL;
|
||||
}
|
||||
|
||||
/* Search all history actions which match "keyword" with function
|
||||
* match_func(action, keyword).
|
||||
*
|
||||
* @return a list of GtkAction*, to free with:
|
||||
* g_list_free_full (result, (GDestroyNotify) g_object_unref);
|
||||
*/
|
||||
GList *
|
||||
gimp_action_history_search (const gchar *keyword,
|
||||
GimpActionMatchFunc match_func,
|
||||
GimpGuiConfig *config)
|
||||
{
|
||||
GList *actions;
|
||||
GList *result = NULL;
|
||||
gint i;
|
||||
|
||||
for (actions = history.items, i = 0;
|
||||
actions && i < config->action_history_size;
|
||||
actions = g_list_next (actions), i++)
|
||||
{
|
||||
GimpActionHistoryItem *item = actions->data;
|
||||
GtkAction *action = item->action;
|
||||
|
||||
if (! gtk_action_is_sensitive (action) &&
|
||||
! config->search_show_unavailable)
|
||||
continue;
|
||||
|
||||
if (match_func (action, keyword, NULL, FALSE))
|
||||
result = g_list_prepend (result, g_object_ref (action));
|
||||
}
|
||||
|
||||
return g_list_reverse (result);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
|
|
|
@ -21,23 +21,26 @@
|
|||
#ifndef __GIMP_ACTION_HISTORY_H__
|
||||
#define __GIMP_ACTION_HISTORY_H__
|
||||
|
||||
typedef gboolean (* GimpActionMatchFunc) (GtkAction *action,
|
||||
const gchar *keyword,
|
||||
gint *section,
|
||||
gboolean match_fuzzy);
|
||||
|
||||
void gimp_action_history_init (GimpGuiConfig *config);
|
||||
void gimp_action_history_exit (GimpGuiConfig *config);
|
||||
typedef gboolean (* GimpActionMatchFunc) (GtkAction *action,
|
||||
const gchar *keyword,
|
||||
gint *section,
|
||||
gboolean match_fuzzy);
|
||||
|
||||
|
||||
void gimp_action_history_init (Gimp *gimp);
|
||||
void gimp_action_history_exit (Gimp *gimp);
|
||||
|
||||
void gimp_action_history_clear (Gimp *gimp);
|
||||
|
||||
GList * gimp_action_history_search (Gimp *gimp,
|
||||
GimpActionMatchFunc match_func,
|
||||
const gchar *keyword);
|
||||
|
||||
gboolean gimp_action_history_excluded_action (const gchar *action_name);
|
||||
|
||||
void gimp_action_history_activate_callback (GtkAction *action,
|
||||
gpointer user_data);
|
||||
|
||||
void gimp_action_history_empty (void);
|
||||
|
||||
GList * gimp_action_history_search (const gchar *keyword,
|
||||
GimpActionMatchFunc match_func,
|
||||
GimpGuiConfig *config);
|
||||
|
||||
gboolean gimp_action_history_excluded_action (const gchar *action_name);
|
||||
|
||||
#endif /* __GIMP_ACTION_HISTORY_H__ */
|
||||
|
|
Loading…
Reference in New Issue