[gtk/wip/matthiasc/shortcut-2: 72/88] shortcuts: Use a flatten list model
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shortcut-2: 72/88] shortcuts: Use a flatten list model
- Date: Tue, 24 Mar 2020 04:21:27 +0000 (UTC)
commit 411e9cdf56a8292262d7cc9f68bc380ce51c0155
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 22 13:47:37 2020 -0400
shortcuts: Use a flatten list model
gtk/gtkshortcutcontroller.c | 6 +++---
gtk/gtkshortcutmanager.c | 43 ++++++++++++++++++++++++++++++-------------
2 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index b17b5f0d75..46961ce9ba 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -35,7 +35,7 @@
#include "gtkshortcutcontrollerprivate.h"
#include "gtkbuildable.h"
-#include "gtkconcatmodelprivate.h"
+#include "gtkflattenlistmodel.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkintl.h"
#include "gtkshortcut.h"
@@ -252,9 +252,9 @@ gtk_shortcut_controller_trigger_shortcut (GtkShortcutController *self,
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (!self->custom_shortcuts &&
- GTK_IS_CONCAT_MODEL (self->shortcuts))
+ GTK_IS_FLATTEN_LIST_MODEL (self->shortcuts))
{
- GListModel *model = gtk_concat_model_get_model_for_item (GTK_CONCAT_MODEL (self->shortcuts), position);
+ GListModel *model = gtk_flatten_list_model_get_model_for_item (GTK_FLATTEN_LIST_MODEL
(self->shortcuts), position);
if (GTK_IS_SHORTCUT_CONTROLLER (model))
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (model));
}
diff --git a/gtk/gtkshortcutmanager.c b/gtk/gtkshortcutmanager.c
index 64fdd7ba8e..625e594d84 100644
--- a/gtk/gtkshortcutmanager.c
+++ b/gtk/gtkshortcutmanager.c
@@ -21,7 +21,7 @@
#include "gtkshortcutmanager.h"
#include "gtkshortcutmanagerprivate.h"
-#include "gtkconcatmodelprivate.h"
+#include "gtkflattenlistmodel.h"
/**
* SECTION:gtkshortcutmanager
@@ -37,16 +37,21 @@ G_DEFINE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, G_TYPE_OBJECT)
void
gtk_shortcut_manager_create_controllers (GtkWidget *widget)
{
- GtkConcatModel *model;
+ GListStore *store;
+ GtkFlattenListModel *model;
GtkEventController *controller;
- model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
+ store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
+ model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
+ g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-bubble");
gtk_widget_add_controller (widget, controller);
- model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
+ store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
+ model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
+ g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-capture");
@@ -54,7 +59,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget)
gtk_widget_add_controller (widget, controller);
}
-static GtkConcatModel *
+static GtkFlattenListModel *
gtk_shortcut_manager_get_model (GtkShortcutManager *self,
GtkPropagationPhase phase)
{
@@ -77,24 +82,36 @@ static void
gtk_shortcut_manager_default_add_controller (GtkShortcutManager *self,
GtkShortcutController *controller)
{
- GtkConcatModel *model;
+ GtkFlattenListModel *model;
+ GtkPropagationPhase phase;
- model = gtk_shortcut_manager_get_model (self,
- gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER
(controller)));
+ phase = gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER (controller));
+ model = gtk_shortcut_manager_get_model (self, phase);
if (model)
- gtk_concat_model_append (model, G_LIST_MODEL (controller));
+ {
+ GListModel *store = gtk_flatten_list_model_get_model (model);
+ g_list_store_append (G_LIST_STORE (store), controller);
+ }
}
static void
gtk_shortcut_manager_default_remove_controller (GtkShortcutManager *self,
GtkShortcutController *controller)
{
- GtkConcatModel *model;
+ GtkFlattenListModel *model;
+ GtkPropagationPhase phase;
- model = gtk_shortcut_manager_get_model (self,
- gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER
(controller)));
+ phase = gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER (controller));
+ model = gtk_shortcut_manager_get_model (self, phase);
if (model)
- gtk_concat_model_remove (model, G_LIST_MODEL (controller));
+ {
+ GListModel *store;
+ guint position;
+
+ store = gtk_flatten_list_model_get_model (model);
+ if (g_list_store_find (G_LIST_STORE (store), controller, &position))
+ g_list_store_remove (G_LIST_STORE (store), position);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]