diff --git a/crates/encodings/src/lib.rs b/crates/encodings/src/lib.rs index 293091705f38df49a4ff37fafdbe4459a4eab8f8..4d7256db6f3b0b4d7e3694836d8475e0ca139d89 100644 --- a/crates/encodings/src/lib.rs +++ b/crates/encodings/src/lib.rs @@ -8,6 +8,7 @@ use language::Buffer; use ui::{App, Button, ButtonCommon, Context, LabelSize, Render, Tooltip, Window, div}; use ui::{Clickable, ParentElement}; use workspace::{ItemHandle, StatusItemView, Workspace, with_active_or_new_workspace}; +use zed_actions::encodings::Toggle; use crate::selectors::encoding::EncodingSelector; use crate::selectors::save_or_reopen::EncodingSaveOrReopenSelector; @@ -76,6 +77,7 @@ impl Render for EncodingIndicator { Action::Save, Some(buffer.downgrade()), weak_workspace, + None, ); selector }) @@ -291,11 +293,14 @@ pub fn encoding_from_name(name: &str) -> &'static Encoding { } pub fn init(cx: &mut App) { - cx.on_action(|_: &zed_actions::encodings::Toggle, cx: &mut App| { + cx.on_action(|action: &Toggle, cx: &mut App| { + let Toggle(path) = action.clone(); + let path = path.to_path_buf(); + with_active_or_new_workspace(cx, |workspace, window, cx| { let weak_workspace = workspace.weak_handle(); workspace.toggle_modal(window, cx, |window, cx| { - EncodingSelector::new(window, cx, Action::Reopen, None, weak_workspace) + EncodingSelector::new(window, cx, Action::Reopen, None, weak_workspace, Some(path)) }); }); }); diff --git a/crates/encodings/src/selectors.rs b/crates/encodings/src/selectors.rs index 010662e8b8bf708fe2912f32684f51c0c5f648a8..f3e26f8bf5842ffffb6c1baec6e9bce7b6f64a05 100644 --- a/crates/encodings/src/selectors.rs +++ b/crates/encodings/src/selectors.rs @@ -125,6 +125,7 @@ pub mod save_or_reopen { Action::Save, Some(buffer.downgrade()), weak_workspace, + None, ); selector }) @@ -149,6 +150,7 @@ pub mod save_or_reopen { Action::Reopen, Some(buffer.downgrade()), weak_workspace, + None, ); selector }); @@ -275,7 +277,7 @@ pub mod save_or_reopen { /// This module contains the encoding selector for choosing an encoding to save or reopen a file with. pub mod encoding { - use std::sync::atomic::AtomicBool; + use std::{path::PathBuf, sync::atomic::AtomicBool}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{AppContext, DismissEvent, Entity, EventEmitter, Focusable, WeakEntity}; @@ -294,6 +296,7 @@ pub mod encoding { pub struct EncodingSelector { picker: Entity>, workspace: WeakEntity, + path: Option, } pub struct EncodingSelectorDelegate { @@ -497,11 +500,16 @@ pub mod encoding { action: Action, buffer: Option>, workspace: WeakEntity, + path: Option, ) -> EncodingSelector { let delegate = EncodingSelectorDelegate::new(cx.entity().downgrade(), buffer, action); let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx)); - EncodingSelector { picker, workspace } + EncodingSelector { + picker, + workspace, + path, + } } } diff --git a/crates/project/src/invalid_item_view.rs b/crates/project/src/invalid_item_view.rs index fa42e4c2d32479b8a5540dd1a3b7621a7b4c51ee..92952a788b6fd27f25889577731005858454ab0a 100644 --- a/crates/project/src/invalid_item_view.rs +++ b/crates/project/src/invalid_item_view.rs @@ -78,6 +78,8 @@ impl Focusable for InvalidItemView { impl Render for InvalidItemView { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl gpui::IntoElement { let abs_path = self.abs_path.clone(); + let path = self.abs_path.clone(); + v_flex() .size_full() .track_focus(&self.focus_handle(cx)) @@ -120,9 +122,11 @@ impl Render for InvalidItemView { ) .style(ButtonStyle::Outlined) .on_click( - |_, window, cx| { + move |_, window, cx| { window.dispatch_action( - Box::new(zed_actions::encodings::Toggle), + Box::new(zed_actions::encodings::Toggle( + path.clone(), + )), cx, ) }, diff --git a/crates/zed_actions/src/lib.rs b/crates/zed_actions/src/lib.rs index ba35639d1b476fe9d61d7792388ad9a2d89cde3d..5a4558aa3dcad47b14298837aa93d4e8cde64dba 100644 --- a/crates/zed_actions/src/lib.rs +++ b/crates/zed_actions/src/lib.rs @@ -300,10 +300,14 @@ pub mod settings_profile_selector { } pub mod encodings { + use std::sync::Arc; + use gpui::Action; + use schemars::JsonSchema; + use serde::Deserialize; - #[derive(PartialEq, Debug, Clone, Action)] - pub struct Toggle; + #[derive(PartialEq, Debug, Clone, Action, JsonSchema, Deserialize)] + pub struct Toggle(pub Arc); } pub mod agent {