[gitg] Added supported diff options for commit diff
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Added supported diff options for commit diff
- Date: Thu, 10 Jul 2014 17:58:20 +0000 (UTC)
commit ed1412628c6a179a07a8deff4a43beb893bccae2
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Thu Jul 10 19:56:24 2014 +0200
Added supported diff options for commit diff
data/org.gnome.gitg.gschema.xml.in.in | 20 +++++++++++++++++
gitg/commit/gitg-commit.vala | 36 ++++++++++++++++++++++++++++++-
libgitg/gitg-diff-view-options.vala | 20 +++++++++++++++++
libgitg/gitg-diff-view.vala | 21 +++++++++++-------
libgitg/gitg-stage.vala | 32 +++++++++++++++++++++-------
libgitg/resources/diff-view-options.ui | 2 +-
6 files changed, 112 insertions(+), 19 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index e947162..1d8efb2 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -75,6 +75,7 @@
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit"
path="/org/gnome/gitg/preferences/commit/">
<child name="message" schema="org.gnome.gitg.preferences.commit.message" />
+ <child name="diff" schema="org.gnome.gitg.preferences.commit.diff" />
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit.message"
path="/org/gnome/gitg/preferences/commit/message/">
<key name="show-markup" type="b">
@@ -140,6 +141,25 @@
<default>4</default>
</key>
</schema>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit.diff"
path="/org/gnome/gitg/preferences/commit/diff/">
+ <key name="context-lines" type="i">
+ <default>3</default>
+ <_summary>Number of Before/After Context Lines</_summary>
+ <_description>
+ Setting that determines how many lines of context (before and after)
+ should be shown when showing the diff to be staged/unstaged in the
+ commit area.
+ </_description>
+ </key>
+ <key name="tab-width" type="i">
+ <default>4</default>
+ <_summary>Rendered Width of a Tab Character</_summary>
+ <_description>
+ Setting that determines how much space a tab character should occupy
+ when showing the diff of a commit.
+ </_description>
+ </key>
+ </schema>
<schema id="org.gnome.gitg.state" path="/org/gnome/gitg/state/">
<child name="window" schema="org.gnome.gitg.state.window"/>
<child name="history" schema="org.gnome.gitg.state.history"/>
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 0e2484a..c53811d 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -140,11 +140,14 @@ namespace GitgCommit
private delegate void StageUnstageCallback(Gitg.StageStatusFile f, int numclick);
+ private delegate void UpdateDiffCallback();
+ private UpdateDiffCallback? d_update_diff_callback;
+
private void show_unstaged_diff(Gitg.StageStatusFile f)
{
var stage = application.repository.stage;
- stage.diff_workdir.begin(f, (obj, res) => {
+ stage.diff_workdir.begin(f, d_main.diff_view.options, (obj, res) => {
try
{
var d = stage.diff_workdir.end(res);
@@ -163,6 +166,10 @@ namespace GitgCommit
d_main.diff_view.diff = null;
}
});
+
+ d_update_diff_callback = () => {
+ show_unstaged_diff(f);
+ };
}
private void stage_file(Gitg.StageStatusFile f)
@@ -229,7 +236,7 @@ namespace GitgCommit
{
var stage = application.repository.stage;
- stage.diff_index.begin(f, (obj, res) => {
+ stage.diff_index.begin(f, d_main.diff_view.options, (obj, res) => {
try
{
var d = stage.diff_index.end(res);
@@ -248,6 +255,10 @@ namespace GitgCommit
d_main.diff_view.diff = null;
}
});
+
+ d_update_diff_callback = () => {
+ show_staged_diff(f);
+ };
}
private void delete_index_file(Gitg.StageStatusFile f)
@@ -1005,6 +1016,13 @@ namespace GitgCommit
{
d_main = new Paned();
+ d_main.diff_view.options_changed.connect(() => {
+ if (d_update_diff_callback != null)
+ {
+ d_update_diff_callback();
+ }
+ });
+
d_main.sidebar.deselected.connect(() => {
d_main.diff_view.diff = null;
});
@@ -1023,6 +1041,20 @@ namespace GitgCommit
d_main.sidebar.populate_popup.connect(do_populate_menu);
+ var settings = new Settings("org.gnome.gitg.preferences.commit.diff");
+
+ settings.bind("context-lines",
+ d_main.diff_view,
+ "context-lines",
+ SettingsBindFlags.GET |
+ SettingsBindFlags.SET);
+
+ settings.bind("tab-width",
+ d_main.diff_view,
+ "tab-width",
+ SettingsBindFlags.GET |
+ SettingsBindFlags.SET);
+
d_main.diff_view.bind_property("has-selection",
d_main.button_stage,
"sensitive",
diff --git a/libgitg/gitg-diff-view-options.vala b/libgitg/gitg-diff-view-options.vala
index e353c94..323cde4 100644
--- a/libgitg/gitg-diff-view-options.vala
+++ b/libgitg/gitg-diff-view-options.vala
@@ -26,9 +26,15 @@ public class DiffViewOptions : Gtk.Grid
[GtkChild (name = "switch_changes_inline")]
private Gtk.Switch d_switch_changes_inline;
+ [GtkChild (name = "label_changes_inline")]
+ private Gtk.Label d_label_changes_inline;
+
[GtkChild (name = "switch_ignore_whitespace")]
private Gtk.Switch d_switch_ignore_whitespace;
+ [GtkChild (name = "label_ignore_whitespace")]
+ private Gtk.Label d_label_ignore_whitespace;
+
[GtkChild (name = "adjustment_context")]
private Gtk.Adjustment d_adjustment_context;
@@ -41,6 +47,9 @@ public class DiffViewOptions : Gtk.Grid
[GtkChild (name = "separator_developer_tools")]
private Gtk.Separator d_separator_developer_tools;
+ [GtkChild (name = "separator_first_options")]
+ private Gtk.Separator d_separator_first_options;
+
public bool changes_inline { get; set; }
public bool ignore_whitespace { get; set; }
public int context_lines { get; set; }
@@ -127,6 +136,17 @@ public class DiffViewOptions : Gtk.Grid
d_separator_developer_tools.visible = dbg;
d_button_developer_tools.visible = dbg;
+
+ if (view.commit == null)
+ {
+ d_label_changes_inline.visible = false;
+ d_switch_changes_inline.visible = false;
+
+ d_label_ignore_whitespace.visible = false;
+ d_switch_ignore_whitespace.visible = false;
+
+ d_separator_first_options.visible = false;
+ }
}
[GtkCallback]
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 3d09725..0c608d8 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -60,6 +60,14 @@ namespace Gitg
public File? custom_css { get; construct; }
public File? custom_js { get; construct; }
+ public virtual signal void options_changed()
+ {
+ if (d_commit != null)
+ {
+ update();
+ }
+ }
+
public Ggit.DiffOptions options
{
get
@@ -148,7 +156,8 @@ namespace Gitg
if (flags != options.flags)
{
options.flags = flags;
- update();
+
+ options_changed();
}
}
@@ -168,7 +177,8 @@ namespace Gitg
if (d_changes_inline != value)
{
d_changes_inline = value;
- update();
+
+ options_changed();
}
}
}
@@ -184,7 +194,7 @@ namespace Gitg
options.n_context_lines = value;
options.n_interhunk_lines = value;
- update();
+ options_changed();
}
}
@@ -592,11 +602,6 @@ namespace Gitg
Gdk.Event event,
WebKit.HitTestResult hit_test_result)
{
- if (d_commit == null)
- {
- return true;
- }
-
var m = new Gtk.Popover(this);
var opts = new DiffViewOptions(this);
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index d8b9a41..75b84e8 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -904,7 +904,7 @@ public class Stage : Object
});
}
- public async Ggit.Diff? diff_index(StageStatusFile f) throws Error
+ public async Ggit.Diff? diff_index(StageStatusFile f, Ggit.DiffOptions? defopts = null) throws Error
{
var opts = new Ggit.DiffOptions();
@@ -912,11 +912,19 @@ public class Stage : Object
Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
Ggit.DiffOption.RECURSE_UNTRACKED_DIRS;
- opts.n_context_lines = 3;
- opts.n_interhunk_lines = 3;
-
opts.pathspec = new string[] {f.path};
+ if (defopts != null)
+ {
+ opts.flags |= defopts.flags;
+
+ opts.n_context_lines = defopts.n_context_lines;
+ opts.n_interhunk_lines = defopts.n_interhunk_lines;
+
+ opts.old_prefix = defopts.old_prefix;
+ opts.new_prefix = defopts.new_prefix;
+ }
+
var tree = yield get_head_tree();
return new Ggit.Diff.tree_to_index(d_repository,
@@ -925,7 +933,7 @@ public class Stage : Object
opts);
}
- public async Ggit.Diff? diff_workdir(StageStatusFile f) throws Error
+ public async Ggit.Diff? diff_workdir(StageStatusFile f, Ggit.DiffOptions? defopts = null) throws Error
{
var opts = new Ggit.DiffOptions();
@@ -933,11 +941,19 @@ public class Stage : Object
Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
Ggit.DiffOption.RECURSE_UNTRACKED_DIRS;
- opts.n_context_lines = 3;
- opts.n_interhunk_lines = 3;
-
opts.pathspec = new string[] {f.path};
+ if (defopts != null)
+ {
+ opts.flags |= defopts.flags;
+
+ opts.n_context_lines = defopts.n_context_lines;
+ opts.n_interhunk_lines = defopts.n_interhunk_lines;
+
+ opts.old_prefix = defopts.old_prefix;
+ opts.new_prefix = defopts.new_prefix;
+ }
+
return new Ggit.Diff.index_to_workdir(d_repository,
d_repository.get_index(),
opts);
diff --git a/libgitg/resources/diff-view-options.ui b/libgitg/resources/diff-view-options.ui
index 0291293..62f36ee 100644
--- a/libgitg/resources/diff-view-options.ui
+++ b/libgitg/resources/diff-view-options.ui
@@ -71,7 +71,7 @@
</packing>
</child>
<child>
- <object class="GtkSeparator" id="separator1">
+ <object class="GtkSeparator" id="separator_first_options">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]