[gnome-builder/editor-layout] tab: implement scroll helpers



commit 779fe078b2f74773896b2b2d84f4a60e05c35f94
Author: Christian Hergert <christian hergert me>
Date:   Sun Nov 30 02:48:33 2014 -0800

    tab: implement scroll helpers

 src/editor/gb-editor-tab.c |   54 +++++++++++++++++++++++++++++++++++++++++++-
 src/editor/gb-editor-tab.h |   10 +++++---
 2 files changed, 59 insertions(+), 5 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index df8d7fa..5a53edb 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -24,6 +24,7 @@
 #include "gb-animation.h"
 #include "gb-editor-document.h"
 #include "gb-editor-frame.h"
+#include "gb-editor-frame-private.h"
 #include "gb-editor-tab.h"
 #include "gb-log.h"
 #include "gb-widget.h"
@@ -276,7 +277,7 @@ gb_editor_tab_on_split_toggled (GbEditorTab     *tab,
     }
 }
 
-GbEditorFrame *
+static GbEditorFrame *
 gb_editor_tab_get_last_frame (GbEditorTab *tab)
 {
   g_return_val_if_fail (GB_IS_EDITOR_TAB (tab), NULL);
@@ -288,6 +289,57 @@ gb_editor_tab_get_last_frame (GbEditorTab *tab)
 }
 
 static void
+gb_editor_tab_scroll (GbEditorTab      *tab,
+                      GtkDirectionType  dir)
+{
+  GtkAdjustment *vadj;
+  GbEditorFrame *last_frame;
+  GtkScrolledWindow *scroller;
+  GtkTextMark *insert;
+  GtkTextView *view;
+  GtkTextBuffer *buffer;
+  GdkRectangle rect;
+  GtkTextIter iter;
+  gdouble amount;
+  gdouble value;
+  gdouble upper;
+
+  g_assert (GB_IS_EDITOR_TAB (tab));
+
+  last_frame = gb_editor_tab_get_last_frame (tab);
+  scroller = last_frame->priv->scrolled_window;
+  view = GTK_TEXT_VIEW (last_frame->priv->source_view);
+  buffer = GTK_TEXT_BUFFER (last_frame->priv->document);
+
+  insert = gtk_text_buffer_get_insert (buffer);
+  gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+  gtk_text_view_get_iter_location (view, &iter, &rect);
+
+  amount = (dir == GTK_DIR_UP) ? -rect.height : rect.height;
+
+  vadj = gtk_scrolled_window_get_vadjustment (scroller);
+  value = gtk_adjustment_get_value (vadj);
+  upper = gtk_adjustment_get_upper (vadj);
+  gtk_adjustment_set_value (vadj, CLAMP (value + amount, 0, upper));
+}
+
+void
+gb_editor_tab_scroll_up (GbEditorTab *tab)
+{
+  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+  gb_editor_tab_scroll (tab, GTK_DIR_UP);
+}
+
+void
+gb_editor_tab_scroll_down (GbEditorTab *tab)
+{
+  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+  gb_editor_tab_scroll (tab, GTK_DIR_DOWN);
+}
+
+static void
 gb_editor_tab_grab_focus (GtkWidget *widget)
 {
   GbEditorFrame *last_frame;
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index 31d9f65..9bb06c5 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -51,10 +51,12 @@ struct _GbEditorTabClass
   GbTabClass parent_class;
 };
 
-GType gb_editor_tab_get_type (void) G_GNUC_CONST;
-void  gb_editor_tab_save     (GbEditorTab *tab);
-void  gb_editor_tab_save_as  (GbEditorTab *tab);
-void  gb_editor_tab_open     (GbEditorTab *tab);
+GType gb_editor_tab_get_type    (void) G_GNUC_CONST;
+void  gb_editor_tab_save        (GbEditorTab *tab);
+void  gb_editor_tab_save_as     (GbEditorTab *tab);
+void  gb_editor_tab_open        (GbEditorTab *tab);
+void  gb_editor_tab_scroll_up   (GbEditorTab *tab);
+void  gb_editor_tab_scroll_down (GbEditorTab *tab);
 
 G_END_DECLS
 


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