File: bookmarks-view.vala

package info (click to toggle)
dconf-editor 49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,904 kB
  • sloc: xml: 446; sh: 21; makefile: 4
file content (196 lines) | stat: -rw-r--r-- 5,387 bytes parent folder | download | duplicates (4)
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
/*
  This file is part of Dconf Editor

  Dconf Editor 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 3 of the License, or
  (at your option) any later version.

  Dconf Editor 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 Dconf Editor.  If not, see <https://www.gnu.org/licenses/>.
*/

using Gtk;

private class BookmarksView : BrowserView, AdaptativeWidget
{
    construct
    {
        create_bookmarks_list ();
    }

    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
    {
        base.set_window_size (new_size);

        bookmarks_list.set_window_size (new_size);
    }

    internal override bool is_in_in_window_mode ()
    {
        return (in_window_bookmarks || base.is_in_in_window_mode ());
    }

    internal override void show_default_view ()
    {
        if (in_window_bookmarks)
        {
            if (in_window_bookmarks_edit_mode)
                leave_bookmarks_edit_mode ();
            in_window_bookmarks = false;
            set_visible_child_name ("main-view");
        }
        else
            base.show_default_view ();
    }

    /*\
    * * bookmarks view
    \*/

    [CCode (notify = false)] internal bool in_window_bookmarks           { internal get; private set; default = false; }
    [CCode (notify = false)] internal bool in_window_bookmarks_edit_mode { internal get; private set; default = false; }

    private BookmarksList bookmarks_list;

    private void create_bookmarks_list ()
    {
        bookmarks_list = new BookmarksList (/* needs shadows            */ false,
                                            /* big placeholder          */ true,
                                            /* edit-mode action prefix  */ "bmk",
                                            /* schema path              */ "/ca/desrt/dconf-editor/");
        bookmarks_list.selection_changed.connect (on_bookmarks_selection_changed);
        bookmarks_list.update_bookmarks_icons.connect (on_update_bookmarks_icons);
        bookmarks_list.show ();
        add (bookmarks_list);
    }

    private string [] old_bookmarks = new string [0];

    internal void show_bookmarks_view (string [] bookmarks)
    {
        if (is_in_in_window_mode ())
            show_default_view ();

        bookmarks_list.reset ();

        if (bookmarks != old_bookmarks)
        {
            Variant variant = new Variant.strv (bookmarks);
            bookmarks_list.create_bookmark_rows (variant);

            old_bookmarks = bookmarks;
        }
        set_visible_child (bookmarks_list);
        in_window_bookmarks = true;
    }

    internal void update_bookmark_icon (string bookmark, BookmarkIcon icon)
    {
        bookmarks_list.update_bookmark_icon (bookmark, icon);
    }

    /*\
    * * edit mode
    \*/

    internal void enter_bookmarks_edit_mode ()
        requires (in_window_bookmarks == true)
    {
        bookmarks_list.enter_edit_mode ();
        in_window_bookmarks_edit_mode = true;
    }

    internal bool leave_bookmarks_edit_mode ()
        requires (in_window_bookmarks == true)
    {
        in_window_bookmarks_edit_mode = false;
        return bookmarks_list.leave_edit_mode ();
    }

    internal OverlayedList.SelectionState get_bookmarks_selection_state ()
    {
        return bookmarks_list.get_selection_state ();
    }

    internal void trash_bookmark ()
    {
        bookmarks_list.trash_bookmark ();
    }

    internal void move_top ()
    {
        bookmarks_list.move_top ();
    }

    internal void move_up ()
    {
        bookmarks_list.move_up ();
    }

    internal void move_down ()
    {
        bookmarks_list.move_down ();
    }

    internal void move_bottom ()
    {
        bookmarks_list.move_bottom ();
    }

    /*\
    * * callbacks
    \*/

    private void on_bookmarks_selection_changed ()
    {
        if (!in_window_bookmarks)
            return;
        bookmarks_selection_changed ();
    }

    internal signal void bookmarks_selection_changed ();

    internal signal void update_bookmarks_icons (Variant bookmarks_variant);
    private void on_update_bookmarks_icons (Variant bookmarks_variant)
    {
        update_bookmarks_icons (bookmarks_variant);
    }

    /*\
    * * keyboard calls
    \*/

    internal override bool next_match ()
    {
        if (in_window_bookmarks)
            return bookmarks_list.next_match ();
        return base.next_match ();
    }

    internal override bool previous_match ()
    {
        if (in_window_bookmarks)
            return bookmarks_list.previous_match ();
        return base.previous_match ();
    }

    internal override bool handle_copy_text (out string copy_text)
    {
        if (in_window_bookmarks)
            return bookmarks_list.handle_copy_text (out copy_text);
        return base.handle_copy_text (out copy_text);
    }

    internal override bool toggle_row_popover ()     // Menu
    {
        if (in_window_bookmarks)
            return false;
        return base.toggle_row_popover ();
     }
}