place shortcuts in existing config
This commit is contained in:
parent
e520b7b0e3
commit
d5f1ac4e91
5 changed files with 24 additions and 62 deletions
5
justfile
5
justfile
|
|
@ -23,9 +23,6 @@ metainfo-dst := clean(rootdir / prefix) / 'share' / 'metainfo' / metainfo
|
||||||
icons-src := 'res' / 'icons' / 'hicolor'
|
icons-src := 'res' / 'icons' / 'hicolor'
|
||||||
icons-dst := clean(rootdir / prefix) / 'share' / 'icons' / 'hicolor'
|
icons-dst := clean(rootdir / prefix) / 'share' / 'icons' / 'hicolor'
|
||||||
|
|
||||||
shortcuts-src := 'res' / 'com.system76.CosmicTerm.Shortcuts' / 'v1'
|
|
||||||
shortcuts-dst := clean(rootdir / prefix) / 'share' / 'cosmic' / 'com.system76.CosmicTerm.Shortcuts' / 'v1'
|
|
||||||
|
|
||||||
# Default recipe which runs `just build-release`
|
# Default recipe which runs `just build-release`
|
||||||
default: build-release
|
default: build-release
|
||||||
|
|
||||||
|
|
@ -70,8 +67,6 @@ install:
|
||||||
install -Dm0755 {{bin-src}} {{bin-dst}}
|
install -Dm0755 {{bin-src}} {{bin-dst}}
|
||||||
install -Dm0644 {{desktop-src}} {{desktop-dst}}
|
install -Dm0644 {{desktop-src}} {{desktop-dst}}
|
||||||
install -Dm0644 {{metainfo-src}} {{metainfo-dst}}
|
install -Dm0644 {{metainfo-src}} {{metainfo-dst}}
|
||||||
install -Dm0644 {{shortcuts-src}}/defaults {{shortcuts-dst}}/defaults
|
|
||||||
install -Dm0644 {{shortcuts-src}}/custom {{shortcuts-dst}}/custom
|
|
||||||
for size in `ls {{icons-src}}`; do \
|
for size in `ls {{icons-src}}`; do \
|
||||||
install -Dm0644 "{{icons-src}}/$size/apps/{{APPID}}.svg" "{{icons-dst}}/$size/apps/{{APPID}}.svg"; \
|
install -Dm0644 "{{icons-src}}/$size/apps/{{APPID}}.svg" "{{icons-dst}}/$size/apps/{{APPID}}.svg"; \
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
||||||
|
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::sync::OnceLock;
|
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 CONFIG_VERSION: u64 = 1;
|
||||||
pub const COSMIC_THEME_DARK: &str = "COSMIC Dark";
|
pub const COSMIC_THEME_DARK: &str = "COSMIC Dark";
|
||||||
|
|
@ -236,6 +236,8 @@ pub struct Config {
|
||||||
pub syntax_theme_light: String,
|
pub syntax_theme_light: String,
|
||||||
pub focus_follow_mouse: bool,
|
pub focus_follow_mouse: bool,
|
||||||
pub default_profile: Option<ProfileId>,
|
pub default_profile: Option<ProfileId>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub shortcuts_custom: Shortcuts,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
|
@ -259,6 +261,7 @@ impl Default for Config {
|
||||||
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
|
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
|
||||||
use_bright_bold: false,
|
use_bright_bold: false,
|
||||||
default_profile: None,
|
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 startup_options = if let Some(shell_program) = shell_program_opt {
|
||||||
let options = tty::Options {
|
let options = tty::Options {
|
||||||
|
|
@ -192,7 +195,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let flags = Flags {
|
let flags = Flags {
|
||||||
config_handler,
|
config_handler,
|
||||||
config,
|
config,
|
||||||
shortcuts_config_handler,
|
|
||||||
shortcuts_config,
|
shortcuts_config,
|
||||||
startup_options,
|
startup_options,
|
||||||
term_config,
|
term_config,
|
||||||
|
|
@ -220,7 +222,6 @@ Options:
|
||||||
pub struct Flags {
|
pub struct Flags {
|
||||||
config_handler: Option<cosmic_config::Config>,
|
config_handler: Option<cosmic_config::Config>,
|
||||||
config: Config,
|
config: Config,
|
||||||
shortcuts_config_handler: Option<cosmic_config::Config>,
|
|
||||||
shortcuts_config: shortcuts::ShortcutsConfig,
|
shortcuts_config: shortcuts::ShortcutsConfig,
|
||||||
startup_options: Option<tty::Options>,
|
startup_options: Option<tty::Options>,
|
||||||
term_config: term::Config,
|
term_config: term::Config,
|
||||||
|
|
@ -351,7 +352,6 @@ pub enum Message {
|
||||||
ColorSchemeRenameSubmit,
|
ColorSchemeRenameSubmit,
|
||||||
ColorSchemeTabActivate(widget::segmented_button::Entity),
|
ColorSchemeTabActivate(widget::segmented_button::Entity),
|
||||||
Config(Config),
|
Config(Config),
|
||||||
ShortcutsConfig(shortcuts::ShortcutsConfig),
|
|
||||||
Copy(Option<segmented_button::Entity>),
|
Copy(Option<segmented_button::Entity>),
|
||||||
CopyOrSigint(Option<segmented_button::Entity>),
|
CopyOrSigint(Option<segmented_button::Entity>),
|
||||||
CopyPrimary(Option<segmented_button::Entity>),
|
CopyPrimary(Option<segmented_button::Entity>),
|
||||||
|
|
@ -451,7 +451,6 @@ pub struct App {
|
||||||
pane_model: TerminalPaneGrid,
|
pane_model: TerminalPaneGrid,
|
||||||
config_handler: Option<cosmic_config::Config>,
|
config_handler: Option<cosmic_config::Config>,
|
||||||
config: Config,
|
config: Config,
|
||||||
shortcuts_config_handler: Option<cosmic_config::Config>,
|
|
||||||
shortcuts_config: shortcuts::ShortcutsConfig,
|
shortcuts_config: shortcuts::ShortcutsConfig,
|
||||||
key_binds: HashMap<KeyBind, Action>,
|
key_binds: HashMap<KeyBind, Action>,
|
||||||
app_themes: Vec<String>,
|
app_themes: Vec<String>,
|
||||||
|
|
@ -561,9 +560,13 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_shortcuts_custom(&mut self) {
|
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) => {
|
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);
|
log::warn!("failed to save shortcuts custom config: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1705,7 +1708,6 @@ impl Application for App {
|
||||||
pane_model,
|
pane_model,
|
||||||
config_handler: flags.config_handler,
|
config_handler: flags.config_handler,
|
||||||
config: flags.config,
|
config: flags.config,
|
||||||
shortcuts_config_handler: flags.shortcuts_config_handler,
|
|
||||||
shortcuts_config: flags.shortcuts_config,
|
shortcuts_config: flags.shortcuts_config,
|
||||||
key_binds,
|
key_binds,
|
||||||
app_themes,
|
app_themes,
|
||||||
|
|
@ -2023,19 +2025,21 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::Config(config) => {
|
Message::Config(config) => {
|
||||||
if config != self.config {
|
if config != self.config {
|
||||||
|
let shortcuts_changed =
|
||||||
|
config.shortcuts_custom != self.config.shortcuts_custom;
|
||||||
log::info!("update config");
|
log::info!("update config");
|
||||||
//TODO: update syntax theme by clearing tabs, only if needed
|
//TODO: update syntax theme by clearing tabs, only if needed
|
||||||
self.config = config;
|
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();
|
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) => {
|
Message::Copy(entity_opt) => {
|
||||||
if let Some(tab_model) = self.pane_model.active() {
|
if let Some(tab_model) = self.pane_model.active() {
|
||||||
let entity = entity_opt.unwrap_or_else(|| tab_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> {
|
fn subscription(&self) -> Subscription<Self::Message> {
|
||||||
struct ConfigSubscription;
|
struct ConfigSubscription;
|
||||||
struct ShortcutsConfigSubscription;
|
|
||||||
struct TerminalEventSubscription;
|
struct TerminalEventSubscription;
|
||||||
|
|
||||||
Subscription::batch([
|
Subscription::batch([
|
||||||
|
|
@ -3216,21 +3219,6 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::Config(update.config)
|
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 {
|
match &self.dialog_opt {
|
||||||
Some(dialog) => dialog.subscription(),
|
Some(dialog) => dialog.subscription(),
|
||||||
None => Subscription::none(),
|
None => Subscription::none(),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use cosmic::widget::menu::key_bind::{KeyBind, Modifier};
|
use cosmic::widget::menu::key_bind::{KeyBind, Modifier};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
cosmic_config::{self, CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry},
|
|
||||||
iced::keyboard::{Key, Modifiers},
|
iced::keyboard::{Key, Modifiers},
|
||||||
iced_core::keyboard::key::Named,
|
iced_core::keyboard::key::Named,
|
||||||
};
|
};
|
||||||
|
|
@ -11,9 +10,6 @@ use std::collections::{BTreeMap, HashMap};
|
||||||
|
|
||||||
use crate::Action;
|
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)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
pub enum ModifierName {
|
pub enum ModifierName {
|
||||||
Ctrl,
|
Ctrl,
|
||||||
|
|
@ -167,7 +163,7 @@ pub struct ResolvedBinding {
|
||||||
pub source: BindingSource,
|
pub source: BindingSource,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, CosmicConfigEntry)]
|
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
pub struct ShortcutsConfig {
|
pub struct ShortcutsConfig {
|
||||||
pub defaults: Shortcuts,
|
pub defaults: Shortcuts,
|
||||||
pub custom: 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 {
|
pub fn action_label(action: KeyBindAction) -> &'static str {
|
||||||
match action {
|
match action {
|
||||||
KeyBindAction::Unbind => "Unbind",
|
KeyBindAction::Unbind => "Unbind",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue