[gnome-builder/wip/libide-merge] track preview state



commit 6a78d11cb59a5d9fa064889a46446e693f17a9ee
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 19 17:06:18 2015 -0700

    track preview state

 src/editor/gb-editor-view-actions.c |   26 ++++++++++++++++++++++++++
 src/editor/gb-editor-view-actions.h |    3 ++-
 src/editor/gb-editor-view.c         |    2 ++
 3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/src/editor/gb-editor-view-actions.c b/src/editor/gb-editor-view-actions.c
index 922a6bd..ef3bfa3 100644
--- a/src/editor/gb-editor-view-actions.c
+++ b/src/editor/gb-editor-view-actions.c
@@ -129,6 +129,7 @@ gb_editor_view_actions_language (GSimpleAction *action,
     {
       language = gtk_source_language_manager_get_language (manager, name);
       gtk_source_buffer_set_language (buffer, language);
+      gb_editor_view_actions_update (self);
     }
 }
 
@@ -494,3 +495,28 @@ gb_editor_view_actions_init (GbEditorView *self)
 
 #undef WATCH_PROPERTY
 }
+
+void
+gb_editor_view_actions_update (GbEditorView *self)
+{
+  GtkSourceLanguage *language;
+  const gchar *lang_id = NULL;
+  GActionGroup *group;
+  GAction *action;
+  gboolean enabled;
+
+  g_assert (GB_IS_EDITOR_VIEW (self));
+
+  group = gtk_widget_get_action_group (GTK_WIDGET (self), "view");
+  if (!G_IS_SIMPLE_ACTION_GROUP (group))
+    return;
+
+  /* update preview sensitivity */
+  language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (self->document));
+  if (language)
+    lang_id = gtk_source_language_get_id (language);
+  enabled = ((g_strcmp0 (lang_id, "html") == 0) ||
+             (g_strcmp0 (lang_id, "markdown") == 0));
+  action = g_action_map_lookup_action (G_ACTION_MAP (group), "preview");
+  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+}
diff --git a/src/editor/gb-editor-view-actions.h b/src/editor/gb-editor-view-actions.h
index f623ab2..f893758 100644
--- a/src/editor/gb-editor-view-actions.h
+++ b/src/editor/gb-editor-view-actions.h
@@ -23,7 +23,8 @@
 
 G_BEGIN_DECLS
 
-void gb_editor_view_actions_init (GbEditorView *self);
+void gb_editor_view_actions_init   (GbEditorView *self);
+void gb_editor_view_actions_update (GbEditorView *self);
 
 G_END_DECLS
 
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index fc50394..c912674 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -85,6 +85,8 @@ gb_editor_view_set_document (GbEditorView     *self,
                                    language_to_string, NULL, NULL, NULL);
 
       g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOCUMENT]);
+
+      gb_editor_view_actions_update (self);
     }
 }
 


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