sidebar-common.vala 2.51 KB
Newer Older
1
/* Copyright 2011-2014 Yorba Foundation
Eric Gregory's avatar
Eric Gregory committed
2 3
 *
 * This software is licensed under the GNU Lesser General Public License
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
Eric Gregory's avatar
Eric Gregory committed
5 6 7 8 9 10 11
 */

// A simple grouping Entry that is only expandable
public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry,
    Sidebar.RenameableEntry {
    
    private string name;
12
    private string? tooltip;
13
    private string? icon;
Eric Gregory's avatar
Eric Gregory committed
14
    
15
    public Grouping(string name, string? icon, string? tooltip = null) {
Eric Gregory's avatar
Eric Gregory committed
16
        this.name = name;
17
        this.icon = icon;
18
        this.tooltip = tooltip;
Eric Gregory's avatar
Eric Gregory committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    }
    
    public void rename(string name) {
        this.name = name;
        sidebar_name_changed(name);
    }
    
    public bool is_user_renameable() {
        return false;
    }
    
    public string get_sidebar_name() {
        return name;
    }
    
    public string? get_sidebar_tooltip() {
35
        return tooltip;
Eric Gregory's avatar
Eric Gregory committed
36 37
    }
    
38 39
    public string? get_sidebar_icon() {
        return icon;
Eric Gregory's avatar
Eric Gregory committed
40 41
    }
    
42 43 44 45
    public int get_count() {
        return -1;
    }
    
Eric Gregory's avatar
Eric Gregory committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    public string to_string() {
        return name;
    }
    
    public bool expand_on_select() {
        return true;
    }
}

// A simple Sidebar.Branch where the root node is the branch in entirety.
public class Sidebar.RootOnlyBranch : Sidebar.Branch {
    public RootOnlyBranch(Sidebar.Entry root) {
        base (root, Sidebar.Branch.Options.NONE, null_comparator);
    }
    
    private static int null_comparator(Sidebar.Entry a, Sidebar.Entry b) {
        return (a != b) ? -1 : 0;
    }
}

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/**
 * A header is an entry that is visually distinguished from its children. Bug 6397 recommends
 * headers to appear bolded and without any icons. To prevent the icons from rendering, we set the
 * icons to null in the base class @see Sidebar.Grouping. But we also go a step further by
 * using a custom cell_data_function (@see Sidebar.Tree::icon_renderer_function) which ensures that
 * header icons won't be rendered. This approach avoids the blank icon spacing issues.
 */
public class Sidebar.Header : Sidebar.Grouping, Sidebar.EmphasizableEntry {
    private bool emphasized;
    
    public Header(string name, bool emphasized = true) {
        base(name, null);
        this.emphasized = emphasized;
    }
    
    public bool is_emphasized() {
        return emphasized;
    }
}

Eric Gregory's avatar
Eric Gregory committed
86 87 88 89 90
public interface Sidebar.Contextable : Object {
    // Return null if the context menu should not be invoked for this event
    public abstract Gtk.Menu? get_sidebar_context_menu(Gdk.EventButton event);
}