mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Remove unescessary enum
This commit is contained in:
parent
60b4054b0a
commit
dacfd70fb4
@ -9,7 +9,6 @@ use gpui::{
|
||||
};
|
||||
use menu::*;
|
||||
use std::{any::TypeId, borrow::Cow, sync::Arc, time::Duration};
|
||||
use theme::ToggleState;
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(ContextMenu::select_first);
|
||||
@ -329,12 +328,7 @@ impl ContextMenu {
|
||||
Flex::column().with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
||||
match item {
|
||||
ContextMenuItem::Item { label, .. } => {
|
||||
let toggle_state = if Some(ix) == self.selected_index {
|
||||
ToggleState::Active
|
||||
} else {
|
||||
ToggleState::Inactive
|
||||
};
|
||||
let style = style.item.in_state(toggle_state);
|
||||
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||
let style = style.style_for(&mut Default::default());
|
||||
|
||||
match label {
|
||||
@ -367,12 +361,7 @@ impl ContextMenu {
|
||||
.with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
||||
match item {
|
||||
ContextMenuItem::Item { action, .. } => {
|
||||
let toggle_state = if Some(ix) == self.selected_index {
|
||||
ToggleState::Active
|
||||
} else {
|
||||
ToggleState::Inactive
|
||||
};
|
||||
let style = style.item.in_state(toggle_state);
|
||||
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||
let style = style.style_for(&mut Default::default());
|
||||
|
||||
match action {
|
||||
@ -419,12 +408,7 @@ impl ContextMenu {
|
||||
let action = action.clone();
|
||||
let view_id = self.parent_view_id;
|
||||
MouseEventHandler::<MenuItem, ContextMenu>::new(ix, cx, |state, _| {
|
||||
let toggle_state = if Some(ix) == self.selected_index {
|
||||
ToggleState::Active
|
||||
} else {
|
||||
ToggleState::Inactive
|
||||
};
|
||||
let style = style.item.in_state(toggle_state);
|
||||
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||
let style = style.style_for(state);
|
||||
let keystroke = match &action {
|
||||
ContextMenuItemAction::Action(action) => Some(
|
||||
|
@ -816,37 +816,22 @@ pub struct Toggleable<T> {
|
||||
inactive: T,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq)]
|
||||
pub enum ToggleState {
|
||||
#[default]
|
||||
Inactive,
|
||||
Active,
|
||||
}
|
||||
|
||||
impl<T: std::borrow::Borrow<bool>> From<T> for ToggleState {
|
||||
fn from(item: T) -> Self {
|
||||
match *item.borrow() {
|
||||
true => Self::Active,
|
||||
false => Self::Inactive,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Toggleable<T> {
|
||||
pub fn new(active: T, inactive: T) -> Self {
|
||||
Self { active, inactive }
|
||||
}
|
||||
pub fn in_state(&self, state: impl Into<ToggleState>) -> &T {
|
||||
match state.into() {
|
||||
ToggleState::Inactive => &self.inactive,
|
||||
ToggleState::Active => &self.active,
|
||||
pub fn in_state(&self, active: bool) -> &T {
|
||||
if active {
|
||||
&self.inactive
|
||||
} else {
|
||||
&self.active
|
||||
}
|
||||
}
|
||||
pub fn active_state(&self) -> &T {
|
||||
self.in_state(ToggleState::Active)
|
||||
self.in_state(true)
|
||||
}
|
||||
pub fn inactive_state(&self) -> &T {
|
||||
self.in_state(ToggleState::Inactive)
|
||||
self.in_state(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use gpui::{
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::rc::Rc;
|
||||
use theme::{ThemeSettings, ToggleState};
|
||||
use theme::ThemeSettings;
|
||||
|
||||
pub trait Panel: View {
|
||||
fn position(&self, cx: &WindowContext) -> DockPosition;
|
||||
@ -498,12 +498,7 @@ impl View for PanelButtons {
|
||||
Stack::new()
|
||||
.with_child(
|
||||
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
||||
let toggle_state = if is_active {
|
||||
ToggleState::Active
|
||||
} else {
|
||||
ToggleState::Inactive
|
||||
};
|
||||
let style = button_style.in_state(toggle_state);
|
||||
let style = button_style.in_state(is_active);
|
||||
|
||||
let style = style.style_for(state);
|
||||
Flex::row()
|
||||
|
Loading…
Reference in New Issue
Block a user