[gedit-code-assistance] Reparse on view focus



commit 14b68614ee1bcbd6ae61a19dc050c5d3e7006205
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Thu Dec 12 20:55:34 2013 +0100

    Reparse on view focus

 src/Makefile.am                 |    1 +
 src/gca-plugin.vala             |    3 ++
 src/gca-view-activatable.vala   |    3 ++
 src/gca-view.vala               |   11 +++++--
 src/gca-window-activatable.vala |   56 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 71 insertions(+), 3 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 41f3be4..9fc00ab 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ gedit_plugin_vala_sources =                                     \
        src/gca-plugin.vala                                     \
        src/gca-app-activatable.vala                            \
        src/gca-view-activatable.vala                           \
+       src/gca-window-activatable.vala                         \
        src/gca-source-location.vala                            \
        src/gca-source-range.vala                               \
        src/gca-source-range-support.vala                       \
diff --git a/src/gca-plugin.vala b/src/gca-plugin.vala
index 95b63c9..bbfd370 100644
--- a/src/gca-plugin.vala
+++ b/src/gca-plugin.vala
@@ -25,6 +25,9 @@ public static void peas_register_types(TypeModule module)
        mod.register_extension_type(typeof(Gedit.ViewActivatable),
                                    typeof(Gca.ViewActivatable));
 
+       mod.register_extension_type(typeof(Gedit.WindowActivatable),
+                                   typeof(Gca.WindowActivatable));
+
        mod.register_extension_type(typeof(Gedit.AppActivatable),
                                    typeof(Gca.AppActivatable));
 }
diff --git a/src/gca-view-activatable.vala b/src/gca-view-activatable.vala
index e730f79..8b9f96d 100644
--- a/src/gca-view-activatable.vala
+++ b/src/gca-view-activatable.vala
@@ -31,10 +31,13 @@ class ViewActivatable : GLib.Object, Gedit.ViewActivatable
        public void activate()
        {
                d_view = new Gca.View(view);
+               view.set_data("GcaView", d_view);
        }
 
        public void deactivate()
        {
+               view.set_data("GcaView", null);
+
                d_view.deactivate();
                d_view = null;
        }
diff --git a/src/gca-view.vala b/src/gca-view.vala
index e1e8e7d..228e9d1 100644
--- a/src/gca-view.vala
+++ b/src/gca-view.vala
@@ -142,10 +142,8 @@ class View : Object
                path_changed(prevpath);
        }
 
-       private void on_document_changed()
+       public void reparse()
        {
-               d_scrollbar_marker.max_line = d_document.document.get_line_count();
-
                if (d_timeout != 0)
                {
                        Source.remove(d_timeout);
@@ -158,6 +156,13 @@ class View : Object
                });
        }
 
+       private void on_document_changed()
+       {
+               d_scrollbar_marker.max_line = d_document.document.get_line_count();
+               reparse();
+
+       }
+
        private void update_backend()
        {
                unregister_backend();
diff --git a/src/gca-window-activatable.vala b/src/gca-window-activatable.vala
new file mode 100644
index 0000000..18df8e7
--- /dev/null
+++ b/src/gca-window-activatable.vala
@@ -0,0 +1,56 @@
+/*
+ * This file is part of gedit-code-assistant.
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * gedit-code-assistant 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.
+ *
+ * gedit-code-assistant 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 gedit-code-assistant.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+namespace Gca
+{
+
+class WindowActivatable : GLib.Object, Gedit.WindowActivatable
+{
+       public Gedit.Window window { construct; owned get; }
+
+       public void activate()
+       {
+               window.active_tab_changed.connect(on_active_tab_changed);
+       }
+
+       public void deactivate()
+       {
+               window.active_tab_changed.disconnect(on_active_tab_changed);
+       }
+
+       public void update_state()
+       {
+       }
+
+       private void on_active_tab_changed(Gedit.Window window, Gedit.Tab tab)
+       {
+               var v = tab.get_view().get_data<View?>("GcaView");
+
+               if (v != null)
+               {
+                       v.reparse();
+               }
+       }
+}
+
+}
+
+/* vi:ex:ts=4 */


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