Trait gtk::prelude::GtkApplicationExt
source · [−]pub trait GtkApplicationExt: 'static {
Show 29 methods
fn add_window(&self, window: &impl IsA<Window>);
fn accels_for_action(&self, detailed_action_name: &str) -> Vec<GString>;
fn actions_for_accel(&self, accel: &str) -> Vec<GString>;
fn active_window(&self) -> Option<Window>;
fn app_menu(&self) -> Option<MenuModel>;
fn menu_by_id(&self, id: &str) -> Option<Menu>;
fn menubar(&self) -> Option<MenuModel>;
fn window_by_id(&self, id: u32) -> Option<Window>;
fn windows(&self) -> Vec<Window>;
fn inhibit(
&self,
window: Option<&impl IsA<Window>>,
flags: ApplicationInhibitFlags,
reason: Option<&str>
) -> u32;
fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool;
fn list_action_descriptions(&self) -> Vec<GString>;
fn prefers_app_menu(&self) -> bool;
fn remove_window(&self, window: &impl IsA<Window>);
fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]);
fn set_app_menu(&self, app_menu: Option<&impl IsA<MenuModel>>);
fn set_menubar(&self, menubar: Option<&impl IsA<MenuModel>>);
fn uninhibit(&self, cookie: u32);
fn is_register_session(&self) -> bool;
fn set_register_session(&self, register_session: bool);
fn is_screensaver_active(&self) -> bool;
fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_window_added<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_active_window_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_app_menu_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_menubar_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_register_session_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
}
Expand description
Required Methods
fn add_window(&self, window: &impl IsA<Window>)
fn add_window(&self, window: &impl IsA<Window>)
Adds a window to self
.
This call can only happen after the self
has started;
typically, you should add new application windows in response
to the emission of the signal::gio::Application::activate
signal.
This call is equivalent to setting the property::Window::application
property of window
to self
.
Normally, the connection between the application and the window
will remain until the window is destroyed, but you can explicitly
remove it with remove_window()
.
GTK+ will keep the self
running as long as it has
any windows.
window
a Window
fn accels_for_action(&self, detailed_action_name: &str) -> Vec<GString>
fn accels_for_action(&self, detailed_action_name: &str) -> Vec<GString>
Gets the accelerators that are currently associated with the given action.
detailed_action_name
a detailed action name, specifying an action and target to obtain accelerators for
Returns
accelerators for detailed_action_name
, as
a None
-terminated array. Free with g_strfreev()
when no longer needed
fn actions_for_accel(&self, accel: &str) -> Vec<GString>
fn actions_for_accel(&self, accel: &str) -> Vec<GString>
Returns the list of actions (possibly empty) that accel
maps to.
Each item in the list is a detailed action name in the usual form.
This might be useful to discover if an accel already exists in order to prevent installation of a conflicting accelerator (from an accelerator editor or a plugin system, for example). Note that having more than one action per accelerator may not be a bad thing and might make sense in cases where the actions never appear in the same context.
In case there are no actions for a given accelerator, an empty array
is returned. None
is never returned.
It is a programmer error to pass an invalid accelerator string.
If you are unsure, check it with accelerator_parse()
first.
accel
an accelerator that can be parsed by accelerator_parse()
Returns
a None
-terminated array of actions for accel
fn active_window(&self) -> Option<Window>
fn active_window(&self) -> Option<Window>
Gets the “active” window for the application.
The active window is the one that was most recently focused (within the application). This window may not have the focus at the moment if another application has it — this is just the most recently-focused window within this application.
Returns
the active window, or None
if
there isn’t one.
Returns the menu model that has been set with
set_app_menu()
.
Returns
the application menu of self
or None
if no application menu has been set.
Returns the menu model that has been set with
set_menubar()
.
Returns
the menubar for windows of self
fn window_by_id(&self, id: u32) -> Option<Window>
fn window_by_id(&self, id: u32) -> Option<Window>
Returns the ApplicationWindow
with the given ID.
The ID of a ApplicationWindow
can be retrieved with
ApplicationWindowExt::id()
.
id
an identifier number
Returns
the window with ID id
, or
None
if there is no window with this ID
Gets a list of the GtkWindows
associated with self
.
The list is sorted by most recently focused window, such that the first element is the currently focused window. (Useful for choosing a parent for a transient window.)
The list that is returned should not be modified in any way. It will only remain valid until the next focus change or window creation or deletion.
Returns
a GList
of Window
Inform the session manager that certain types of actions should be inhibited. This is not guaranteed to work on all platforms and for all types of actions.
Applications should invoke this method when they begin an operation
that should not be interrupted, such as creating a CD or DVD. The
types of actions that may be blocked are specified by the flags
parameter. When the application completes the operation it should
call uninhibit()
to remove the inhibitor. Note that
an application can have multiple inhibitors, and all of them must
be individually removed. Inhibitors are also cleared when the
application exits.
Applications should not expect that they will always be able to block the action. In most cases, users will be given the option to force the action to take place.
Reasons should be short and to the point.
If window
is given, the session manager may point the user to
this window to find out more about why the action is inhibited.
window
flags
what types of actions should be inhibited
reason
a short, human-readable string that explains why these operations are inhibited
Returns
A non-zero cookie that is used to uniquely identify this
request. It should be used as an argument to uninhibit()
in order to remove the request. If the platform does not support
inhibiting or the request failed for some reason, 0 is returned.
fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool
fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool
Determines if any of the actions specified in flags
are
currently inhibited (possibly by another application).
Note that this information may not be available (for example when the application is running in a sandbox).
flags
what types of actions should be queried
Returns
true
if any of the actions specified in flags
are inhibited
fn list_action_descriptions(&self) -> Vec<GString>
fn list_action_descriptions(&self) -> Vec<GString>
Lists the detailed action names which have associated accelerators.
See set_accels_for_action()
.
Returns
a None
-terminated array of strings,
free with g_strfreev()
when done
Determines if the desktop environment in which the application is running would prefer an application menu be shown.
If this function returns true
then the application should call
set_app_menu()
with the contents of an application
menu, which will be shown by the desktop environment. If it returns
false
then you should consider using an alternate approach, such as
a menubar.
The value returned by this function is purely advisory and you are
free to ignore it. If you call set_app_menu()
even
if the desktop environment doesn’t support app menus, then a fallback
will be provided.
Applications are similarly free not to set an app menu even if the desktop environment wants to show one. In that case, a fallback will also be created by the desktop environment (GNOME, for example, uses a menu with only a “Quit” item in it).
The value returned by this function never changes. Once it returns a particular value, it is guaranteed to always return the same value.
You may only call this function after the application has been registered and after the base startup handler has run. You’re most likely to want to use this from your own startup handler. It may also make sense to consult this function while constructing UI (in activate, open or an action activation handler) in order to determine if you should show a gear menu or not.
This function will return false
on Mac OS and a default app menu
will be created automatically with the “usual” contents of that menu
typical to most Mac OS applications. If you call
set_app_menu()
anyway, then this menu will be
replaced with your own.
Returns
true
if you should set an app menu
fn remove_window(&self, window: &impl IsA<Window>)
fn remove_window(&self, window: &impl IsA<Window>)
Sets zero or more keyboard accelerators that will trigger the
given action. The first item in accels
will be the primary
accelerator, which may be displayed in the UI.
To remove all accelerators for an action, use an empty, zero-terminated
array for accels
.
For the detailed_action_name
, see g_action_parse_detailed_name()
and
g_action_print_detailed_name()
.
detailed_action_name
a detailed action name, specifying an action and target to associate accelerators with
accels
a list of accelerators in the format
understood by accelerator_parse()
Sets or unsets the application menu for self
.
This can only be done in the primary instance of the application,
after it has been registered. signal::gio::Application::startup
is a good place
to call this.
The application menu is a single menu containing items that typically impact the application as a whole, rather than acting on a specific window or document. For example, you would expect to see “Preferences” or “Quit” in an application menu, but not “Save” or “Print”.
If supported, the application menu will be rendered by the desktop environment.
Use the base gio::ActionMap
interface to add actions, to respond to the user
selecting these menu items.
app_menu
a gio::MenuModel
, or None
Sets or unsets the menubar for windows of self
.
This is a menubar in the traditional sense.
This can only be done in the primary instance of the application,
after it has been registered. signal::gio::Application::startup
is a good place
to call this.
Depending on the desktop environment, this may appear at the top of each window, or at the top of the screen. In some environments, if both the application menu and the menubar are set, the application menu will be presented as if it were the first item of the menubar. Other environments treat the two as completely separate — for example, the application menu may be rendered by the desktop shell while the menubar (if set) remains in each individual window.
Use the base gio::ActionMap
interface to add actions, to respond to the
user selecting these menu items.
menubar
a gio::MenuModel
, or None
fn is_register_session(&self) -> bool
fn is_register_session(&self) -> bool
Set this property to true
to register with the session manager.
fn set_register_session(&self, register_session: bool)
fn set_register_session(&self, register_session: bool)
Set this property to true
to register with the session manager.
fn is_screensaver_active(&self) -> bool
fn is_screensaver_active(&self) -> bool
v3_24
only.fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
v3_24_8
only.Emitted when the session manager is about to end the session, only
if signal::Application::register-session
is true
. Applications can
connect to this signal and call inhibit()
with
ApplicationInhibitFlags::LOGOUT
to delay the end of the session
until state has been saved.
fn connect_window_added<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_window_added<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when a Window
is removed from application
,
either as a side-effect of being destroyed or explicitly
through remove_window()
.
window
the Window
that is being removed
fn connect_active_window_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_register_session_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
v3_24
only.