~pantheon-photos/pantheon-photos/trunk

« back to all changes in this revision

Viewing changes to src/sidebar/metadata/MetadataSidebar.vala

  • Committer: RabbitBot
  • Author(s): Maddie May, madelynn-r-may
  • Date: 2014-08-27 06:02:55 UTC
  • mfrom: (2546.1.21 fix-1332978)
  • Revision ID: rabbitbot-20140827060255-4619a5y4s9mqk8qs
Moves all photo metadata context menu editors to a right sidebar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2011-2014 Yorba Foundation
 
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.
 
5
 */
 
6
 
 
7
public class MetadataView : Gtk.ScrolledWindow {
 
8
    private List<Properties> properties_collection = new List<Properties> ();
 
9
    private Gtk.Notebook notebook = new Gtk.Notebook ();
 
10
    private Gtk.Grid grid = new Gtk.Grid ();
 
11
    private int line_count = 0;
 
12
    private BasicProperties colletion_page_properties = new BasicProperties ();
 
13
    private Gtk.Label no_items_label = new Gtk.Label ("No items selected");
 
14
    public const int SIDEBAR_PADDING = 12;
 
15
    public MetadataView () {
 
16
        set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
 
17
        get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
 
18
        properties_collection.append (new LibraryProperties ());
 
19
        properties_collection.append (new BasicProperties ());
 
20
        properties_collection.append (new ExtendedProperties ());
 
21
 
 
22
        foreach (var properties in properties_collection)
 
23
            add_expander (properties);
 
24
 
 
25
        grid.set_row_spacing (16);
 
26
        grid.margin = SIDEBAR_PADDING;
 
27
        colletion_page_properties.margin = SIDEBAR_PADDING;
 
28
        add (notebook);
 
29
        notebook.append_page (grid);
 
30
        notebook.append_page (colletion_page_properties);
 
31
        notebook.append_page (no_items_label);
 
32
        notebook.set_show_tabs (false);
 
33
 
 
34
        grid.hexpand = true;
 
35
    }
 
36
 
 
37
    private void add_expander (Properties properties) {
 
38
        var expander = new Gtk.Expander ("<b>" + properties.get_header_title () + "</b>");
 
39
        expander.use_markup = true;
 
40
        expander.add (properties);
 
41
        expander.set_spacing (10);
 
42
        grid.attach (expander, 0, line_count, 1, 1);
 
43
        line_count++;
 
44
        expander.set_expanded (true);
 
45
    }
 
46
 
 
47
    public void update_properties (Page page) {
 
48
        /* figure out if we have a single image selected */
 
49
        ViewCollection view = page.get_view ();
 
50
        bool display_single = false;
 
51
 
 
52
        if (view == null) {
 
53
            notebook.set_current_page ( notebook.page_num (no_items_label));
 
54
            save_changes ();
 
55
            return;
 
56
        }
 
57
 
 
58
        int count = view.get_selected_count ();
 
59
        Gee.Iterable<DataView> iter = null;
 
60
        if (count != 0) {
 
61
            iter = view.get_selected ();
 
62
        } else {
 
63
            count = view.get_count ();
 
64
            iter = (Gee.Iterable<DataView>) view.get_all ();
 
65
        }
 
66
 
 
67
        if (iter == null || count == 0) {
 
68
            notebook.set_current_page (notebook.page_num (no_items_label));
 
69
            save_changes ();
 
70
            return;
 
71
        }
 
72
 
 
73
        if (count == 1) {
 
74
            foreach (DataView item in iter) {
 
75
                var source = item.get_source () as MediaSource;
 
76
                if (source == null)
 
77
                    display_single = true;
 
78
                break;
 
79
            }
 
80
        } else {
 
81
            display_single = true;
 
82
        }
 
83
 
 
84
        int page_num = 0;
 
85
        if (display_single) {
 
86
            save_changes ();
 
87
            colletion_page_properties.update_properties (page);
 
88
            page_num = notebook.page_num (colletion_page_properties);
 
89
        } else {
 
90
            foreach (var properties in properties_collection)
 
91
                properties.update_properties (page);
 
92
            page_num = notebook.page_num (grid);
 
93
        }
 
94
        notebook.set_current_page (page_num);
 
95
    }
 
96
 
 
97
    public void save_changes () {
 
98
        foreach (var properties in properties_collection)
 
99
            properties.save_changes_to_source ();
 
100
    }
 
101
}
 
102
 
 
103
 
 
104
 
 
105