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 GitgHistory 21{ 22 23[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-history-paned.ui")] 24class Paned : Gitg.AnimatedPaned 25{ 26 [GtkChild] 27 private Gtk.Box d_box_sidebar; 28 29 [GtkChild] 30 private Gitg.AnimatedPaned d_paned_panels; 31 32 [GtkChild] 33 private Gtk.StackSwitcher d_stack_switcher_panels; 34 35 [GtkChild] 36 private RefsList d_refs_list; 37 38 [GtkChild] 39 private Gitg.CommitListView d_commit_list_view; 40 41 [GtkChild] 42 private Gtk.Stack d_stack_panel; 43 44 [GtkChild] 45 private Gtk.ScrolledWindow d_scrolled_window_commit_list; 46 47 public Gtk.Orientation inner_orientation 48 { 49 get { return d_paned_panels.orientation; } 50 51 set 52 { 53 if (d_paned_panels.orientation != value) 54 { 55 d_paned_panels.orientation = value; 56 57 // Swap children 58 d_paned_panels.remove(d_scrolled_window_commit_list); 59 d_paned_panels.remove(d_stack_panel); 60 61 Gtk.Widget p1; 62 Gtk.Widget p2; 63 64 if (value == Gtk.Orientation.HORIZONTAL) 65 { 66 p1 = d_stack_panel; 67 p2 = d_scrolled_window_commit_list; 68 } 69 else 70 { 71 p1 = d_scrolled_window_commit_list; 72 p2 = d_stack_panel; 73 } 74 75 d_paned_panels.pack1(p1, true, true); 76 d_paned_panels.pack2(p2, false, false); 77 } 78 } 79 } 80 81 // private void slide_in() 82 // { 83 // slide(Gitg.SlidePanedChild.FIRST, Gitg.SlideDirection.IN); 84 85 // Gitg.SlidePanedChild child; 86 87 // if (inner_orientation == Gtk.Orientation.HORIZONTAL) 88 // { 89 // child = Gitg.SlidePanedChild.FIRST; 90 // } 91 // else 92 // { 93 // child = Gitg.SlidePanedChild.SECOND; 94 // } 95 96 // d_paned_panels.slide(child, Gitg.SlideDirection.IN); 97 // } 98 99 // private void slide_out() 100 // { 101 // slide(Gitg.SlidePanedChild.FIRST, Gitg.SlideDirection.OUT); 102 103 // Gitg.SlidePanedChild child; 104 105 // if (inner_orientation == Gtk.Orientation.HORIZONTAL) 106 // { 107 // child = Gitg.SlidePanedChild.FIRST; 108 // } 109 // else 110 // { 111 // child = Gitg.SlidePanedChild.SECOND; 112 // } 113 114 // d_paned_panels.slide(child, Gitg.SlideDirection.OUT); 115 // } 116 117 private void store_paned_position(Gitg.AnimatedPaned paned, Settings settings, string key) 118 { 119 if (paned.is_animating) 120 { 121 return; 122 } 123 124 if (!paned.get_child1().visible || !paned.get_child2().visible) 125 { 126 return; 127 } 128 129 settings.set_int(key, paned.get_position()); 130 } 131 132 construct 133 { 134 var state_settings = new Settings(Gitg.Config.APPLICATION_ID + ".state.history"); 135 136 position = state_settings.get_int("paned-sidebar-position"); 137 d_paned_panels.position = state_settings.get_int("paned-panels-position"); 138 139 notify["position"].connect(() => { 140 store_paned_position(this, state_settings, "paned-sidebar-position"); 141 }); 142 143 d_paned_panels.notify["position"].connect(() => { 144 store_paned_position(d_paned_panels, state_settings, "paned-panels-position"); 145 }); 146 147 var interface_settings = new Settings(Gitg.Config.APPLICATION_ID + ".preferences.interface"); 148 149 interface_settings.bind("orientation", 150 this, 151 "inner_orientation", 152 SettingsBindFlags.GET); 153 154 d_stack_switcher_panels.set_stack(d_stack_panel); 155 } 156 157 public Paned() 158 { 159 Object(orientation: Gtk.Orientation.HORIZONTAL); 160 } 161 162 public RefsList refs_list 163 { 164 get { return d_refs_list; } 165 } 166 167 public Gitg.CommitListView commit_list_view 168 { 169 get { return d_commit_list_view; } 170 } 171 172 public Gtk.Paned paned_panels 173 { 174 get { return d_paned_panels; } 175 } 176 177 public Gtk.Stack stack_panel 178 { 179 get { return d_stack_panel; } 180 } 181 182 protected override bool draw(Cairo.Context context) 183 { 184 var ret = base.draw(context); 185 186 if (!get_child1().visible || !get_child2().visible) 187 { 188 return ret; 189 } 190 191 var window = d_box_sidebar.get_window(); 192 var handlewin = get_handle_window(); 193 194 var c = get_style_context(); 195 c.save(); 196 197 c.add_region("panel-switcher", 0); 198 199 Gtk.Allocation alloc; 200 d_stack_switcher_panels.get_allocation(out alloc); 201 202 var y = alloc.y - d_box_sidebar.spacing; 203 var hw = 1; 204 var w = position + hw; 205 var h = alloc.height + d_box_sidebar.spacing + d_stack_switcher_panels.margin_bottom; 206 207 if (window != null) 208 { 209 int wx; 210 window.get_position(out wx, null); 211 c.render_frame(context, wx, y, w, h); 212 } 213 214 if (handlewin != null) 215 { 216 int hx; 217 handlewin.get_position(out hx, null); 218 219 c.render_background(context, hx, y, hw, h); 220 } 221 222 c.restore(); 223 224 return ret; 225 } 226} 227 228} 229 230// ex: ts=4 noet 231