|
|
@ -233,6 +233,7 @@ enum PromptAction {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
RemoveDir,
|
|
|
|
RemoveDir,
|
|
|
|
RemoveFile,
|
|
|
|
RemoveFile,
|
|
|
|
|
|
|
|
RenameFile,
|
|
|
|
Filter,
|
|
|
|
Filter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -289,13 +290,9 @@ impl Explorer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn reveal_current_file(&mut self, cx: &mut Context) {
|
|
|
|
fn reveal_file(&mut self, cx: &mut Context, path: PathBuf) {
|
|
|
|
let current_document_path = doc!(cx.editor).path().cloned();
|
|
|
|
|
|
|
|
match current_document_path {
|
|
|
|
|
|
|
|
None => cx.editor.set_error("No opened document."),
|
|
|
|
|
|
|
|
Some(current_path) => {
|
|
|
|
|
|
|
|
let current_root = &self.state.current_root;
|
|
|
|
let current_root = &self.state.current_root;
|
|
|
|
let current_path = current_path.as_path().to_string_lossy().to_string();
|
|
|
|
let current_path = path.as_path().to_string_lossy().to_string();
|
|
|
|
let current_root = current_root.as_path().to_string_lossy().to_string() + "/";
|
|
|
|
let current_root = current_root.as_path().to_string_lossy().to_string() + "/";
|
|
|
|
let segments = current_path
|
|
|
|
let segments = current_path
|
|
|
|
.strip_prefix(current_root.as_str())
|
|
|
|
.strip_prefix(current_root.as_str())
|
|
|
@ -315,6 +312,12 @@ impl Explorer {
|
|
|
|
Err(error) => cx.editor.set_error(error.to_string()),
|
|
|
|
Err(error) => cx.editor.set_error(error.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn reveal_current_file(&mut self, cx: &mut Context) {
|
|
|
|
|
|
|
|
let current_document_path = doc!(cx.editor).path().cloned();
|
|
|
|
|
|
|
|
match current_document_path {
|
|
|
|
|
|
|
|
None => cx.editor.set_error("No opened document."),
|
|
|
|
|
|
|
|
Some(current_path) => self.reveal_file(cx, current_path),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -467,6 +470,20 @@ impl Explorer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn new_rename_prompt(&mut self) {
|
|
|
|
|
|
|
|
let name = self.tree.current_item().path.to_string_lossy();
|
|
|
|
|
|
|
|
self.prompt = Some((
|
|
|
|
|
|
|
|
PromptAction::RenameFile,
|
|
|
|
|
|
|
|
Prompt::new(
|
|
|
|
|
|
|
|
format!(" Rename to ").into(),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
ui::completers::none,
|
|
|
|
|
|
|
|
|_, _, _| {},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.with_line(name.to_string()),
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn new_remove_file_prompt(&mut self, cx: &mut Context) {
|
|
|
|
fn new_remove_file_prompt(&mut self, cx: &mut Context) {
|
|
|
|
let item = self.tree.current_item();
|
|
|
|
let item = self.tree.current_item();
|
|
|
|
let check = || {
|
|
|
|
let check = || {
|
|
|
@ -807,6 +824,15 @@ impl Explorer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(PromptAction::RenameFile, key!(Enter)) => {
|
|
|
|
|
|
|
|
let item = self.tree.current_item();
|
|
|
|
|
|
|
|
if let Err(e) = std::fs::rename(&item.path, line) {
|
|
|
|
|
|
|
|
cx.editor.set_error(format!("{e}"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.tree.remove_current();
|
|
|
|
|
|
|
|
self.reveal_file(cx, PathBuf::from(line))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
(_, key!(Esc) | ctrl!('c')) => {}
|
|
|
|
(_, key!(Esc) | ctrl!('c')) => {}
|
|
|
|
_ => {
|
|
|
|
_ => {
|
|
|
|
prompt.handle_event(Event::Key(event), cx);
|
|
|
|
prompt.handle_event(Event::Key(event), cx);
|
|
|
@ -907,16 +933,7 @@ impl Component for Explorer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key!(']') => self.change_root(cx, self.tree.current_item().path.clone()),
|
|
|
|
key!(']') => self.change_root(cx, self.tree.current_item().path.clone()),
|
|
|
|
key!('d') => self.new_remove_prompt(cx),
|
|
|
|
key!('d') => self.new_remove_prompt(cx),
|
|
|
|
key!('r') => {
|
|
|
|
key!('r') => self.new_rename_prompt(),
|
|
|
|
self.on_next_key = Some(Box::new(|cx, explorer, event| {
|
|
|
|
|
|
|
|
match event.into() {
|
|
|
|
|
|
|
|
key!('d') => explorer.new_remove_dir_prompt(cx),
|
|
|
|
|
|
|
|
key!('f') => explorer.new_remove_file_prompt(cx),
|
|
|
|
|
|
|
|
_ => return EventResult::Ignored(None),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
EventResult::Consumed(None)
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
_ => {
|
|
|
|
self.tree
|
|
|
|
self.tree
|
|
|
|
.handle_event(Event::Key(key_event), cx, &mut self.state);
|
|
|
|
.handle_event(Event::Key(key_event), cx, &mut self.state);
|
|
|
|