[gitg] Expose diff view options
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Expose diff view options
- Date: Wed, 9 Jul 2014 19:48:01 +0000 (UTC)
commit cf892f0a3d8ee8facd12f4faf4acecb09769d932
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Wed Jul 9 21:42:55 2014 +0200
Expose diff view options
data/org.gnome.gitg.gschema.xml.in.in | 18 +++--
libgitg/Makefile.am | 1 +
libgitg/gitg-diff-view-options.vala | 121 ++++++++++++++++++++++++++
libgitg/gitg-diff-view.vala | 109 ++++++++++++++----------
libgitg/resources/diff-view-options.ui | 146 ++++++++++++++++++++++++++++++++
libgitg/resources/resources.xml | 3 +
plugins/diff/gitg-diff.vala | 14 +++-
po/POTFILES.in | 1 +
8 files changed, 362 insertions(+), 51 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index a26534f..7b2388a 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -9,6 +9,7 @@
<child name="history" schema="org.gnome.gitg.preferences.history" />
<child name="commit" schema="org.gnome.gitg.preferences.commit" />
<child name="hidden" schema="org.gnome.gitg.preferences.hidden" />
+ <child name="diff" schema="org.gnome.gitg.preferences.diff" />
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.main"
path="/org/gnome/gitg/preferences/main/">
<key name="clone-directory" type="s">
@@ -125,11 +126,21 @@
<!-- TODO _description -->
</key>
</schema>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.diff"
path="/org/gnome/gitg/preferences/diff/">
+ <key name="ignore-whitespace" type="b">
+ <default>false</default>
+ </key>
+ <key name="changes-inline" type="b">
+ <default>false</default>
+ </key>
+ <key name="context-lines" type="i">
+ <default>3</default>
+ </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"/>
<child name="commit" schema="org.gnome.gitg.state.commit"/>
- <child name="diff" schema="org.gnome.gitg.state.diff"/>
</schema>
<schema id="org.gnome.gitg.state.window" path="/org/gnome/gitg/state/window/">
<key name="state" type="i">
@@ -167,9 +178,4 @@
<default>false</default>
</key>
</schema>
- <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.state.diff"
path="/org/gnome/gitg/state/diff/">
- <key name="ignore-whitespace" type="b">
- <default>false</default>
- </key>
- </schema>
</schemalist>
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index 53e85c3..60b75e9 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -57,6 +57,7 @@ libgitg_libgitg_1_0_la_VALASOURCES = \
libgitg/gitg-cell-renderer-lanes.vala \
libgitg/gitg-commit-list-view.vala \
libgitg/gitg-diff-view.vala \
+ libgitg/gitg-diff-view-options.vala \
libgitg/gitg-diff-view-request.vala \
libgitg/gitg-diff-view-request-icon.vala \
libgitg/gitg-diff-view-request-resource.vala \
diff --git a/libgitg/gitg-diff-view-options.vala b/libgitg/gitg-diff-view-options.vala
new file mode 100644
index 0000000..d8ff280
--- /dev/null
+++ b/libgitg/gitg-diff-view-options.vala
@@ -0,0 +1,121 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2014 - 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 Gitg
+{
+
+[GtkTemplate ( ui = "/org/gnome/gitg/gtk/diff-view/diff-view-options.ui" )]
+public class DiffViewOptions : Gtk.Grid
+{
+ [GtkChild (name = "switch_changes_inline")]
+ private Gtk.Switch d_switch_changes_inline;
+
+ [GtkChild (name = "switch_ignore_whitespace")]
+ private Gtk.Switch d_switch_ignore_whitespace;
+
+ [GtkChild (name = "adjustment_context")]
+ private Gtk.Adjustment d_adjustment_context;
+
+ [GtkChild (name = "button_developer_tools")]
+ private Gtk.Button d_button_developer_tools;
+
+ [GtkChild (name = "separator_developer_tools")]
+ private Gtk.Separator d_separator_developer_tools;
+
+ public bool changes_inline { get; set; }
+ public bool ignore_whitespace { get; set; }
+ public int context_lines { get; set; }
+
+ public DiffView view { get; construct set; }
+
+ public DiffViewOptions(DiffView view)
+ {
+ Object(view: view);
+ }
+
+ private bool transform_double_to_int(Binding binding,
+ Value source_value,
+ ref Value target_value)
+ {
+ target_value.set_int((int)source_value.get_double());
+ return true;
+ }
+
+ private bool transform_int_to_double(Binding binding,
+ Value source_value,
+ ref Value target_value)
+ {
+ target_value.set_double((double)source_value.get_int());
+ return true;
+ }
+
+ protected override void constructed()
+ {
+ view.bind_property("changes-inline",
+ this,
+ "changes-inline",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE);
+
+ view.bind_property("ignore-whitespace",
+ this,
+ "ignore-whitespace",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE);
+
+ view.bind_property("context-lines",
+ this,
+ "context-lines",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE);
+
+ bind_property("changes-inline",
+ d_switch_changes_inline,
+ "active",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE);
+
+ bind_property("ignore-whitespace",
+ d_switch_ignore_whitespace,
+ "active",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE);
+
+ bind_property("context-lines",
+ d_adjustment_context,
+ "value",
+ BindingFlags.BIDIRECTIONAL |
+ BindingFlags.SYNC_CREATE,
+ transform_int_to_double,
+ transform_double_to_int);
+
+ var dbg = (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != null);
+
+ d_separator_developer_tools.visible = dbg;
+ d_button_developer_tools.visible = dbg;
+ }
+
+ [GtkCallback]
+ private void on_button_developer_tools_clicked()
+ {
+ view.get_inspector().show();
+ }
+}
+
+}
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 2000e44..44fe3d3 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -104,25 +104,63 @@ namespace Gitg
public bool unstaged { get; set; default = false; }
public int tab_width { get; set; default = 4; }
+ private bool flag_get(Ggit.DiffOption f)
+ {
+ return (options.flags & f) != 0;
+ }
+
+ private void flag_set(Ggit.DiffOption f, bool val)
+ {
+ if (val)
+ {
+ options.flags |= f;
+ }
+ else
+ {
+ options.flags &= ~f;
+ }
+
+ update();
+ }
+
public bool ignore_whitespace
{
- get { return (options.flags & Ggit.DiffOption.IGNORE_WHITESPACE) != 0; }
+ get { return flag_get(Ggit.DiffOption.IGNORE_WHITESPACE); }
+ set { flag_set(Ggit.DiffOption.IGNORE_WHITESPACE, value); }
+ default = false;
+ }
+
+ private bool d_changes_inline;
+
+ public bool changes_inline
+ {
+ get { return d_changes_inline; }
set
{
- if (value != ignore_whitespace)
+ if (d_changes_inline != value)
{
- if (value)
- {
- options.flags |= Ggit.DiffOption.IGNORE_WHITESPACE;
- }
- else
- {
- options.flags &= ~Ggit.DiffOption.IGNORE_WHITESPACE;
- }
-
- update();
+ d_changes_inline = value;
}
+
+ update();
+ }
+
+ default = false;
+ }
+
+ public int context_lines
+ {
+ get { return options.n_context_lines; }
+
+ set
+ {
+ options.n_context_lines = value;
+ options.n_interhunk_lines = value;
+
+ update();
}
+
+ default = 3;
}
static construct
@@ -146,6 +184,7 @@ namespace Gitg
o.set_boolean_member("staged", staged);
o.set_boolean_member("unstaged", unstaged);
o.set_boolean_member("debug", Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") !=
null);
+ o.set_boolean_member("changes_inline", changes_inline);
var strings = new Json.Object();
@@ -516,45 +555,27 @@ namespace Gitg
return true;
}
- var m = new Gtk.Menu();
-
- var item = new Gtk.CheckMenuItem.with_label(_("Ignore whitespace changes"));
- item.active = ignore_whitespace;
+ var m = new Gtk.Popover(this);
+ var opts = new DiffViewOptions(this);
- item.toggled.connect((i) => {
- ignore_whitespace = i.active;
- });
-
- m.append(item);
-
- var dbg = Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != null;
-
- if (dbg)
- {
- var dev = new Gtk.MenuItem.with_label("Developer tools");
-
- dev.activate.connect(() => {
- var inspector = get_inspector();
- inspector.show();
- });
-
- m.append(dev);
- }
-
- m.show_all();
-
- m.attach_to_widget(this, null);
+ m.add(opts);
if (event.type == Gdk.EventType.BUTTON_PRESS ||
event.type == Gdk.EventType.BUTTON_RELEASE)
{
- m.popup(null, null, null, event.button.button, event.button.time);
- }
- else
- {
- m.popup(null, null, null, 0, Gdk.CURRENT_TIME);
+ var r = Gdk.Rectangle() {
+ x = (int)event.button.x,
+ y = (int)event.button.y,
+ width = 1,
+ height = 1
+ };
+
+ m.set_pointing_to(r);
}
+ opts.show();
+ m.show();
+
return true;
}
}
diff --git a/libgitg/resources/diff-view-options.ui b/libgitg/resources/diff-view-options.ui
new file mode 100644
index 0000000..c76d403
--- /dev/null
+++ b/libgitg/resources/diff-view-options.ui
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkAdjustment" id="adjustment_context">
+ <property name="upper">12</property>
+ <property name="value">3</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">3</property>
+ </object>
+ <template class="GitgDiffViewOptions" parent="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkSwitch" id="switch_ignore_whitespace">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">center</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_ignore_whitespace">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Ignore whitespace changes</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="switch_changes_inline">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">center</property>
+ <property name="hexpand">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_changes_inline">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Show changes inline</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box_context">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="label_context">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Context</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScale" id="scale_context">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="adjustment">adjustment_context</property>
+ <property name="round_digits">0</property>
+ <property name="digits">0</property>
+ <property name="value_pos">right</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_developer_tools">
+ <property name="label" translatable="yes">Developer tools</property>
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="on_button_developer_tools_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator_developer_tools">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/libgitg/resources/resources.xml b/libgitg/resources/resources.xml
index c3159d6..010ed19 100644
--- a/libgitg/resources/resources.xml
+++ b/libgitg/resources/resources.xml
@@ -13,6 +13,9 @@
<gresource prefix="/org/gnome/gitg/gtk/sidebar">
<file compressed="true">sidebar-view.ui</file>
</gresource>
+ <gresource prefix="/org/gnome/gitg/gtk/diff-view">
+ <file compressed="true">diff-view-options.ui</file>
+ </gresource>
</gresources>
<!-- ex: et ts=2 -->
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 61dd9a3..c66cf74 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -38,7 +38,7 @@ namespace GitgDiff
d_diff = new Gitg.DiffView();
- var settings = new Settings("org.gnome.gitg.state.diff");
+ var settings = new Settings("org.gnome.gitg.preferences.diff");
settings.bind("ignore-whitespace",
d_diff,
@@ -46,6 +46,18 @@ namespace GitgDiff
SettingsBindFlags.GET |
SettingsBindFlags.SET);
+ settings.bind("changes-inline",
+ d_diff,
+ "changes-inline",
+ SettingsBindFlags.GET |
+ SettingsBindFlags.SET);
+
+ settings.bind("context-lines",
+ d_diff,
+ "context-lines",
+ SettingsBindFlags.GET |
+ SettingsBindFlags.SET);
+
d_diff.show();
d_sw.add(d_diff);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ffb6a07..55b3626 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -33,4 +33,5 @@ plugins/files/gitg-files.vala
[type: gettext/glade]gitg/resources/ui/gitg-preferences.ui
[type: gettext/glade]gitg/resources/ui/gitg-window.ui
[type: gettext/glade]libgitg/resources/gitg-repository-list-box-row.ui
+[type: gettext/glade]libgitg/resources/diff-view-options.ui
[type: gettext/glade]plugins/files/resources/view-files.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]