place shortcuts in existing config
This commit is contained in:
parent
e520b7b0e3
commit
d5f1ac4e91
5 changed files with 24 additions and 62 deletions
|
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||
use std::collections::BTreeMap;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use crate::{fl, localize::LANGUAGE_SORTER};
|
||||
use crate::{fl, localize::LANGUAGE_SORTER, shortcuts::Shortcuts};
|
||||
|
||||
pub const CONFIG_VERSION: u64 = 1;
|
||||
pub const COSMIC_THEME_DARK: &str = "COSMIC Dark";
|
||||
|
|
@ -236,6 +236,8 @@ pub struct Config {
|
|||
pub syntax_theme_light: String,
|
||||
pub focus_follow_mouse: bool,
|
||||
pub default_profile: Option<ProfileId>,
|
||||
#[serde(default)]
|
||||
pub shortcuts_custom: Shortcuts,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
@ -259,6 +261,7 @@ impl Default for Config {
|
|||
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
|
||||
use_bright_bold: false,
|
||||
default_profile: None,
|
||||
shortcuts_custom: Shortcuts::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
src/main.rs
50
src/main.rs
|
|
@ -162,7 +162,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
};
|
||||
|
||||
let (shortcuts_config_handler, shortcuts_config) = shortcuts::load();
|
||||
let shortcuts_config = shortcuts::ShortcutsConfig {
|
||||
defaults: shortcuts::Shortcuts::default(),
|
||||
custom: config.shortcuts_custom.clone(),
|
||||
};
|
||||
|
||||
let startup_options = if let Some(shell_program) = shell_program_opt {
|
||||
let options = tty::Options {
|
||||
|
|
@ -192,7 +195,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let flags = Flags {
|
||||
config_handler,
|
||||
config,
|
||||
shortcuts_config_handler,
|
||||
shortcuts_config,
|
||||
startup_options,
|
||||
term_config,
|
||||
|
|
@ -220,7 +222,6 @@ Options:
|
|||
pub struct Flags {
|
||||
config_handler: Option<cosmic_config::Config>,
|
||||
config: Config,
|
||||
shortcuts_config_handler: Option<cosmic_config::Config>,
|
||||
shortcuts_config: shortcuts::ShortcutsConfig,
|
||||
startup_options: Option<tty::Options>,
|
||||
term_config: term::Config,
|
||||
|
|
@ -351,7 +352,6 @@ pub enum Message {
|
|||
ColorSchemeRenameSubmit,
|
||||
ColorSchemeTabActivate(widget::segmented_button::Entity),
|
||||
Config(Config),
|
||||
ShortcutsConfig(shortcuts::ShortcutsConfig),
|
||||
Copy(Option<segmented_button::Entity>),
|
||||
CopyOrSigint(Option<segmented_button::Entity>),
|
||||
CopyPrimary(Option<segmented_button::Entity>),
|
||||
|
|
@ -451,7 +451,6 @@ pub struct App {
|
|||
pane_model: TerminalPaneGrid,
|
||||
config_handler: Option<cosmic_config::Config>,
|
||||
config: Config,
|
||||
shortcuts_config_handler: Option<cosmic_config::Config>,
|
||||
shortcuts_config: shortcuts::ShortcutsConfig,
|
||||
key_binds: HashMap<KeyBind, Action>,
|
||||
app_themes: Vec<String>,
|
||||
|
|
@ -561,9 +560,13 @@ impl App {
|
|||
}
|
||||
|
||||
fn save_shortcuts_custom(&mut self) {
|
||||
match &self.shortcuts_config_handler {
|
||||
self.config.shortcuts_custom = self.shortcuts_config.custom.clone();
|
||||
match &self.config_handler {
|
||||
Some(config_handler) => {
|
||||
if let Err(err) = config_handler.set("custom", &self.shortcuts_config.custom) {
|
||||
if let Err(err) = config_handler.set(
|
||||
"shortcuts_custom",
|
||||
&self.config.shortcuts_custom,
|
||||
) {
|
||||
log::warn!("failed to save shortcuts custom config: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
@ -1705,7 +1708,6 @@ impl Application for App {
|
|||
pane_model,
|
||||
config_handler: flags.config_handler,
|
||||
config: flags.config,
|
||||
shortcuts_config_handler: flags.shortcuts_config_handler,
|
||||
shortcuts_config: flags.shortcuts_config,
|
||||
key_binds,
|
||||
app_themes,
|
||||
|
|
@ -2023,19 +2025,21 @@ impl Application for App {
|
|||
}
|
||||
Message::Config(config) => {
|
||||
if config != self.config {
|
||||
let shortcuts_changed =
|
||||
config.shortcuts_custom != self.config.shortcuts_custom;
|
||||
log::info!("update config");
|
||||
//TODO: update syntax theme by clearing tabs, only if needed
|
||||
self.config = config;
|
||||
if shortcuts_changed {
|
||||
self.shortcuts_config = shortcuts::ShortcutsConfig {
|
||||
defaults: shortcuts::Shortcuts::default(),
|
||||
custom: self.config.shortcuts_custom.clone(),
|
||||
};
|
||||
self.key_binds = key_binds(&self.shortcuts_config);
|
||||
}
|
||||
return self.update_config();
|
||||
}
|
||||
}
|
||||
Message::ShortcutsConfig(config) => {
|
||||
if config != self.shortcuts_config {
|
||||
log::info!("update shortcuts config");
|
||||
self.shortcuts_config = config;
|
||||
self.key_binds = key_binds(&self.shortcuts_config);
|
||||
}
|
||||
}
|
||||
Message::Copy(entity_opt) => {
|
||||
if let Some(tab_model) = self.pane_model.active() {
|
||||
let entity = entity_opt.unwrap_or_else(|| tab_model.active());
|
||||
|
|
@ -3169,7 +3173,6 @@ impl Application for App {
|
|||
|
||||
fn subscription(&self) -> Subscription<Self::Message> {
|
||||
struct ConfigSubscription;
|
||||
struct ShortcutsConfigSubscription;
|
||||
struct TerminalEventSubscription;
|
||||
|
||||
Subscription::batch([
|
||||
|
|
@ -3216,21 +3219,6 @@ impl Application for App {
|
|||
}
|
||||
Message::Config(update.config)
|
||||
}),
|
||||
cosmic_config::config_subscription::<_, shortcuts::ShortcutsConfig>(
|
||||
TypeId::of::<ShortcutsConfigSubscription>(),
|
||||
shortcuts::SHORTCUTS_CONFIG_ID.into(),
|
||||
shortcuts::SHORTCUTS_CONFIG_VERSION,
|
||||
)
|
||||
.map(|update| {
|
||||
if !update.errors.is_empty() {
|
||||
log::debug!(
|
||||
"errors loading shortcuts config {:?}: {:?}",
|
||||
update.keys,
|
||||
update.errors
|
||||
);
|
||||
}
|
||||
Message::ShortcutsConfig(update.config)
|
||||
}),
|
||||
match &self.dialog_opt {
|
||||
Some(dialog) => dialog.subscription(),
|
||||
None => Subscription::none(),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use cosmic::widget::menu::key_bind::{KeyBind, Modifier};
|
||||
use cosmic::{
|
||||
cosmic_config::{self, CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry},
|
||||
iced::keyboard::{Key, Modifiers},
|
||||
iced_core::keyboard::key::Named,
|
||||
};
|
||||
|
|
@ -11,9 +10,6 @@ use std::collections::{BTreeMap, HashMap};
|
|||
|
||||
use crate::Action;
|
||||
|
||||
pub const SHORTCUTS_CONFIG_ID: &str = "com.system76.CosmicTerm.Shortcuts";
|
||||
pub const SHORTCUTS_CONFIG_VERSION: u64 = 1;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
pub enum ModifierName {
|
||||
Ctrl,
|
||||
|
|
@ -167,7 +163,7 @@ pub struct ResolvedBinding {
|
|||
pub source: BindingSource,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, CosmicConfigEntry)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ShortcutsConfig {
|
||||
pub defaults: Shortcuts,
|
||||
pub custom: Shortcuts,
|
||||
|
|
@ -231,25 +227,6 @@ impl ShortcutsConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn load() -> (Option<cosmic_config::Config>, ShortcutsConfig) {
|
||||
match cosmic_config::Config::new(SHORTCUTS_CONFIG_ID, SHORTCUTS_CONFIG_VERSION) {
|
||||
Ok(config_handler) => {
|
||||
let config = match ShortcutsConfig::get_entry(&config_handler) {
|
||||
Ok(config) => config,
|
||||
Err((errors, config)) => {
|
||||
log::info!("errors loading shortcuts config: {:?}", errors);
|
||||
config
|
||||
}
|
||||
};
|
||||
(Some(config_handler), config)
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("failed to create shortcuts config handler: {}", err);
|
||||
(None, ShortcutsConfig::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn action_label(action: KeyBindAction) -> &'static str {
|
||||
match action {
|
||||
KeyBindAction::Unbind => "Unbind",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue