save local file paths in bookmark (#204)

* fix: renamed Bookmark 'directory' to 'remote_path' (keep name in file)

* feat: local_path as file transfer parameter and in bookmark
This commit is contained in:
Christian Visintin
2023-07-06 16:05:22 +02:00
committed by GitHub
parent ee28d34f29
commit ca005cbecd
16 changed files with 261 additions and 98 deletions

View File

@@ -150,7 +150,13 @@ impl AuthActivity {
self.mount_protocol(bookmark.protocol);
self.mount_remote_directory(
bookmark
.entry_directory
.remote_path
.map(|x| x.to_string_lossy().to_string())
.unwrap_or_default(),
);
self.mount_local_directory(
bookmark
.local_path
.map(|x| x.to_string_lossy().to_string())
.unwrap_or_default(),
);

View File

@@ -8,13 +8,12 @@ use tuirealm::event::{Key, KeyEvent, KeyModifiers};
use tuirealm::props::{Alignment, BorderType, Borders, Color, InputType, Style};
use tuirealm::{Component, Event, MockComponent, NoUserEvent, State, StateValue};
use super::{FileTransferProtocol, FormMsg, Msg, UiMsg};
use crate::ui::activities::auth::{
RADIO_PROTOCOL_FTP, RADIO_PROTOCOL_FTPS, RADIO_PROTOCOL_S3, RADIO_PROTOCOL_SCP,
RADIO_PROTOCOL_SFTP, RADIO_PROTOCOL_SMB,
};
use super::{FileTransferProtocol, FormMsg, Msg, UiMsg};
// -- protocol
#[derive(MockComponent)]
@@ -118,7 +117,7 @@ impl InputRemoteDirectory {
)
.foreground(color)
.placeholder("/home/foo", Style::default().fg(Color::Rgb(128, 128, 128)))
.title("Default remote directory", Alignment::Left)
.title("Default remote working directory", Alignment::Left)
.input_type(InputType::Text)
.value(remote_dir),
}
@@ -136,6 +135,42 @@ impl Component<Msg, NoUserEvent> for InputRemoteDirectory {
}
}
// -- remote directory
#[derive(MockComponent)]
pub struct InputLocalDirectory {
component: Input,
}
impl InputLocalDirectory {
pub fn new(local_dir: &str, color: Color) -> Self {
Self {
component: Input::default()
.borders(
Borders::default()
.color(color)
.modifiers(BorderType::Rounded),
)
.foreground(color)
.placeholder("/home/foo", Style::default().fg(Color::Rgb(128, 128, 128)))
.title("Default local working directory", Alignment::Left)
.input_type(InputType::Text)
.value(local_dir),
}
}
}
impl Component<Msg, NoUserEvent> for InputLocalDirectory {
fn on(&mut self, ev: Event<NoUserEvent>) -> Option<Msg> {
handle_input_ev(
self,
ev,
Msg::Ui(UiMsg::LocalDirectoryBlurDown),
Msg::Ui(UiMsg::LocalDirectoryBlurUp),
)
}
}
// -- address
#[derive(MockComponent)]

View File

@@ -16,9 +16,10 @@ pub use bookmarks::{
#[cfg(unix)]
pub use form::InputSmbWorkgroup;
pub use form::{
InputAddress, InputPassword, InputPort, InputRemoteDirectory, InputS3AccessKey, InputS3Bucket,
InputS3Endpoint, InputS3Profile, InputS3Region, InputS3SecretAccessKey, InputS3SecurityToken,
InputS3SessionToken, InputSmbShare, InputUsername, ProtocolRadio, RadioS3NewPathStyle,
InputAddress, InputLocalDirectory, InputPassword, InputPort, InputRemoteDirectory,
InputS3AccessKey, InputS3Bucket, InputS3Endpoint, InputS3Profile, InputS3Region,
InputS3SecretAccessKey, InputS3SecurityToken, InputS3SessionToken, InputSmbShare,
InputUsername, ProtocolRadio, RadioS3NewPathStyle,
};
pub use popup::{
ErrorPopup, InfoPopup, InstallUpdatePopup, Keybindings, QuitPopup, ReleaseNotes, WaitPopup,

View File

@@ -59,7 +59,8 @@ impl AuthActivity {
Ok(FileTransferParams {
protocol,
params: ProtocolParams::Generic(params),
entry_directory: self.get_input_remote_directory(),
local_path: self.get_input_local_directory(),
remote_path: self.get_input_remote_directory(),
})
}
@@ -72,7 +73,8 @@ impl AuthActivity {
Ok(FileTransferParams {
protocol: FileTransferProtocol::AwsS3,
params: ProtocolParams::AwsS3(params),
entry_directory: self.get_input_remote_directory(),
local_path: self.get_input_local_directory(),
remote_path: self.get_input_remote_directory(),
})
}
@@ -91,7 +93,8 @@ impl AuthActivity {
Ok(FileTransferParams {
protocol: FileTransferProtocol::Smb,
params: ProtocolParams::Smb(params),
entry_directory: self.get_input_remote_directory(),
local_path: self.get_input_local_directory(),
remote_path: self.get_input_remote_directory(),
})
}

View File

@@ -46,6 +46,7 @@ pub enum Id {
InfoPopup,
InstallUpdatePopup,
Keybindings,
LocalDirectory,
NewVersionChangelog,
NewVersionDisclaimer,
Password,
@@ -108,6 +109,8 @@ pub enum UiMsg {
CloseKeybindingsPopup,
CloseQuitPopup,
CloseSaveBookmark,
LocalDirectoryBlurDown,
LocalDirectoryBlurUp,
ParamsFormBlur,
PasswordBlurDown,
PasswordBlurUp,

View File

@@ -158,6 +158,12 @@ impl AuthActivity {
assert!(self.app.umount(&Id::BookmarkName).is_ok());
assert!(self.app.umount(&Id::BookmarkSavePassword).is_ok());
}
UiMsg::LocalDirectoryBlurDown => {
assert!(self.app.active(&Id::Protocol).is_ok());
}
UiMsg::LocalDirectoryBlurUp => {
assert!(self.app.active(&Id::RemoteDirectory).is_ok());
}
UiMsg::ParamsFormBlur => {
assert!(self.app.active(&Id::BookmarksList).is_ok());
}
@@ -201,13 +207,13 @@ impl AuthActivity {
.is_ok());
}
UiMsg::ProtocolBlurUp => {
assert!(self.app.active(&Id::RemoteDirectory).is_ok());
assert!(self.app.active(&Id::LocalDirectory).is_ok());
}
UiMsg::RececentsListBlur => {
assert!(self.app.active(&Id::BookmarksList).is_ok());
}
UiMsg::RemoteDirectoryBlurDown => {
assert!(self.app.active(&Id::Protocol).is_ok());
assert!(self.app.active(&Id::LocalDirectory).is_ok());
}
UiMsg::RemoteDirectoryBlurUp => {
assert!(self

View File

@@ -43,6 +43,7 @@ impl AuthActivity {
// Auth form
self.mount_protocol(default_protocol);
self.mount_remote_directory("");
self.mount_local_directory("");
self.mount_address("");
self.mount_port(Self::get_default_port_for_protocol(default_protocol));
self.mount_username("");
@@ -582,14 +583,14 @@ impl AuthActivity {
.is_ok());
}
pub(super) fn mount_remote_directory<S: AsRef<str>>(&mut self, entry_directory: S) {
pub(super) fn mount_remote_directory<S: AsRef<str>>(&mut self, remote_path: S) {
let protocol_color = self.theme().auth_protocol;
assert!(self
.app
.remount(
Id::RemoteDirectory,
Box::new(components::InputRemoteDirectory::new(
entry_directory.as_ref(),
remote_path.as_ref(),
protocol_color
)),
vec![]
@@ -597,6 +598,21 @@ impl AuthActivity {
.is_ok());
}
pub(super) fn mount_local_directory<S: AsRef<str>>(&mut self, local_path: S) {
let color = self.theme().auth_username;
assert!(self
.app
.remount(
Id::LocalDirectory,
Box::new(components::InputLocalDirectory::new(
local_path.as_ref(),
color
)),
vec![]
)
.is_ok());
}
pub(super) fn mount_address(&mut self, address: &str) {
let addr_color = self.theme().auth_address;
assert!(self
@@ -853,6 +869,15 @@ impl AuthActivity {
}
}
pub(super) fn get_input_local_directory(&self) -> Option<PathBuf> {
match self.app.state(&Id::LocalDirectory) {
Ok(State::One(StateValue::String(x))) if !x.is_empty() => {
Some(PathBuf::from(x.as_str()))
}
_ => None,
}
}
pub(super) fn get_input_addr(&self) -> String {
match self.app.state(&Id::Address) {
Ok(State::One(StateValue::String(x))) => x,
@@ -1053,6 +1078,12 @@ impl AuthActivity {
Some(&Id::RemoteDirectory) => {
[Id::Port, Id::Username, Id::Password, Id::RemoteDirectory]
}
Some(&Id::LocalDirectory) => [
Id::Username,
Id::Password,
Id::RemoteDirectory,
Id::LocalDirectory,
],
_ => [Id::Address, Id::Port, Id::Username, Id::Password],
}
}
@@ -1093,6 +1124,12 @@ impl AuthActivity {
Id::S3NewPathStyle,
Id::RemoteDirectory,
],
Some(&Id::LocalDirectory) => [
Id::S3SessionToken,
Id::S3NewPathStyle,
Id::RemoteDirectory,
Id::LocalDirectory,
],
_ => [Id::S3Bucket, Id::S3Region, Id::S3Endpoint, Id::S3Profile],
}
}
@@ -1111,6 +1148,12 @@ impl AuthActivity {
Id::SmbWorkgroup,
Id::RemoteDirectory,
],
Some(&Id::LocalDirectory) => [
Id::Password,
Id::SmbWorkgroup,
Id::RemoteDirectory,
Id::LocalDirectory,
],
_ => [Id::Address, Id::Port, Id::SmbShare, Id::Username],
}
}
@@ -1127,6 +1170,12 @@ impl AuthActivity {
Id::Password,
Id::RemoteDirectory,
],
Some(&Id::LocalDirectory) => [
Id::Username,
Id::Password,
Id::RemoteDirectory,
Id::LocalDirectory,
],
_ => [Id::Address, Id::SmbShare, Id::Username, Id::Password],
}
}

View File

@@ -220,7 +220,7 @@ pub struct FileTransferActivity {
cache: Option<TempDir>,
/// Fs watcher
fswatcher: Option<FsWatcher>,
/// conncted once
/// connected once
connected: bool,
}

View File

@@ -53,7 +53,7 @@ impl FileTransferActivity {
/// Connect to remote
pub(super) fn connect(&mut self) {
let ft_params = self.context().ft_params().unwrap().clone();
let entry_dir: Option<PathBuf> = ft_params.entry_directory;
let entry_dir: Option<PathBuf> = ft_params.remote_path;
// Connect to remote
match self.client.connect() {
Ok(Welcome { banner, .. }) => {
@@ -71,11 +71,11 @@ impl FileTransferActivity {
}
// Try to change directory to entry directory
let mut remote_chdir: Option<PathBuf> = None;
if let Some(entry_directory) = &entry_dir {
remote_chdir = Some(entry_directory.clone());
if let Some(remote_path) = &entry_dir {
remote_chdir = Some(remote_path.clone());
}
if let Some(entry_directory) = remote_chdir {
self.remote_changedir(entry_directory.as_path(), false);
if let Some(remote_path) = remote_chdir {
self.remote_changedir(remote_path.as_path(), false);
}
// Set state to explorer
self.umount_wait();