diff --git a/src/ui/activities/auth_activity/bookmarks.rs b/src/ui/activities/auth_activity/bookmarks.rs index fc90b46..99211a4 100644 --- a/src/ui/activities/auth_activity/bookmarks.rs +++ b/src/ui/activities/auth_activity/bookmarks.rs @@ -250,7 +250,7 @@ impl AuthActivity { }; Ok(Bookmark { address: self.address.clone(), - port: port, + port, protocol: match self.protocol { FileTransferProtocol::Ftp(secure) => match secure { true => String::from("FTPS"), @@ -267,33 +267,21 @@ impl AuthActivity { /// /// Write bookmarks to file fn write_bookmarks(&mut self) { - if self.bookmarks.is_some() { - if self.context.is_some() { - // Open file for write - if let Some(bookmarks_file) = self.init_bookmarks() { - match self - .context - .as_ref() - .unwrap() - .local - .open_file_write(bookmarks_file.as_path()) - { - Ok(writer) => { - let serializer: BookmarkSerializer = BookmarkSerializer {}; - if let Err(err) = serializer - .serialize(Box::new(writer), &self.bookmarks.as_ref().unwrap()) - { - self.input_mode = InputMode::Popup(PopupType::Alert( - Color::Yellow, - format!( - "Could not write default bookmarks at \"{}\": {}", - bookmarks_file.display(), - err - ), - )); - } - } - Err(err) => { + if self.bookmarks.is_some() && self.context.is_some() { + // Open file for write + if let Some(bookmarks_file) = self.init_bookmarks() { + match self + .context + .as_ref() + .unwrap() + .local + .open_file_write(bookmarks_file.as_path()) + { + Ok(writer) => { + let serializer: BookmarkSerializer = BookmarkSerializer {}; + if let Err(err) = serializer + .serialize(Box::new(writer), &self.bookmarks.as_ref().unwrap()) + { self.input_mode = InputMode::Popup(PopupType::Alert( Color::Yellow, format!( @@ -301,9 +289,19 @@ impl AuthActivity { bookmarks_file.display(), err ), - )) + )); } } + Err(err) => { + self.input_mode = InputMode::Popup(PopupType::Alert( + Color::Yellow, + format!( + "Could not write default bookmarks at \"{}\": {}", + bookmarks_file.display(), + err + ), + )) + } } } } @@ -348,40 +346,27 @@ impl AuthActivity { // Append bookmarks.toml p.push("bookmarks.toml"); // If bookmarks.toml doesn't exist, initializae it - if self.context.is_some() { - if !self + if self.context.is_some() + && !self .context .as_ref() .unwrap() .local .file_exists(p.as_path()) + { + // Write file + let default_hosts: UserHosts = Default::default(); + match self + .context + .as_ref() + .unwrap() + .local + .open_file_write(p.as_path()) { - // Write file - let default_hosts: UserHosts = Default::default(); - match self - .context - .as_ref() - .unwrap() - .local - .open_file_write(p.as_path()) - { - Ok(writer) => { - let serializer: BookmarkSerializer = BookmarkSerializer {}; - // Serialize and write - if let Err(err) = serializer.serialize(Box::new(writer), &default_hosts) - { - self.input_mode = InputMode::Popup(PopupType::Alert( - Color::Yellow, - format!( - "Could not write default bookmarks at \"{}\": {}", - p.display(), - err - ), - )); - return None; - } - } - Err(err) => { + Ok(writer) => { + let serializer: BookmarkSerializer = BookmarkSerializer {}; + // Serialize and write + if let Err(err) = serializer.serialize(Box::new(writer), &default_hosts) { self.input_mode = InputMode::Popup(PopupType::Alert( Color::Yellow, format!( @@ -393,6 +378,17 @@ impl AuthActivity { return None; } } + Err(err) => { + self.input_mode = InputMode::Popup(PopupType::Alert( + Color::Yellow, + format!( + "Could not write default bookmarks at \"{}\": {}", + p.display(), + err + ), + )); + return None; + } } } // return path diff --git a/src/ui/activities/auth_activity/input.rs b/src/ui/activities/auth_activity/input.rs index 4fc1794..3bcc7c5 100644 --- a/src/ui/activities/auth_activity/input.rs +++ b/src/ui/activities/auth_activity/input.rs @@ -234,11 +234,9 @@ impl AuthActivity { // Move bookmarks index up if self.bookmarks_idx > 0 { self.bookmarks_idx -= 1; - } else { - if let Some(hosts) = &self.bookmarks { - // Put to last index (wrap) - self.bookmarks_idx = hosts.bookmarks.len() - 1; - } + } else if let Some(hosts) = &self.bookmarks { + // Put to last index (wrap) + self.bookmarks_idx = hosts.bookmarks.len() - 1; } } KeyCode::Down => { @@ -317,11 +315,9 @@ impl AuthActivity { // Move bookmarks index up if self.recents_idx > 0 { self.recents_idx -= 1; - } else { - if let Some(hosts) = &self.bookmarks { - // Put to last index (wrap) - self.recents_idx = hosts.recents.len() - 1; - } + } else if let Some(hosts) = &self.bookmarks { + // Put to last index (wrap) + self.recents_idx = hosts.recents.len() - 1; } } KeyCode::Down => { diff --git a/src/ui/activities/auth_activity/layout.rs b/src/ui/activities/auth_activity/layout.rs index e91087d..02be048 100644 --- a/src/ui/activities/auth_activity/layout.rs +++ b/src/ui/activities/auth_activity/layout.rs @@ -273,9 +273,7 @@ impl AuthActivity { /// /// Draw local explorer list pub(super) fn draw_bookmarks_tab(&self) -> Option { - if self.bookmarks.is_none() { - return None; - } + self.bookmarks.as_ref()?; let hosts: Vec = self .bookmarks .as_ref() @@ -318,9 +316,7 @@ impl AuthActivity { /// /// Draw local explorer list pub(super) fn draw_recents_tab(&self) -> Option { - if self.bookmarks.is_none() { - return None; - } + self.bookmarks.as_ref()?; let hosts: Vec = self .bookmarks .as_ref()