summaryrefslogtreecommitdiff
path: root/src/AppWindow.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2016-11-25 04:11:58 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2016-11-25 04:11:58 +0100
commitccff5442184e84d511c2bd25ed3da53e4336a272 (patch)
tree8402a0ba68852e0aec5841ed4519ccfe88352223 /src/AppWindow.vala
parenta1e1833f48ed618273dab9198b547148a89832a7 (diff)
parent4a3f1fdfe1eb3743564adcee35d5513224339260 (diff)
Merge tag 'upstream/0.25.1'
Upstream version 0.25.1
Diffstat (limited to 'src/AppWindow.vala')
-rw-r--r--src/AppWindow.vala197
1 files changed, 51 insertions, 146 deletions
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 0103300..41751e8 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -19,26 +19,19 @@ public class FullscreenWindow : PageWindow {
private bool switched_to = false;
private bool is_toolbar_dismissal_enabled;
+ private const GLib.ActionEntry[] entries = {
+ { "LeaveFullscreen", on_close }
+ };
+
public FullscreenWindow(Page page) {
- set_current_page(page);
+ base ();
- File ui_file = Resources.get_ui("fullscreen.ui");
+ set_current_page(page);
- try {
- ui.add_ui_from_file(ui_file.get_path());
- } catch (Error err) {
- error("Error loading UI file %s: %s", ui_file.get_path(), err.message);
- }
-
- Gtk.ActionGroup action_group = new Gtk.ActionGroup("FullscreenActionGroup");
- action_group.add_actions(create_actions(), this);
- ui.insert_action_group(action_group, 0);
- ui.ensure_update();
+ AppWindow.get_instance().add_action_entries (entries, this);
+ const string[] accels = { "F11" };
+ Application.set_accels_for_action ("win.LeaveFullscreen", accels);
- Gtk.AccelGroup accel_group = ui.get_accel_group();
- if (accel_group != null)
- add_accel_group(accel_group);
-
set_screen(AppWindow.get_instance().get_screen());
// Needed so fullscreen will occur on correct monitor in multi-monitor setups
@@ -58,7 +51,7 @@ public class FullscreenWindow : PageWindow {
close_button.set_icon_name("view-restore");
close_button.set_tooltip_text(_("Leave fullscreen"));
- close_button.clicked.connect(on_close);
+ close_button.set_action_name ("win.LeaveFullscreen");
toolbar = page.get_toolbar();
toolbar.set_show_arrow(false);
@@ -101,6 +94,9 @@ public class FullscreenWindow : PageWindow {
// Toolbar steals keyboard focus from page, put it back again
page.grab_focus ();
+
+ // Do not show menubar in fullscreen
+ set_show_menubar (false);
}
public void disable_toolbar_dismissal() {
@@ -130,18 +126,6 @@ public class FullscreenWindow : PageWindow {
return result;
}
-
- private Gtk.ActionEntry[] create_actions() {
- Gtk.ActionEntry[] actions = new Gtk.ActionEntry[0];
-
- Gtk.ActionEntry leave_fullscreen = { "LeaveFullscreen", Resources.LEAVE_FULLSCREEN_LABEL,
- TRANSLATABLE, "F11", TRANSLATABLE, on_close };
- leave_fullscreen.label = Resources.LEAVE_FULLSCREEN_LABEL;
- leave_fullscreen.tooltip = Resources.LEAVE_FULLSCREEN_LABEL;
- actions += leave_fullscreen;
-
- return actions;
- }
public override bool key_press_event(Gdk.EventKey event) {
// check for an escape/abort
@@ -289,9 +273,7 @@ public class FullscreenWindow : PageWindow {
// subclass. A subclass should set current_page to the user-visible Page for it to receive
// various notifications. It is the responsibility of the subclass to notify Pages when they're
// switched to and from, and other aspects of the Page interface.
-public abstract class PageWindow : Gtk.Window {
- protected Gtk.UIManager ui = new Gtk.UIManager();
-
+public abstract class PageWindow : Gtk.ApplicationWindow {
private Page current_page = null;
private int busy_counter = 0;
@@ -299,15 +281,12 @@ public abstract class PageWindow : Gtk.Window {
}
public PageWindow() {
+ Object (application: Application.get_instance().get_system_app ());
+
// the current page needs to know when modifier keys are pressed
add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK
| Gdk.EventMask.STRUCTURE_MASK);
-
- set_has_resize_grip(false);
- }
-
- public Gtk.UIManager get_ui_manager() {
- return ui;
+ set_show_menubar (true);
}
public Page? get_current_page() {
@@ -381,8 +360,10 @@ public abstract class PageWindow : Gtk.Window {
public void set_busy_cursor() {
if (busy_counter++ > 0)
return;
-
- get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.WATCH));
+
+ var display = get_window ().get_display ();
+ var cursor = new Gdk.Cursor.for_display (display, Gdk.CursorType.WATCH);
+ get_window().set_cursor (cursor);
spin_event_loop();
}
@@ -394,7 +375,9 @@ public abstract class PageWindow : Gtk.Window {
return;
}
- get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.LEFT_PTR));
+ var display = get_window ().get_display ();
+ var cursor = new Gdk.Cursor.for_display (display, Gdk.CursorType.LEFT_PTR);
+ get_window().set_cursor (cursor);
spin_event_loop();
}
@@ -416,14 +399,11 @@ public abstract class AppWindow : PageWindow {
// the AppWindow maintains its own UI manager because the first UIManager an action group is
// added to is the one that claims its accelerators
- protected Gtk.ActionGroup[] common_action_groups;
protected bool maximized = false;
protected Dimensions dimensions;
protected int pos_x = 0;
protected int pos_y = 0;
- private Gtk.ActionGroup common_action_group = new Gtk.ActionGroup("AppWindowGlobalActionGroup");
-
public AppWindow() {
// although there are multiple AppWindow types, only one may exist per-process
assert(instance == null);
@@ -454,18 +434,8 @@ public abstract class AppWindow : PageWindow {
// UIManager. In order to activate those accelerators, we need to create a dummy UI string
// that lists all the common actions. We build it on-the-fly from the actions associated
// with each ActionGroup while we're adding the groups to the UIManager.
- common_action_groups = create_common_action_groups();
- foreach (Gtk.ActionGroup group in common_action_groups)
- ui.insert_action_group(group, 0);
-
- try {
- ui.add_ui_from_string(build_dummy_ui_string(common_action_groups), -1);
- } catch (Error err) {
- error("Unable to add AppWindow UI: %s", err.message);
- }
-
- ui.ensure_update();
- add_accel_group(ui.get_accel_group());
+
+ add_actions ();
Gtk.CssProvider provider = new Gtk.CssProvider();
try {
@@ -475,67 +445,20 @@ public abstract class AppWindow : PageWindow {
debug("Unable to load custom CSS: %s", err.message);
}
}
-
- private Gtk.ActionEntry[] create_common_actions() {
- Gtk.ActionEntry[] actions = new Gtk.ActionEntry[0];
-
- Gtk.ActionEntry quit = { "CommonQuit", Resources.QUIT_LABEL, TRANSLATABLE, "<Ctrl>Q",
- TRANSLATABLE, on_quit };
- quit.label = Resources.QUIT_LABEL;
- actions += quit;
-
- Gtk.ActionEntry about = { "CommonAbout", Resources.ABOUT_LABEL, TRANSLATABLE, null,
- TRANSLATABLE, on_about };
- about.label = Resources.ABOUT_LABEL;
- actions += about;
-
- Gtk.ActionEntry fullscreen = { "CommonFullscreen", Resources.FULLSCREEN_LABEL,
- TRANSLATABLE, "F11", TRANSLATABLE, on_fullscreen };
- fullscreen.label = Resources.FULLSCREEN_LABEL;
- actions += fullscreen;
-
- Gtk.ActionEntry help_contents = { "CommonHelpContents", Resources.HELP_LABEL,
- TRANSLATABLE, "F1", TRANSLATABLE, on_help_contents };
- help_contents.label = _("_Contents");
- actions += help_contents;
-
- Gtk.ActionEntry help_faq = { "CommonHelpFAQ", null, TRANSLATABLE, null,
- TRANSLATABLE, on_help_faq };
- help_faq.label = _("_Frequently Asked Questions");
- actions += help_faq;
-
- Gtk.ActionEntry help_report_problem = { "CommonHelpReportProblem", null, TRANSLATABLE, null,
- TRANSLATABLE, on_help_report_problem };
- help_report_problem.label = _("_Report a Problem…");
- actions += help_report_problem;
- Gtk.ActionEntry undo = { "CommonUndo", Resources.UNDO_MENU, TRANSLATABLE, "<Ctrl>Z",
- TRANSLATABLE, on_undo };
- undo.label = Resources.UNDO_MENU;
- actions += undo;
-
- Gtk.ActionEntry redo = { "CommonRedo", Resources.REDO_MENU, TRANSLATABLE, "<Ctrl><Shift>Z",
- TRANSLATABLE, on_redo };
- redo.label = Resources.REDO_MENU;
- actions += redo;
+ private const GLib.ActionEntry[] common_actions = {
+ { "CommonQuit", on_quit },
+ { "CommonFullscreen", on_fullscreen },
+ { "CommonHelpContents", on_help_contents },
+ { "CommonHelpFAQ", on_help_faq },
+ { "CommonHelpReportProblem", on_help_report_problem },
+ { "CommonUndo", on_undo },
+ { "CommonRedo", on_redo },
+ { "CommonJumpToFile", on_jump_to_file },
+ { "CommonSelectAll", on_select_all },
+ { "CommonSelectNone", on_select_none }
+ };
- Gtk.ActionEntry jump_to_file = { "CommonJumpToFile", Resources.JUMP_TO_FILE_MENU, TRANSLATABLE,
- "<Ctrl><Shift>M", TRANSLATABLE, on_jump_to_file };
- jump_to_file.label = Resources.JUMP_TO_FILE_MENU;
- actions += jump_to_file;
-
- Gtk.ActionEntry select_all = { "CommonSelectAll", Resources.SELECT_ALL_MENU, TRANSLATABLE,
- "<Ctrl>A", TRANSLATABLE, on_select_all };
- select_all.label = Resources.SELECT_ALL_MENU;
- actions += select_all;
-
- Gtk.ActionEntry select_none = { "CommonSelectNone", null, null,
- "<Ctrl><Shift>A", TRANSLATABLE, on_select_none };
- actions += select_none;
-
- return actions;
- }
-
protected abstract void on_fullscreen();
public static bool has_instance() {
@@ -747,22 +670,10 @@ public abstract class AppWindow : PageWindow {
sys_show_uri(get_window().get_screen(), url);
}
- protected virtual Gtk.ActionGroup[] create_common_action_groups() {
- Gtk.ActionGroup[] groups = new Gtk.ActionGroup[0];
-
- common_action_group.add_actions(create_common_actions(), this);
- groups += common_action_group;
-
- return groups;
- }
-
- public Gtk.ActionGroup[] get_common_action_groups() {
- return common_action_groups;
+ protected virtual void add_actions () {
+ this.add_action_entries (AppWindow.common_actions, this);
}
-
- public virtual void replace_common_placeholders(Gtk.UIManager ui) {
- }
-
+
public void go_fullscreen(Page page) {
// if already fullscreen, use that
if (fullscreen_window != null) {
@@ -801,34 +712,26 @@ public abstract class AppWindow : PageWindow {
present();
}
- public Gtk.Action? get_common_action(string name) {
- foreach (Gtk.ActionGroup group in common_action_groups) {
- Gtk.Action? action = group.get_action(name);
- if (action != null)
- return action;
- }
-
- warning("No common action found: %s", name);
-
- return null;
+ public GLib.Action? get_common_action(string name) {
+ return lookup_action (name);
}
public void set_common_action_sensitive(string name, bool sensitive) {
- Gtk.Action? action = get_common_action(name);
+ var action = get_common_action(name) as GLib.SimpleAction;
if (action != null)
- action.sensitive = sensitive;
+ action.set_enabled (sensitive);
}
public void set_common_action_important(string name, bool important) {
- Gtk.Action? action = get_common_action(name);
+ var action = get_common_action(name) as GLib.SimpleAction;
if (action != null)
- action.is_important = important;
+ action.set_enabled (sensitive);
}
public void set_common_action_visible(string name, bool visible) {
- Gtk.Action? action = get_common_action(name);
+ var action = get_common_action(name) as GLib.SimpleAction;
if (action != null)
- action.visible = visible;
+ action.set_enabled (sensitive);
}
protected override void switched_pages(Page? old_page, Page? new_page) {
@@ -891,6 +794,7 @@ public abstract class AppWindow : PageWindow {
private void decorate_command_manager_action(string name, string prefix,
string default_explanation, CommandDescription? desc) {
+#if 0
Gtk.Action? action = get_common_action(name);
if (action == null)
return;
@@ -904,6 +808,7 @@ public abstract class AppWindow : PageWindow {
action.tooltip = default_explanation;
action.sensitive = false;
}
+#endif
}
public void decorate_undo_action() {