app: log actions upon activation before emitting "selected" signal

In GimpAction, instead of connecting the action-history log
function to the action's "activate" signal as a user-provided
handler, call it directly from the default handler.

In subclasses of GimpAction, chain to the parent's activate()
function before emitting the "selected" signal, so that we always
log the action in the history before responding to it.

This allows us to avoid the hack in commit
6544ce4301.
This commit is contained in:
Ell 2018-07-06 00:00:16 -04:00
parent b4aece8a27
commit 114d49510f
6 changed files with 22 additions and 29 deletions

View File

@ -348,29 +348,18 @@ gimp_action_history_is_excluded_action (const gchar *action_name)
g_strcmp0 (action_name, "filters-reshow") == 0);
}
/* Callback run on the `activate` signal of an action.
* It allows us to log all used action.
/* Called whenever a GimpAction is activated.
* It allows us to log all used actions.
*/
void
gimp_action_history_activate_callback (GtkAction *action,
gpointer user_data)
gimp_action_history_action_activated (GtkAction *action)
{
GimpGuiConfig *config;
const gchar *action_name;
GList *link;
GimpActionHistoryItem *item;
/* we can get here after gimp_action_history_exit() has been called, if
* gimp_exit() was called during the execution of a temporary procedure,
* which was executed in response to a GimpProcedureAction, such as a script-
* fu script (temporary procedures run a nested mainloop, during which
* anything can happen.) the GimpProcedureAction's "selected" signal, in
* response to which the procedure is run, is emitted before any user-
* provided "activate" handlers are invoked, and so this function will be
* called *after* the procedure returns.
*/
if (! history.gimp)
return;
g_return_if_fail (history.gimp != NULL);
config = GIMP_GUI_CONFIG (history.gimp->config);

View File

@ -40,8 +40,7 @@ GList * gimp_action_history_search (Gimp *gimp,
gboolean gimp_action_history_is_blacklisted_action (const gchar *action_name);
gboolean gimp_action_history_is_excluded_action (const gchar *action_name);
void gimp_action_history_activate_callback (GtkAction *action,
gpointer user_data);
void gimp_action_history_action_activated (GtkAction *action);
#endif /* __GIMP_ACTION_HISTORY_H__ */

View File

@ -57,7 +57,6 @@ enum
};
static void gimp_action_constructed (GObject *object);
static void gimp_action_finalize (GObject *object);
static void gimp_action_set_property (GObject *object,
guint prop_id,
@ -68,6 +67,7 @@ static void gimp_action_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void gimp_action_activate (GtkAction *action);
static void gimp_action_connect_proxy (GtkAction *action,
GtkWidget *proxy);
static void gimp_action_set_proxy (GimpAction *action,
@ -91,11 +91,11 @@ gimp_action_class_init (GimpActionClass *klass)
GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
GimpRGB black;
object_class->constructed = gimp_action_constructed;
object_class->finalize = gimp_action_finalize;
object_class->set_property = gimp_action_set_property;
object_class->get_property = gimp_action_get_property;
action_class->activate = gimp_action_activate;
action_class->connect_proxy = gimp_action_connect_proxy;
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
@ -145,16 +145,6 @@ gimp_action_init (GimpAction *action)
NULL);
}
static void
gimp_action_constructed (GObject *object)
{
GimpAction *action = GIMP_ACTION (object);
g_signal_connect (action, "activate",
(GCallback) gimp_action_history_activate_callback,
NULL);
}
static void
gimp_action_finalize (GObject *object)
{
@ -262,6 +252,15 @@ gimp_action_set_property (GObject *object,
}
}
static void
gimp_action_activate (GtkAction *action)
{
if (GTK_ACTION_CLASS (parent_class)->activate)
GTK_ACTION_CLASS (parent_class)->activate (action);
gimp_action_history_action_activated (action);
}
static void
gimp_action_connect_proxy (GtkAction *action,
GtkWidget *proxy)

View File

@ -170,6 +170,8 @@ gimp_enum_action_activate (GtkAction *action)
{
GimpEnumAction *enum_action = GIMP_ENUM_ACTION (action);
GTK_ACTION_CLASS (parent_class)->activate (action);
gimp_enum_action_selected (enum_action, enum_action->value);
}

View File

@ -161,6 +161,8 @@ gimp_procedure_action_activate (GtkAction *action)
{
GimpProcedureAction *procedure_action = GIMP_PROCEDURE_ACTION (action);
GTK_ACTION_CLASS (parent_class)->activate (action);
/* Not all actions have procedures associated with them, for example
* unused "filters-recent-[N]" actions, so check for NULL before we
* invoke the action

View File

@ -175,6 +175,8 @@ gimp_string_action_activate (GtkAction *action)
{
GimpStringAction *string_action = GIMP_STRING_ACTION (action);
GTK_ACTION_CLASS (parent_class)->activate (action);
gimp_string_action_selected (string_action, string_action->value);
}