mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
removed args from SaveBookmark
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
|
||||
use super::{
|
||||
AuthActivity, DialogCallback, DialogYesNoOption, FileTransferProtocol, InputEvent, InputField,
|
||||
InputForm, InputMode, OnInputSubmitCallback, PopupType,
|
||||
InputForm, InputMode, PopupType,
|
||||
};
|
||||
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
@@ -163,10 +163,7 @@ impl AuthActivity {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark);
|
||||
}
|
||||
_ => { /* Nothing to do */ }
|
||||
}
|
||||
@@ -287,10 +284,7 @@ impl AuthActivity {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark);
|
||||
}
|
||||
_ => { /* Nothing to do */ }
|
||||
},
|
||||
@@ -370,10 +364,7 @@ impl AuthActivity {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark);
|
||||
}
|
||||
_ => { /* Nothing to do */ }
|
||||
},
|
||||
@@ -389,7 +380,7 @@ impl AuthActivity {
|
||||
match ptype {
|
||||
PopupType::Alert(_, _) => self.handle_input_event_mode_popup_alert(ev),
|
||||
PopupType::Help => self.handle_input_event_mode_popup_help(ev),
|
||||
PopupType::SaveBookmark(_, cb) => self.handle_input_event_mode_popup_save_bookmark(ev, cb),
|
||||
PopupType::SaveBookmark => self.handle_input_event_mode_popup_save_bookmark(ev),
|
||||
PopupType::YesNo(_, yes_cb, no_cb) => {
|
||||
self.handle_input_event_mode_popup_yesno(ev, yes_cb, no_cb)
|
||||
}
|
||||
@@ -427,11 +418,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_popup_save_bookmark
|
||||
///
|
||||
/// Input event handler for SaveBookmark popup
|
||||
pub(super) fn handle_input_event_mode_popup_save_bookmark(
|
||||
&mut self,
|
||||
ev: &InputEvent,
|
||||
cb: OnInputSubmitCallback,
|
||||
) {
|
||||
pub(super) fn handle_input_event_mode_popup_save_bookmark(&mut self, ev: &InputEvent) {
|
||||
// If enter, close popup, otherwise push chars to input
|
||||
if let InputEvent::Key(key) = ev {
|
||||
match key.code {
|
||||
@@ -452,7 +439,7 @@ impl AuthActivity {
|
||||
// Set mode back to form BEFORE CALLBACKS!!! Callback can then overwrite this, clever uh?
|
||||
self.input_mode = InputMode::Form;
|
||||
// Call cb
|
||||
cb(self, input_text);
|
||||
self.callback_save_bookmark(input_text);
|
||||
// Reset choice option to yes
|
||||
self.choice_opt = DialogYesNoOption::Yes;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ impl AuthActivity {
|
||||
let (width, height): (u16, u16) = match popup {
|
||||
PopupType::Alert(_, _) => (50, 10),
|
||||
PopupType::Help => (50, 70),
|
||||
PopupType::SaveBookmark(_, _) => (40, 20),
|
||||
PopupType::SaveBookmark => (40, 20),
|
||||
PopupType::YesNo(_, _, _) => (30, 10),
|
||||
};
|
||||
let popup_area: Rect = self.draw_popup_area(f.size(), width, height);
|
||||
@@ -137,7 +137,7 @@ impl AuthActivity {
|
||||
popup_area,
|
||||
),
|
||||
PopupType::Help => f.render_widget(self.draw_popup_help(), popup_area),
|
||||
PopupType::SaveBookmark(txt, _) => {
|
||||
PopupType::SaveBookmark => {
|
||||
let popup_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
@@ -149,8 +149,7 @@ impl AuthActivity {
|
||||
.as_ref(),
|
||||
)
|
||||
.split(popup_area);
|
||||
let (input, yes_no): (Paragraph, Tabs) =
|
||||
self.draw_popup_save_bookmark(txt.clone());
|
||||
let (input, yes_no): (Paragraph, Tabs) = self.draw_popup_save_bookmark();
|
||||
// Render parts
|
||||
f.render_widget(input, popup_chunks[0]);
|
||||
f.render_widget(yes_no, popup_chunks[1]);
|
||||
@@ -429,10 +428,14 @@ impl AuthActivity {
|
||||
/// ### draw_popup_input
|
||||
///
|
||||
/// Draw input popup
|
||||
pub(super) fn draw_popup_save_bookmark(&self, text: String) -> (Paragraph, Tabs) {
|
||||
pub(super) fn draw_popup_save_bookmark(&self) -> (Paragraph, Tabs) {
|
||||
let input: Paragraph = Paragraph::new(self.input_txt.as_ref())
|
||||
.style(Style::default().fg(Color::LightYellow))
|
||||
.block(Block::default().borders(Borders::ALL).title(text));
|
||||
.style(Style::default().fg(Color::White))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::TOP | Borders::RIGHT | Borders::LEFT)
|
||||
.title("Save bookmark as..."),
|
||||
);
|
||||
let choices: Vec<Spans> = vec![Spans::from("Yes"), Spans::from("No")];
|
||||
let index: usize = match self.choice_opt {
|
||||
DialogYesNoOption::Yes => 0,
|
||||
@@ -441,7 +444,7 @@ impl AuthActivity {
|
||||
let tabs: Tabs = Tabs::new(choices)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.borders(Borders::BOTTOM | Borders::RIGHT | Borders::LEFT)
|
||||
.title("Save password?"),
|
||||
)
|
||||
.select(index)
|
||||
|
||||
@@ -46,7 +46,6 @@ use tui::style::Color;
|
||||
|
||||
// Types
|
||||
type DialogCallback = fn(&mut AuthActivity);
|
||||
type OnInputSubmitCallback = fn(&mut AuthActivity, String);
|
||||
|
||||
/// ### InputField
|
||||
///
|
||||
@@ -76,7 +75,7 @@ enum DialogYesNoOption {
|
||||
enum PopupType {
|
||||
Alert(Color, String), // Show a message displaying text with the provided color
|
||||
Help, // Help page
|
||||
SaveBookmark(String, OnInputSubmitCallback), // Input description; Callback for submit
|
||||
SaveBookmark,
|
||||
YesNo(String, DialogCallback, DialogCallback), // Yes, no callback
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user