[gnome-builder] navigation: start on navigation for editor.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] navigation: start on navigation for editor.
- Date: Wed, 24 Sep 2014 06:59:51 +0000 (UTC)
commit f46e39c0f34f9e52707eec3942f39c720482bed2
Author: Christian Hergert <christian hergert me>
Date: Tue Sep 23 23:59:46 2014 -0700
navigation: start on navigation for editor.
src/editor/gb-editor-navigation-item.c | 246 ++++++++++++++++++++++++++++++++
src/editor/gb-editor-navigation-item.h | 63 ++++++++
src/gnome-builder.mk | 2 +
src/navigation/gb-navigation-item.c | 8 +-
src/navigation/gb-navigation-item.h | 8 +-
src/navigation/gb-navigation-list.c | 35 +++++-
6 files changed, 355 insertions(+), 7 deletions(-)
---
diff --git a/src/editor/gb-editor-navigation-item.c b/src/editor/gb-editor-navigation-item.c
new file mode 100644
index 0000000..9ece561
--- /dev/null
+++ b/src/editor/gb-editor-navigation-item.c
@@ -0,0 +1,246 @@
+/* gb-editor-navigation-item.c
+ *
+ * Copyright (C) 2014 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-navigation-item.h"
+
+struct _GbEditorNavigationItemPrivate
+{
+ GFile *file;
+ guint line;
+ guint line_offset;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbEditorNavigationItem, gb_editor_navigation_item,
+ GB_TYPE_NAVIGATION_ITEM)
+
+enum {
+ PROP_0,
+ PROP_FILE,
+ PROP_LINE,
+ PROP_LINE_OFFSET,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GbNavigationItem *
+gb_editor_navigation_item_new (GFile *file,
+ guint line,
+ guint line_offset)
+{
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ return g_object_new (GB_TYPE_EDITOR_NAVIGATION_ITEM,
+ "file", file,
+ "line", line,
+ "line-offset", line_offset,
+ NULL);
+}
+
+GFile *
+gb_editor_navigation_item_get_file (GbEditorNavigationItem *item)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item), NULL);
+
+ return item->priv->file;
+}
+
+static void
+gb_editor_navigation_item_set_file (GbEditorNavigationItem *item,
+ GFile *file)
+{
+ g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item));
+ g_return_if_fail (!file || G_IS_FILE (file));
+
+ if (file == item->priv->file)
+ return;
+
+ g_clear_object (&item->priv->file);
+ item->priv->file = file ? g_object_ref (file) : NULL;
+ g_object_notify_by_pspec (G_OBJECT (item), gParamSpecs [PROP_FILE]);
+}
+
+guint
+gb_editor_navigation_item_get_line (GbEditorNavigationItem *item)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item), 0);
+
+ return item->priv->line;
+}
+
+void
+gb_editor_navigation_item_set_line (GbEditorNavigationItem *item,
+ guint line)
+{
+ g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item));
+
+ item->priv->line = line;
+ g_object_notify_by_pspec (G_OBJECT (item), gParamSpecs [PROP_LINE]);
+}
+
+guint
+gb_editor_navigation_item_get_line_offset (GbEditorNavigationItem *item)
+{
+ g_return_val_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item), 0);
+
+ return item->priv->line_offset;
+}
+
+static void
+gb_editor_navigation_item_set_line_offset (GbEditorNavigationItem *item,
+ guint line_offset)
+{
+ g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (item));
+
+ item->priv->line_offset = line_offset;
+ g_object_notify_by_pspec (G_OBJECT (item), gParamSpecs [PROP_LINE_OFFSET]);
+}
+
+static void
+gb_editor_navigation_item_activate (GbNavigationItem *item,
+ GbWorkbench *workbench)
+{
+ GbEditorNavigationItem *self = (GbEditorNavigationItem *)item;
+
+ g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (self));
+ g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+ g_print ("Activate item\n");
+}
+
+static void
+gb_editor_navigation_item_finalize (GObject *object)
+{
+ GbEditorNavigationItemPrivate *priv = GB_EDITOR_NAVIGATION_ITEM (object)->priv;
+
+ g_clear_object (&priv->file);
+
+ G_OBJECT_CLASS (gb_editor_navigation_item_parent_class)->finalize (object);
+}
+
+static void
+gb_editor_navigation_item_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbEditorNavigationItem *self = GB_EDITOR_NAVIGATION_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_FILE:
+ g_value_set_object (value, gb_editor_navigation_item_get_file (self));
+ break;
+
+ case PROP_LINE:
+ g_value_set_uint (value, gb_editor_navigation_item_get_line (self));
+ break;
+
+ case PROP_LINE_OFFSET:
+ g_value_set_uint (value, gb_editor_navigation_item_get_line_offset (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_editor_navigation_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbEditorNavigationItem *self = GB_EDITOR_NAVIGATION_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_FILE:
+ gb_editor_navigation_item_set_file (self, g_value_get_object (value));
+ break;
+
+ case PROP_LINE:
+ gb_editor_navigation_item_set_line (self, g_value_get_uint (value));
+ break;
+
+ case PROP_LINE_OFFSET:
+ gb_editor_navigation_item_set_line_offset (self, g_value_get_uint (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_editor_navigation_item_class_init (GbEditorNavigationItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GbNavigationItemClass *item_class = GB_NAVIGATION_ITEM_CLASS (klass);
+
+ object_class->finalize = gb_editor_navigation_item_finalize;
+ object_class->get_property = gb_editor_navigation_item_get_property;
+ object_class->set_property = gb_editor_navigation_item_set_property;
+
+ item_class->activate = gb_editor_navigation_item_activate;
+
+ gParamSpecs [PROP_FILE] =
+ g_param_spec_object ("file",
+ _("File"),
+ _("The file that is being edited."),
+ G_TYPE_FILE,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_FILE,
+ gParamSpecs [PROP_FILE]);
+
+ gParamSpecs [PROP_LINE] =
+ g_param_spec_uint ("line",
+ _("Line"),
+ _("The line number within the file."),
+ 0,
+ G_MAXUINT,
+ 0,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_LINE,
+ gParamSpecs [PROP_LINE]);
+
+ gParamSpecs [PROP_LINE_OFFSET] =
+ g_param_spec_uint ("line-offset",
+ _("Line Offset"),
+ _("The offset within the line."),
+ 0,
+ G_MAXUINT,
+ 0,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_LINE_OFFSET,
+ gParamSpecs [PROP_LINE_OFFSET]);
+}
+
+static void
+gb_editor_navigation_item_init (GbEditorNavigationItem *self)
+{
+ self->priv = gb_editor_navigation_item_get_instance_private (self);
+}
diff --git a/src/editor/gb-editor-navigation-item.h b/src/editor/gb-editor-navigation-item.h
new file mode 100644
index 0000000..f7ced6f
--- /dev/null
+++ b/src/editor/gb-editor-navigation-item.h
@@ -0,0 +1,63 @@
+/* gb-editor-navigation-item.h
+ *
+ * Copyright (C) 2014 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_EDITOR_NAVIGATION_ITEM_H
+#define GB_EDITOR_NAVIGATION_ITEM_H
+
+#include <gio/gio.h>
+
+#include "gb-navigation-item.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_EDITOR_NAVIGATION_ITEM (gb_editor_navigation_item_get_type())
+#define GB_EDITOR_NAVIGATION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_EDITOR_NAVIGATION_ITEM, GbEditorNavigationItem))
+#define GB_EDITOR_NAVIGATION_ITEM_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_EDITOR_NAVIGATION_ITEM, GbEditorNavigationItem const))
+#define GB_EDITOR_NAVIGATION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_EDITOR_NAVIGATION_ITEM, GbEditorNavigationItemClass))
+#define GB_IS_EDITOR_NAVIGATION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_EDITOR_NAVIGATION_ITEM))
+#define GB_IS_EDITOR_NAVIGATION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_EDITOR_NAVIGATION_ITEM))
+#define GB_EDITOR_NAVIGATION_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_EDITOR_NAVIGATION_ITEM, GbEditorNavigationItemClass))
+
+typedef struct _GbEditorNavigationItem GbEditorNavigationItem;
+typedef struct _GbEditorNavigationItemClass GbEditorNavigationItemClass;
+typedef struct _GbEditorNavigationItemPrivate GbEditorNavigationItemPrivate;
+
+struct _GbEditorNavigationItem
+{
+ GbNavigationItem parent;
+
+ /*< private >*/
+ GbEditorNavigationItemPrivate *priv;
+};
+
+struct _GbEditorNavigationItemClass
+{
+ GbNavigationItemClass parent;
+};
+
+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);
+GType gb_editor_navigation_item_get_type (void) G_GNUC_CONST;
+GbNavigationItem *gb_editor_navigation_item_new (GFile *file,
+ guint line,
+ guint line_offset);
+
+G_END_DECLS
+
+#endif /* GB_EDITOR_NAVIGATION_ITEM_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 105ad01..5ad1d4e 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -18,6 +18,8 @@ gnome_builder_SOURCES = \
src/editor/gb-editor-commands.h \
src/editor/gb-editor-document.c \
src/editor/gb-editor-document.h \
+ src/editor/gb-editor-navigation-item.c \
+ src/editor/gb-editor-navigation-item.h \
src/editor/gb-editor-settings.c \
src/editor/gb-editor-settings.h \
src/editor/gb-editor-tab.c \
diff --git a/src/navigation/gb-navigation-item.c b/src/navigation/gb-navigation-item.c
index b50d581..58ae131 100644
--- a/src/navigation/gb-navigation-item.c
+++ b/src/navigation/gb-navigation-item.c
@@ -25,7 +25,8 @@ struct _GbNavigationItemPrivate
gchar *label;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GbNavigationItem, gb_navigation_item, G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_TYPE_WITH_PRIVATE (GbNavigationItem, gb_navigation_item,
+ G_TYPE_INITIALLY_UNOWNED)
enum {
PROP_0,
@@ -69,11 +70,12 @@ gb_navigation_item_set_label (GbNavigationItem *item,
}
void
-gb_navigation_item_emit_activate (GbNavigationItem *item)
+gb_navigation_item_emit_activate (GbNavigationItem *item,
+ GbWorkbench *workbench)
{
g_return_if_fail (GB_IS_NAVIGATION_ITEM (item));
- g_signal_emit (item, gSignals [ACTIVATE], 0);
+ g_signal_emit (item, gSignals [ACTIVATE], 0, workbench);
}
static void
diff --git a/src/navigation/gb-navigation-item.h b/src/navigation/gb-navigation-item.h
index b467f06..83a8ab9 100644
--- a/src/navigation/gb-navigation-item.h
+++ b/src/navigation/gb-navigation-item.h
@@ -21,6 +21,8 @@
#include <glib-object.h>
+#include "gb-workbench.h"
+
G_BEGIN_DECLS
#define GB_TYPE_NAVIGATION_ITEM (gb_navigation_item_get_type())
@@ -47,12 +49,14 @@ struct _GbNavigationItemClass
{
GInitiallyUnownedClass parent;
- void (*activate) (GbNavigationItem *item);
+ void (*activate) (GbNavigationItem *item,
+ GbWorkbench *workbench);
};
GType gb_navigation_item_get_type (void) G_GNUC_CONST;
GbNavigationItem *gb_navigation_item_new (const gchar *label);
-void gb_navigation_item_emit_activate (GbNavigationItem *item);
+void gb_navigation_item_emit_activate (GbNavigationItem *item,
+ GbWorkbench *workbench);
const gchar *gb_navigation_item_get_label (GbNavigationItem *item);
void gb_navigation_item_set_label (GbNavigationItem *item,
const gchar *label);
diff --git a/src/navigation/gb-navigation-list.c b/src/navigation/gb-navigation-list.c
index f055ee7..5372447 100644
--- a/src/navigation/gb-navigation-list.c
+++ b/src/navigation/gb-navigation-list.c
@@ -67,6 +67,8 @@ gb_navigation_list_go_backward (GbNavigationList *list)
if (gb_navigation_list_get_can_go_backward (list))
{
+ list->priv->current--;
+
g_object_notify_by_pspec (G_OBJECT (list),
gParamSpecs [PROP_CURRENT_ITEM]);
g_object_notify_by_pspec (G_OBJECT (list),
@@ -83,6 +85,8 @@ gb_navigation_list_go_forward (GbNavigationList *list)
if (gb_navigation_list_get_can_go_forward (list))
{
+ list->priv->current++;
+
g_object_notify_by_pspec (G_OBJECT (list),
gParamSpecs [PROP_CURRENT_ITEM]);
g_object_notify_by_pspec (G_OBJECT (list),
@@ -103,6 +107,30 @@ gb_navigation_list_get_current_item (GbNavigationList *list)
return NULL;
}
+void
+gb_navigation_list_append (GbNavigationList *list,
+ GbNavigationItem *item)
+{
+ guint position;
+
+ g_return_if_fail (GB_IS_NAVIGATION_LIST (list));
+ g_return_if_fail (GB_IS_NAVIGATION_ITEM (item));
+
+ position = list->priv->current + 1;
+
+ if (list->priv->items->len)
+ g_ptr_array_remove_range (list->priv->items, position,
+ list->priv->items->len - 1);
+
+ g_ptr_array_add (list->priv->items, g_object_ref_sink (item));
+
+ list->priv->current++;
+
+ g_object_notify_by_pspec (G_OBJECT (list), gParamSpecs [PROP_CURRENT_ITEM]);
+ g_object_notify_by_pspec (G_OBJECT (list), gParamSpecs [PROP_CAN_GO_BACKWARD]);
+ g_object_notify_by_pspec (G_OBJECT (list), gParamSpecs [PROP_CAN_GO_FORWARD]);
+}
+
static void
gb_navigation_list_finalize (GObject *object)
{
@@ -124,11 +152,13 @@ gb_navigation_list_get_property (GObject *object,
switch (prop_id)
{
case PROP_CAN_GO_BACKWARD:
- g_value_set_boolean (value, gb_navigation_list_get_can_go_backward (self));
+ g_value_set_boolean (value,
+ gb_navigation_list_get_can_go_backward (self));
break;
case PROP_CAN_GO_FORWARD:
- g_value_set_boolean (value, gb_navigation_list_get_can_go_forward (self));
+ g_value_set_boolean (value,
+ gb_navigation_list_get_can_go_forward (self));
break;
case PROP_CURRENT_ITEM:
@@ -184,4 +214,5 @@ gb_navigation_list_init (GbNavigationList *self)
{
self->priv = gb_navigation_list_get_instance_private (self);
self->priv->items = g_ptr_array_new_with_free_func (g_object_unref);
+ self->priv->current = -1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]