[gitg/wip/headerbar] Factor out GitgHeaderBar



commit 6563a1be1714ccd4372601094ec8c98a900e2bd6
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat Jul 6 20:39:32 2013 +0200

    Factor out GitgHeaderBar

 gitg/Makefile.am                     |    1 +
 gitg/gitg-header-bar.vala            |  127 ++++++++++++++++++++++++++++++++++
 gitg/gitg-window.vala                |   81 +++++-----------------
 gitg/resources/gitg-resources.xml    |    1 +
 gitg/resources/ui/gitg-header-bar.ui |  107 ++++++++++++++++++++++++++++
 gitg/resources/ui/gitg-window.ui     |  105 +---------------------------
 6 files changed, 255 insertions(+), 167 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index b433cad..3199348 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -37,6 +37,7 @@ AM_VALAFLAGS = \
 VALASOURCES =                                                  \
        gitg.vala                                               \
        gitg-dirs.vala                                          \
+       gitg-header-bar.vala                                    \
        gitg-window.vala                                        \
        gitg-resource.vala                                      \
        gitg-application.vala                                   \
diff --git a/gitg/gitg-header-bar.vala b/gitg/gitg-header-bar.vala
new file mode 100644
index 0000000..b880711
--- /dev/null
+++ b/gitg/gitg-header-bar.vala
@@ -0,0 +1,127 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * gitg 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-header-bar.ui")]
+public class HeaderBar : Gtk.HeaderBar
+{
+       private Mode d_mode;
+
+       [GtkChild]
+       private Gtk.MenuButton d_gear_menu;
+       private MenuModel d_dash_model;
+       private MenuModel d_activities_model;
+
+       [GtkChild]
+       private Gtk.Button d_dash_button;
+
+       [GtkChild]
+       private Gtk.ToggleButton d_search_button;
+       [GtkChild]
+       private Gtk.StackSwitcher d_activities_switcher;
+
+       public signal void request_dash();
+
+       public enum Mode
+       {
+               DASH,
+               ACTIVITIES,
+               COMMIT
+       }
+
+       [CCode (notify = false)]
+       public Mode mode
+       {
+               get { return d_mode; }
+               set
+               {
+                       d_mode = value;
+
+                       if (d_mode == Mode.COMMIT)
+                       {
+                               get_style_context().add_class("selection-mode");
+                       }
+                       else
+                       {
+                               get_style_context().remove_class("selection-mode");
+                       }
+
+                       if (d_mode == Mode.DASH)
+                       {
+                               d_gear_menu.menu_model = d_dash_model;
+                               d_dash_button.hide();
+                               d_activities_switcher.hide();
+                       }
+                       else if (d_mode == Mode.ACTIVITIES)
+                       {
+                               d_gear_menu.menu_model = d_activities_model;
+                               d_dash_button.show();
+                               d_activities_switcher.show();
+                       }
+
+                       notify_property("mode");
+               }
+       }
+
+       [GtkCallback]
+       private void close_button_clicked(Gtk.Button button)
+       {
+               Gtk.Window window = (Gtk.Window)get_toplevel();
+               window.close();
+       }
+
+       [GtkCallback]
+       private void dash_button_clicked(Gtk.Button dash)
+       {
+               request_dash();
+       }
+
+       construct
+       {
+               string menuname;
+
+               if (Gtk.Settings.get_default().gtk_shell_shows_app_menu)
+               {
+                       menuname = "win-menu";
+               }
+               else
+               {
+                       menuname = "app-win-menu";
+               }
+
+               d_dash_model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", menuname + "-dash");
+               d_activities_model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", menuname + "-views");
+       }
+
+       public Gtk.ToggleButton get_search_button()
+       {
+               return d_search_button;
+       }
+
+       public Gtk.StackSwitcher get_activities_switcher()
+       {
+               return d_activities_switcher;
+       }
+}
+
+}
+
+// ex:ts=4 noet
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index eb602fa..13dbb60 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -35,20 +35,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
        // Widgets
        [GtkChild]
-       private Gtk.HeaderBar d_header_bar;
-       [GtkChild]
-       private Gtk.ToggleButton d_search_button;
-       [GtkChild]
-       private Gtk.MenuButton d_gear_menu;
-       private MenuModel d_dash_model;
-       private MenuModel d_activities_model;
-
-
-
-       [GtkChild]
-       private Gtk.Button d_dash_button;
-       [GtkChild]
-       private Gtk.StackSwitcher d_activities_switcher;
+       private Gitg.HeaderBar d_header_bar;
 
        [GtkChild]
        private Gtk.SearchBar d_search_bar;
@@ -89,31 +76,6 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        };
 
        [GtkCallback]
-       private void close_button_clicked(Gtk.Button button)
-       {
-               close();
-       }
-
-       [GtkCallback]
-       private void dash_button_clicked(Gtk.Button dash)
-       {
-               repository = null;
-       }
-
-       [GtkCallback]
-       private void search_button_toggled(Gtk.ToggleButton button)
-       {
-               if (button.get_active())
-               {
-                       d_search_entry.grab_focus();
-               }
-               else
-               {
-                       d_search_entry.set_text("");
-               }
-       }
-
-       [GtkCallback]
        private void search_entry_changed(Gtk.Editable entry)
        {
                // FIXME: this is a weird way to know the dash is visible
@@ -136,25 +98,23 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                d_main_settings = new Settings("org.gnome.gitg.preferences.main");
                d_interface_settings = new Settings("org.gnome.gitg.preferences.interface");
 
-               string menuname;
-
-               if (Gtk.Settings.get_default().gtk_shell_shows_app_menu)
-               {
-                       menuname = "win-menu";
-               }
-               else
-               {
-                       menuname = "app-win-menu";
-               }
-
-               d_dash_model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", menuname + "-dash");
-               d_activities_model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", menuname + "-views");
-
                // search bar
                d_search_bar.connect_entry(d_search_entry);
-               d_search_button.bind_property("active", d_search_bar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
-
-               d_activities_switcher.set_stack(d_stack_activities);
+               d_header_bar.get_search_button().bind_property("active", d_search_bar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
+               d_header_bar.get_search_button().toggled.connect((b) => {
+                       if (b.get_active())
+                       {
+                               d_search_entry.grab_focus();
+                       }
+                       else
+                       {
+                               d_search_entry.set_text("");
+                       }
+               });
+               d_header_bar.get_activities_switcher().set_stack(d_stack_activities);
+               d_header_bar.request_dash.connect(() => {
+                       repository = null;
+               });
 
                d_environment = new Gee.HashMap<string, string>();
 
@@ -239,13 +199,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        catch {}
 
                        d_header_bar.set_subtitle(Markup.escape_text(head_name));
-
                        d_main_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT;
                        d_main_stack.set_visible_child(d_stack_activities);
-                       d_activities_switcher.show();
-                       d_dash_button.show();
                        d_dash_view.add_repository(d_repository);
-                       d_gear_menu.menu_model = d_activities_model;
+                       d_header_bar.mode = HeaderBar.Mode.ACTIVITIES;
                }
                else
                {
@@ -256,9 +213,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
                        d_main_stack.transition_type = Gtk.StackTransitionType.SLIDE_RIGHT;
                        d_main_stack.set_visible_child(d_dash_scrolled_window);
-                       d_activities_switcher.hide();
-                       d_dash_button.hide();
-                       d_gear_menu.menu_model = d_dash_model;
+                       d_header_bar.mode = HeaderBar.Mode.DASH;
                }
 
                d_activities.update();
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index 2dee59c..6fc19d6 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/gitg">
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-window.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-header-bar.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-menus.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-history.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-commit.ui</file>
diff --git a/gitg/resources/ui/gitg-header-bar.ui b/gitg/resources/ui/gitg-header-bar.ui
new file mode 100644
index 0000000..d75eec2
--- /dev/null
+++ b/gitg/resources/ui/gitg-header-bar.ui
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GitgHeaderBar" parent="Gtk.HeaderBar">
+    <child>
+      <object class="GtkButton" id="d_dash_button">
+        <property name="visible">False</property>
+        <property name="valign">center</property>
+        <property name="can_focus">False</property>
+        <signal name="clicked" handler="dash_button_clicked" swapped="no"/>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="dash_image">
+            <property name="visible">True</property>
+            <property name="icon_size">1</property>
+            <property name="icon_name">go-previous-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">start</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkToggleButton" id="d_search_button">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="can_focus">False</property>
+        <property name="action_name">win.search</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="search_image">
+            <property name="visible">True</property>
+            <property name="icon_size">1</property>
+            <property name="icon_name">edit-find-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkStackSwitcher" id="d_activities_switcher">
+        <property name="visible">False</property>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkMenuButton" id="d_gear_menu">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="can_focus">False</property>
+        <property name="action_name">win.gear-menu</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="gear_image">
+            <property name="visible">True</property>
+            <property name="icon_size">1</property>
+            <property name="icon_name">emblem-system-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkSeparator" id="close_button_separator">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="valign">fill</property>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="d_close_button">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="relief">none</property>
+        <signal name="clicked" handler="close_button_clicked" swapped="no"/>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="close_image">
+            <property name="visible">True</property>
+            <property name="icon_size">1</property>
+            <property name="icon_name">window-close-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index bad83c9..cb37a52 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -9,113 +9,10 @@
     <property name="default_width">1000</property>
     <property name="default_height">600</property>
     <child type="titlebar">
-      <object class="GtkHeaderBar" id="d_header_bar">
+      <object class="GitgHeaderBar" id="d_header_bar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="vexpand">False</property>
-        <child>
-          <object class="GtkButton" id="d_dash_button">
-            <property name="visible">False</property>
-            <property name="valign">center</property>
-            <property name="can_focus">False</property>
-            <signal name="clicked" handler="dash_button_clicked" swapped="no"/>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage" id="dash_image">
-                <property name="visible">True</property>
-                <property name="icon_size">1</property>
-                <property name="icon_name">go-previous-symbolic</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="pack_type">start</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkToggleButton" id="d_search_button">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="can_focus">False</property>
-            <property name="action_name">win.search</property>
-            <signal name="toggled" handler="search_button_toggled" swapped="no"/>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage" id="search_image">
-                <property name="visible">True</property>
-                <property name="icon_size">1</property>
-                <property name="icon_name">edit-find-symbolic</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkStackSwitcher" id="d_activities_switcher">
-            <property name="visible">False</property>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkMenuButton" id="d_gear_menu">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="can_focus">False</property>
-            <property name="action_name">win.gear-menu</property>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage" id="gear_image">
-                <property name="visible">True</property>
-                <property name="icon_size">1</property>
-                <property name="icon_name">emblem-system-symbolic</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkSeparator" id="close_button_separator">
-            <property name="visible">True</property>
-            <property name="orientation">vertical</property>
-            <property name="valign">fill</property>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="d_close_button">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="relief">none</property>
-            <signal name="clicked" handler="close_button_clicked" swapped="no"/>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage" id="close_image">
-                <property name="visible">True</property>
-                <property name="icon_size">1</property>
-                <property name="icon_name">window-close-symbolic</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
       </object>
     </child>
     <child>



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