Skip to content

Commit

Permalink
rename closable
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Dec 20, 2024
1 parent 245e490 commit 29d5901
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crates/story/src/button_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl super::Story for ButtonStory {
"Displays a button or a component that looks like a button."
}

fn closeable() -> bool {
fn closable() -> bool {
false
}

Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/input_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl super::Story for InputStory {
"Input"
}

fn closeable() -> bool {
fn closable() -> bool {
false
}

Expand Down
18 changes: 9 additions & 9 deletions crates/story/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn init(cx: &mut AppContext) {
};

let view = cx.new_view(|cx| {
let (title, description, closeable, zoomable, story) = story_state.to_story(cx);
let (title, description, closable, zoomable, story) = story_state.to_story(cx);
let mut container = StoryContainer::new(cx).story(story, story_state.story_klass);

cx.on_focus_in(&container.focus_handle, |this: &mut StoryContainer, _| {
Expand All @@ -110,7 +110,7 @@ pub fn init(cx: &mut AppContext) {

container.name = title.into();
container.description = description.into();
container.closeable = closeable;
container.closable = closable;
container.zoomable = zoomable;
container
});
Expand Down Expand Up @@ -146,7 +146,7 @@ pub struct StoryContainer {
height: Option<gpui::Pixels>,
story: Option<AnyView>,
story_klass: Option<SharedString>,
closeable: bool,
closable: bool,
zoomable: bool,
}

Expand All @@ -164,7 +164,7 @@ pub trait Story: FocusableView {
fn description() -> &'static str {
""
}
fn closeable() -> bool {
fn closable() -> bool {
true
}
fn zoomable() -> bool {
Expand All @@ -191,7 +191,7 @@ impl StoryContainer {
height: None,
story: None,
story_klass: None,
closeable: true,
closable: true,
zoomable: true,
}
}
Expand All @@ -206,7 +206,7 @@ impl StoryContainer {
let view = cx.new_view(|cx| {
let mut story = Self::new(cx).story(story.into(), story_klass);
story.focus_handle = focus_handle;
story.closeable = S::closeable();
story.closable = S::closable();
story.zoomable = S::zoomable();
story.name = name.into();
story.description = description.into();
Expand Down Expand Up @@ -266,7 +266,7 @@ impl StoryState {
(
$klass::title(),
$klass::description(),
$klass::closeable(),
$klass::closable(),
$klass::zoomable(),
$klass::view(cx).into(),
)
Expand Down Expand Up @@ -320,8 +320,8 @@ impl Panel for StoryContainer {
}
}

fn closeable(&self, _cx: &AppContext) -> bool {
self.closeable
fn closable(&self, _cx: &AppContext) -> bool {
self.closable
}

fn zoomable(&self, _cx: &AppContext) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/table_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl super::Story for TableStory {
Self::view(cx)
}

fn closeable() -> bool {
fn closable() -> bool {
false
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/dock/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Dock {
) -> Self {
let panel = cx.new_view(|cx| {
let mut tab = TabPanel::new(None, dock_area.clone(), cx);
tab.closeable = false;
tab.closable = false;
tab
});

Expand Down
8 changes: 4 additions & 4 deletions crates/ui/src/dock/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
/// Whether the panel can be closed, default is `true`.
///
/// This method called in Panel render, we should make sure it is fast.
fn closeable(&self, cx: &AppContext) -> bool {
fn closable(&self, cx: &AppContext) -> bool {
true
}

Expand Down Expand Up @@ -107,7 +107,7 @@ pub trait PanelView: 'static + Send + Sync {
fn panel_name(&self, cx: &AppContext) -> &'static str;
fn title(&self, cx: &WindowContext) -> AnyElement;
fn title_style(&self, cx: &AppContext) -> Option<TitleStyle>;
fn closeable(&self, cx: &AppContext) -> bool;
fn closable(&self, cx: &AppContext) -> bool;
fn zoomable(&self, cx: &AppContext) -> bool;
fn visible(&self, cx: &AppContext) -> bool;
fn set_active(&self, active: bool, cx: &mut WindowContext);
Expand All @@ -132,8 +132,8 @@ impl<T: Panel> PanelView for View<T> {
self.read(cx).title_style(cx)
}

fn closeable(&self, cx: &AppContext) -> bool {
self.read(cx).closeable(cx)
fn closable(&self, cx: &AppContext) -> bool {
self.read(cx).closable(cx)
}

fn zoomable(&self, cx: &AppContext) -> bool {
Expand Down
20 changes: 10 additions & 10 deletions crates/ui/src/dock/tab_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::{

#[derive(Clone, Copy)]
struct TabState {
closeable: bool,
closable: bool,
zoomable: bool,
draggable: bool,
droppable: bool,
Expand Down Expand Up @@ -71,9 +71,9 @@ pub struct TabPanel {
stack_panel: Option<WeakView<StackPanel>>,
pub(crate) panels: Vec<Arc<dyn PanelView>>,
pub(crate) active_ix: usize,
/// If this is true, the Panel closeable will follow the active panel's closeable,
/// If this is true, the Panel closable will follow the active panel's closable,
/// otherwise this TabPanel will not able to close
pub(crate) closeable: bool,
pub(crate) closable: bool,

tab_bar_scroll_handle: ScrollHandle,
is_zoomed: bool,
Expand All @@ -93,13 +93,13 @@ impl Panel for TabPanel {
.unwrap_or("Empty Tab".into_any_element())
}

fn closeable(&self, cx: &AppContext) -> bool {
if !self.closeable {
fn closable(&self, cx: &AppContext) -> bool {
if !self.closable {
return false;
}

self.active_panel(cx)
.map(|panel| panel.closeable(cx))
.map(|panel| panel.closable(cx))
.unwrap_or(false)
}

Expand Down Expand Up @@ -155,7 +155,7 @@ impl TabPanel {
will_split_placement: None,
is_zoomed: false,
is_collapsed: false,
closeable: true,
closable: true,
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ impl TabPanel {
};
this.separator().menu(name, Box::new(ToggleZoom))
})
.when(state.closeable, |this| {
.when(state.closable, |this| {
this.separator()
.menu(t!("Dock.Close"), Box::new(ClosePanel))
})
Expand Down Expand Up @@ -977,13 +977,13 @@ impl Render for TabPanel {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl gpui::IntoElement {
let focus_handle = self.focus_handle(cx);
let mut state = TabState {
closeable: self.closeable(cx),
closable: self.closable(cx),
draggable: self.draggable(cx),
droppable: self.droppable(cx),
zoomable: self.zoomable(cx),
};
if !state.draggable {
state.closeable = false;
state.closable = false;
}

v_flex()
Expand Down

0 comments on commit 29d5901

Please sign in to comment.