Added + menu for opening terminal or ssh, shortcuts for the command. Command palette functionallity to type quick terminal/ssh
This commit is contained in:
1 parent
c963558fff
commit
e8d6575ab3
1 file changed
+495
-46
+495
-46
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use iced::time::{Duration, Instant};
|
||||
use iced::widget::text::Wrapping;
|
||||
use iced::widget::{Id, operation};
|
||||
use iced::widget::{
|
||||
button, checkbox, column, container, mouse_area, pick_list, responsive, row, rule, scrollable,
|
||||
@@ -182,11 +183,23 @@ fn subscription(state: &Moorly) -> Subscription<Message> {
|
||||
.with((
|
||||
state.saved_shortcuts.settings.clone(),
|
||||
state.saved_shortcuts.quit.clone(),
|
||||
state.saved_shortcuts.quick_terminal.clone(),
|
||||
state.saved_shortcuts.quick_ssh.clone(),
|
||||
state.shortcut_capture.is_some(),
|
||||
active_window,
|
||||
))
|
||||
.filter_map(
|
||||
|((settings_shortcut, quit_shortcut, capturing, window), event)| {
|
||||
|(
|
||||
(
|
||||
settings_shortcut,
|
||||
quit_shortcut,
|
||||
quick_terminal_shortcut,
|
||||
quick_ssh_shortcut,
|
||||
capturing,
|
||||
window,
|
||||
),
|
||||
event,
|
||||
)| {
|
||||
let keyboard::Event::KeyPressed {
|
||||
key,
|
||||
modifiers,
|
||||
@@ -208,21 +221,25 @@ fn subscription(state: &Moorly) -> Subscription<Message> {
|
||||
return Some(Message::Quit);
|
||||
}
|
||||
|
||||
if let Some(shortcut) = &settings_shortcut {
|
||||
if shortcut.matches(&key, modifiers) {
|
||||
return window.map(|window| Message::SelectTab(window, Tab::Settings));
|
||||
}
|
||||
if let Some(shortcut) = &settings_shortcut
|
||||
&& shortcut.matches(&key, modifiers)
|
||||
{
|
||||
return window.map(|window| Message::SelectTab(window, Tab::Settings));
|
||||
}
|
||||
|
||||
if let Some(shortcut) = &quick_terminal_shortcut
|
||||
&& shortcut.matches(&key, modifiers)
|
||||
{
|
||||
return window.map(Message::QuickTerminal);
|
||||
}
|
||||
|
||||
if let Some(shortcut) = &quick_ssh_shortcut
|
||||
&& shortcut.matches(&key, modifiers)
|
||||
{
|
||||
return window.map(Message::QuickSsh);
|
||||
}
|
||||
|
||||
match key {
|
||||
keyboard::Key::Character(key)
|
||||
if cfg!(debug_assertions)
|
||||
&& key.eq_ignore_ascii_case("t")
|
||||
&& modifiers.control()
|
||||
&& modifiers.shift() =>
|
||||
{
|
||||
window.map(Message::AddTab)
|
||||
}
|
||||
keyboard::Key::Character(key)
|
||||
if cfg!(debug_assertions)
|
||||
&& key.eq_ignore_ascii_case("n")
|
||||
@@ -255,14 +272,18 @@ fn subscription(state: &Moorly) -> Subscription<Message> {
|
||||
.with((
|
||||
state.saved_shortcuts.command_palette.clone(),
|
||||
state.shortcut_capture.is_some(),
|
||||
state.command_palette_enabled,
|
||||
))
|
||||
.filter_map(|((shortcut, capturing), (key, modifiers, window))| {
|
||||
(!capturing
|
||||
&& shortcut
|
||||
.as_ref()
|
||||
.is_some_and(|shortcut| shortcut.matches(&key, modifiers)))
|
||||
.then_some(Message::ToggleCommandPalette(window))
|
||||
});
|
||||
.filter_map(
|
||||
|((shortcut, capturing, enabled), (key, modifiers, window))| {
|
||||
(enabled
|
||||
&& !capturing
|
||||
&& shortcut
|
||||
.as_ref()
|
||||
.is_some_and(|shortcut| shortcut.matches(&key, modifiers)))
|
||||
.then_some(Message::ToggleCommandPalette(window))
|
||||
},
|
||||
);
|
||||
|
||||
let mut subscriptions = vec![
|
||||
keyboard,
|
||||
@@ -414,6 +435,8 @@ enum ShortcutAction {
|
||||
Settings,
|
||||
Quit,
|
||||
CommandPalette,
|
||||
QuickTerminal,
|
||||
QuickSsh,
|
||||
}
|
||||
|
||||
impl ShortcutAction {
|
||||
@@ -422,6 +445,8 @@ impl ShortcutAction {
|
||||
Self::Settings => "Settings",
|
||||
Self::Quit => "Quit",
|
||||
Self::CommandPalette => "Command palette",
|
||||
Self::QuickTerminal => "Quick terminal",
|
||||
Self::QuickSsh => "Quick SSH",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,6 +456,8 @@ struct Shortcuts {
|
||||
settings: Option<Shortcut>,
|
||||
quit: Option<Shortcut>,
|
||||
command_palette: Option<Shortcut>,
|
||||
quick_terminal: Option<Shortcut>,
|
||||
quick_ssh: Option<Shortcut>,
|
||||
}
|
||||
|
||||
impl Default for Shortcuts {
|
||||
@@ -439,6 +466,8 @@ impl Default for Shortcuts {
|
||||
settings: Shortcut::parse("Ctrl+,"),
|
||||
quit: Shortcut::parse("Ctrl+Shift+Q"),
|
||||
command_palette: Shortcut::parse("Ctrl+Shift+Space"),
|
||||
quick_terminal: Shortcut::parse("Ctrl+Shift+T"),
|
||||
quick_ssh: Shortcut::parse("Ctrl+Shift+S"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,6 +478,8 @@ impl Shortcuts {
|
||||
ShortcutAction::Settings => self.settings.as_ref(),
|
||||
ShortcutAction::Quit => self.quit.as_ref(),
|
||||
ShortcutAction::CommandPalette => self.command_palette.as_ref(),
|
||||
ShortcutAction::QuickTerminal => self.quick_terminal.as_ref(),
|
||||
ShortcutAction::QuickSsh => self.quick_ssh.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,6 +488,8 @@ impl Shortcuts {
|
||||
ShortcutAction::Settings => self.settings = shortcut,
|
||||
ShortcutAction::Quit => self.quit = shortcut,
|
||||
ShortcutAction::CommandPalette => self.command_palette = shortcut,
|
||||
ShortcutAction::QuickTerminal => self.quick_terminal = shortcut,
|
||||
ShortcutAction::QuickSsh => self.quick_ssh = shortcut,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,6 +500,8 @@ impl Shortcuts {
|
||||
(ShortcutAction::Settings, &self.settings),
|
||||
(ShortcutAction::Quit, &self.quit),
|
||||
(ShortcutAction::CommandPalette, &self.command_palette),
|
||||
(ShortcutAction::QuickTerminal, &self.quick_terminal),
|
||||
(ShortcutAction::QuickSsh, &self.quick_ssh),
|
||||
];
|
||||
if let Some((action, _)) = configurable
|
||||
.iter()
|
||||
@@ -476,14 +511,7 @@ impl Shortcuts {
|
||||
}
|
||||
|
||||
// Shortcuts that are fixed for now but still own their keys.
|
||||
let reserved: &[(&str, &str)] = if cfg!(debug_assertions) {
|
||||
&[
|
||||
("Close Active Tab", "Ctrl+Shift+W"),
|
||||
("Add Tab", "Ctrl+Shift+T"),
|
||||
]
|
||||
} else {
|
||||
&[("Close Active Tab", "Ctrl+Shift+W")]
|
||||
};
|
||||
let reserved: &[(&str, &str)] = &[("Close Active Tab", "Ctrl+Shift+W")];
|
||||
|
||||
reserved.iter().find_map(|(name, text)| {
|
||||
(Shortcut::parse(text).as_ref() == Some(candidate)).then_some(*name)
|
||||
@@ -1173,6 +1201,10 @@ enum Command {
|
||||
Settings,
|
||||
Close,
|
||||
Move,
|
||||
Left,
|
||||
Right,
|
||||
QuickTerminal,
|
||||
QuickSsh,
|
||||
MoveToWindow(window::Id),
|
||||
FocusWindow(window::Id),
|
||||
FocusTab(window::Id, Tab),
|
||||
@@ -1181,13 +1213,26 @@ enum Command {
|
||||
}
|
||||
|
||||
impl Command {
|
||||
const ALL: [Self; 4] = [Self::Settings, Self::Close, Self::Move, Self::Exit];
|
||||
const ALL: [Self; 8] = [
|
||||
Self::Settings,
|
||||
Self::Close,
|
||||
Self::Move,
|
||||
Self::Left,
|
||||
Self::Right,
|
||||
Self::QuickTerminal,
|
||||
Self::QuickSsh,
|
||||
Self::Exit,
|
||||
];
|
||||
|
||||
fn label(&self, state: &Moorly) -> String {
|
||||
match self {
|
||||
Self::Settings => "Settings".to_owned(),
|
||||
Self::Close => "Close".to_owned(),
|
||||
Self::Move => "Move".to_owned(),
|
||||
Self::Left => "Left".to_owned(),
|
||||
Self::Right => "Right".to_owned(),
|
||||
Self::QuickTerminal => "Quick Terminal".to_owned(),
|
||||
Self::QuickSsh => "Quick SSH".to_owned(),
|
||||
Self::MoveToWindow(id) | Self::FocusWindow(id) => window_title(state, *id),
|
||||
Self::FocusTab(_, tab) => tab.title(),
|
||||
Self::SelectProfile { folder, profile } => state
|
||||
@@ -1205,6 +1250,10 @@ impl Command {
|
||||
Self::Settings => "Opens the settings tab".to_owned(),
|
||||
Self::Close => "Closes the active tab".to_owned(),
|
||||
Self::Move => "Moves the active tab to a new window".to_owned(),
|
||||
Self::Left => "Switches to the tab on the left".to_owned(),
|
||||
Self::Right => "Switches to the tab on the right".to_owned(),
|
||||
Self::QuickTerminal => "Opens a quick terminal".to_owned(),
|
||||
Self::QuickSsh => "Opens a quick SSH session".to_owned(),
|
||||
Self::MoveToWindow(id) => {
|
||||
format!("Moves the active tab to {}", window_title(state, *id))
|
||||
}
|
||||
@@ -1225,6 +1274,15 @@ impl Command {
|
||||
}
|
||||
}
|
||||
|
||||
/// Left/Right only exist while there is a tab to switch to.
|
||||
fn available(&self, state: &Moorly, window: window::Id) -> bool {
|
||||
match self {
|
||||
Self::Left => adjacent_tab(state, window, -1).is_some(),
|
||||
Self::Right => adjacent_tab(state, window, 1).is_some(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn profile_glyph(&self, state: &Moorly) -> Option<(ProfileKind, Color)> {
|
||||
match self {
|
||||
Self::SelectProfile { folder, profile } => state
|
||||
@@ -1239,6 +1297,7 @@ impl Command {
|
||||
fn matching(state: &Moorly, source: window::Id, query: &str) -> Vec<Self> {
|
||||
let mut commands: Vec<Self> = Self::ALL
|
||||
.into_iter()
|
||||
.filter(|command| command.available(state, source))
|
||||
.filter(|command| fuzzy_match(&command.label(state), query))
|
||||
.collect();
|
||||
|
||||
@@ -1287,6 +1346,18 @@ impl Command {
|
||||
}
|
||||
}
|
||||
|
||||
/// The tab next to the active one in `window`, or `None` at either end.
|
||||
fn adjacent_tab(state: &Moorly, window: window::Id, delta: isize) -> Option<Tab> {
|
||||
let window_state = state.windows.get(&window)?;
|
||||
let active = window_state.active_tab?;
|
||||
let index = window_state.tabs.iter().position(|tab| *tab == active)?;
|
||||
|
||||
window_state
|
||||
.tabs
|
||||
.get(index.checked_add_signed(delta)?)
|
||||
.copied()
|
||||
}
|
||||
|
||||
/// Case-insensitive subsequence match, so `stg` finds `Settings`.
|
||||
fn fuzzy_match(haystack: &str, needle: &str) -> bool {
|
||||
let needle = needle.trim();
|
||||
@@ -1307,6 +1378,7 @@ struct WindowState {
|
||||
active_tab: Option<Tab>,
|
||||
menu_open: bool,
|
||||
tabs_submenu_open: bool,
|
||||
quick_menu_open: bool,
|
||||
command_palette_open: bool,
|
||||
command_palette_query: String,
|
||||
command_palette_selected: usize,
|
||||
@@ -1329,6 +1401,7 @@ impl WindowState {
|
||||
active_tab: show_start_tab.then_some(Tab::Start),
|
||||
menu_open: false,
|
||||
tabs_submenu_open: false,
|
||||
quick_menu_open: false,
|
||||
command_palette_open: false,
|
||||
command_palette_query: String::new(),
|
||||
command_palette_selected: 0,
|
||||
@@ -1347,6 +1420,7 @@ impl WindowState {
|
||||
active_tab: Some(tab),
|
||||
menu_open: false,
|
||||
tabs_submenu_open: false,
|
||||
quick_menu_open: false,
|
||||
command_palette_open: false,
|
||||
command_palette_query: String::new(),
|
||||
command_palette_selected: 0,
|
||||
@@ -1395,6 +1469,8 @@ struct Moorly {
|
||||
fade_settings_draft: bool,
|
||||
hide_tab_close: bool,
|
||||
hide_tab_close_draft: bool,
|
||||
command_palette_enabled: bool,
|
||||
command_palette_enabled_draft: bool,
|
||||
advanced_open: bool,
|
||||
colors: [Color; 5],
|
||||
saved_colors: [Color; 5],
|
||||
@@ -1741,6 +1817,8 @@ struct ConfigFile {
|
||||
appearance: AppearanceConfig,
|
||||
#[serde(default)]
|
||||
shortcuts: ShortcutConfig,
|
||||
#[serde(default)]
|
||||
command_palette: CommandPaletteConfig,
|
||||
}
|
||||
|
||||
impl Default for ConfigFile {
|
||||
@@ -1750,6 +1828,7 @@ impl Default for ConfigFile {
|
||||
startup: StartupConfig::default(),
|
||||
appearance: AppearanceConfig::default(),
|
||||
shortcuts: ShortcutConfig::default(),
|
||||
command_palette: CommandPaletteConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1816,6 +1895,10 @@ struct ShortcutConfig {
|
||||
quit: String,
|
||||
#[serde(default = "default_command_palette_shortcut")]
|
||||
command_palette: String,
|
||||
#[serde(default = "default_quick_terminal_shortcut")]
|
||||
quick_terminal: String,
|
||||
#[serde(default = "default_quick_ssh_shortcut")]
|
||||
quick_ssh: String,
|
||||
}
|
||||
|
||||
impl Default for ShortcutConfig {
|
||||
@@ -1824,10 +1907,24 @@ impl Default for ShortcutConfig {
|
||||
settings: default_settings_shortcut(),
|
||||
quit: default_quit_shortcut(),
|
||||
command_palette: default_command_palette_shortcut(),
|
||||
quick_terminal: default_quick_terminal_shortcut(),
|
||||
quick_ssh: default_quick_ssh_shortcut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct CommandPaletteConfig {
|
||||
#[serde(default = "default_true")]
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl Default for CommandPaletteConfig {
|
||||
fn default() -> Self {
|
||||
Self { enabled: true }
|
||||
}
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
@@ -1857,6 +1954,20 @@ fn default_command_palette_shortcut() -> String {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn default_quick_terminal_shortcut() -> String {
|
||||
Shortcuts::default()
|
||||
.quick_terminal
|
||||
.map(|shortcut| shortcut.to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn default_quick_ssh_shortcut() -> String {
|
||||
Shortcuts::default()
|
||||
.quick_ssh
|
||||
.map(|shortcut| shortcut.to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn color_to_hex(color: Color) -> String {
|
||||
let r = (color.r * 255.0).round() as u8;
|
||||
let g = (color.g * 255.0).round() as u8;
|
||||
@@ -3270,15 +3381,17 @@ enum SettingsSection {
|
||||
Startup,
|
||||
Appearance,
|
||||
Shortcuts,
|
||||
CommandPalette,
|
||||
Profiles,
|
||||
}
|
||||
|
||||
impl SettingsSection {
|
||||
const ALL: [Self; 5] = [
|
||||
const ALL: [Self; 6] = [
|
||||
Self::General,
|
||||
Self::Startup,
|
||||
Self::Appearance,
|
||||
Self::Shortcuts,
|
||||
Self::CommandPalette,
|
||||
Self::Profiles,
|
||||
];
|
||||
|
||||
@@ -3288,6 +3401,7 @@ impl SettingsSection {
|
||||
Self::Startup => "Startup",
|
||||
Self::Appearance => "Appearance",
|
||||
Self::Shortcuts => "Shortcuts",
|
||||
Self::CommandPalette => "Command Palette",
|
||||
Self::Profiles => "Profiles",
|
||||
}
|
||||
}
|
||||
@@ -3436,6 +3550,7 @@ fn apply_settings(state: &mut Moorly) {
|
||||
state.show_start_tab = state.show_start_tab_draft;
|
||||
state.fade_settings = state.fade_settings_draft;
|
||||
state.hide_tab_close = state.hide_tab_close_draft;
|
||||
state.command_palette_enabled = state.command_palette_enabled_draft;
|
||||
|
||||
state.saved_theme = state.theme;
|
||||
state.saved_theme_choice = state.theme_choice.clone();
|
||||
@@ -3463,6 +3578,7 @@ fn undo_settings(state: &mut Moorly) {
|
||||
state.show_start_tab_draft = state.show_start_tab;
|
||||
state.fade_settings_draft = state.fade_settings;
|
||||
state.hide_tab_close_draft = state.hide_tab_close;
|
||||
state.command_palette_enabled_draft = state.command_palette_enabled;
|
||||
state.shortcuts = state.saved_shortcuts.clone();
|
||||
state.shortcut_capture = None;
|
||||
state.theme_choice = state.saved_theme_choice.clone();
|
||||
@@ -3543,6 +3659,21 @@ fn config_file(state: &Moorly) -> ConfigFile {
|
||||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
quick_terminal: state
|
||||
.saved_shortcuts
|
||||
.quick_terminal
|
||||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
quick_ssh: state
|
||||
.saved_shortcuts
|
||||
.quick_ssh
|
||||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
},
|
||||
command_palette: CommandPaletteConfig {
|
||||
enabled: state.command_palette_enabled,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -3558,10 +3689,13 @@ impl Default for Moorly {
|
||||
let show_start_tab = config.startup.show_start_tab;
|
||||
let fade_settings = config.general.fade_settings;
|
||||
let hide_tab_close = config.appearance.hide_tab_close;
|
||||
let command_palette_enabled = config.command_palette.enabled;
|
||||
let shortcuts = Shortcuts {
|
||||
settings: Shortcut::parse(&config.shortcuts.settings),
|
||||
quit: Shortcut::parse(&config.shortcuts.quit),
|
||||
command_palette: Shortcut::parse(&config.shortcuts.command_palette),
|
||||
quick_terminal: Shortcut::parse(&config.shortcuts.quick_terminal),
|
||||
quick_ssh: Shortcut::parse(&config.shortcuts.quick_ssh),
|
||||
};
|
||||
let mut notifications = notifications::NotificationManager::default();
|
||||
|
||||
@@ -3595,6 +3729,8 @@ impl Default for Moorly {
|
||||
fade_settings_draft: fade_settings,
|
||||
hide_tab_close,
|
||||
hide_tab_close_draft: hide_tab_close,
|
||||
command_palette_enabled,
|
||||
command_palette_enabled_draft: command_palette_enabled,
|
||||
advanced_open: false,
|
||||
colors,
|
||||
saved_colors: colors,
|
||||
@@ -3640,6 +3776,10 @@ enum Message {
|
||||
DragTick,
|
||||
ToggleMenu(window::Id),
|
||||
CloseMenu(window::Id),
|
||||
ToggleQuickAddMenu(window::Id),
|
||||
CloseQuickAddMenu(window::Id),
|
||||
QuickTerminal(window::Id),
|
||||
QuickSsh(window::Id),
|
||||
ToggleTabsSubmenu(window::Id),
|
||||
AddTab(window::Id),
|
||||
CloseActiveTab(window::Id),
|
||||
@@ -3665,6 +3805,7 @@ enum Message {
|
||||
SetShowStartTab(bool),
|
||||
SetFadeSettings(bool),
|
||||
SetHideTabClose(bool),
|
||||
SetCommandPaletteEnabled(bool),
|
||||
ToggleAdvanced,
|
||||
SetCustomToasts(bool),
|
||||
OpenColorPicker(ColorOption),
|
||||
@@ -3826,6 +3967,7 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
if let Some(state) = state.windows.get_mut(&window) {
|
||||
state.menu_open = !state.menu_open;
|
||||
state.tabs_submenu_open = false;
|
||||
state.quick_menu_open = false;
|
||||
}
|
||||
}
|
||||
Message::CloseMenu(window) => {
|
||||
@@ -3834,6 +3976,23 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
state.tabs_submenu_open = false;
|
||||
}
|
||||
}
|
||||
Message::ToggleQuickAddMenu(window) => {
|
||||
if let Some(state) = state.windows.get_mut(&window) {
|
||||
state.quick_menu_open = !state.quick_menu_open;
|
||||
state.menu_open = false;
|
||||
state.tabs_submenu_open = false;
|
||||
}
|
||||
}
|
||||
Message::CloseQuickAddMenu(window) => {
|
||||
if let Some(state) = state.windows.get_mut(&window) {
|
||||
state.quick_menu_open = false;
|
||||
}
|
||||
}
|
||||
Message::QuickTerminal(window) | Message::QuickSsh(window) => {
|
||||
if let Some(state) = state.windows.get_mut(&window) {
|
||||
state.quick_menu_open = false;
|
||||
}
|
||||
}
|
||||
Message::ToggleTabsSubmenu(window) => {
|
||||
if let Some(state) = state.windows.get_mut(&window) {
|
||||
state.tabs_submenu_open = !state.tabs_submenu_open;
|
||||
@@ -3900,6 +4059,7 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
close_command_palette(state, window);
|
||||
} else {
|
||||
window_state.command_palette_open = true;
|
||||
window_state.quick_menu_open = false;
|
||||
window_state.command_palette_query.clear();
|
||||
window_state.command_palette_selected = 0;
|
||||
return operation::focus(window_state.command_palette_input.clone());
|
||||
@@ -3969,6 +4129,22 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Command::Close => {
|
||||
return update(state, Message::CloseActiveTab(window));
|
||||
}
|
||||
Command::Left => {
|
||||
if let Some(target) = adjacent_tab(state, window, -1) {
|
||||
return update(state, Message::SelectTab(window, target));
|
||||
}
|
||||
}
|
||||
Command::Right => {
|
||||
if let Some(target) = adjacent_tab(state, window, 1) {
|
||||
return update(state, Message::SelectTab(window, target));
|
||||
}
|
||||
}
|
||||
Command::QuickTerminal => {
|
||||
return update(state, Message::QuickTerminal(window));
|
||||
}
|
||||
Command::QuickSsh => {
|
||||
return update(state, Message::QuickSsh(window));
|
||||
}
|
||||
Command::Move => {
|
||||
if let Some(tab) = tab {
|
||||
return detach_tab(state, window, tab, None);
|
||||
@@ -4209,6 +4385,7 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
window_state.active_tab = Some(tab);
|
||||
window_state.menu_open = false;
|
||||
window_state.tabs_submenu_open = false;
|
||||
window_state.quick_menu_open = false;
|
||||
state.folder_menu = None;
|
||||
|
||||
// New tabs land at the end, so bring that end into view.
|
||||
@@ -4249,6 +4426,9 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
|
||||
Message::SetShowStartTab(value) => state.show_start_tab_draft = value,
|
||||
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
|
||||
Message::SetHideTabClose(value) => state.hide_tab_close_draft = value,
|
||||
Message::SetCommandPaletteEnabled(value) => {
|
||||
state.command_palette_enabled_draft = value;
|
||||
}
|
||||
Message::ToggleAdvanced => state.advanced_open = !state.advanced_open,
|
||||
Message::SetCustomToasts(value) => {
|
||||
state.custom_toasts = value;
|
||||
@@ -4951,14 +5131,15 @@ fn remove_window(state: &mut Moorly, window: window::Id) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Width the tab strip gets after the scroll buttons and hamburger.
|
||||
/// Width the tab strip gets after the quick-add button, scroll buttons and
|
||||
/// hamburger.
|
||||
fn tab_strip_width(window_width: f32) -> f32 {
|
||||
(window_width
|
||||
- TAB_STRIP_LEFT
|
||||
- MENUBAR_RIGHT_PADDING
|
||||
- 2.0 * SCROLL_BUTTON_WIDTH
|
||||
- HAMBURGER_WIDTH
|
||||
- 3.0 * TAB_SPACING)
|
||||
- 2.0 * HAMBURGER_WIDTH
|
||||
- 4.0 * TAB_SPACING)
|
||||
.max(0.0)
|
||||
}
|
||||
|
||||
@@ -5430,6 +5611,46 @@ fn reveal_active_tab(state: &Moorly, window: window::Id) -> Task<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
fn quick_add_button(
|
||||
open: bool,
|
||||
text_color: Color,
|
||||
window: window::Id,
|
||||
) -> iced::widget::Button<'static, Message> {
|
||||
let glyph = if open { "+▴" } else { "+▾" };
|
||||
|
||||
button(text(glyph).size(14))
|
||||
.on_press(Message::ToggleQuickAddMenu(window))
|
||||
.width(HAMBURGER_WIDTH)
|
||||
.padding([2, 8])
|
||||
.style(move |theme, status| theme::menubar_button(theme, status, text_color))
|
||||
}
|
||||
|
||||
/// Dropdown under the quick-add button.
|
||||
fn quick_add_menu(window: window::Id) -> Element<'static, Message> {
|
||||
let menu = container(
|
||||
column![
|
||||
menu_item("Quick Terminal", None, Message::QuickTerminal(window)),
|
||||
menu_item("Quick SSH", None, Message::QuickSsh(window)),
|
||||
]
|
||||
.spacing(4),
|
||||
)
|
||||
.width(180)
|
||||
.padding(MENU_PADDING)
|
||||
.style(theme::menu);
|
||||
|
||||
container(menu)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.align_x(Alignment::Start)
|
||||
.align_y(Alignment::Start)
|
||||
.padding(Padding {
|
||||
top: MENUBAR_HEIGHT,
|
||||
left: TAB_STRIP_LEFT,
|
||||
..Padding::ZERO
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn hamburger(
|
||||
open: bool,
|
||||
text_color: Color,
|
||||
@@ -6071,6 +6292,14 @@ fn shortcuts_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
ShortcutAction::CommandPalette,
|
||||
state.shortcuts.get(ShortcutAction::CommandPalette),
|
||||
),
|
||||
shortcut_row(
|
||||
ShortcutAction::QuickTerminal,
|
||||
state.shortcuts.get(ShortcutAction::QuickTerminal),
|
||||
),
|
||||
shortcut_row(
|
||||
ShortcutAction::QuickSsh,
|
||||
state.shortcuts.get(ShortcutAction::QuickSsh),
|
||||
),
|
||||
]
|
||||
.spacing(8);
|
||||
|
||||
@@ -7409,6 +7638,63 @@ fn start_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
}
|
||||
|
||||
/// General settings that are edited as a draft until saved.
|
||||
/// Reference table of every command the command palette can offer.
|
||||
fn command_palette_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
let mut rows = column![
|
||||
row![
|
||||
text("Enable command palette").size(14),
|
||||
space::horizontal(),
|
||||
toggler(state.command_palette_enabled_draft)
|
||||
.on_toggle(Message::SetCommandPaletteEnabled),
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
rule::horizontal(1),
|
||||
row![
|
||||
container(text("Command").size(13)).width(180),
|
||||
text("Description").size(13),
|
||||
]
|
||||
.spacing(12),
|
||||
rule::horizontal(1),
|
||||
]
|
||||
.spacing(8);
|
||||
|
||||
for command in Command::ALL {
|
||||
rows = rows.push(command_palette_row(
|
||||
command.label(state),
|
||||
command.description(state),
|
||||
));
|
||||
}
|
||||
|
||||
// Commands generated from the current profiles, tabs and windows.
|
||||
for (label, description) in [
|
||||
(
|
||||
"Profile name",
|
||||
"Switches to the matching profile and opens the Start tab",
|
||||
),
|
||||
("Tab title", "Focuses the matching tab in its window"),
|
||||
(
|
||||
"Window title",
|
||||
"Focuses the matching window, or moves the active tab into it",
|
||||
),
|
||||
] {
|
||||
rows = rows.push(command_palette_row(
|
||||
label.to_owned(),
|
||||
description.to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
rows.into()
|
||||
}
|
||||
|
||||
fn command_palette_row(command: String, description: String) -> Element<'static, Message> {
|
||||
row![
|
||||
container(text(command).size(13)).width(180),
|
||||
text(description).size(13),
|
||||
]
|
||||
.spacing(12)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn general_panel(state: &Moorly) -> Element<'_, Message> {
|
||||
row![
|
||||
text("Fade In/Fade out animation"),
|
||||
@@ -7491,10 +7777,26 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
let text_color = state.colors[ColorOption::Text.index()];
|
||||
let main_background = state.colors[ColorOption::MainBackground.index()];
|
||||
|
||||
// Fit the longest section name, but stop growing at 20 characters and
|
||||
// wrap instead. The 10 px estimate covers the default font's average glyph.
|
||||
let label_chars = SettingsSection::ALL
|
||||
.iter()
|
||||
.map(|section| section.label().chars().count())
|
||||
.max()
|
||||
.unwrap_or(1)
|
||||
.min(20);
|
||||
let label_width = label_chars as f32 * 10.0;
|
||||
// Menu padding (8 both sides) plus button padding (10 both sides).
|
||||
let menu_width = label_width + 36.0;
|
||||
|
||||
let menu_item = |section: SettingsSection| {
|
||||
let label = container(text(section.label()))
|
||||
.width(Length::Fill)
|
||||
.align_x(Alignment::Start);
|
||||
let label = container(
|
||||
text(section.label())
|
||||
.width(Length::Fixed(label_width))
|
||||
.wrapping(Wrapping::WordOrGlyph),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.align_x(Alignment::Start);
|
||||
let item = button(label)
|
||||
.on_press(Message::SelectSettingsSection(section))
|
||||
.width(Length::Fill)
|
||||
@@ -7509,7 +7811,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
|
||||
let menu =
|
||||
container(column(SettingsSection::ALL.map(|section| menu_item(section).into())).spacing(2))
|
||||
.width(160)
|
||||
.width(menu_width)
|
||||
.height(Length::Fill)
|
||||
.padding(8);
|
||||
|
||||
@@ -7534,6 +7836,9 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
if state.settings_section == SettingsSection::Shortcuts {
|
||||
content = content.push(shortcuts_panel(state));
|
||||
}
|
||||
if state.settings_section == SettingsSection::CommandPalette {
|
||||
content = content.push(command_palette_panel(state));
|
||||
}
|
||||
if state.settings_section == SettingsSection::Profiles {
|
||||
content = content.push(profiles_panel(state, window, true));
|
||||
}
|
||||
@@ -7584,6 +7889,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
let dirty = state.show_start_tab_draft != state.show_start_tab
|
||||
|| state.fade_settings_draft != state.fade_settings
|
||||
|| state.hide_tab_close_draft != state.hide_tab_close
|
||||
|| state.command_palette_enabled_draft != state.command_palette_enabled
|
||||
|| state.theme_choice != state.saved_theme_choice
|
||||
|| state.shortcuts != state.saved_shortcuts;
|
||||
|
||||
@@ -7798,6 +8104,7 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
let tabs = window_state.tabs.clone();
|
||||
let active_tab = window_state.active_tab;
|
||||
let menu_open = window_state.menu_open;
|
||||
let quick_menu_open = window_state.quick_menu_open;
|
||||
let tabs_submenu_open = window_state.tabs_submenu_open;
|
||||
let scroll_id = window_state.scroll_id.clone();
|
||||
let hide_close = state.hide_tab_close;
|
||||
@@ -7857,6 +8164,7 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
let (can_scroll_left, can_scroll_right) = tab_scroll_limits(state, window);
|
||||
|
||||
let mut bar = row![
|
||||
quick_add_button(quick_menu_open, text_color, window),
|
||||
tab_strip,
|
||||
scroll_button("◀", -TAB_SCROLL_STEP, can_scroll_left, text_color, window),
|
||||
scroll_button("▶", TAB_SCROLL_STEP, can_scroll_right, text_color, window),
|
||||
@@ -7920,6 +8228,17 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
if let Some(drop_panel) = drop_panel {
|
||||
root = root.push(drop_panel);
|
||||
}
|
||||
if quick_menu_open {
|
||||
let backdrop = mouse_area(
|
||||
container(space::horizontal())
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
)
|
||||
.on_press(Message::CloseQuickAddMenu(window));
|
||||
|
||||
root = root.push(backdrop);
|
||||
root = root.push(quick_add_menu(window));
|
||||
}
|
||||
|
||||
return root.into();
|
||||
}
|
||||
@@ -7943,11 +8262,7 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
));
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
menu_items = menu_items.push(menu_item(
|
||||
"temp Add Tab",
|
||||
Some("Ctrl+Shift+T".to_owned()),
|
||||
Message::AddTab(window),
|
||||
));
|
||||
menu_items = menu_items.push(menu_item("temp Add Tab", None, Message::AddTab(window)));
|
||||
}
|
||||
|
||||
let menu_items = menu_items
|
||||
@@ -8226,6 +8541,8 @@ mod tests {
|
||||
fade_settings_draft: true,
|
||||
hide_tab_close: true,
|
||||
hide_tab_close_draft: true,
|
||||
command_palette_enabled: true,
|
||||
command_palette_enabled_draft: true,
|
||||
advanced_open: false,
|
||||
colors: super::DEFAULT_COLORS,
|
||||
saved_colors: super::DEFAULT_COLORS,
|
||||
@@ -8364,6 +8681,29 @@ mod tests {
|
||||
assert_eq!(state.hide_tab_close_draft, state.hide_tab_close);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabling_the_command_palette_waits_for_save_or_undo() {
|
||||
let mut state = state();
|
||||
|
||||
let _ = update(&mut state, Message::SetCommandPaletteEnabled(false));
|
||||
assert!(state.command_palette_enabled);
|
||||
assert!(!state.command_palette_enabled_draft);
|
||||
|
||||
let _ = update(&mut state, Message::UndoChanges);
|
||||
assert_eq!(
|
||||
state.command_palette_enabled_draft,
|
||||
state.command_palette_enabled
|
||||
);
|
||||
|
||||
let _ = update(&mut state, Message::SetCommandPaletteEnabled(false));
|
||||
super::apply_settings(&mut state);
|
||||
assert!(!state.command_palette_enabled);
|
||||
assert_eq!(
|
||||
state.command_palette_enabled_draft,
|
||||
state.command_palette_enabled
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theme_selection_waits_for_save_or_undo() {
|
||||
let mut state = state();
|
||||
@@ -8393,6 +8733,7 @@ mod tests {
|
||||
state.fade_settings = false;
|
||||
state.show_start_tab = false;
|
||||
state.hide_tab_close = false;
|
||||
state.command_palette_enabled = false;
|
||||
state.saved_theme = theme::Preference::Dark;
|
||||
state.saved_theme_choice = super::ThemeChoice::BuiltIn(theme::Preference::Dark);
|
||||
state.builtin_custom_toasts = true;
|
||||
@@ -8407,6 +8748,7 @@ mod tests {
|
||||
assert!(text.contains("[appearance]\ntheme = \"dark\""));
|
||||
assert!(text.contains("[appearance.toast]"));
|
||||
assert!(text.contains("[shortcuts]"));
|
||||
assert!(text.contains("[command_palette]\nenabled = false"));
|
||||
assert_eq!(parsed["general"]["fade_settings"].as_bool(), Some(false));
|
||||
assert_eq!(parsed["appearance"]["theme"].as_str(), Some("dark"));
|
||||
assert_eq!(
|
||||
@@ -8418,6 +8760,14 @@ mod tests {
|
||||
Some("#010203")
|
||||
);
|
||||
assert_eq!(parsed["shortcuts"]["settings"].as_str(), Some("Ctrl+,"));
|
||||
assert_eq!(
|
||||
parsed["shortcuts"]["quick_terminal"].as_str(),
|
||||
Some("Ctrl+Shift+T")
|
||||
);
|
||||
assert_eq!(
|
||||
parsed["shortcuts"]["quick_ssh"].as_str(),
|
||||
Some("Ctrl+Shift+S")
|
||||
);
|
||||
|
||||
state.saved_theme_choice = super::ThemeChoice::Custom {
|
||||
id: "abc".to_owned(),
|
||||
@@ -8666,8 +9016,8 @@ mod tests {
|
||||
let window = test_window();
|
||||
{
|
||||
let window_state = window_state_mut(&mut state);
|
||||
// 315px window => 200px strip; five tabs overflow at the min width.
|
||||
window_state.size = iced::Size::new(315.0, 768.0);
|
||||
// 349px window => 200px strip; five tabs overflow at the min width.
|
||||
window_state.size = iced::Size::new(349.0, 768.0);
|
||||
window_state.tabs = (1..=5).map(Tab::Blank).collect();
|
||||
}
|
||||
|
||||
@@ -8705,8 +9055,8 @@ mod tests {
|
||||
let window = test_window();
|
||||
{
|
||||
let window_state = window_state_mut(&mut state);
|
||||
// 515px window => 400px strip; ten tabs overflow at the min width.
|
||||
window_state.size = iced::Size::new(515.0, 768.0);
|
||||
// 549px window => 400px strip; ten tabs overflow at the min width.
|
||||
window_state.size = iced::Size::new(549.0, 768.0);
|
||||
window_state.tabs = (1..=10).map(Tab::Blank).collect();
|
||||
window_state.active_tab = Some(Tab::Blank(10));
|
||||
}
|
||||
@@ -8955,6 +9305,87 @@ mod tests {
|
||||
assert!(!window_state(&state).command_palette_open);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_add_menu_toggles_and_closes() {
|
||||
let mut state = state();
|
||||
let window = test_window();
|
||||
|
||||
let _ = update(&mut state, Message::ToggleQuickAddMenu(window));
|
||||
assert!(window_state(&state).quick_menu_open);
|
||||
assert!(!window_state(&state).menu_open);
|
||||
|
||||
let _ = update(&mut state, Message::QuickTerminal(window));
|
||||
assert!(!window_state(&state).quick_menu_open);
|
||||
|
||||
let _ = update(&mut state, Message::ToggleQuickAddMenu(window));
|
||||
let _ = update(&mut state, Message::CloseQuickAddMenu(window));
|
||||
assert!(!window_state(&state).quick_menu_open);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_commands_are_in_the_palette_and_do_nothing_yet() {
|
||||
let mut state = state();
|
||||
let window = test_window();
|
||||
let tabs = window_state(&state).tabs.clone();
|
||||
|
||||
assert_eq!(
|
||||
super::Command::matching(&state, window, "quick terminal"),
|
||||
vec![super::Command::QuickTerminal]
|
||||
);
|
||||
assert_eq!(
|
||||
super::Command::matching(&state, window, "quick ssh"),
|
||||
vec![super::Command::QuickSsh]
|
||||
);
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::RunCommand(window, super::Command::QuickTerminal),
|
||||
);
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::RunCommand(window, super::Command::QuickSsh),
|
||||
);
|
||||
assert_eq!(window_state(&state).tabs, tabs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn left_and_right_commands_switch_adjacent_tabs() {
|
||||
let mut state = state();
|
||||
let window = test_window();
|
||||
window_state_mut(&mut state).tabs = vec![Tab::Start, Tab::Settings, Tab::Blank(1)];
|
||||
window_state_mut(&mut state).active_tab = Some(Tab::Start);
|
||||
|
||||
assert!(super::Command::matching(&state, window, "left").is_empty());
|
||||
assert_eq!(
|
||||
super::Command::matching(&state, window, "right"),
|
||||
vec![super::Command::Right]
|
||||
);
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::RunCommand(window, super::Command::Right),
|
||||
);
|
||||
assert_eq!(window_state(&state).active_tab, Some(Tab::Settings));
|
||||
assert_eq!(
|
||||
super::Command::matching(&state, window, "left"),
|
||||
vec![super::Command::Left]
|
||||
);
|
||||
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::RunCommand(window, super::Command::Left),
|
||||
);
|
||||
assert_eq!(window_state(&state).active_tab, Some(Tab::Start));
|
||||
|
||||
window_state_mut(&mut state).active_tab = Some(Tab::Blank(1));
|
||||
assert!(super::Command::matching(&state, window, "right").is_empty());
|
||||
let _ = update(
|
||||
&mut state,
|
||||
Message::RunCommand(window, super::Command::Right),
|
||||
);
|
||||
assert_eq!(window_state(&state).active_tab, Some(Tab::Blank(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_palette_close_closes_the_active_tab() {
|
||||
let mut state = state();
|
||||
@@ -9269,6 +9700,24 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_actions_have_default_shortcuts() {
|
||||
let state = state();
|
||||
|
||||
assert_eq!(
|
||||
state
|
||||
.shortcuts
|
||||
.quick_terminal
|
||||
.as_ref()
|
||||
.map(ToString::to_string),
|
||||
Some("Ctrl+Shift+T".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
state.shortcuts.quick_ssh.as_ref().map(ToString::to_string),
|
||||
Some("Ctrl+Shift+S".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profiles_start_with_an_ungrouped_map() {
|
||||
let state = state();
|
||||
|
||||
Reference in new issue
Block a user