[gnome-builder] greeter: add delete-selection API
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] greeter: add delete-selection API
- Date: Sat, 18 Nov 2017 06:18:44 +0000 (UTC)
commit 386a59f26fd5b3556bc2719e96baf38530d31fb2
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 17 22:14:36 2017 -0800
greeter: add delete-selection API
This allows the selections to be deleted when the delete button
is activated.
src/libide/greeter/ide-greeter-perspective.c | 18 +++++++++++
src/libide/greeter/ide-greeter-section.c | 9 +++++
src/libide/greeter/ide-greeter-section.h | 3 ++
src/plugins/recent/gbp-recent-section.c | 42 ++++++++++++++++++++++++++
4 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/greeter/ide-greeter-perspective.c b/src/libide/greeter/ide-greeter-perspective.c
index 08d0763..bed12ae 100644
--- a/src/libide/greeter/ide-greeter-perspective.c
+++ b/src/libide/greeter/ide-greeter-perspective.c
@@ -1042,6 +1042,21 @@ ide_greeter_perspective_constructed (GObject *object)
}
static void
+delete_selected_rows_cb (PeasExtensionSet *set,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ IdeGreeterSection *section = (IdeGreeterSection *)exten;
+
+ g_assert (PEAS_IS_EXTENSION_SET (set));
+ g_assert (plugin_info != NULL);
+ g_assert (IDE_IS_GREETER_SECTION (section));
+
+ ide_greeter_section_delete_selected (section);
+}
+
+static void
delete_selected_rows (GSimpleAction *simple,
GVariant *param,
gpointer user_data)
@@ -1052,6 +1067,9 @@ delete_selected_rows (GSimpleAction *simple,
g_assert (IDE_IS_GREETER_PERSPECTIVE (self));
+ peas_extension_set_foreach (self->sections, delete_selected_rows_cb, NULL);
+ dzl_state_machine_set_state (self->state_machine, "browse");
+
IDE_EXIT;
}
diff --git a/src/libide/greeter/ide-greeter-section.c b/src/libide/greeter/ide-greeter-section.c
index 3168c05..c9a7797 100644
--- a/src/libide/greeter/ide-greeter-section.c
+++ b/src/libide/greeter/ide-greeter-section.c
@@ -150,3 +150,12 @@ ide_greeter_section_set_selection_mode (IdeGreeterSection *self,
if (IDE_GREETER_SECTION_GET_IFACE (self)->set_selection_mode)
IDE_GREETER_SECTION_GET_IFACE (self)->set_selection_mode (self, selection_mode);
}
+
+void
+ide_greeter_section_delete_selected (IdeGreeterSection *self)
+{
+ g_assert (IDE_IS_GREETER_SECTION (self));
+
+ if (IDE_GREETER_SECTION_GET_IFACE (self)->delete_selected)
+ IDE_GREETER_SECTION_GET_IFACE (self)->delete_selected (self);
+}
diff --git a/src/libide/greeter/ide-greeter-section.h b/src/libide/greeter/ide-greeter-section.h
index d9a959c..1c66565 100644
--- a/src/libide/greeter/ide-greeter-section.h
+++ b/src/libide/greeter/ide-greeter-section.h
@@ -42,6 +42,7 @@ struct _IdeGreeterSectionInterface
gboolean (*activate_first) (IdeGreeterSection *self);
void (*set_selection_mode) (IdeGreeterSection *self,
gboolean selection_mode);
+ void (*delete_selected) (IdeGreeterSection *self);
};
IDE_AVAILABLE_IN_3_28
@@ -57,5 +58,7 @@ gboolean ide_greeter_section_activate_first (IdeGreeterSection *self);
IDE_AVAILABLE_IN_3_28
void ide_greeter_section_set_selection_mode (IdeGreeterSection *self,
gboolean selection_mode);
+IDE_AVAILABLE_IN_3_28
+void ide_greeter_section_delete_selected (IdeGreeterSection *self);
G_END_DECLS
diff --git a/src/plugins/recent/gbp-recent-section.c b/src/plugins/recent/gbp-recent-section.c
index 2d96de9..e27782c 100644
--- a/src/plugins/recent/gbp-recent-section.c
+++ b/src/plugins/recent/gbp-recent-section.c
@@ -196,12 +196,54 @@ gbp_recent_section_set_selection_mode (IdeGreeterSection *section,
}
static void
+gbp_recent_section_delete_selected_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ GbpRecentProjectRow *row = (GbpRecentProjectRow *)widget;
+ GList **list = user_data;
+ gboolean selected = FALSE;
+
+ g_assert (GBP_IS_RECENT_PROJECT_ROW (row));
+ g_assert (list != NULL);
+
+ g_object_get (row, "selected", &selected, NULL);
+
+ if (selected)
+ {
+ IdeProjectInfo *project_info;
+
+ project_info = gbp_recent_project_row_get_project_info (row);
+ *list = g_list_prepend (*list, g_object_ref (project_info));
+ gtk_widget_destroy (GTK_WIDGET (row));
+ }
+}
+
+static void
+gbp_recent_section_delete_selected (IdeGreeterSection *section)
+{
+ GbpRecentSection *self = (GbpRecentSection *)section;
+ IdeRecentProjects *projects;
+ GList *infos = NULL;
+
+ g_assert (GBP_IS_RECENT_SECTION (self));
+
+ gtk_container_foreach (GTK_CONTAINER (self->listbox),
+ gbp_recent_section_delete_selected_cb,
+ &infos);
+
+ projects = ide_application_get_recent_projects (IDE_APPLICATION_DEFAULT);
+ ide_recent_projects_remove (projects, infos);
+ g_list_free_full (infos, g_object_unref);
+}
+
+static void
greeter_section_iface_init (IdeGreeterSectionInterface *iface)
{
iface->get_priority = gbp_recent_section_get_priority;
iface->filter = gbp_recent_section_filter;
iface->activate_first = gbp_recent_section_activate_first;
iface->set_selection_mode = gbp_recent_section_set_selection_mode;
+ iface->delete_selected = gbp_recent_section_delete_selected;
}
G_DEFINE_TYPE_WITH_CODE (GbpRecentSection, gbp_recent_section, GTK_TYPE_BIN,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]