[gnome-builder] editor: add tab to GbEditorNavigationItem
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: add tab to GbEditorNavigationItem
- Date: Thu, 25 Sep 2014 00:54:42 +0000 (UTC)
commit 0be3a7fb68e73b264fb45f49fb29afaf0f26c1a3
Author: Christian Hergert <christian hergert me>
Date: Wed Sep 24 17:11:32 2014 -0700
editor: add tab to GbEditorNavigationItem
We can then use this to save us some lookup time to reselect the tab
if it has not yet been closed.
Otherwise, we have to compare the file to everything in the tab list and
then fallback to opening the tab.
src/editor/gb-editor-commands.c | 1 +
src/editor/gb-editor-navigation-item.c | 65 ++++++++++++++++++++++++++++++--
src/editor/gb-editor-navigation-item.h | 2 +
3 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index 676b4aa..d778bcc 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -490,6 +490,7 @@ gb_editor_tab_do_save (GbEditorTab *tab)
"file", gtk_source_file_get_location (priv->file),
"line", line,
"line-offset", line_offset,
+ "tab", tab,
NULL);
gb_navigation_list_append (list, item);
}
diff --git a/src/editor/gb-editor-navigation-item.c b/src/editor/gb-editor-navigation-item.c
index 8f23c64..3449d0b 100644
--- a/src/editor/gb-editor-navigation-item.c
+++ b/src/editor/gb-editor-navigation-item.c
@@ -22,9 +22,10 @@
struct _GbEditorNavigationItemPrivate
{
- GFile *file;
- guint line;
- guint line_offset;
+ GFile *file;
+ guint line;
+ guint line_offset;
+ GbEditorTab *tab;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorNavigationItem, gb_editor_navigation_item,
@@ -35,6 +36,7 @@ enum {
PROP_FILE,
PROP_LINE,
PROP_LINE_OFFSET,
+ PROP_TAB,
LAST_PROP
};
@@ -54,6 +56,42 @@ gb_editor_navigation_item_new (GFile *file,
NULL);
}
+GbEditorTab *
+gb_editor_navigation_item_get_tab (GbEditorNavigationItem *item)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item), NULL);
+
+ return item->priv->tab;
+}
+
+static void
+gb_editor_navigation_item_set_tab (GbEditorNavigationItem *item,
+ GbEditorTab *tab)
+{
+ GbEditorNavigationItemPrivate *priv;
+
+ g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item));
+ g_return_if_fail (!tab || GB_IS_EDITOR_TAB (tab));
+
+ priv = item->priv;
+
+ if (priv->tab)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (priv->tab),
+ (gpointer *)&priv->tab);
+ priv->tab = NULL;
+ }
+
+ if (tab)
+ {
+ priv->tab = tab;
+ g_object_add_weak_pointer (G_OBJECT (priv->tab),
+ (gpointer *)&priv->tab);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (item), gParamSpecs [PROP_TAB]);
+}
+
GFile *
gb_editor_navigation_item_get_file (GbEditorNavigationItem *item)
{
@@ -85,7 +123,7 @@ gb_editor_navigation_item_get_line (GbEditorNavigationItem *item)
return item->priv->line;
}
-void
+static void
gb_editor_navigation_item_set_line (GbEditorNavigationItem *item,
guint line)
{
@@ -155,6 +193,10 @@ gb_editor_navigation_item_get_property (GObject *object,
g_value_set_uint (value, gb_editor_navigation_item_get_line_offset (self));
break;
+ case PROP_TAB:
+ g_value_set_object (value, gb_editor_navigation_item_get_tab (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -182,6 +224,10 @@ gb_editor_navigation_item_set_property (GObject *object,
gb_editor_navigation_item_set_line_offset (self, g_value_get_uint (value));
break;
+ case PROP_TAB:
+ gb_editor_navigation_item_set_tab (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -235,6 +281,17 @@ gb_editor_navigation_item_class_init (GbEditorNavigationItemClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_LINE_OFFSET,
gParamSpecs [PROP_LINE_OFFSET]);
+
+ gParamSpecs [PROP_TAB] =
+ g_param_spec_object ("tab",
+ _("Tab"),
+ _("The editor tab."),
+ GB_TYPE_EDITOR_TAB,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_TAB,
+ gParamSpecs [PROP_TAB]);
}
static void
diff --git a/src/editor/gb-editor-navigation-item.h b/src/editor/gb-editor-navigation-item.h
index f7ced6f..97ec7af 100644
--- a/src/editor/gb-editor-navigation-item.h
+++ b/src/editor/gb-editor-navigation-item.h
@@ -21,6 +21,7 @@
#include <gio/gio.h>
+#include "gb-editor-tab.h"
#include "gb-navigation-item.h"
G_BEGIN_DECLS
@@ -53,6 +54,7 @@ struct _GbEditorNavigationItemClass
GFile *gb_editor_navigation_item_get_file (GbEditorNavigationItem *item);
guint gb_editor_navigation_item_get_line (GbEditorNavigationItem *item);
guint gb_editor_navigation_item_get_line_offset (GbEditorNavigationItem *item);
+GbEditorTab *gb_editor_navigation_item_get_tab (GbEditorNavigationItem *item);
GType gb_editor_navigation_item_get_type (void) G_GNUC_CONST;
GbNavigationItem *gb_editor_navigation_item_new (GFile *file,
guint line,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]