GtkShortcutScope scope;
GdkModifierType mnemonics_modifiers;
+ guint custom_shortcuts : 1;
guint run_class : 1;
guint run_managed : 1;
};
enum {
PROP_0,
PROP_MNEMONICS_MODIFIERS,
+ PROP_MODEL,
PROP_SCOPE,
N_PROPS
gtk_shortcut_controller_set_mnemonics_modifiers (self, g_value_get_flags (value));
break;
+ case PROP_MODEL:
+ {
+ GListModel *model = g_value_get_object (value);
+ if (model && g_list_model_get_item_type (model) != GTK_TYPE_SHORTCUT)
+ {
+ g_warning ("Setting a model with type '%s' on a shortcut controller that requires 'GtkShortcut'",
+ g_type_name (g_list_model_get_item_type (model)));
+ model = NULL;
+ }
+ if (model == NULL)
+ {
+ self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
+ self->custom_shortcuts = TRUE;
+ }
+ else
+ {
+ self->shortcuts = g_object_ref (model);
+ self->custom_shortcuts = FALSE;
+ }
+ g_signal_connect_swapped (self->shortcuts, "items-changed", G_CALLBACK (g_list_model_items_changed), self);
+ }
+ break;
+
case PROP_SCOPE:
gtk_shortcut_controller_set_scope (self, g_value_get_enum (value));
break;
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
- g_list_store_remove_all (G_LIST_STORE (self->shortcuts));
+ if (self->custom_shortcuts)
+ g_list_store_remove_all (G_LIST_STORE (self->shortcuts));
G_OBJECT_CLASS (gtk_shortcut_controller_parent_class)->dispose (object);
}
GDK_MOD1_MASK,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GtkShortcutController:model:
+ *
+ * A list model to take shortcuts from
+ */
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model",
+ P_("Model"),
+ P_("A list model to take shortcuts from"),
+ G_TYPE_LIST_MODEL,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
/**
* GtkShortcutController:scope:
*
gtk_shortcut_controller_init (GtkShortcutController *self)
{
self->mnemonics_modifiers = GDK_MOD1_MASK;
-
- self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
- g_signal_connect_swapped (self->shortcuts, "items-changed", G_CALLBACK (g_list_model_items_changed), self);
}
void
NULL);
}
+GtkEventController *
+gtk_shortcut_controller_new_for_model (GListModel *model)
+{
+ g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (g_list_model_get_item_type (model) == GTK_TYPE_SHORTCUT, NULL);
+
+ return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
+ "model", model,
+ NULL);
+}
+
void
gtk_shortcut_controller_set_run_class (GtkShortcutController *controller,
gboolean run_class)
*
* Adds @shortcut to the list of shortcuts handled by @self.
*
+ * If this controller uses an external shortcut list, this function does
+ * nothing.
+ *
* The shortcut is added to the list so that it is triggered before
* all existing shortcuts.
*
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
g_return_if_fail (GTK_IS_SHORTCUT (shortcut));
+ if (!self->custom_shortcuts)
+ return;
+
g_list_store_append (G_LIST_STORE (self->shortcuts), shortcut);
}
*
* Removes @shortcut from the list of shortcuts handled by @self.
*
- * If @shortcut had not been added to @controller, this function does
- * nothing.
+ * If @shortcut had not been added to @controller or this controller
+ * uses an external shortcut list, this function does nothing.
**/
void
gtk_shortcut_controller_remove_shortcut (GtkShortcutController *self,
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
g_return_if_fail (GTK_IS_SHORTCUT (shortcut));
+ if (!self->custom_shortcuts)
+ return;
+
for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
{
GtkShortcut *item = g_list_model_get_item (self->shortcuts, i);