[gitg/wip/albfan/keyboard-stage: 252/252] Use keyboard to stage selection




commit e77a9ac265be4fe8076fa0e87fe6f072007497b1
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Mon Oct 28 07:47:59 2019 +0100

    Use keyboard to stage selection

 README.md                                      |  3 ++
 gitg/commit/gitg-commit.vala                   | 17 +++++++
 libgitg/gitg-diff-view-file-renderer-text.vala | 12 ++++-
 libgitg/gitg-diff-view-file-selectable.vala    | 65 ++++++++++++++++++++++++--
 libgitg/gitg-diff-view.vala                    | 26 +++++++++++
 libgitg/gitg-sidebar.vala                      | 11 ++++-
 libgitg/resources/ui/libgitg-style.css         | 29 ++++++++++++
 7 files changed, 158 insertions(+), 5 deletions(-)
---
diff --git a/README.md b/README.md
index 04b16de8..6a06438c 100644
--- a/README.md
+++ b/README.md
@@ -38,5 +38,8 @@ $ sudo ninja -C build install
 Alternatively you can build using Flatpak with the org.gnome.gitgDevel.json manifest.
 
 ## Using gitg
+Hello
 
 When gitg is installed, you can run gitg from the GNOME menu, or from a terminal by issueing: 'gitg'. Type 
'gitg --help' to show the options you can specify on the command line.
+Bye
+
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 2b00cc39..510a6776 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -143,6 +143,23 @@ namespace GitgCommit
 
                public bool on_key_pressed (Gdk.EventKey event) {
                        var mmask = Gtk.accelerator_get_default_mod_mask();
+                       var modifiers = event.state;
+
+                       if (Gdk.ModifierType.CONTROL_MASK in modifiers
+                               && Gdk.ModifierType.SHIFT_MASK in modifiers)
+                       {
+                               if (event.keyval == Gdk.Key.Up)
+                               {
+                    d_main.diff_view.move_highlight_mark_up ();
+                                       print ("Up\n");
+                                       return true;
+                               } else if (event.keyval == Gdk.Key.Down)
+                               {
+                    d_main.diff_view.move_highlight_mark_down ();
+                                       print ("Down\n");
+                                       return true;
+                               }
+                       }
 
                        if ((mmask & event.state) == Gdk.ModifierType.CONTROL_MASK)
                        {
diff --git a/libgitg/gitg-diff-view-file-renderer-text.vala b/libgitg/gitg-diff-view-file-renderer-text.vala
index ae3352d9..b638327b 100644
--- a/libgitg/gitg-diff-view-file-renderer-text.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text.vala
@@ -49,7 +49,7 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
 
        private Gee.HashMap<int, PatchSet.Patch?> d_lines;
 
-       private DiffViewFileSelectable d_selectable;
+       public DiffViewFileSelectable d_selectable;
        private DiffViewLinesRenderer d_old_lines;
        private DiffViewLinesRenderer d_new_lines;
        private DiffViewLinesRenderer d_sym_lines;
@@ -255,6 +255,16 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
                highlight = true;
        }
 
+       public void move_highlight_mark_down ()
+       {
+               d_selectable.move_highlight_mark_down ();
+       }
+
+       public void move_highlight_mark_up ()
+       {
+               d_selectable.move_highlight_mark_up ();
+       }
+
        protected override void dispose()
        {
                base.dispose();
diff --git a/libgitg/gitg-diff-view-file-selectable.vala b/libgitg/gitg-diff-view-file-selectable.vala
index c80fe9a5..b9aabf4d 100644
--- a/libgitg/gitg-diff-view-file-selectable.vala
+++ b/libgitg/gitg-diff-view-file-selectable.vala
@@ -26,6 +26,7 @@ enum Gitg.DiffSelectionMode {
 class Gitg.DiffViewFileSelectable : Object
 {
        private string d_selection_category = "selection";
+       private string d_highligth_category = "highlight";
        private Gtk.TextTag d_selection_tag;
        private DiffSelectionMode d_selection_mode;
        private Gtk.TextMark d_start_selection_mark;
@@ -138,7 +139,10 @@ class Gitg.DiffViewFileSelectable : Object
        private void update_theme()
        {
                var selection_attributes = new Gtk.SourceMarkAttributes();
+               var highlight_attributes = new Gtk.SourceMarkAttributes();
+               highlight_attributes.icon_name = "pan-end-symbolic";
                var context = source_view.get_style_context();
+               source_view.show_line_marks = true;
 
                Gdk.RGBA theme_selected_bg_color, theme_selected_fg_color;
 
@@ -146,13 +150,14 @@ class Gitg.DiffViewFileSelectable : Object
                {
                        selection_attributes.background = theme_selected_bg_color;
                }
-               
+
                if (context.lookup_color("theme_selected_fg_color", out theme_selected_fg_color))
                {
                        d_selection_tag.foreground_rgba = theme_selected_fg_color;
                }
 
-               source_view.set_mark_attributes(d_selection_category, selection_attributes, 0);
+               source_view.set_mark_attributes(d_highligth_category, highlight_attributes, 0);
+               source_view.set_mark_attributes(d_selection_category, selection_attributes, 1);
        }
 
        private bool get_line_selected(Gtk.TextIter iter)
@@ -273,6 +278,11 @@ class Gitg.DiffViewFileSelectable : Object
                                        }
 
                                        buffer.apply_tag(d_selection_tag, current, line_end);
+                                       Gtk.TextIter start_iter, end_iter;
+                                       buffer.get_start_iter (out start_iter);
+                                       buffer.get_end_iter (out end_iter);
+                    buffer.remove_source_marks (start_iter, end_iter, d_highligth_category);
+                                       buffer.create_source_mark(null, d_highligth_category, current);
                                }
                        }
 
@@ -359,6 +369,53 @@ class Gitg.DiffViewFileSelectable : Object
                update_selection_range(iter, end, select);
        }
 
+       public void move_highlight_mark_up() {
+               Gtk.TextIter start_iter, end_iter;
+               var buffer = source_view.buffer as Gtk.SourceBuffer;
+               buffer.get_start_iter (out start_iter);
+               buffer.get_end_iter (out end_iter);
+
+               Gtk.TextIter iter;
+               buffer.get_start_iter (out iter);
+               buffer.forward_iter_to_source_mark (iter, d_highligth_category);
+        iter.backward_line ();
+               while (iter.get_line () >= start_iter.get_line ())
+               {
+                       if (get_line_is_diff(iter))
+                       {
+                buffer.remove_source_marks (start_iter, end_iter, d_highligth_category);
+                           buffer.create_source_mark(null, d_highligth_category, iter);
+                               break;
+                       }
+                       iter.backward_line ();
+               }
+       }
+
+       public void move_highlight_mark_down() {
+               Gtk.TextIter start_iter, end_iter;
+               var buffer = source_view.buffer as Gtk.SourceBuffer;
+               buffer.get_start_iter (out start_iter);
+               buffer.get_end_iter (out end_iter);
+
+               Gtk.TextIter iter;
+               buffer.get_start_iter(out iter);
+               if (buffer.forward_iter_to_source_mark (iter, d_highligth_category))
+               {
+            iter.forward_line ();
+               }
+               while (iter.get_line () <= end_iter.get_line ())
+               {
+                       print ("next line %d\n", iter.get_line ());
+                       if (get_line_is_diff(iter))
+                       {
+                buffer.remove_source_marks (start_iter, end_iter, d_highligth_category);
+                           buffer.create_source_mark(null, d_highligth_category, iter);
+                               break;
+                       }
+            iter.forward_line ();
+               }
+       }
+
        private bool button_press_event_on_view(Gdk.EventButton event)
        {
                if (event.button != 1)
@@ -375,7 +432,9 @@ class Gitg.DiffViewFileSelectable : Object
 
                var buffer = source_view.buffer;
 
-               if ((event.state & Gdk.ModifierType.SHIFT_MASK) != 0)
+               var mmask = Gtk.accelerator_get_default_mod_mask();
+
+               if ((mmask & event.state) == Gdk.ModifierType.SHIFT_MASK)
                {
                        update_selection(iter);
                        return true;
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index f40bcfcb..464e2fd0 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -757,6 +757,7 @@ public class Gitg.DiffView : Gtk.Grid
                        if (current_file != null)
                        {
                                current_file.show();
+                               current_file.renderer.notify["has-selection"].connect(on_selection_changed);
 
                                files.add(current_file);
 
@@ -1061,6 +1062,31 @@ public class Gitg.DiffView : Gtk.Grid
                return ret;
        }
 
+       public void move_highlight_mark_down ()
+       {
+               //TODO: select only the current one
+               //TODO: There's a selection for any of them
+               //TODO: Remove all this pile of function call
+               //Make sure highlight file is shown (scroll)
+               foreach (var file in d_grid_files.get_children())
+               {
+                       var renderer = (file as Gitg.DiffViewFile).renderer as DiffViewFileRendererText;
+                       renderer.move_highlight_mark_down ();
+                       break;
+               }
+       }
+
+       public void move_highlight_mark_up ()
+       {
+               //TODO: select only the current one
+               foreach (var file in d_grid_files.get_children())
+               {
+                       var renderer = (file as Gitg.DiffViewFile).renderer as DiffViewFileRendererText;
+                       renderer.move_highlight_mark_up ();
+                       break;
+               }
+       }
+
        private void update_hide_show_options(Gdk.Window window, int ex, int ey)
        {
                void *data;
diff --git a/libgitg/gitg-sidebar.vala b/libgitg/gitg-sidebar.vala
index deebbeae..5edc1c9f 100644
--- a/libgitg/gitg-sidebar.vala
+++ b/libgitg/gitg-sidebar.vala
@@ -423,7 +423,16 @@ public class Sidebar : Gtk.TreeView
 
        protected override bool key_press_event(Gdk.EventKey event)
        {
-               if ((event.state & Gtk.accelerator_get_default_mod_mask()) != 0)
+               var mmask = Gtk.accelerator_get_default_mod_mask();
+               var modifiers = event.state;
+
+               if (Gdk.ModifierType.CONTROL_MASK in modifiers && Gdk.ModifierType.SHIFT_MASK in modifiers
+                       && (event.keyval == Gdk.Key.Up || event.keyval == Gdk.Key.Down))
+               {
+                       return false;
+               }
+
+               if ((event.state & mmask) != 0)
                {
                        return base.key_press_event(event);
                }
diff --git a/libgitg/resources/ui/libgitg-style.css b/libgitg/resources/ui/libgitg-style.css
index d9d27594..a87de349 100644
--- a/libgitg/resources/ui/libgitg-style.css
+++ b/libgitg/resources/ui/libgitg-style.css
@@ -125,3 +125,32 @@ GitgDiffImageSideBySide.old {
 GitgDiffImageSideBySide.new {
        border: 10px solid #ddffdd;
 }
+
+@define-color indicator_label_error
+    alpha(mix(@error_color, @theme_selected_fg_color, 0.3), 0.9);
+@define-color indicator_label_success
+    alpha(mix(shade(@success_color, 0.85), @theme_selected_fg_color, 0.3), 0.9);
+@define-color indicator_label_warning
+    alpha(mix(@warning_color, @theme_selected_fg_color, 0.3), 0.9);
+@define-color indicator_label_theme
+    mix(@theme_selected_bg_color, @theme_selected_fg_color, 0.3);
+
+.LabelError {
+    background-color: @indicator_label_error;
+    border-color: alpha(mix(@indicator_label_error, @theme_selected_fg_color, 0.66), 0.5);
+}
+
+.LabelSuccess {
+    background-color: @indicator_label_success;
+    border-color: alpha(mix(@indicator_label_success, @theme_selected_fg_color, 0.66), 0.5);
+}
+
+.LabelWarning {
+    background-color: @indicator_label_warning;
+    border-color: alpha(mix(@indicator_label_warning, @theme_selected_fg_color, 0.66), 0.5);
+}
+
+.LabelTheme {
+    background-color: @indicator_label_theme;
+    border-color: alpha(mix(@indicator_label_theme, @theme_selected_fg_color, 0.66), 0.5);
+}


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