context getters

This commit is contained in:
veeso
2021-07-08 15:43:23 +02:00
parent e6b44e1461
commit 37abe596c7
14 changed files with 168 additions and 97 deletions

View File

@@ -111,7 +111,7 @@ impl FileTransferActivity {
/// Read one event.
/// Returns whether at least one event has been handled
pub(super) fn read_input_event(&mut self) -> bool {
if let Ok(Some(event)) = self.context.as_ref().unwrap().input_hnd.read_event() {
if let Ok(Some(event)) = self.context().input_hnd().read_event() {
// Handle event
let msg = self.view.on(event);
self.update(msg);

View File

@@ -210,18 +210,32 @@ impl FileTransferActivity {
})
}
/// ### context
///
/// Returns a reference to context
fn context(&self) -> &Context {
self.context.as_ref().unwrap()
}
/// ### context_mut
///
/// Returns a mutable reference to context
fn context_mut(&mut self) -> &mut Context {
self.context.as_mut().unwrap()
}
/// ### config
///
/// Returns config client reference
fn config(&self) -> &ConfigClient {
&self.context.as_ref().unwrap().config_client
&self.context().config()
}
/// ### theme
///
/// Get a reference to `Theme`
fn theme(&self) -> &Theme {
self.context.as_ref().unwrap().theme_provider.theme()
self.context().theme_provider().theme()
}
}
@@ -241,7 +255,7 @@ impl Activity for FileTransferActivity {
// Set context
self.context = Some(context);
// Clear terminal
self.context.as_mut().unwrap().clear_screen();
self.context_mut().clear_screen();
// Put raw mode on enabled
if let Err(err) = enable_raw_mode() {
error!("Failed to enter raw mode: {}", err);
@@ -276,7 +290,7 @@ impl Activity for FileTransferActivity {
}
// Check if connected (popup must be None, otherwise would try reconnecting in loop in case of error)
if !self.client.is_connected() && self.view.get_props(COMPONENT_TEXT_FATAL).is_none() {
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
let params = self.context().ft_params().unwrap();
info!(
"Client is not connected to remote; connecting to {}:{}",
params.address, params.port

View File

@@ -76,15 +76,15 @@ impl FileTransferActivity {
///
/// Connect to remote
pub(super) fn connect(&mut self) {
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
let params = self.context().ft_params().unwrap().clone();
let addr: String = params.address.clone();
let entry_dir: Option<PathBuf> = params.entry_directory.clone();
// Connect to remote
match self.client.connect(
params.address.clone(),
params.address,
params.port,
params.username.clone(),
params.password.clone(),
params.username,
params.password,
) {
Ok(welcome) => {
if let Some(banner) = welcome {
@@ -121,7 +121,7 @@ impl FileTransferActivity {
///
/// disconnect from remote
pub(super) fn disconnect(&mut self) {
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
let params = self.context().ft_params().unwrap();
let msg: String = format!("Disconnecting from {}...", params.address);
// Show popup disconnecting
self.mount_wait(msg.as_str());

View File

@@ -720,10 +720,8 @@ impl FileTransferActivity {
Some(props) => {
// Get width
let width: usize = self
.context
.as_ref()
.unwrap()
.store
.context()
.store()
.get_unsigned(super::STORAGE_EXPLORER_WIDTH)
.unwrap_or(256);
let hostname: String = match hostname::get() {
@@ -768,13 +766,11 @@ impl FileTransferActivity {
Some(props) => {
// Get width
let width: usize = self
.context
.as_ref()
.unwrap()
.store
.context()
.store()
.get_unsigned(super::STORAGE_EXPLORER_WIDTH)
.unwrap_or(256);
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
let params = self.context().ft_params().unwrap();
let hostname: String = format!(
"{}:{} ",
params.address,