parent
0508323427
commit
d6b39ebf37
2 changed files with 78 additions and 56 deletions
|
|
@ -387,21 +387,30 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortcutMessage::DeleteBinding(id) => {
|
ShortcutMessage::DeleteBinding(id) => {
|
||||||
|
eprintln!("delete shortcut");
|
||||||
if let Some(short_id) = self.shortcut_context {
|
if let Some(short_id) = self.shortcut_context {
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
||||||
let shortcut = model.bindings.remove(id);
|
let shortcut = model.bindings.remove(id);
|
||||||
if shortcut.is_default {
|
if shortcut.is_default {
|
||||||
|
eprintln!("disabling {shortcut:?}");
|
||||||
self.config_add(Action::Disable, shortcut.binding.clone());
|
self.config_add(Action::Disable, shortcut.binding.clone());
|
||||||
} else {
|
} else {
|
||||||
|
eprintln!("removing {shortcut:?}");
|
||||||
self.config_remove(&shortcut.binding);
|
self.config_remove(&shortcut.binding);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("no shortcut model found");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("no shortcut context");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortcutMessage::DeleteShortcut(id) => {
|
ShortcutMessage::DeleteShortcut(id) => {
|
||||||
|
eprintln!("deleting shortcut");
|
||||||
let model = self.shortcut_models.remove(id);
|
let model = self.shortcut_models.remove(id);
|
||||||
for (_, shortcut) in model.bindings {
|
for (_, shortcut) in model.bindings {
|
||||||
|
eprintln!("removing shortcut {shortcut:?}");
|
||||||
self.config_remove(&shortcut.binding);
|
self.config_remove(&shortcut.binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,70 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
self.shortcuts_context = cosmic_settings_config::shortcuts::context().ok();
|
self.shortcuts_context = cosmic_settings_config::shortcuts::context().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.reload_search();
|
||||||
|
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_leave(&mut self) -> Task<crate::pages::Message> {
|
||||||
|
self.clear();
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Page {
|
||||||
|
pub fn update(&mut self, message: Message) -> Task<crate::app::Message> {
|
||||||
|
match message {
|
||||||
|
Message::Category(category) => match category {
|
||||||
|
Category::Custom => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.custom))
|
||||||
|
}
|
||||||
|
|
||||||
|
Category::ManageWindow => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.manage_window))
|
||||||
|
}
|
||||||
|
|
||||||
|
Category::MoveWindow => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.move_window))
|
||||||
|
}
|
||||||
|
|
||||||
|
Category::Nav => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.nav))
|
||||||
|
}
|
||||||
|
|
||||||
|
Category::System => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.system))
|
||||||
|
}
|
||||||
|
|
||||||
|
Category::WindowTiling => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.window_tiling))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Message::Search(input) => {
|
||||||
|
self.search(input);
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::SearchShortcut(message) => self.search_model.update(message),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.search.actions = SlotMap::new();
|
||||||
|
self.search.localized = SecondaryMap::new();
|
||||||
|
self.search.input = String::new();
|
||||||
|
self.search_model.on_clear();
|
||||||
|
self.modified.custom = 0;
|
||||||
|
self.modified.manage_windows = 0;
|
||||||
|
self.modified.move_windows = 0;
|
||||||
|
self.modified.nav = 0;
|
||||||
|
self.modified.system = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reload_search(&mut self) {
|
||||||
|
self.clear();
|
||||||
|
|
||||||
if let Some(context) = self.shortcuts_context.as_ref() {
|
if let Some(context) = self.shortcuts_context.as_ref() {
|
||||||
let mut defaults = context.get::<Shortcuts>("defaults").unwrap_or_default();
|
let mut defaults = context.get::<Shortcuts>("defaults").unwrap_or_default();
|
||||||
let custom = context.get::<Shortcuts>("custom").unwrap_or_default();
|
let custom = context.get::<Shortcuts>("custom").unwrap_or_default();
|
||||||
|
|
@ -200,72 +264,21 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
defaults.0.extend(custom.0);
|
defaults.0.extend(custom.0);
|
||||||
self.search.shortcuts = defaults;
|
self.search.shortcuts = defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_leave(&mut self) -> Task<crate::pages::Message> {
|
|
||||||
self.search.actions = SlotMap::new();
|
|
||||||
self.search.localized = SecondaryMap::new();
|
|
||||||
self.search.input = String::new();
|
|
||||||
self.search_model.on_clear();
|
|
||||||
self.modified.custom = 0;
|
|
||||||
self.modified.manage_windows = 0;
|
|
||||||
self.modified.move_windows = 0;
|
|
||||||
self.modified.nav = 0;
|
|
||||||
self.modified.system = 0;
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Page {
|
|
||||||
pub fn update(&mut self, message: Message) -> Task<crate::app::Message> {
|
|
||||||
match message {
|
|
||||||
Message::Category(category) => match category {
|
|
||||||
Category::Custom => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.custom))
|
|
||||||
}
|
|
||||||
|
|
||||||
Category::ManageWindow => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.manage_window))
|
|
||||||
}
|
|
||||||
|
|
||||||
Category::MoveWindow => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.move_window))
|
|
||||||
}
|
|
||||||
|
|
||||||
Category::Nav => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.nav))
|
|
||||||
}
|
|
||||||
|
|
||||||
Category::System => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.system))
|
|
||||||
}
|
|
||||||
|
|
||||||
Category::WindowTiling => {
|
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.window_tiling))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Message::Search(input) => {
|
|
||||||
self.search(input);
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::SearchShortcut(message) => self.search_model.update(message),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search(&mut self, input: String) {
|
fn search(&mut self, input: String) {
|
||||||
self.search.input = input;
|
self.reload_search();
|
||||||
if self.search.input.is_empty() {
|
|
||||||
|
if input.is_empty() {
|
||||||
self.search_model.on_clear();
|
self.search_model.on_clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.search.actions.is_empty() {
|
if self.search.actions.is_empty() {
|
||||||
self.search.cache_localized_actions();
|
self.search.cache_localized_actions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.search.input = input;
|
||||||
self.search_model.shortcut_models = self.search.shortcut_models();
|
self.search_model.shortcut_models = self.search.shortcut_models();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue