diff options
author | Christian Persch <chpe@gnome.org> | 2015-09-23 18:55:22 +0200 |
---|---|---|
committer | Christian Persch <chpe@gnome.org> | 2015-09-23 20:35:18 +0200 |
commit | 52032cd4867214c0a3d4eb546bf5d7a93bd76c4b (patch) | |
tree | 27f381dd57c5f4ebdf28ea8bb403369cc708942d | |
parent | 62925f3191367bce01c913e7f8da9b223ad192a8 (diff) | |
download | vte-52032cd4867214c0a3d4eb546bf5d7a93bd76c4b.tar.gz |
vteapp: Use a header bar and a gear menu
-rw-r--r-- | src/app.ui | 161 | ||||
-rw-r--r-- | src/app.vala | 100 |
2 files changed, 159 insertions, 102 deletions
@@ -4,118 +4,145 @@ <requires lib="gtk+" version="3.10"/> <template class="TestWindow" parent="GtkApplicationWindow"> <property name="can_focus">False</property> + <property name="role">vte-terminal</property> + <property name="icon_name">utilities-terminal</property> <child> - <object class="GtkBox" id="main_box"> + <object class="GtkBox" id="terminal_box"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="orientation">vertical</property> <child> - <object class="GtkToolbar" id="toolbar"> + <placeholder/> + </child> + <child> + <object class="GtkScrollbar" id="scrollbar"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="restrict_to_fill_level">False</property> + <property name="fill_level">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <child type="titlebar"> + <object class="GtkHeaderBar" id="headerbar1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="show_close_button">True</property> + <property name="decoration_layout">icon:close</property> + <child> + <object class="GtkButton" id="copy_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="tooltip_text" translatable="yes">Copy</property> + <property name="action_name">win.copy</property> + <property name="focus_on_click">False</property> <child> - <object class="GtkToolButton" id="copy_toolbutton"> + <object class="GtkImage" id="image2"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="tooltip_text" translatable="yes">Copy</property> - <property name="action_name">win.copy</property> - <property name="label" translatable="yes">Copy</property> <property name="icon_name">edit-copy-symbolic</property> + <property name="use_fallback">True</property> </object> - <packing> - <property name="expand">False</property> - <property name="homogeneous">False</property> - </packing> </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="paste_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="tooltip_text" translatable="yes">Paste</property> + <property name="action_name">win.paste</property> + <property name="focus_on_click">False</property> <child> - <object class="GtkToolButton" id="paste_toolbutton"> + <object class="GtkImage" id="image3"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="tooltip_text" translatable="yes">Paste</property> - <property name="action_name">win.paste</property> - <property name="label" translatable="yes">Paste</property> <property name="icon_name">edit-paste-symbolic</property> + <property name="use_fallback">True</property> </object> - <packing> - <property name="expand">False</property> - <property name="homogeneous">False</property> - </packing> - </child> - <child> - <object class="GtkToolButton" id="reset_toolbutton"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="tooltip_text" translatable="yes">Reset (use Ctrl to reset and clear)</property> - <property name="action_name">win.reset</property> - <property name="label" translatable="yes">Reset</property> - </object> - <packing> - <property name="expand">False</property> - <property name="homogeneous">False</property> - </packing> </child> + </object> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkToggleButton" id="find_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="focus_on_click">False</property> <child> - <object class="GtkToggleToolButton" id="input_enabled_toolbutton"> + <object class="GtkImage" id="image5"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="tooltip_text" translatable="yes">Toggle input enabled setting</property> - <property name="is_important">True</property> - <property name="action_name">win.input-enabled</property> - <property name="label" translatable="yes">Input</property> - <property name="icon_name">input-keyboard</property> + <property name="icon_name">edit-find-symbolic</property> + <property name="use_fallback">True</property> </object> - <packing> - <property name="expand">False</property> - <property name="homogeneous">False</property> - </packing> </child> + </object> + <packing> + <property name="position">4</property> + </packing> + </child> + <child type="title"> + <placeholder/> + </child> + <child> + <object class="GtkMenuButton" id="gear_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="focus_on_click">False</property> <child> - <object class="GtkToggleToolButton" id="search_toolbutton"> + <object class="GtkImage" id="image1"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">Search</property> - <property name="use_underline">True</property> - <property name="icon_name">edit-find-symbolic</property> + <property name="icon_name">open-menu-symbolic</property> + <property name="use_fallback">True</property> </object> - <packing> - <property name="expand">False</property> - <property name="homogeneous">True</property> - </packing> </child> </object> <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> + <property name="pack_type">end</property> + <property name="position">3</property> </packing> </child> <child> - <object class="GtkBox" id="terminal_box"> + <object class="GtkBox" id="notifications_box"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> <child> - <placeholder/> - </child> - <child> - <object class="GtkScrollbar" id="scrollbar"> - <property name="visible">True</property> + <object class="GtkImage" id="readonly_emblem"> <property name="can_focus">False</property> - <property name="orientation">vertical</property> - <property name="restrict_to_fill_level">False</property> - <property name="fill_level">0</property> + <property name="tooltip_text" translatable="yes">Read-only</property> + <property name="icon_name">emblem-readonly</property> + <property name="use_fallback">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="pack_type">end</property> - <property name="position">1</property> + <property name="position">0</property> </packing> </child> </object> <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> + <property name="pack_type">end</property> + <property name="position">4</property> </packing> </child> </object> diff --git a/src/app.vala b/src/app.vala index f329e902..13eeb766 100644 --- a/src/app.vala +++ b/src/app.vala @@ -130,19 +130,19 @@ class SearchPopover : Gtk.Popover [GtkTemplate (ui = "/org/gnome/vte/test/app/ui/window.ui")] class Window : Gtk.ApplicationWindow { - [GtkChild] private Gtk.Toolbar toolbar; [GtkChild] private Gtk.Scrollbar scrollbar; [GtkChild] private Gtk.Box terminal_box; - /* [GtkChild] private Gtk.ToolButton copy_toolbutton; */ - /* [GtkChild] private Gtk.ToolButton paste_toolbutton; */ - /* [GtkChild] private Gtk.ToolButton reset_toolbutton; */ - /* [GtkChild] private Gtk.ToggleToolButton input_enabled_toolbutton; */ - [GtkChild] private Gtk.ToggleToolButton search_toolbutton; + /* [GtkChild] private Gtk.Box notifications_box; */ + [GtkChild] private Gtk.Widget readonly_emblem; + /* [GtkChild] private Gtk.Button copy_button; */ + /* [GtkChild] private Gtk.Button paste_button; */ + [GtkChild] private Gtk.ToggleButton find_button; + [GtkChild] private Gtk.MenuButton gear_button; private Vte.Terminal terminal; private Gtk.Clipboard clipboard; private GLib.Pid child_pid; - private SearchPopover? search_popover; + private SearchPopover search_popover; private string[] builtin_dingus = { "(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?", @@ -153,16 +153,65 @@ class Window : Gtk.ApplicationWindow { "copy", action_copy_cb }, { "copy-match", action_copy_match_cb, "s" }, { "paste", action_paste_cb }, - { "reset", action_reset_cb }, - { "find", action_find_cb } + { "reset", action_reset_cb, "b" }, + { "find", action_find_cb }, + { "quit", action_quit_cb } }; public Window(App app) { Object(application: app); + /* Create terminal and connect scrollbar */ + terminal = new Vte.Terminal(); + scrollbar.set_adjustment(terminal.get_vadjustment()); + + /* Create actions */ add_action_entries (action_entries, this); + /* Property actions */ + var action = new GLib.PropertyAction ("input-enabled", terminal, "input-enabled"); + add_action(action); + action.notify["state"].connect((obj, pspec) => { + GLib.Action a = (GLib.Action)obj; + readonly_emblem.set_visible(!a.state.get_boolean()); + }); + + /* Find */ + search_popover = new SearchPopover(terminal, find_button); + search_popover.closed.connect(() => { + if (find_button.active) + find_button.set_active(false); + }); + + find_button.toggled.connect(() => { + var active = find_button.active; + if (search_popover.visible != active) + search_popover.set_visible(active); + }); + + /* Gear menu */ + /* FIXME: figure out how to put this into the .ui file */ + var menu = new GLib.Menu(); + + var section = new GLib.Menu(); + section.append("_Copy", "win.copy"); + section.append("_Paste", "win.paste"); + section.append("_Find…", "win.find"); + menu.append_section(null, section); + + section = new GLib.Menu(); + section.append("_Reset", "win.reset(false)"); + section.append("Reset and C_lear", "win.reset(true)"); + section.append("_Input enabled", "win.input-enabled"); + menu.append_section(null, section); + + section = new GLib.Menu(); + section.append("_Quit", "win.quit"); + menu.append_section(null, section); + + gear_button.set_menu_model(menu); + /* set_resize_mode(Gtk.ResizeMode.IMMEDIATE); */ clipboard = get_clipboard(Gdk.SELECTION_CLIPBOARD); @@ -183,15 +232,6 @@ class Window : Gtk.ApplicationWindow app_paintable = true; } - if (App.Options.no_toolbar) - toolbar.hide(); - - search_toolbutton.toggled.connect(search_toolbutton_toggled_cb); - - /* Create terminal and connect scrollbar */ - terminal = new Vte.Terminal(); - scrollbar.set_adjustment(terminal.get_vadjustment()); - /* Signals */ terminal.button_press_event.connect(button_press_event_cb); terminal.char_size_changed.connect(char_size_changed_cb); @@ -258,9 +298,6 @@ class Window : Gtk.ApplicationWindow if (App.Options.dingus != null) add_dingus(App.Options.dingus); - /* Property actions */ - add_action(new GLib.PropertyAction ("input-enabled", terminal, "input-enabled")); - /* Done! */ terminal_box.pack_start(terminal); terminal.show(); @@ -458,12 +495,14 @@ class Window : Gtk.ApplicationWindow terminal.paste_clipboard(); } - private void action_reset_cb() + private void action_reset_cb(GLib.SimpleAction action, GLib.Variant? parameter) { bool clear; Gdk.ModifierType modifiers; - if (Gtk.get_current_event_state(out modifiers)) + if (parameter != null) { + clear = parameter.get_boolean(); + } else if (Gtk.get_current_event_state(out modifiers)) clear = (modifiers & Gdk.ModifierType.CONTROL_MASK) != 0; else clear = false; @@ -473,18 +512,12 @@ class Window : Gtk.ApplicationWindow private void action_find_cb() { - search_toolbutton.active = true; + find_button.set_active(true); } - private void search_toolbutton_toggled_cb() + private void action_quit_cb() { - if (search_toolbutton.active && search_popover == null) { - search_popover = new SearchPopover(terminal, search_toolbutton); - search_popover.closed.connect(() => { search_toolbutton.set_active(false); }); - } - - if (search_popover.visible != search_toolbutton.active) - search_popover.set_visible(search_toolbutton.active); + destroy(); } private bool button_press_event_cb(Gtk.Widget widget, Gdk.EventButton event) @@ -690,7 +723,6 @@ class App : Gtk.Application public static bool no_geometry_hints = false; public static bool no_rewrap = false; public static bool no_shell = false; - public static bool no_toolbar = false; public static bool object_notifications = false; public static string? output_filename = null; private static string? pty_flags_string = null; @@ -877,8 +909,6 @@ class App : Gtk.Application "Disable rewrapping on resize", null }, { "no-shell", 'S', 0, OptionArg.NONE, ref no_shell, "Disable spawning a shell inside the terminal", null }, - { "no-toolbar", 0, 0, OptionArg.NONE, ref no_toolbar, - "Disable toolbar", null }, { "object-notifications", 'N', 0, OptionArg.NONE, ref object_notifications, "Print VteTerminal object notifications", null }, { "output-file", 0, 0, OptionArg.FILENAME, ref output_filename, |