[gitg] Implement opening file from staging area
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Implement opening file from staging area
- Date: Wed, 17 Dec 2014 19:31:33 +0000 (UTC)
commit fc072c5bad1a41ba18a5ca1846ea2b63e2b8a871
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Wed Dec 17 20:30:39 2014 +0100
Implement opening file from staging area
gitg/commit/gitg-commit-sidebar.vala | 9 ++++++
gitg/commit/gitg-commit.vala | 51 ++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-sidebar.vala b/gitg/commit/gitg-commit-sidebar.vala
index 9dac9b0..993aec0 100644
--- a/gitg/commit/gitg-commit-sidebar.vala
+++ b/gitg/commit/gitg-commit-sidebar.vala
@@ -31,6 +31,9 @@ class Sidebar : Gitg.Sidebar
[Signal(action = true)]
public signal void discard_selection();
+ [Signal(action = true)]
+ public signal void edit_selection();
+
public signal void selected_items_changed(Gitg.SidebarItem[] items);
public class Item : Object, Gitg.SidebarItem
@@ -96,6 +99,12 @@ class Sidebar : Gitg.Sidebar
"discard-selection",
0);
+ Gtk.BindingEntry.add_signal(binding_set,
+ Gdk.Key.e,
+ Gdk.ModifierType.CONTROL_MASK,
+ "edit-selection",
+ 0);
+
var sel = get_selection();
sel.mode = Gtk.SelectionMode.MULTIPLE;
}
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index a2be9ea..880f831 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -1342,6 +1342,26 @@ namespace GitgCommit
}
}
+ private void do_edit_items(Gitg.StageStatusItem[] items)
+ {
+ var screen = d_main.get_screen();
+ var root = application.repository.get_workdir();
+
+ foreach (var item in items)
+ {
+ var file = root.get_child(item.path);
+
+ try
+ {
+ Gtk.show_uri(screen, file.get_uri(), Gdk.CURRENT_TIME);
+ }
+ catch (Error e)
+ {
+ stderr.printf("Failed to launch application for %s: %s\n", item.path,
e.message);
+ }
+ }
+ }
+
private bool do_discard_items(GitgExt.UserQuery q, Gitg.StageStatusItem[] items)
{
application.busy = true;
@@ -1463,6 +1483,29 @@ namespace GitgCommit
on_discard_menu_activated(sitems);
});
}
+
+ var canedit = true;
+
+ foreach (var item in sitems)
+ {
+ var file = item as Gitg.StageStatusFile;
+
+ if (file == null || (file.flags & Ggit.StatusFlags.WORKING_TREE_DELETED) != 0)
+ {
+ canedit = false;
+ break;
+ }
+ }
+
+ if (canedit)
+ {
+ var edit = new Gtk.MenuItem.with_mnemonic(_("_Edit file"));
+ menu.append(edit);
+
+ edit.activate.connect(() => {
+ do_edit_items(sitems);
+ });
+ }
}
private Gitg.StageStatusItem[] items_to_stage_items(Sidebar.Item[] items)
@@ -1595,6 +1638,14 @@ namespace GitgCommit
}
});
+ d_main.sidebar.edit_selection.connect(() => {
+ var sel = d_main.sidebar.get_selected_items<Gitg.SidebarItem>();
+ Sidebar.Item.Type type;
+
+ var sitems = items_for_items(sel, out type);
+ do_edit_items(sitems);
+ });
+
d_main.sidebar.selected_items_changed.connect(sidebar_selection_changed);
d_main.button_commit.clicked.connect(() => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]