1/* 2 * This file is part of gitg 3 * 4 * Copyright (C) 2012 - Jesse van den Kieboom 5 * 6 * gitg is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * gitg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with gitg. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20namespace GitgDiff 21{ 22 public class Panel : Object, GitgExt.UIElement, GitgExt.HistoryPanel 23 { 24 // Do this to pull in config.h before glib.h (for gettext...) 25 private const string version = Gitg.Config.VERSION; 26 27 public GitgExt.Application? application { owned get; construct set; } 28 public GitgExt.History? history { owned get; construct set; } 29 30 private Gitg.DiffView d_diff; 31 private Gitg.WhenMapped d_whenMapped; 32 33 private ulong d_selection_changed_id; 34 35 protected override void constructed() 36 { 37 base.constructed(); 38 39 d_diff = new Gitg.DiffView(); 40 41 d_diff.show_parents = true; 42 43 application.bind_property("repository", d_diff, "repository", BindingFlags.SYNC_CREATE); 44 45 d_diff.show(); 46 47 var settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.diff"); 48 49 settings.bind("ignore-whitespace", 50 d_diff, 51 "ignore-whitespace", 52 SettingsBindFlags.GET | SettingsBindFlags.SET); 53 54 settings.bind("changes-inline", 55 d_diff, 56 "changes-inline", 57 SettingsBindFlags.GET | SettingsBindFlags.SET); 58 59 settings.bind("context-lines", 60 d_diff, 61 "context-lines", 62 SettingsBindFlags.GET | SettingsBindFlags.SET); 63 64 settings.bind("tab-width", 65 d_diff, 66 "tab-width", 67 SettingsBindFlags.GET | SettingsBindFlags.SET); 68 69 settings.bind("wrap", 70 d_diff, 71 "wrap-lines", 72 SettingsBindFlags.GET | SettingsBindFlags.SET); 73 74 settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.interface"); 75 76 settings.bind("use-gravatar", 77 d_diff, 78 "use-gravatar", 79 SettingsBindFlags.GET | SettingsBindFlags.SET); 80 81 settings.bind("enable-diff-highlighting", 82 d_diff, 83 "highlight", 84 SettingsBindFlags.GET | SettingsBindFlags.SET); 85 86 d_whenMapped = new Gitg.WhenMapped(d_diff); 87 88 d_selection_changed_id = history.selection_changed.connect(on_selection_changed); 89 on_selection_changed(history); 90 } 91 92 protected override void dispose() 93 { 94 if (history != null && d_selection_changed_id != 0) 95 { 96 history.disconnect(d_selection_changed_id); 97 d_selection_changed_id = 0; 98 } 99 100 base.dispose(); 101 } 102 103 public string id 104 { 105 owned get { return "/org/gnome/gitg/Panels/Diff"; } 106 } 107 108 public bool available 109 { 110 get { return true; } 111 } 112 113 public string display_name 114 { 115 owned get { return _("Diff"); } 116 } 117 118 public string description 119 { 120 owned get { return _("Show the changes introduced by the selected commit"); } 121 } 122 123 public string? icon 124 { 125 owned get { return "diff-symbolic"; } 126 } 127 128 private void on_selection_changed(GitgExt.History history) 129 { 130 var hasset = false; 131 132 history.foreach_selected((commit) => { 133 var c = commit as Gitg.Commit; 134 135 if (c != null) 136 { 137 d_whenMapped.update(() => { 138 d_diff.commit = c; 139 hasset = true; 140 }, this); 141 142 return false; 143 } 144 145 return true; 146 }); 147 148 if (!hasset) 149 { 150 d_diff.commit = null; 151 } 152 } 153 154 public Gtk.Widget? widget 155 { 156 owned get { return d_diff; } 157 } 158 159 public bool enabled 160 { 161 get { return true; } 162 } 163 164 public int negotiate_order(GitgExt.UIElement other) 165 { 166 // Should appear before the files 167 if (other.id == "/org/gnome/gitg/Panels/Files") 168 { 169 return -1; 170 } 171 else 172 { 173 return 0; 174 } 175 } 176 } 177} 178 179[ModuleInit] 180public void peas_register_types(TypeModule module) 181{ 182 Peas.ObjectModule mod = module as Peas.ObjectModule; 183 184 mod.register_extension_type(typeof(GitgExt.HistoryPanel), 185 typeof(GitgDiff.Panel)); 186} 187 188// ex: ts=4 noet 189