[gnome-builder] libide: add internal helper to discover most recent file position
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add internal helper to discover most recent file position
- Date: Tue, 24 Mar 2015 00:16:47 +0000 (UTC)
commit 314d062efdb98cd1902c6d9b47514732ce7bd114
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 12 19:13:58 2015 -0700
libide: add internal helper to discover most recent file position
This let's us piggyback on the navigation list to get the previous position
within a file. Sort of nice so we don't need to track things in multiple
places.
libide/ide-back-forward-list.c | 53 +++++++++++++++++++++++++++++
libide/ide-internal.h | 72 +++++++++++++++++++++-------------------
2 files changed, 91 insertions(+), 34 deletions(-)
---
diff --git a/libide/ide-back-forward-list.c b/libide/ide-back-forward-list.c
index 1103100..0f0f834 100644
--- a/libide/ide-back-forward-list.c
+++ b/libide/ide-back-forward-list.c
@@ -22,6 +22,8 @@
#include "ide-back-forward-item.h"
#include "ide-back-forward-list.h"
+#include "ide-file.h"
+#include "ide-source-location.h"
struct _IdeBackForwardList
{
@@ -429,3 +431,54 @@ ide_back_forward_list_init (IdeBackForwardList *self)
self->backward = g_queue_new ();
self->forward = g_queue_new ();
}
+
+/**
+ * _ide_back_forward_list_find:
+ * @self: A #IdeBackForwardList.
+ * @file: The target #IdeFile
+ *
+ * This internal function will attempt to discover the most recent jump point for @file. It starts
+ * from the most recent item and works backwards until the target file is found or the list is
+ * exhausted.
+ *
+ * This is useful if you want to place the insert mark on the last used position within the buffer.
+ *
+ * Returns: (transfer none): An #IdeBackForwardItem or %NULL.
+ */
+IdeBackForwardItem *
+_ide_back_forward_list_find (IdeBackForwardList *self,
+ IdeFile *file)
+{
+ GList *iter;
+
+ g_return_val_if_fail (IDE_IS_BACK_FORWARD_LIST (self), NULL);
+ g_return_val_if_fail (IDE_IS_FILE (file), NULL);
+
+ for (iter = self->forward->tail; iter; iter = iter->prev)
+ {
+ IdeBackForwardItem *item = iter->data;
+ IdeSourceLocation *item_loc;
+ IdeFile *item_file;
+
+ item_loc = ide_back_forward_item_get_location (item);
+ item_file = ide_source_location_get_file (item_loc);
+
+ if (ide_file_equal (item_file, file))
+ return item;
+ }
+
+ for (iter = self->backward->head; iter; iter = iter->next)
+ {
+ IdeBackForwardItem *item = iter->data;
+ IdeSourceLocation *item_loc;
+ IdeFile *item_file;
+
+ item_loc = ide_back_forward_item_get_location (item);
+ item_file = ide_source_location_get_file (item_loc);
+
+ if (ide_file_equal (item_file, file))
+ return item;
+ }
+
+ return NULL;
+}
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 409e4bb..32a4100 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -22,6 +22,8 @@
#include <clang-c/Index.h>
#include <gtksourceview/gtksource.h>
+#include "ide-back-forward-item.h"
+#include "ide-back-forward-list.h"
#include "ide-clang-translation-unit.h"
#include "ide-diagnostic.h"
#include "ide-types.h"
@@ -30,40 +32,42 @@
G_BEGIN_DECLS
-void _ide_diagnostic_add_range (IdeDiagnostic *self,
- IdeSourceRange *range);
-IdeDiagnostic *_ide_diagnostic_new (IdeDiagnosticSeverity severity,
- const gchar *text,
- IdeSourceLocation *location);
-void _ide_diagnostic_take_range (IdeDiagnostic *self,
- IdeSourceRange *range);
-void _ide_diagnostician_add_provider (IdeDiagnostician *self,
- IdeDiagnosticProvider *provider);
-void _ide_diagnostician_remove_provider (IdeDiagnostician *self,
- IdeDiagnosticProvider *provider);
-IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
-GtkSourceFile *_ide_file_get_source_file (IdeFile *file);
-void _ide_project_set_name (IdeProject *project,
- const gchar *name);
-void _ide_search_context_add_provider (IdeSearchContext *context,
- IdeSearchProvider *provider,
- gsize max_results);
-IdeSourceRange *_ide_source_range_new (IdeSourceLocation *begin,
- IdeSourceLocation *end);
-gboolean _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
- GdkEventKey *event,
- gboolean *remove);
-IdeSourceViewMode *_ide_source_view_mode_new (GtkWidget *view,
- const char *mode,
- IdeSourceViewModeType type);
-void _ide_source_view_set_count (IdeSourceView *self,
- guint count);
-void _ide_source_view_set_modifier (IdeSourceView *self,
- gunichar modifier);
-IdeUnsavedFile *_ide_unsaved_file_new (GFile *file,
- GBytes *content,
- const gchar *temp_path,
- gint64 sequence);
+IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
+ IdeFile *file);
+void _ide_diagnostic_add_range (IdeDiagnostic *self,
+ IdeSourceRange *range);
+IdeDiagnostic *_ide_diagnostic_new (IdeDiagnosticSeverity severity,
+ const gchar *text,
+ IdeSourceLocation *location);
+void _ide_diagnostic_take_range (IdeDiagnostic *self,
+ IdeSourceRange *range);
+void _ide_diagnostician_add_provider (IdeDiagnostician *self,
+ IdeDiagnosticProvider *provider);
+void _ide_diagnostician_remove_provider (IdeDiagnostician *self,
+ IdeDiagnosticProvider *provider);
+IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
+GtkSourceFile *_ide_file_get_source_file (IdeFile *file);
+void _ide_project_set_name (IdeProject *project,
+ const gchar *name);
+void _ide_search_context_add_provider (IdeSearchContext *context,
+ IdeSearchProvider *provider,
+ gsize max_results);
+IdeSourceRange *_ide_source_range_new (IdeSourceLocation *begin,
+ IdeSourceLocation *end);
+gboolean _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
+ GdkEventKey *event,
+ gboolean *remove);
+IdeSourceViewMode *_ide_source_view_mode_new (GtkWidget *view,
+ const char *mode,
+ IdeSourceViewModeType type);
+void _ide_source_view_set_count (IdeSourceView *self,
+ guint count);
+void _ide_source_view_set_modifier (IdeSourceView *self,
+ gunichar modifier);
+IdeUnsavedFile *_ide_unsaved_file_new (GFile *file,
+ GBytes *content,
+ const gchar *temp_path,
+ gint64 sequence);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]