Unverified Commit 73bd2e1a authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

subclass gio::ActionMap for app & window

parent d97307a7
Pipeline #181989 passed with stage
in 12 minutes and 57 seconds
......@@ -77,7 +77,7 @@ glib_wrapper! {
Object<subclass::simple::InstanceStruct<ApplicationPrivate>,
subclass::simple::ClassStruct<ApplicationPrivate>,
SwApplicationClass>)
@extends gio::Application, gtk::Application;
@extends gio::Application, gtk::Application, gio::ActionMap;
match fn {
get_type => || ApplicationPrivate::get_type().to_glib(),
......@@ -95,6 +95,7 @@ impl Application {
.unwrap()
.downcast::<Application>()
.unwrap();
app.setup_actions();
app.setup_accels();
// Start running gtk::Application
......@@ -126,11 +127,37 @@ impl Application {
window
}
fn setup_actions(&self) {
// Quit
action!(
self,
"quit",
clone!(@strong self as app => move |_, _| {
app.quit();
})
);
let window = self.get_active_window();
// About
action!(
self,
"about",
clone!(@strong window => move |_, _| {
let builder = gtk::Builder::new_from_resource("/org/gnome/design/Contrast/about_dialog.ui");
get_widget!(builder, gtk::AboutDialog, about_dialog);
about_dialog.set_transient_for(window.as_ref());
about_dialog.connect_response(|dialog, _| dialog.destroy());
about_dialog.show();
})
);
}
fn setup_accels(&self) {
// Accels
self.set_accels_for_action("app.quit", &["<primary>q"]);
self.set_accels_for_action("win.show-help-overlay", &["<primary>question"]);
self.set_accels_for_action("window.reverse-colors", &["<primary>r"]);
self.set_accels_for_action("win.reverse-colors", &["<primary>r"]);
}
fn do_action(&self, action: Action) -> glib::Continue {
......
......@@ -82,7 +82,7 @@ impl ObjectImpl for WindowPrivate {
let reverse_btn = gtk::Button::new();
reverse_btn.set_tooltip_text(Some(&gettext("Reverse Colours")));
reverse_btn.set_halign(gtk::Align::Center);
reverse_btn.set_action_name(Some("window.reverse-colors"));
reverse_btn.set_action_name(Some("win.reverse-colors"));
let reverse_img = gtk::Image::new_from_icon_name(Some("network-transmit-receive-symbolic"), gtk::IconSize::Button);
reverse_btn.set_image(Some(&reverse_img));
......@@ -135,7 +135,7 @@ glib_wrapper! {
Object<subclass::simple::InstanceStruct<WindowPrivate>,
subclass::simple::ClassStruct<WindowPrivate>,
SwApplicationWindowClass>)
@extends gtk::Widget, gtk::Container, gtk::Bin, gtk::Window, gtk::ApplicationWindow;
@extends gtk::Widget, gtk::Container, gtk::Bin, gtk::Window, gtk::ApplicationWindow, gio::ActionMap;
match fn {
get_type => || WindowPrivate::get_type().to_glib(),
......@@ -146,7 +146,6 @@ impl Window {
pub fn new(sender: glib::Sender<Action>, app: &Application) -> Self {
let window = glib::Object::new(Window::static_type(), &[("application", app)]).unwrap().downcast::<Window>().unwrap();
window.setup_signals(sender);
window.setup_actions(app);
window
}
......@@ -185,9 +184,9 @@ impl Window {
let bg_handle = self_.bg_entry.get_entry().connect_changed(on_entry_changed.clone());
let fg_handle = self_.fg_entry.get_entry().connect_changed(on_entry_changed);
let actions = gio::SimpleActionGroup::new();
action!(
actions,
self,
"reverse-colors",
clone!(@strong self_.fg_entry as fg_entry, @strong self_.bg_entry as bg_entry,
@strong self as window => move |_, _| {
......@@ -204,32 +203,6 @@ impl Window {
window.colour_changed(fg_colour, bg_colour);
})
);
self.insert_action_group("window", Some(&actions));
self.colour_changed(self_.bg_entry.get_text(), self_.fg_entry.get_text());
}
fn setup_actions(&self, app: &Application) {
// Quit
action!(
self.get_application().unwrap(),
"quit",
clone!(@strong app => move |_, _| {
app.quit();
})
);
// About
action!(
self.get_application().unwrap(),
"about",
clone!(@strong self as window => move |_, _| {
let builder = gtk::Builder::new_from_resource("/org/gnome/design/Contrast/about_dialog.ui");
get_widget!(builder, gtk::AboutDialog, about_dialog);
about_dialog.set_transient_for(Some(&window));
about_dialog.connect_response(|dialog, _| dialog.destroy());
about_dialog.show();
})
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment