1/* 2* Copyright (c) 2011-2013 Yorba Foundation 3* 4* This program is free software; you can redistribute it and/or 5* modify it under the terms of the GNU Lesser General Public 6* License as published by the Free Software Foundation; either 7* version 2.1 of the License, or (at your option) any later version. 8* 9* This program is distributed in the hope that it will be useful, 10* but WITHOUT ANY WARRANTY; without even the implied warranty of 11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12* General Public License for more details. 13* 14* You should have received a copy of the GNU General Public 15* License along with this program; if not, write to the 16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17* Boston, MA 02110-1301 USA 18*/ 19 20// A simple grouping Entry that is only expandable 21public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry { 22 private string name; 23 private Icon? open_icon; 24 private Icon? closed_icon; 25 26 public Grouping (string name, Icon? open_icon, Icon? closed_icon = null) { 27 this.name = name; 28 this.open_icon = open_icon; 29 this.closed_icon = closed_icon ?? open_icon; 30 } 31 32 public string get_sidebar_name () { 33 return name; 34 } 35 36 public string? get_sidebar_tooltip () { 37 return name; 38 } 39 40 public Icon? get_sidebar_icon () { 41 return null; 42 } 43 44 public Icon? get_sidebar_open_icon () { 45 return open_icon; 46 } 47 48 public Icon? get_sidebar_closed_icon () { 49 return closed_icon; 50 } 51 52 public string to_string () { 53 return name; 54 } 55 56 public bool expand_on_select () { 57 return true; 58 } 59} 60 61// An end-node on the sidebar that represents a Page with its page context menu. Additional 62// interfaces can be added if additional functionality is required (such as a drop target). 63// This class also handles the bookwork of creating the Page on-demand and maintaining it in memory. 64public abstract class Sidebar.SimplePageEntry : Object, Sidebar.Entry, Sidebar.SelectableEntry, 65 Sidebar.PageRepresentative, Sidebar.Contextable { 66 private Page? page = null; 67 68 protected SimplePageEntry () { 69 } 70 71 public abstract string get_sidebar_name (); 72 73 public virtual string? get_sidebar_tooltip () { 74 return get_sidebar_name (); 75 } 76 77 public abstract Icon? get_sidebar_icon (); 78 79 public virtual string to_string () { 80 return get_sidebar_name (); 81 } 82 83 protected abstract Page create_page (); 84 85 public bool has_page () { 86 return page != null; 87 } 88 89 protected Page get_page () { 90 if (page == null) { 91 page = create_page (); 92 page_created (page); 93 } 94 95 return page; 96 } 97 98 internal void pruned (Sidebar.Tree tree) { 99 if (page == null) 100 return; 101 102 destroying_page (page); 103 page.destroy (); 104 page = null; 105 } 106 107 public Gtk.Menu? get_sidebar_context_menu (Gdk.EventButton? event) { 108 return get_page ().get_page_sidebar_menu (); 109 } 110} 111 112// A simple Sidebar.Branch where the root node is the branch in entirety. 113public class Sidebar.RootOnlyBranch : Sidebar.Branch { 114 public RootOnlyBranch (Sidebar.Entry root) { 115 base (root, Sidebar.Branch.Options.NONE, null_comparator); 116 } 117 118 private static int null_comparator (Sidebar.Entry a, Sidebar.Entry b) { 119 return (a != b) ? -1 : 0; 120 } 121} 122 123public interface Sidebar.Contextable : Object { 124 // Return null if the context menu should not be invoked for this event 125 public abstract Gtk.Menu? get_sidebar_context_menu (Gdk.EventButton? event); 126} 127