[gnome-builder] tree: move tree actions into their own module
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: move tree actions into their own module
- Date: Thu, 9 Apr 2015 00:09:56 +0000 (UTC)
commit 8dad746c290cd7f6eb90b13105b552436c73e233
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 8 13:59:17 2015 -0700
tree: move tree actions into their own module
src/editor/gb-editor-workspace-actions.c | 152 ------------------------
src/editor/gb-editor-workspace.c | 2 +
src/editor/gb-project-tree-actions.c | 186 ++++++++++++++++++++++++++++++
src/editor/gb-project-tree-actions.h | 30 +++++
src/gnome-builder.mk | 2 +
5 files changed, 220 insertions(+), 152 deletions(-)
---
diff --git a/src/editor/gb-editor-workspace-actions.c b/src/editor/gb-editor-workspace-actions.c
index e077ade..08cae57 100644
--- a/src/editor/gb-editor-workspace-actions.c
+++ b/src/editor/gb-editor-workspace-actions.c
@@ -83,170 +83,18 @@ gb_editor_workspace_actions_toggle_sidebar (GSimpleAction *action,
g_variant_unref (state);
}
-static void
-gb_editor_workspace_tree_actions_refresh (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GbEditorWorkspace *self = user_data;
-
- g_assert (GB_IS_EDITOR_WORKSPACE (self));
-
- gb_tree_rebuild (self->project_tree);
-
- /* TODO: Try to expand back to our current position */
-}
-
-static void
-gb_editor_workspace_tree_actions_collapse_all_nodes (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GbEditorWorkspace *self = user_data;
-
- g_assert (GB_IS_EDITOR_WORKSPACE (self));
-
- gtk_tree_view_collapse_all (GTK_TREE_VIEW (self->project_tree));
-}
-
-static void
-gb_editor_workspace_tree_actions_open (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GbEditorWorkspace *self = user_data;
- GbTreeNode *selected;
- GObject *item;
-
- g_assert (GB_IS_EDITOR_WORKSPACE (self));
-
- if (!(selected = gb_tree_get_selected (self->project_tree)) ||
- !(item = gb_tree_node_get_item (selected)))
- return;
-
- item = gb_tree_node_get_item (selected);
-
- if (IDE_IS_PROJECT_FILE (item))
- {
- GbWorkbench *workbench;
- GFileInfo *file_info;
- GFile *file;
-
- file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
- if (!file_info)
- return;
-
- if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
- return;
-
- file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
- if (!file)
- return;
-
- workbench = gb_widget_get_workbench (GTK_WIDGET (self));
- gb_workbench_open (workbench, file);
- }
-}
-
-static void
-gb_editor_workspace_tree_actions_open_with_editor (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GbEditorWorkspace *self = user_data;
- GbTreeNode *selected;
- GObject *item;
-
- g_assert (GB_IS_EDITOR_WORKSPACE (self));
-
- if (!(selected = gb_tree_get_selected (self->project_tree)) ||
- !(item = gb_tree_node_get_item (selected)))
- return;
-
- item = gb_tree_node_get_item (selected);
-
- if (IDE_IS_PROJECT_FILE (item))
- {
- GbWorkbench *workbench;
- GFileInfo *file_info;
- GFile *file;
-
- file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
- if (!file_info)
- return;
-
- if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
- return;
-
- file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
- if (!file)
- return;
-
- workbench = gb_widget_get_workbench (GTK_WIDGET (self));
- gb_workbench_open_with_editor (workbench, file);
- }
-}
-
-static void
-gb_editor_workspace_tree_actions_open_containing_folder (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GbEditorWorkspace *self = user_data;
- GbTreeNode *selected;
- GObject *item;
-
- g_assert (GB_IS_EDITOR_WORKSPACE (self));
-
- if (!(selected = gb_tree_get_selected (self->project_tree)) ||
- !(item = gb_tree_node_get_item (selected)))
- return;
-
- item = gb_tree_node_get_item (selected);
-
- if (IDE_IS_PROJECT_FILE (item))
- {
- GFile *file;
-
- file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
- if (!file)
- return;
-
- gb_nautilus_select_file (GTK_WIDGET (self), file, GDK_CURRENT_TIME);
- }
-}
-
static const GActionEntry GbEditorWorkspaceActions[] = {
{ "show-sidebar", NULL, NULL, "false", gb_editor_workspace_actions_show_sidebar },
{ "toggle-sidebar", gb_editor_workspace_actions_toggle_sidebar },
};
-static const GActionEntry GbEditorWorkspaceTreeActions[] = {
- { "open", gb_editor_workspace_tree_actions_open },
- { "open-with-editor", gb_editor_workspace_tree_actions_open_with_editor },
- { "open-containing-folder", gb_editor_workspace_tree_actions_open_containing_folder },
- { "refresh", gb_editor_workspace_tree_actions_refresh },
- { "collapse-all-nodes", gb_editor_workspace_tree_actions_collapse_all_nodes },
-};
-
void
gb_editor_workspace_actions_init (GbEditorWorkspace *self)
{
g_autoptr(GSimpleActionGroup) group = NULL;
- g_autoptr(GSimpleActionGroup) tree_group = NULL;
- g_autoptr(GSettings) settings = NULL;
- g_autoptr(GAction) action = NULL;
group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (group), GbEditorWorkspaceActions,
G_N_ELEMENTS (GbEditorWorkspaceActions), self);
gtk_widget_insert_action_group (GTK_WIDGET (self), "workspace", G_ACTION_GROUP (group));
-
- tree_group = g_simple_action_group_new ();
- settings = g_settings_new ("org.gtk.Settings.FileChooser");
- action = g_settings_create_action (settings, "sort-directories-first");
- g_action_map_add_action (G_ACTION_MAP (tree_group), action);
- g_action_map_add_action_entries (G_ACTION_MAP (tree_group), GbEditorWorkspaceTreeActions,
- G_N_ELEMENTS (GbEditorWorkspaceTreeActions), self);
- gtk_widget_insert_action_group (GTK_WIDGET (self), "project-tree", G_ACTION_GROUP (tree_group));
}
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 55a7bec..b380862 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -27,6 +27,7 @@
#include "gb-editor-workspace-actions.h"
#include "gb-editor-workspace-private.h"
#include "gb-project-tree-builder.h"
+#include "gb-project-tree-actions.h"
#include "gb-string.h"
#include "gb-tree.h"
#include "gb-view-grid.h"
@@ -152,6 +153,7 @@ gb_editor_workspace_constructed (GObject *object)
G_OBJECT_CLASS (gb_editor_workspace_parent_class)->constructed (object);
gb_editor_workspace_actions_init (self);
+ gb_project_tree_actions_init (self);
IDE_EXIT;
}
diff --git a/src/editor/gb-project-tree-actions.c b/src/editor/gb-project-tree-actions.c
new file mode 100644
index 0000000..106da7f
--- /dev/null
+++ b/src/editor/gb-project-tree-actions.c
@@ -0,0 +1,186 @@
+/* gb-project-tree-actions.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gb-editor-workspace.h"
+#include "gb-editor-workspace-private.h"
+#include "gb-nautilus.h"
+#include "gb-tree.h"
+#include "gb-widget.h"
+#include "gb-workbench.h"
+
+static void
+gb_project_tree_actions_refresh (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbEditorWorkspace *self = user_data;
+
+ g_assert (GB_IS_EDITOR_WORKSPACE (self));
+
+ gb_tree_rebuild (self->project_tree);
+
+ /* TODO: Try to expand back to our current position */
+}
+
+static void
+gb_project_tree_actions_collapse_all_nodes (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbEditorWorkspace *self = user_data;
+
+ g_assert (GB_IS_EDITOR_WORKSPACE (self));
+
+ gtk_tree_view_collapse_all (GTK_TREE_VIEW (self->project_tree));
+}
+
+static void
+gb_project_tree_actions_open (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbEditorWorkspace *self = user_data;
+ GbTreeNode *selected;
+ GObject *item;
+
+ g_assert (GB_IS_EDITOR_WORKSPACE (self));
+
+ if (!(selected = gb_tree_get_selected (self->project_tree)) ||
+ !(item = gb_tree_node_get_item (selected)))
+ return;
+
+ item = gb_tree_node_get_item (selected);
+
+ if (IDE_IS_PROJECT_FILE (item))
+ {
+ GbWorkbench *workbench;
+ GFileInfo *file_info;
+ GFile *file;
+
+ file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
+ if (!file_info)
+ return;
+
+ if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
+ return;
+
+ file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
+ if (!file)
+ return;
+
+ workbench = gb_widget_get_workbench (GTK_WIDGET (self));
+ gb_workbench_open (workbench, file);
+ }
+}
+
+static void
+gb_project_tree_actions_open_with_editor (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbEditorWorkspace *self = user_data;
+ GbTreeNode *selected;
+ GObject *item;
+
+ g_assert (GB_IS_EDITOR_WORKSPACE (self));
+
+ if (!(selected = gb_tree_get_selected (self->project_tree)) ||
+ !(item = gb_tree_node_get_item (selected)))
+ return;
+
+ item = gb_tree_node_get_item (selected);
+
+ if (IDE_IS_PROJECT_FILE (item))
+ {
+ GbWorkbench *workbench;
+ GFileInfo *file_info;
+ GFile *file;
+
+ file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
+ if (!file_info)
+ return;
+
+ if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
+ return;
+
+ file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
+ if (!file)
+ return;
+
+ workbench = gb_widget_get_workbench (GTK_WIDGET (self));
+ gb_workbench_open_with_editor (workbench, file);
+ }
+}
+
+static void
+gb_project_tree_actions_open_containing_folder (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbEditorWorkspace *self = user_data;
+ GbTreeNode *selected;
+ GObject *item;
+
+ g_assert (GB_IS_EDITOR_WORKSPACE (self));
+
+ if (!(selected = gb_tree_get_selected (self->project_tree)) ||
+ !(item = gb_tree_node_get_item (selected)))
+ return;
+
+ item = gb_tree_node_get_item (selected);
+
+ if (IDE_IS_PROJECT_FILE (item))
+ {
+ GFile *file;
+
+ file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
+ if (!file)
+ return;
+
+ gb_nautilus_select_file (GTK_WIDGET (self), file, GDK_CURRENT_TIME);
+ }
+}
+
+static GActionEntry GbProjectTreeActions[] = {
+ { "open", gb_project_tree_actions_open },
+ { "open-with-editor", gb_project_tree_actions_open_with_editor },
+ { "open-containing-folder", gb_project_tree_actions_open_containing_folder },
+ { "refresh", gb_project_tree_actions_refresh },
+ { "collapse-all-nodes", gb_project_tree_actions_collapse_all_nodes },
+};
+
+void
+gb_project_tree_actions_init (GbEditorWorkspace *editor)
+{
+ g_autoptr(GSettings) settings = NULL;
+ g_autoptr(GSimpleActionGroup) actions = NULL;
+ g_autoptr(GAction) action = NULL;
+
+ settings = g_settings_new ("org.gtk.Settings.FileChooser");
+ actions = g_simple_action_group_new ();
+
+ g_action_map_add_action_entries (G_ACTION_MAP (actions), GbProjectTreeActions,
+ G_N_ELEMENTS (GbProjectTreeActions), editor);
+
+ action = g_settings_create_action (settings, "sort-directories-first");
+ g_action_map_add_action (G_ACTION_MAP (actions), action);
+
+ gtk_widget_insert_action_group (GTK_WIDGET (editor), "project-tree", G_ACTION_GROUP (actions));
+}
diff --git a/src/editor/gb-project-tree-actions.h b/src/editor/gb-project-tree-actions.h
new file mode 100644
index 0000000..6f570e7
--- /dev/null
+++ b/src/editor/gb-project-tree-actions.h
@@ -0,0 +1,30 @@
+/* gb-project-tree-actions.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_PROJECT_TREE_ACTIONS_H
+#define GB_PROJECT_TREE_ACTIONS_H
+
+#include "gb-editor-workspace.h"
+
+G_BEGIN_DECLS
+
+void gb_project_tree_actions_init (GbEditorWorkspace *editor);
+
+G_END_DECLS
+
+#endif /* GB_PROJECT_TREE_ACTIONS_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index ce786e6..2c65715 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -64,6 +64,8 @@ libgnome_builder_la_SOURCES = \
src/editor/gb-editor-workspace-private.h \
src/editor/gb-editor-workspace.c \
src/editor/gb-editor-workspace.h \
+ src/editor/gb-project-tree-actions.c \
+ src/editor/gb-project-tree-actions.h \
src/gd/gd-tagged-entry.c \
src/gd/gd-tagged-entry.h \
src/gedit/gedit-close-button.c \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]