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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/*
* 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/>.
*/
[GtkTemplate ( ui = "/org/gnome/gitg/ui/gitg-diff-view-options.ui" )]
public class Gitg.DiffViewOptions : Gtk.Toolbar
{
[GtkChild (name = "adjustment_context")]
private unowned Gtk.Adjustment d_adjustment_context;
[GtkChild (name = "tool_button_spacing")]
private unowned Gtk.ToolButton d_tool_button_spacing;
public int context_lines { get; set; }
private Gee.List<Binding> d_bindings;
private DiffView? d_view;
private ulong d_notify_commit_id;
private DiffViewOptionsSpacing d_popover_spacing;
public DiffView? view
{
get { return d_view; }
construct set
{
if (d_view == value)
{
return;
}
var old_view = d_view;
d_view = value;
view_changed(old_view);
}
}
public DiffViewOptions(DiffView? view = null)
{
Object(view: view);
}
construct
{
d_bindings = new Gee.LinkedList<Binding>();
d_popover_spacing = new DiffViewOptionsSpacing();
d_popover_spacing.relative_to = d_tool_button_spacing;
}
public override void dispose()
{
this.view = null;
base.dispose();
}
private void view_changed(DiffView? old_view)
{
foreach (var binding in d_bindings)
{
binding.unbind();
}
d_bindings.clear();
if (d_notify_commit_id != 0)
{
old_view.disconnect(d_notify_commit_id);
d_notify_commit_id = 0;
}
if (d_view == null)
{
update_commit();
return;
}
d_bindings.add(
d_view.bind_property("ignore-whitespace",
d_popover_spacing,
"ignore-whitespace",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE)
);
d_bindings.add(
d_view.bind_property("wrap-lines",
d_popover_spacing,
"wrap-lines",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE)
);
d_bindings.add(
d_view.bind_property("tab-width",
d_popover_spacing,
"tab-width",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE)
);
d_bindings.add(
d_view.bind_property("context-lines",
this,
"context-lines",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE)
);
d_notify_commit_id = d_view.notify["commit"].connect(update_commit);
update_commit();
}
private void update_commit()
{
var iscommit = d_view != null && d_view.commit != null;
d_popover_spacing.ignore_whitespace_visible = iscommit;
}
protected override void constructed()
{
bind_property("context-lines",
d_adjustment_context,
"value",
BindingFlags.BIDIRECTIONAL |
BindingFlags.SYNC_CREATE,
Transforms.int_to_double,
Transforms.double_to_int);
}
[GtkCallback]
private void clicked_on_tool_button_spacing(Gtk.Widget widget)
{
d_popover_spacing.show();
}
}
[GtkTemplate ( ui = "/org/gnome/gitg/ui/gitg-diff-view-options-spacing.ui" )]
private class Gitg.DiffViewOptionsSpacing : Gtk.Popover
{
[GtkChild (name = "switch_ignore_whitespace")]
private unowned Gtk.Switch d_switch_ignore_whitespace;
[GtkChild (name = "label_ignore_whitespace")]
private unowned Gtk.Label d_label_ignore_whitespace;
[GtkChild (name = "switch_wrap_lines")]
private unowned Gtk.Switch d_switch_wrap_lines;
[GtkChild (name = "adjustment_tab_width")]
private unowned Gtk.Adjustment d_adjustment_tab_width;
public bool ignore_whitespace { get; set; }
public bool wrap_lines { get; set; }
public int tab_width { get; set; }
public bool ignore_whitespace_visible { get; set; }
protected override void constructed()
{
bind_property("ignore-whitespace",
d_switch_ignore_whitespace,
"active",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
bind_property("wrap-lines",
d_switch_wrap_lines,
"active",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
bind_property("tab-width",
d_adjustment_tab_width,
"value",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE,
Transforms.int_to_double,
Transforms.double_to_int);
bind_property("ignore-whitespace-visible",
d_switch_ignore_whitespace,
"visible",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
bind_property("ignore-whitespace-visible",
d_label_ignore_whitespace,
"visible",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
}
}
private class Gitg.Transforms
{
public static bool double_to_int(Binding binding,
Value source_value,
ref Value target_value)
{
target_value.set_int((int)source_value.get_double());
return true;
}
public static bool int_to_double(Binding binding,
Value source_value,
ref Value target_value)
{
target_value.set_double((double)source_value.get_int());
return true;
}
}
|