close folder

This commit is contained in:
Dongdong Zhou 2022-03-21 14:15:02 +00:00
parent 3f9de825c1
commit ea92439dfe
4 changed files with 105 additions and 0 deletions

View File

@ -116,12 +116,20 @@ mode = "i"
key = "meta+s"
command = "save"
[[keymaps]]
key = "meta+o"
command = "open_file"
# ----------------------------------- Editor Management -------------------------------
[[keymaps]]
key = "meta+w"
command = "split_close"
[[keymaps]]
key = "meta+k f"
command = "close_folder"
[[keymaps]]
key = "meta+\\"
command = "split_vertical"

View File

@ -116,6 +116,10 @@ mode = "i"
key = "ctrl+s"
command = "save"
[[keymaps]]
key = "ctrl+o"
command = "open_file"
# ----------------------------------- Editor Management -------------------------------
[[keymaps]]
@ -123,6 +127,10 @@ key = "ctrl+w"
command = "split_close"
mode = "i"
[[keymaps]]
key = "ctrl+k f"
command = "close_folder"
[[keymaps]]
key = "ctrl+F4"
command = "split_close"

View File

@ -103,6 +103,14 @@ pub enum LapceWorkbenchCommand {
#[strum(message = "Open Folder")]
OpenFolder,
#[strum(serialize = "close_folder")]
#[strum(message = "Close Folder")]
CloseFolder,
#[strum(serialize = "open_file")]
#[strum(message = "Open File")]
OpenFile,
#[strum(serialize = "change_theme")]
#[strum(message = "Change Theme")]
ChangeTheme,

View File

@ -866,6 +866,17 @@ pub fn run_workbench_command(
env: &Env,
) {
match command {
LapceWorkbenchCommand::CloseFolder => {
if self.workspace.path.is_some() {
let mut workspace = (*self.workspace).clone();
workspace.path = None;
let _ = ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::SetWorkspace(workspace),
Target::Auto,
));
}
}
LapceWorkbenchCommand::OpenFolder => {
if !self.workspace.kind.is_remote() {
let event_sink = ctx.get_external_handle();
@ -939,6 +950,76 @@ pub fn run_workbench_command(
}
}
}
LapceWorkbenchCommand::OpenFile => {
if !self.workspace.kind.is_remote() {
let workspace = self.workspace.clone();
let event_sink = ctx.get_external_handle();
let tab_id = self.id;
thread::spawn(move || {
let dir = workspace.path.clone().unwrap_or_else(|| {
PathBuf::from(
directories::UserDirs::new()
.and_then(|u| {
u.home_dir().to_str().map(|s| s.to_string())
})
.unwrap_or_else(|| ".".to_string()),
)
});
if let Some(path) = tinyfiledialogs::open_file_dialog(
"Open file",
dir.to_str().unwrap(),
None,
) {
let path = PathBuf::from(path);
let _ = event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::OpenFile(path),
Target::Widget(tab_id),
);
}
});
} else {
let picker = Arc::make_mut(&mut self.picker);
picker.active = true;
if let Some(node) = picker.get_file_node(&picker.pwd) {
if !node.read {
let tab_id = self.id;
let path = node.path_buf.clone();
let event_sink = ctx.get_external_handle();
self.proxy.read_dir(
&node.path_buf,
Box::new(move |result| {
if let Ok(res) = result {
let resp: Result<
Vec<FileNodeItem>,
serde_json::Error,
> = serde_json::from_value(res);
if let Ok(items) = resp {
let _ = event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdatePickerItems(
path,
items
.iter()
.map(|item| {
(
item.path_buf
.clone(),
item.clone(),
)
})
.collect(),
),
Target::Widget(tab_id),
);
}
}
}),
);
}
}
}
}
LapceWorkbenchCommand::EnableModal => {
let config = Arc::make_mut(&mut self.config);
config.lapce.modal = true;