Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainWindow: Put search toolbar in a title stack #668

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace Terminal {
private Gtk.Clipboard clipboard;
private Gtk.Clipboard primary_selection;
private Terminal.Widgets.SearchToolbar search_toolbar;
private Gtk.Revealer search_revealer;
private Gtk.Label title_label;
private Gtk.Stack title_stack;
private Gtk.ToggleButton search_button;
private Dialogs.ColorPreferences? color_preferences_dialog;
private Granite.AccelLabel open_in_browser_menuitem_label;
Expand Down Expand Up @@ -237,8 +238,6 @@ namespace Terminal {
setup_ui ();
show_all ();

search_revealer.set_reveal_child (false);

update_font ();
Application.settings_sys.changed["monospace-font-name"].connect (update_font);
Application.settings.changed["font"].connect (update_font);
Expand Down Expand Up @@ -334,22 +333,32 @@ namespace Terminal {
valign = Gtk.Align.CENTER
};

search_toolbar = new Terminal.Widgets.SearchToolbar (this);

title_label = new Gtk.Label (title);
title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);

title_stack = new Gtk.Stack () {
transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN
};
title_stack.add (title_label);
title_stack.add (search_toolbar);
// Must show children before visible_child can be set
title_stack.show_all ();
// We set visible child here to avoid transition being visible on startup.
title_stack.visible_child = title_label;

var header = new Hdy.HeaderBar () {
show_close_button = true,
has_subtitle = false
};
header.pack_end (menu_button);
header.pack_end (search_button);
header.set_custom_title (title_stack);

unowned Gtk.StyleContext header_context = header.get_style_context ();
header_context.add_class ("default-decoration");

search_toolbar = new Terminal.Widgets.SearchToolbar (this);

search_revealer = new Gtk.Revealer ();
search_revealer.set_transition_type (Gtk.RevealerTransitionType.SLIDE_DOWN);
search_revealer.add (search_toolbar);

get_simple_action (ACTION_COPY).set_enabled (false);
get_simple_action (ACTION_COPY_LAST_OUTPUT).set_enabled (false);
get_simple_action (ACTION_SCROLL_TO_LAST_COMMAND).set_enabled (false);
Expand Down Expand Up @@ -382,12 +391,13 @@ namespace Terminal {

var grid = new Gtk.Grid ();
grid.attach (header, 0, 0);
grid.attach (search_revealer, 0, 1);
grid.attach (notebook, 0, 2);
grid.attach (notebook, 0, 1);

get_style_context ().add_class ("terminal-window");
add (grid);

bind_property ("title", title_label, "label");

unowned var menu_popover = (SettingsPopover) menu_button.popover;

menu_popover.show_theme_editor.connect (() => {
Expand Down Expand Up @@ -1226,9 +1236,9 @@ namespace Terminal {
var search_state = search_action.get_state ().get_boolean ();

search_action.set_state (!search_state);
search_revealer.set_reveal_child (search_button.active);

if (search_button.active) {
title_stack.visible_child = search_toolbar;
action_accelerators[ACTION_SEARCH_NEXT] = "<Control>g";
action_accelerators[ACTION_SEARCH_NEXT] = "<Control>Down";
action_accelerators[ACTION_SEARCH_PREVIOUS] = "<Control><Shift>g";
Expand All @@ -1239,6 +1249,7 @@ namespace Terminal {
);
search_toolbar.grab_focus ();
} else {
title_stack.visible_child = title_label;
action_accelerators.remove_all (ACTION_SEARCH_NEXT);
action_accelerators.remove_all (ACTION_SEARCH_PREVIOUS);
search_button.tooltip_markup = Granite.markup_accel_tooltip (
Expand Down
16 changes: 6 additions & 10 deletions src/Widgets/SearchToolbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Terminal.Widgets {

public class SearchToolbar : Gtk.Grid {
public class SearchToolbar : Gtk.Box {
private Gtk.ToggleButton cycle_button;
private uint last_search_term_length = 0;

Expand Down Expand Up @@ -57,16 +57,12 @@ namespace Terminal.Widgets {
cycle_button.set_can_focus (false);
cycle_button.tooltip_text = _("Cyclic search");

var search_grid = new Gtk.Grid ();
search_grid.margin = 3;
search_grid.get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
search_grid.add (search_entry);
search_grid.add (next_button);
search_grid.add (previous_button);
search_grid.add (cycle_button);
get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
add (search_entry);
add (next_button);
add (previous_button);
add (cycle_button);

add (search_grid);
get_style_context ().add_class ("search-bar");
show_all ();

grab_focus.connect (() => {
Expand Down