diff --git a/defaults/settings.toml b/defaults/settings.toml index 7c3cf171..845b6da8 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -5,6 +5,7 @@ modal = false color-theme = "Lapce Dark" icon-theme = "Lapce Codicons" custom-titlebar = true +file-exploerer-double-click = false [editor] font-family = "monospace" diff --git a/lapce-app/src/command.rs b/lapce-app/src/command.rs index c23c3b9c..be43cce6 100644 --- a/lapce-app/src/command.rs +++ b/lapce-app/src/command.rs @@ -604,6 +604,9 @@ pub enum InternalCommand { OpenFile { path: PathBuf, }, + OpenAndConfirmedFile { + path: PathBuf, + }, OpenFileInNewTab { path: PathBuf, }, diff --git a/lapce-app/src/config/core.rs b/lapce-app/src/config/core.rs index fce5ddfb..27d128d2 100644 --- a/lapce-app/src/config/core.rs +++ b/lapce-app/src/config/core.rs @@ -14,4 +14,8 @@ pub struct CoreConfig { desc = "Enable customised titlebar and disable OS native one (Linux, BSD, Windows)" )] pub custom_titlebar: bool, + #[field_names( + desc = "Only allow double-click to open files in the file explorer" + )] + pub file_exploerer_double_click: bool, } diff --git a/lapce-app/src/file_explorer/data.rs b/lapce-app/src/file_explorer/data.rs index 2c695e38..a931c09b 100644 --- a/lapce-app/src/file_explorer/data.rs +++ b/lapce-app/src/file_explorer/data.rs @@ -4,6 +4,7 @@ ffi::OsStr, path::{Path, PathBuf}, rc::Rc, + sync::Arc, }; use floem::{ @@ -12,7 +13,7 @@ ext_event::create_ext_action, keyboard::Modifiers, menu::{Menu, MenuItem}, - reactive::{RwSignal, Scope, SignalGet, SignalUpdate, SignalWith}, + reactive::{ReadSignal, RwSignal, Scope, SignalGet, SignalUpdate, SignalWith}, views::editor::text::SystemClipboard, }; use globset::Glob; @@ -31,6 +32,7 @@ use crate::{ command::{CommandExecuted, CommandKind, InternalCommand, LapceCommand}, + config::LapceConfig, editor::EditorData, keypress::{condition::Condition, KeyPressFocus}, main_split::Editors, @@ -394,10 +396,10 @@ pub fn cancel_naming(&self) { self.naming.set(Naming::None); } - pub fn click(&self, path: &Path) { + pub fn click(&self, path: &Path, config: ReadSignal>) { if self.is_dir(path) { self.toggle_expand(path); - } else { + } else if !config.get_untracked().core.file_exploerer_double_click { self.common .internal_command .send(InternalCommand::OpenFile { @@ -459,9 +461,20 @@ pub fn reveal_in_file_tree(&self, path: PathBuf) { } } - pub fn double_click(&self, path: &Path) -> EventPropagation { + pub fn double_click( + &self, + path: &Path, + config: ReadSignal>, + ) -> EventPropagation { if self.is_dir(path) { EventPropagation::Continue + } else if config.get_untracked().core.file_exploerer_double_click { + self.common.internal_command.send( + InternalCommand::OpenAndConfirmedFile { + path: path.to_path_buf(), + }, + ); + EventPropagation::Stop } else { self.common .internal_command diff --git a/lapce-app/src/file_explorer/view.rs b/lapce-app/src/file_explorer/view.rs index 5b0b77bc..d3ab9868 100644 --- a/lapce-app/src/file_explorer/view.rs +++ b/lapce-app/src/file_explorer/view.rs @@ -401,7 +401,8 @@ fn file_explorer_view( }, ) } - }); + }) + .debug_name("file item"); // Only handle click events if we are not naming the file node if let FileNodeViewKind::Path(path) = &kind { @@ -411,13 +412,18 @@ fn file_explorer_view( let aux_click_path = path.clone(); view.on_click_stop({ let kind = kind.clone(); + let config = config.clone(); move |_| { - click_data.click(&click_path); + click_data.click(&click_path, config); select.update(|x| *x = Some(kind.clone())); } }) - .on_double_click(move |_| { - double_click_data.double_click(&double_click_path) + .on_double_click({ + let config = config.clone(); + move |_| { + double_click_data + .double_click(&double_click_path, config) + } }) .on_secondary_click_stop(move |_| { secondary_click_data.secondary_click(&secondary_click_path); diff --git a/lapce-app/src/window_tab.rs b/lapce-app/src/window_tab.rs index 10aa610c..9e0f7498 100644 --- a/lapce-app/src/window_tab.rs +++ b/lapce-app/src/window_tab.rs @@ -1558,6 +1558,21 @@ pub fn run_internal_command(&self, cmd: InternalCommand) { None, ); } + InternalCommand::OpenAndConfirmedFile { path } => { + self.main_split.jump_to_location( + EditorLocation { + path, + position: None, + scroll_offset: None, + ignore_unconfirmed: false, + same_editor_tab: false, + }, + None, + ); + if let Some(editor) = self.main_split.active_editor.get_untracked() { + editor.confirmed.set(true); + } + } InternalCommand::OpenFileInNewTab { path } => { self.main_split.jump_to_location( EditorLocation {