Remove ViewContext::dispatch_action
This commit is contained in:
parent
d815fc88ae
commit
c4472b0786
41 changed files with 574 additions and 670 deletions
|
@ -2,27 +2,23 @@ use editor::Editor;
|
|||
use gpui::{
|
||||
elements::*,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
Entity, Subscription, View, ViewContext, ViewHandle,
|
||||
Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
use workspace::{item::ItemHandle, StatusItemView};
|
||||
use workspace::{item::ItemHandle, StatusItemView, Workspace};
|
||||
|
||||
pub struct ActiveBufferLanguage {
|
||||
active_language: Option<Option<Arc<str>>>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
_observe_active_editor: Option<Subscription>,
|
||||
}
|
||||
|
||||
impl Default for ActiveBufferLanguage {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveBufferLanguage {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(workspace: &Workspace) -> Self {
|
||||
Self {
|
||||
active_language: None,
|
||||
workspace: workspace.weak_handle(),
|
||||
_observe_active_editor: None,
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +62,12 @@ impl View for ActiveBufferLanguage {
|
|||
.with_style(style.container)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, |_, _, cx| {
|
||||
cx.dispatch_action(crate::Toggle)
|
||||
.on_click(MouseButton::Left, |_, this, cx| {
|
||||
if let Some(workspace) = this.workspace.upgrade(cx) {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
crate::toggle(workspace, &Default::default(), cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any()
|
||||
} else {
|
||||
|
|
|
@ -11,21 +11,18 @@ use project::Project;
|
|||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
use util::ResultExt;
|
||||
use workspace::{AppState, Workspace};
|
||||
use workspace::Workspace;
|
||||
|
||||
actions!(language_selector, [Toggle]);
|
||||
|
||||
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
Picker::<LanguageSelectorDelegate>::init(cx);
|
||||
cx.add_action({
|
||||
let language_registry = app_state.languages.clone();
|
||||
move |workspace, _: &Toggle, cx| toggle(workspace, language_registry.clone(), cx)
|
||||
});
|
||||
cx.add_action(toggle);
|
||||
}
|
||||
|
||||
fn toggle(
|
||||
pub fn toggle(
|
||||
workspace: &mut Workspace,
|
||||
registry: Arc<LanguageRegistry>,
|
||||
_: &Toggle,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Option<()> {
|
||||
let (_, buffer, _) = workspace
|
||||
|
@ -34,6 +31,7 @@ fn toggle(
|
|||
.read(cx)
|
||||
.active_excerpt(cx)?;
|
||||
workspace.toggle_modal(cx, |workspace, cx| {
|
||||
let registry = workspace.app_state().languages.clone();
|
||||
cx.add_view(|cx| {
|
||||
Picker::new(
|
||||
LanguageSelectorDelegate::new(buffer, workspace.project().clone(), registry),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue