mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
File rename
This commit is contained in:
@@ -434,21 +434,30 @@ impl FileTransferActivity {
|
|||||||
// If ctrl is enabled...
|
// If ctrl is enabled...
|
||||||
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
||||||
// Show input popup
|
// Show input popup
|
||||||
self.input_mode = InputMode::Popup(PopupType::Input(String::from("Change working directory"), FileTransferActivity::callback_change_directory));
|
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||||
|
String::from("Change working directory"),
|
||||||
|
FileTransferActivity::callback_change_directory,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'm' | 'M' => {
|
'm' | 'M' => {
|
||||||
// Make directory
|
// Make directory
|
||||||
// If ctrl is enabled...
|
// If ctrl is enabled...
|
||||||
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
||||||
self.input_mode = InputMode::Popup(PopupType::Input(String::from("Insert directory name"), FileTransferActivity::callback_mkdir));
|
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||||
|
String::from("Insert directory name"),
|
||||||
|
FileTransferActivity::callback_mkdir,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'r' | 'R' => {
|
'r' | 'R' => {
|
||||||
// Rename
|
// Rename
|
||||||
// If ctrl is enabled...
|
// If ctrl is enabled...
|
||||||
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
if key.modifiers.intersects(KeyModifiers::CONTROL) {
|
||||||
// TODO:
|
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||||
|
String::from("Insert news name"),
|
||||||
|
FileTransferActivity::callback_rename,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' ' => {
|
' ' => {
|
||||||
@@ -719,13 +728,13 @@ impl FileTransferActivity {
|
|||||||
format!("Could not change working directory: {}", err),
|
format!("Could not change working directory: {}", err),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(_) => self.local.files = context.local.list_dir() // Update files
|
Ok(_) => self.local.files = context.local.list_dir(), // Update files
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### callback_mkdir
|
/// ### callback_mkdir
|
||||||
///
|
///
|
||||||
/// Callback for MKDIR command (supports both locale and remote)
|
/// Callback for MKDIR command (supports both local and remote)
|
||||||
fn callback_mkdir(&mut self, context: &mut Context, input: String) {
|
fn callback_mkdir(&mut self, context: &mut Context, input: String) {
|
||||||
match self.tab {
|
match self.tab {
|
||||||
FileExplorerTab::Local => {
|
FileExplorerTab::Local => {
|
||||||
@@ -734,10 +743,13 @@ impl FileTransferActivity {
|
|||||||
// Reload files
|
// Reload files
|
||||||
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
||||||
self.local.files = context.local.list_dir();
|
self.local.files = context.local.list_dir();
|
||||||
},
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
self.log(LogLevel::Error, format!("Could not create directory \"{}\": {}", input, err));
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!("Could not create directory \"{}\": {}", input, err),
|
||||||
|
);
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
Color::Red,
|
Color::Red,
|
||||||
format!("Could not create directory \"{}\": {}", input, err),
|
format!("Could not create directory \"{}\": {}", input, err),
|
||||||
@@ -751,10 +763,13 @@ impl FileTransferActivity {
|
|||||||
// Reload files
|
// Reload files
|
||||||
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
self.log(LogLevel::Info, format!("Created directory \"{}\"", input));
|
||||||
self.reload_remote_dir();
|
self.reload_remote_dir();
|
||||||
},
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
self.log(LogLevel::Error, format!("Could not create directory \"{}\": {}", input, err));
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!("Could not create directory \"{}\": {}", input, err),
|
||||||
|
);
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
Color::Red,
|
Color::Red,
|
||||||
format!("Could not create directory \"{}\": {}", input, err),
|
format!("Could not create directory \"{}\": {}", input, err),
|
||||||
@@ -765,6 +780,104 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### callback_rename
|
||||||
|
///
|
||||||
|
/// Callback for RENAME command (supports borth local and remote)
|
||||||
|
fn callback_rename(&mut self, context: &mut Context, input: String) {
|
||||||
|
match self.tab {
|
||||||
|
FileExplorerTab::Local => {
|
||||||
|
let mut dst_path: PathBuf = PathBuf::from(input);
|
||||||
|
// Check if path is relative
|
||||||
|
if dst_path.as_path().is_relative() {
|
||||||
|
let wrkdir: PathBuf = context.local.pwd();
|
||||||
|
wrkdir.push(dst_path);
|
||||||
|
dst_path = wrkdir;
|
||||||
|
}
|
||||||
|
// Check if file entry exists
|
||||||
|
if let Some(entry) = self.local.files.get(self.local.index) {
|
||||||
|
let full_path: PathBuf = match entry {
|
||||||
|
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
||||||
|
FsEntry::File(file) => file.abs_path.clone(),
|
||||||
|
};
|
||||||
|
// Rename file or directory and report status as popup
|
||||||
|
match context.local.rename(entry, dst_path.as_path()) {
|
||||||
|
Ok(_) => {
|
||||||
|
// Reload files
|
||||||
|
self.local.files = context.local.list_dir();
|
||||||
|
// Log
|
||||||
|
self.log(
|
||||||
|
LogLevel::Info,
|
||||||
|
format!(
|
||||||
|
"Renamed file \"{}\" to \"{}\"",
|
||||||
|
full_path.display(),
|
||||||
|
dst_path.display()
|
||||||
|
)
|
||||||
|
.as_ref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not rename file \"{}\": {}",
|
||||||
|
full_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_ref(),
|
||||||
|
);
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!("Could not rename file: {}", err),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FileExplorerTab::Remote => {
|
||||||
|
// Check if file entry exists
|
||||||
|
if let Some(entry) = self.remote.files.get(self.remote.index) {
|
||||||
|
let full_path: PathBuf = match entry {
|
||||||
|
FsEntry::Directory(dir) => dir.abs_path.clone(),
|
||||||
|
FsEntry::File(file) => file.abs_path.clone(),
|
||||||
|
};
|
||||||
|
// Rename file or directory and report status as popup
|
||||||
|
let dst_path: PathBuf = PathBuf::from(input);
|
||||||
|
match self.client.rename(entry, dst_path.as_path()) {
|
||||||
|
Ok(_) => {
|
||||||
|
// Reload files
|
||||||
|
self.local.files = context.local.list_dir();
|
||||||
|
// Log
|
||||||
|
self.log(
|
||||||
|
LogLevel::Info,
|
||||||
|
format!(
|
||||||
|
"Renamed file \"{}\" to \"{}\"",
|
||||||
|
full_path.display(),
|
||||||
|
dst_path.display()
|
||||||
|
)
|
||||||
|
.as_ref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not rename file \"{}\": {}",
|
||||||
|
full_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_ref(),
|
||||||
|
);
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!("Could not rename file: {}", err),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// ### callback_delete_fsentry
|
/// ### callback_delete_fsentry
|
||||||
///
|
///
|
||||||
/// Delete current selected fsentry in the currently selected TAB
|
/// Delete current selected fsentry in the currently selected TAB
|
||||||
|
|||||||
Reference in New Issue
Block a user