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 197 198 199 200 201 202 203 204
|
/*
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;
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathwidget.ui")]
private class PathWidget : Box, AdaptativeWidget
{
[GtkChild] private unowned ModelButton search_toggle; // most window size button
[GtkChild] private unowned ModelButton search_button; // extra-small-window only
[GtkChild] private unowned Stack pathwidget_stack;
[GtkChild] private unowned Grid pathbar_grid;
[GtkChild] private unowned AdaptativePathbar pathbar;
[GtkChild] private unowned PathEntry searchentry;
[GtkChild] private unowned Revealer parent_revealer;
[GtkChild] private unowned ModelButton parent_button;
private ThemedIcon search_icon = new ThemedIcon.from_names ({"edit-find-symbolic"});
private ThemedIcon parent_icon = new ThemedIcon.from_names ({"go-up-symbolic"});
construct
{
search_toggle.icon = search_icon;
search_button.icon = search_icon;
parent_button.icon = parent_icon;
}
private bool quite_thin_window = false;
private bool extra_thin_window = false;
private void set_window_size (AdaptativeWidget.WindowSize new_size)
{
pathbar.set_window_size (new_size);
bool _quite_thin_window = AdaptativeWidget.WindowSize.is_quite_thin (new_size);
bool _extra_thin_window = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
if (quite_thin_window != _quite_thin_window
|| extra_thin_window != _extra_thin_window)
{
quite_thin_window = _quite_thin_window;
extra_thin_window = _extra_thin_window;
if (_extra_thin_window)
{
search_toggle.hide ();
search_button.show ();
parent_revealer.set_reveal_child (true);
}
else if (_quite_thin_window)
{
search_toggle.hide ();
search_button.show ();
parent_revealer.set_reveal_child (false);
}
else
{
search_button.hide ();
search_toggle.show ();
parent_revealer.set_reveal_child (false);
}
}
searchentry.set_window_size (new_size);
}
/*\
* * search mode
\*/
[CCode (notify = false)] internal bool search_mode_enabled { internal get; private set; default = false; }
private void enter_search_mode ()
{
search_mode_enabled = true;
search_toggle.set_action_target_value (false);
pathwidget_stack.set_visible_child (searchentry);
}
private void leave_search_mode ()
{
search_mode_enabled = false;
search_toggle.set_action_target_value (true);
pathwidget_stack.set_visible_child (pathbar_grid);
}
/*\
* * proxy calls
\*/
internal void set_path (ViewType type, string path)
{
pathbar.set_path (type, path);
searchentry.set_path (type, path);
bool is_search = type == ViewType.SEARCH;
if (!is_search)
{
if (path != "/")
{
Variant path_variant = new Variant.string (path);
parent_button.set_detailed_action_name ("browser.open-parent(" + path_variant.print (false) + ")");
}
else
parent_button.set_detailed_action_name ("browser.disabled-state-s('/')");
}
if (is_search && !search_mode_enabled)
enter_search_mode ();
else if (!is_search && search_mode_enabled)
leave_search_mode ();
}
internal void close_popovers ()
{
pathbar.close_menu ();
}
internal bool has_popover ()
{
if (pathbar.has_popover ())
return true;
return false;
}
/* path bar */
internal void get_complete_path (out string complete_path)
{
pathbar.get_complete_path (out complete_path);
}
internal void get_fallback_path_and_complete_path (out string fallback_path, out string complete_path)
{
pathbar.get_fallback_path_and_complete_path (out fallback_path, out complete_path);
}
internal void update_ghosts (string fallback_path)
{
pathbar.update_ghosts (fallback_path, search_mode_enabled);
}
internal string get_selected_child (string fallback_path)
{
return pathbar.get_selected_child (fallback_path);
}
internal void toggle_pathbar_menu ()
{
pathbar.toggle_menu ();
}
/* path entry */
internal void entry_grab_focus () { searchentry.entry_grab_focus (); }
internal void entry_grab_focus_without_selecting () { searchentry.entry_grab_focus_without_selecting (); }
internal bool handle_event (Gdk.EventKey event)
{
searchentry.prepare (PathEntry.SearchMode.SEARCH);
if (!searchentry.handle_event (event))
return false;
enter_search_mode ();
return true;
}
internal void prepare_search (PathEntry.SearchMode mode, string? search)
{
searchentry.prepare (mode, search);
}
/* string [] tokens = full_name.split (" ");
uint index = 0;
string token;
while (index < tokens.length)
{
token = tokens [index];
if (token.has_prefix ("/"))
{
path_requested (token, pathbar.get_selected_child (token));
break;
}
index++;
} */
/*\
* * sizing; TODO should be set by the center box of the headerbar, not by one of its children...
\*/
internal override void get_preferred_width (out int minimum_width, out int natural_width)
{
base.get_preferred_width (out minimum_width, out natural_width);
natural_width = MAX_ROW_WIDTH - 46; // see key-list-box-row.vala
}
}
|