[gnome-builder] libide: implement item chaining



commit 4c0b998f564326cc4828016ab0c8dfd18c727d48
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 12 23:28:56 2015 -0700

    libide: implement item chaining

 libide/ide-back-forward-item.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-back-forward-item.c b/libide/ide-back-forward-item.c
index 678085f..da13c07 100644
--- a/libide/ide-back-forward-item.c
+++ b/libide/ide-back-forward-item.c
@@ -19,8 +19,11 @@
 #include <glib/gi18n.h>
 
 #include "ide-back-forward-item.h"
+#include "ide-file.h"
 #include "ide-source-location.h"
 
+#define NUM_LINES_CHAIN_MAX 5
+
 typedef struct
 {
   IdeSourceLocation *location;
@@ -46,6 +49,43 @@ ide_back_forward_item_new (IdeContext        *context,
                        NULL);
 }
 
+gboolean
+ide_back_forward_item_chain (IdeBackForwardItem *self,
+                             IdeBackForwardItem *other)
+{
+  IdeBackForwardItemPrivate *priv = ide_back_forward_item_get_instance_private (self);
+  IdeSourceLocation *loc1;
+  IdeSourceLocation *loc2;
+  IdeFile *file1;
+  IdeFile *file2;
+  gint line1;
+  gint line2;
+
+  g_return_val_if_fail (IDE_IS_BACK_FORWARD_ITEM (self), FALSE);
+  g_return_val_if_fail (IDE_IS_BACK_FORWARD_ITEM (other), FALSE);
+
+  loc1 = ide_back_forward_item_get_location (self);
+  loc2 = ide_back_forward_item_get_location (other);
+
+  file1 = ide_source_location_get_file (loc1);
+  file2 = ide_source_location_get_file (loc2);
+
+  if (!ide_file_equal (file1, file2))
+    return FALSE;
+
+  line1 = ide_source_location_get_line (loc1);
+  line2 = ide_source_location_get_line (loc2);
+
+  if (ABS (line1 - line2) <= NUM_LINES_CHAIN_MAX)
+    {
+      priv->location = ide_source_location_ref (loc2);
+      ide_source_location_unref (loc1);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 IdeSourceLocation *
 ide_back_forward_item_get_location (IdeBackForwardItem *self)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]