summaryrefslogtreecommitdiffstats
path: root/default-plugins/session-manager/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'default-plugins/session-manager/src/main.rs')
-rw-r--r--default-plugins/session-manager/src/main.rs56
1 files changed, 50 insertions, 6 deletions
diff --git a/default-plugins/session-manager/src/main.rs b/default-plugins/session-manager/src/main.rs
index 8040f79e0..7015144fd 100644
--- a/default-plugins/session-manager/src/main.rs
+++ b/default-plugins/session-manager/src/main.rs
@@ -2,9 +2,9 @@ mod new_session_info;
mod resurrectable_sessions;
mod session_list;
mod ui;
-use zellij_tile::prelude::*;
-
use std::collections::BTreeMap;
+use uuid::Uuid;
+use zellij_tile::prelude::*;
use new_session_info::NewSessionInfo;
use ui::{
@@ -45,6 +45,7 @@ struct State {
colors: Colors,
is_welcome_screen: bool,
show_kill_all_sessions_warning: bool,
+ request_ids: Vec<String>,
}
register_plugin!(State);
@@ -66,6 +67,28 @@ impl ZellijPlugin for State {
]);
}
+ fn pipe(&mut self, pipe_message: PipeMessage) -> bool {
+ if pipe_message.name == "filepicker_result" {
+ match (pipe_message.payload, pipe_message.args.get("request_id")) {
+ (Some(payload), Some(request_id)) => {
+ match self.request_ids.iter().position(|p| p == request_id) {
+ Some(request_id_position) => {
+ self.request_ids.remove(request_id_position);
+ let new_session_folder = std::path::PathBuf::from(payload);
+ self.new_session_info.new_session_folder = Some(new_session_folder);
+ },
+ None => {
+ eprintln!("request id not found");
+ },
+ }
+ },
+ _ => {},
+ }
+ true
+ } else {
+ false
+ }
+ }
fn update(&mut self, event: Event) -> bool {
let mut should_render = false;
match event {
@@ -109,7 +132,7 @@ impl ZellijPlugin for State {
render_new_session_block(
&self.new_session_info,
self.colors,
- height,
+ height.saturating_sub(2),
width,
x,
y + 2,
@@ -184,12 +207,33 @@ impl State {
} else if let Key::Ctrl('w') = key {
self.active_screen = ActiveScreen::NewSession;
should_render = true;
- } else if let Key::Ctrl('c') = key {
- self.new_session_info.handle_key(key);
- should_render = true;
} else if let Key::BackTab = key {
self.toggle_active_screen();
should_render = true;
+ } else if let Key::Ctrl('f') = key {
+ let request_id = Uuid::new_v4();
+ let mut config = BTreeMap::new();
+ let mut args = BTreeMap::new();
+ self.request_ids.push(request_id.to_string());
+ // we insert this into the config so that a new plugin will be opened (the plugin's
+ // uniqueness is determined by its name/url as well as its config)
+ config.insert("request_id".to_owned(), request_id.to_string());
+ // we also insert this into the args so that the plugin will have an easier access to
+ // it
+ args.insert("request_id".to_owned(), request_id.to_string());
+ pipe_message_to_plugin(
+ MessageToPlugin::new("filepicker")
+ .with_plugin_url("filepicker")
+ .with_plugin_config(config)
+ .new_plugin_instance_should_have_pane_title(
+ "Select folder for the new session...",
+ )
+ .with_args(args),
+ );
+ should_render = true;
+ } else if let Key::Ctrl('c') = key {
+ self.new_session_info.new_session_folder = None;
+ should_render = true;
} else if let Key::Esc = key {
self.new_session_info.handle_key(key);
should_render = true;