Push language selector handler down into StatusBar
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::{get_workspace_state, Button, ClickHandler, Icon, IconButton, IconColor, ToolDivider};
|
use crate::{get_workspace_state, Button, Icon, IconButton, IconColor, ToolDivider};
|
||||||
|
|
||||||
#[derive(Default, PartialEq)]
|
#[derive(Default, PartialEq)]
|
||||||
pub enum Tool {
|
pub enum Tool {
|
||||||
@@ -35,17 +36,15 @@ pub struct StatusBar<S: 'static + Send + Sync + Clone> {
|
|||||||
left_tools: Option<ToolGroup>,
|
left_tools: Option<ToolGroup>,
|
||||||
right_tools: Option<ToolGroup>,
|
right_tools: Option<ToolGroup>,
|
||||||
bottom_tools: Option<ToolGroup>,
|
bottom_tools: Option<ToolGroup>,
|
||||||
on_select_language: ClickHandler<S>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
|
impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
|
||||||
pub fn new(on_select_language: ClickHandler<S>) -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
left_tools: None,
|
left_tools: None,
|
||||||
right_tools: None,
|
right_tools: None,
|
||||||
bottom_tools: None,
|
bottom_tools: None,
|
||||||
on_select_language,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +147,23 @@ impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
|
|||||||
.items_center()
|
.items_center()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(Button::new("116:25"))
|
.child(Button::new("116:25"))
|
||||||
.child(Button::new("Rust").on_click(self.on_select_language.clone())),
|
.child(Button::new("Rust").on_click(Arc::new(|_, cx| {
|
||||||
|
let is_showing_language_selector = workspace_state
|
||||||
|
.show_language_selector
|
||||||
|
.load(Ordering::SeqCst);
|
||||||
|
|
||||||
|
workspace_state
|
||||||
|
.show_language_selector
|
||||||
|
.compare_exchange(
|
||||||
|
is_showing_language_selector,
|
||||||
|
!is_showing_language_selector,
|
||||||
|
Ordering::SeqCst,
|
||||||
|
Ordering::SeqCst,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
}))),
|
||||||
)
|
)
|
||||||
.child(ToolDivider::new())
|
.child(ToolDivider::new())
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
@@ -218,23 +218,7 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
|
|||||||
.filter(|_| workspace_state.show_chat_panel.load(Ordering::SeqCst)),
|
.filter(|_| workspace_state.show_chat_panel.load(Ordering::SeqCst)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(StatusBar::new(Arc::new(move |_, cx| {
|
.child(StatusBar::new())
|
||||||
let is_showing_language_selector = workspace_state
|
|
||||||
.show_language_selector
|
|
||||||
.load(Ordering::SeqCst);
|
|
||||||
|
|
||||||
workspace_state
|
|
||||||
.show_language_selector
|
|
||||||
.compare_exchange(
|
|
||||||
is_showing_language_selector,
|
|
||||||
!is_showing_language_selector,
|
|
||||||
Ordering::SeqCst,
|
|
||||||
Ordering::SeqCst,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
cx.notify();
|
|
||||||
})))
|
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(
|
||||||
div()
|
div()
|
||||||
|
|||||||
Reference in New Issue
Block a user