Commit 2fd515db authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

Add a keyboard shortcut to reverse colors

parent 1796edfd
Pipeline #107781 failed with stages
in 4 minutes and 31 seconds
......@@ -107,7 +107,7 @@ dependencies = [
[[package]]
name = "contrast"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -11,6 +11,13 @@
<object class="GtkShortcutsGroup">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Reverse Colors</property>
<property name="accelerator">&lt;Primary&gt;R</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
......
......@@ -75,6 +75,8 @@ impl Application {
simple_action.connect_activate(move |_, _| app.quit());
self.app.add_action(&simple_action);
self.app.set_accels_for_action("app.quit", &["<primary>q"]);
self.app.set_accels_for_action("win.show-help-overlay", &["<primary>question"]);
self.app.set_accels_for_action("window.reverse-colors", &["<primary>r"]);
// About
let window = self.window.widget.clone();
......
......@@ -6,9 +6,10 @@ use super::contrast_preview::ContrastPreview;
use super::window_state::WindowState;
use gettextrs::gettext;
use gio::prelude::*;
use glib::ObjectExt;
use gtk::prelude::*;
use libhandy::prelude::*;
use libhandy::HeaderBarExt;
use std::{cell::RefCell, rc::Rc};
pub struct Window {
......@@ -103,7 +104,10 @@ impl Window {
let fg_entry = self.fg_entry.clone();
let bg_entry = self.bg_entry.clone();
let sender = self.sender.clone();
self.reverse_btn.connect_clicked(move |_| {
let actions = gio::SimpleActionGroup::new();
let reverse_colors = gio::SimpleAction::new("reverse-colors", None);
reverse_colors.connect_activate(move |_, _| {
fg_entry.entry.block_signal(&fg_handle);
bg_entry.entry.block_signal(&bg_handle);
let fg_colour = fg_entry.get_text();
......@@ -118,6 +122,9 @@ impl Window {
sender.send(Message::ColorChanged).ok(); // never fails
});
actions.add_action(&reverse_colors);
self.widget.insert_action_group("window", Some(&actions));
}
fn setup_widgets(&self) {
......@@ -130,6 +137,7 @@ impl Window {
self.bg_entry.entry.get_style_context().add_class("bg-entry");
self.reverse_btn.set_halign(gtk::Align::Center);
self.reverse_btn.set_action_name(Some("window.reverse-colors"));
let reverse_img = gtk::Image::new_from_icon_name(Some("network-transmit-receive-symbolic"), gtk::IconSize::Button);
reverse_img.show();
self.reverse_btn.set_image(Some(&reverse_img));
......
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