[gitg/wip/commit: 28/28] Added commit activity



commit 4ac00334a3036fc19e73c518d99add8b15e4a821
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Jul 3 16:44:38 2013 +0200

    Added commit activity

 gitg/Makefile.am                       |    4 +-
 gitg/commit/gitg-commit-paned.vala     |   60 +++++++
 gitg/commit/gitg-commit.vala           |  270 ++++++++++++++++++++++++++++++++
 gitg/gitg-application.vala             |   11 ++
 gitg/gitg-window.vala                  |    3 +-
 gitg/resources/gitg-resources.xml      |    1 +
 gitg/resources/ui/gitg-commit-paned.ui |   61 +++++++
 7 files changed, 408 insertions(+), 2 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 7aa5b27..bc869fe 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -46,7 +46,9 @@ VALASOURCES =                                                 \
        preferences/gitg-preferences-history.vala               \
        history/gitg-history.vala                               \
        history/gitg-history-navigation.vala                    \
-       history/gitg-history-paned.vala
+       history/gitg-history-paned.vala                         \
+       commit/gitg-commit.vala                                 \
+       commit/gitg-commit-paned.vala
 
 BUILT_SOURCES =                                                \
        gitg-resources.c                                        \
diff --git a/gitg/commit/gitg-commit-paned.vala b/gitg/commit/gitg-commit-paned.vala
new file mode 100644
index 0000000..e0aa98d
--- /dev/null
+++ b/gitg/commit/gitg-commit-paned.vala
@@ -0,0 +1,60 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2012 - Jesse van den Kieboom
+ *
+ * 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 GitgCommit
+{
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-commit-paned.ui")]
+class Paned : Gtk.Paned
+{
+       [GtkChild (name = "tree_view_files")]
+       private Gitg.Sidebar d_tree_view_files;
+
+       [GtkChild (name = "diff_view")]
+       private Gitg.DiffView d_diff_view;
+
+       public Gitg.Sidebar tree_view_files
+       {
+               get { return d_tree_view_files; }
+       }
+
+       public Gitg.DiffView diff_view
+       {
+               get { return d_diff_view; }
+       }
+
+       construct
+       {
+               var state_settings = new Settings("org.gnome.gitg.state.commit");
+
+               state_settings.bind("paned-sidebar-position",
+                                   this,
+                                   "position",
+                                   SettingsBindFlags.GET | SettingsBindFlags.SET);
+       }
+
+       public Paned()
+       {
+               Object(orientation: Gtk.Orientation.HORIZONTAL);
+       }
+}
+
+}
+
+// ex: ts=4 noet
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
new file mode 100644
index 0000000..3892c6f
--- /dev/null
+++ b/gitg/commit/gitg-commit.vala
@@ -0,0 +1,270 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2012 - Jesse van den Kieboom
+ *
+ * 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 GitgCommit
+{
+       public class Activity : Object, GitgExt.UIElement, GitgExt.Activity
+       {
+               // Do this to pull in config.h before glib.h (for gettext...)
+               private const string version = Gitg.Config.VERSION;
+               private Paned? d_main;
+
+               public GitgExt.Application? application { owned get; construct set; }
+
+               public Activity(GitgExt.Application application)
+               {
+                       Object(application: application);
+               }
+
+               public string id
+               {
+                       owned get { return "/org/gnome/gitg/Activities/Commit"; }
+               }
+
+               [Notify]
+               public Gitg.Repository repository
+               {
+                       set
+                       {
+                               if (value != null)
+                               {
+                                       reload();
+                               }
+                       }
+               }
+
+               construct
+               {
+                       application.bind_property("repository", this,
+                                                 "repository", BindingFlags.DEFAULT);
+               }
+
+               public string display_name
+               {
+                       owned get { return _("Commit"); }
+               }
+
+               public string? icon
+               {
+                       owned get { return "document-save-symbolic"; }
+               }
+
+               public Gtk.Widget? widget
+               {
+                       owned get
+                       {
+                               if (d_main == null)
+                               {
+                                       build_ui();
+                               }
+
+                               return d_main;
+                       }
+               }
+
+               public bool is_default_for(string action)
+               {
+                       return action == "commit";
+               }
+
+               private string? icon_for_status(Ggit.StatusFlags status)
+               {
+                       if ((status & (Ggit.StatusFlags.INDEX_NEW |
+                                      Ggit.StatusFlags.WORKING_TREE_NEW)) != 0)
+                       {
+                               return "document-new";
+                       }
+                       else if ((status & (Ggit.StatusFlags.INDEX_MODIFIED |
+                                           Ggit.StatusFlags.INDEX_RENAMED |
+                                           Ggit.StatusFlags.INDEX_TYPECHANGE |
+                                           Ggit.StatusFlags.WORKING_TREE_MODIFIED |
+                                           Ggit.StatusFlags.WORKING_TREE_TYPECHANGE)) != 0)
+                       {
+                               return "gtk-edit";
+                       }
+                       else if ((status & (Ggit.StatusFlags.INDEX_DELETED |
+                                           Ggit.StatusFlags.WORKING_TREE_DELETED)) != 0)
+                       {
+                               return "edit-delete";
+                       }
+
+                       return null;
+               }
+
+               private delegate void StageUnstageCallback(Gitg.StageStatusFile f, int numclick);
+
+               private void on_unstaged_activated(Gitg.StageStatusFile f, int numclick)
+               {
+                       if (numclick == 1)
+                       {
+                               var stage = application.repository.stage;
+
+                               stage.diff_workdir.begin(f, (obj, res) => {
+                                       try
+                                       {
+                                               var d = stage.diff_workdir.end(res);
+
+                                               d_main.diff_view.unstaged = true;
+                                               d_main.diff_view.staged = false;
+
+                                               d_main.diff_view.diff = d;
+                                       }
+                                       catch
+                                       {
+                                               // TODO: error reporting
+                                               d_main.diff_view.diff = null;
+                                       }
+                               });
+
+                       }
+               }
+
+               private void on_staged_activated(Gitg.StageStatusFile f, int numclick)
+               {
+                       if (numclick == 1)
+                       {
+                               var stage = application.repository.stage;
+
+                               stage.diff_index.begin(f, (obj, res) => {
+                                       try
+                                       {
+                                               var d = stage.diff_index.end(res);
+
+                                               d_main.diff_view.unstaged = false;
+                                               d_main.diff_view.staged = true;
+
+                                               d_main.diff_view.diff = d;
+                                       }
+                                       catch
+                                       {
+                                               // TODO: error reporting
+                                               d_main.diff_view.diff = null;
+                                       }
+                               });
+                       }
+               }
+
+               private void append_files(Gitg.SidebarStore      model,
+                                         Gitg.StageStatusFile[] files,
+                                         StageUnstageCallback?  callback)
+               {
+                       foreach (var f in files)
+                       {
+                               model.append_normal(f.path, null, icon_for_status(f.flags), (numclick) => {
+                                       if (callback != null)
+                                       {
+                                               callback(f, numclick);
+                                       }
+                               });
+                       }
+               }
+
+               public void reload()
+               {
+                       var model = d_main.tree_view_files.model;
+                       model.clear();
+
+                       var stage = application.repository.stage;
+
+                       var opts = Ggit.StatusOption.INCLUDE_UNTRACKED |
+                                  Ggit.StatusOption.RECURSE_UNTRACKED_DIRS |
+                                  Ggit.StatusOption.SORT_CASE_INSENSITIVELY |
+                                  Ggit.StatusOption.EXCLUDE_SUBMODULES |
+                                  Ggit.StatusOption.DISABLE_PATHSPEC_MATCH;
+
+                       var show = Ggit.StatusShow.INDEX_AND_WORKDIR;
+
+                       var options = new Ggit.StatusOptions(opts, show, null);
+                       var enumerator = stage.file_status(options);
+
+                       var indexflags = Ggit.StatusFlags.INDEX_NEW |
+                                        Ggit.StatusFlags.INDEX_MODIFIED |
+                                        Ggit.StatusFlags.INDEX_DELETED |
+                                        Ggit.StatusFlags.INDEX_RENAMED |
+                                        Ggit.StatusFlags.INDEX_TYPECHANGE;
+
+                       var workflags = Ggit.StatusFlags.WORKING_TREE_NEW |
+                                       Ggit.StatusFlags.WORKING_TREE_MODIFIED |
+                                       Ggit.StatusFlags.WORKING_TREE_DELETED |
+                                       Ggit.StatusFlags.WORKING_TREE_TYPECHANGE;
+
+                       enumerator.next_files.begin(-1, (obj, res) => {
+                               var files = enumerator.next_files.end(res);
+
+                               var staged = new Gitg.StageStatusFile[files.length];
+                               staged.length = 0;
+
+                               var unstaged = new Gitg.StageStatusFile[files.length];
+                               unstaged.length = 0;
+
+                               foreach (var f in files)
+                               {
+                                       if ((f.flags & indexflags) != 0)
+                                       {
+                                               staged += f;
+                                       }
+                                       else if ((f.flags & workflags) != 0)
+                                       {
+                                               unstaged += f;
+                                       }
+                               }
+
+                               model.begin_header(_("Staged"));
+
+                               if (staged.length == 0)
+                               {
+                                       model.append_dummy(_("No staged files"));
+                               }
+                               else
+                               {
+                                       append_files(model, staged, on_staged_activated);
+                               }
+
+                               model.end_header();
+
+                               model.begin_header(_("Unstaged"));
+
+                               if (unstaged.length == 0)
+                               {
+                                       model.append_dummy(_("No unstaged files"));
+                               }
+                               else
+                               {
+                                       append_files(model, unstaged, on_unstaged_activated);
+                               }
+
+                               model.end_header();
+
+                               d_main.tree_view_files.expand_all();
+                       });
+               }
+
+               public void activate()
+               {
+                       reload();
+               }
+
+               private void build_ui()
+               {
+                       d_main = new Paned();
+               }
+       }
+}
+
+// ex: ts=4 noet
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index 5379b5b..8c56164 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -42,16 +42,27 @@ public class Application : Gtk.Application
                public static bool quit = false;
                public static string activity;
                public static bool no_wd = false;
+
                public static ApplicationCommandLine command_line;
 
+               private static void commit_activity()
+               {
+                       activity = "commit";
+               }
+
                public static const OptionEntry[] entries = {
                        {"version", 'v', OptionFlags.NO_ARG, OptionArg.CALLBACK,
                         (void *)show_version_and_quit, N_("Show the application's version"), null},
 
                        {"activity", '\0', 0, OptionArg.STRING,
                         ref activity, N_("Start gitg with a particular activity"), null},
+
+                       {"commit", 'c', OptionFlags.NO_ARG, OptionArg.CALLBACK,
+                        (void *)commit_activity, N_("Start gitg with the commit activity (shorthand for 
--view commit)"), null},
+
                         {"no-wd", 0, 0, OptionArg.NONE,
                         ref no_wd, N_("Do not try to load a repository from the current working directory"), 
null},
+
                        {null}
                };
        }
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index f764099..62e2c5c 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -561,7 +561,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                var engine = PluginsEngine.get_default();
 
                var builtins = new GitgExt.Activity[] {
-                       new GitgHistory.Activity(this)
+                       new GitgHistory.Activity(this),
+                       new GitgCommit.Activity(this)
                };
 
                var extset = new Peas.ExtensionSet(engine,
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index f98883a..78d254b 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -9,6 +9,7 @@
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-clone-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-user-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-history-paned.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-commit-paned.ui</file>
     <file compressed="true">ui/style.css</file>
     <file alias="icons/gitg.svg" compressed="true" 
preprocess="xml-stripblanks">../../data/icons/gitg.svg</file>
     <file alias="icons/gitg128x128.png">../../data/icons/gitg128x128.png</file>
diff --git a/gitg/resources/ui/gitg-commit-paned.ui b/gitg/resources/ui/gitg-commit-paned.ui
new file mode 100644
index 0000000..0f761a1
--- /dev/null
+++ b/gitg/resources/ui/gitg-commit-paned.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.3 -->
+  <!-- interface-requires gitg 0.0 -->
+  <!-- interface-requires gd 1.0 -->
+  <template class="GitgCommitPaned" parent="Gtk.Paned">
+    <property name="visible">True</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="can_focus">True</property>
+    <property name="position">200</property>
+    <property name="position_set">True</property>
+    <style>
+      <class name="sidebar-paned"/>
+    </style>
+    <child>
+      <object class="GtkBox" id="box_sidebar">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolled_window_files">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="hscrollbar_policy">never</property>
+            <property name="name">scrolled_window_files</property>
+            <style>
+              <class name="sidebar"/>
+            </style>
+            <child>
+              <object class="GitgSidebar" id="tree_view_files">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="headers_visible">False</property>
+                <property name="name">tree_view_files</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GitgDiffView" id="diff_view">
+        <property name="visible">True</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="can_focus">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
+
+<!-- ex:set ts=2 et: -->


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