1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*
* 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 GitgDiff
{
public class Panel : Object, GitgExt.UIElement, GitgExt.HistoryPanel
{
// Do this to pull in config.h before glib.h (for gettext...)
private const string version = Gitg.Config.VERSION;
public GitgExt.Application? application { owned get; construct set; }
public GitgExt.History? history { owned get; construct set; }
private Gitg.DiffView d_diff;
private Gitg.WhenMapped d_whenMapped;
private ulong d_selection_changed_id;
public virtual uint? shortcut
{
owned get { return Gdk.Key.d; }
}
protected override void constructed()
{
base.constructed();
d_diff = new Gitg.DiffView();
d_diff.show_parents = true;
application.bind_property("repository", d_diff, "repository", BindingFlags.SYNC_CREATE);
d_diff.show();
var settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.diff");
settings.bind("ignore-whitespace",
d_diff,
"ignore-whitespace",
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);
settings.bind("tab-width",
d_diff,
"tab-width",
SettingsBindFlags.GET | SettingsBindFlags.SET);
settings.bind("wrap",
d_diff,
"wrap-lines",
SettingsBindFlags.GET | SettingsBindFlags.SET);
settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.interface");
settings.bind("use-gravatar",
d_diff,
"use-gravatar",
SettingsBindFlags.GET | SettingsBindFlags.SET);
settings.bind("enable-diff-highlighting",
d_diff,
"highlight",
SettingsBindFlags.GET | SettingsBindFlags.SET);
d_whenMapped = new Gitg.WhenMapped(d_diff);
d_selection_changed_id = history.selection_changed.connect(on_selection_changed);
on_selection_changed(history);
}
protected override void dispose()
{
if (history != null && d_selection_changed_id != 0)
{
history.disconnect(d_selection_changed_id);
d_selection_changed_id = 0;
}
base.dispose();
}
public string id
{
owned get { return "/org/gnome/gitg/Panels/Diff"; }
}
public bool available
{
get { return true; }
}
public string display_name
{
owned get { return _("Diff"); }
}
public string description
{
owned get { return _("Show the changes introduced by the selected commit"); }
}
public string? icon
{
owned get { return "diff-symbolic"; }
}
private void on_selection_changed(GitgExt.History history)
{
var hasset = false;
history.foreach_selected((commit) => {
var c = commit as Gitg.Commit;
if (c != null)
{
d_whenMapped.update(() => {
d_diff.commit = c;
hasset = true;
}, this);
return false;
}
return true;
});
if (!hasset)
{
d_diff.commit = null;
}
}
public Gtk.Widget? widget
{
owned get { return d_diff; }
}
public bool enabled
{
get { return true; }
}
public int negotiate_order(GitgExt.UIElement other)
{
// Should appear before the files
if (other.id == "/org/gnome/gitg/Panels/Files")
{
return -1;
}
else
{
return 0;
}
}
}
}
[ModuleInit]
public void peas_register_types(TypeModule module)
{
Peas.ObjectModule mod = module as Peas.ObjectModule;
mod.register_extension_type(typeof(GitgExt.HistoryPanel),
typeof(GitgDiff.Panel));
}
// ex: ts=4 noet
|