tab: Add setting to hide the close button entirely (#23880)
Closes #23744 Release Notes: - Changed the `always_show_close_button` key to `show_close_button` and introduced a new `hidden` value, that allows never displaying the close button. --------- Co-authored-by: Peter Tripp <peter@zed.dev> Co-authored-by: Danilo Leal <daniloleal09@gmail.com> Co-authored-by: smit <0xtimsb@gmail.com>
This commit is contained in:
parent
ae6d350334
commit
0a4ff2f475
5 changed files with 149 additions and 28 deletions
|
@ -42,7 +42,7 @@ pub struct ItemSettings {
|
|||
pub activate_on_close: ActivateOnClose,
|
||||
pub file_icons: bool,
|
||||
pub show_diagnostics: ShowDiagnostics,
|
||||
pub always_show_close_button: bool,
|
||||
pub show_close_button: ShowCloseButton,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -60,6 +60,15 @@ pub enum ClosePosition {
|
|||
Right,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ShowCloseButton {
|
||||
Always,
|
||||
#[default]
|
||||
Hover,
|
||||
Hidden,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ShowDiagnostics {
|
||||
|
@ -104,7 +113,7 @@ pub struct ItemSettingsContent {
|
|||
/// Whether to always show the close button on tabs.
|
||||
///
|
||||
/// Default: false
|
||||
always_show_close_button: Option<bool>,
|
||||
show_close_button: Option<ShowCloseButton>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
item::{
|
||||
ActivateOnClose, ClosePosition, Item, ItemHandle, ItemSettings, PreviewTabsSettings,
|
||||
ShowDiagnostics, TabContentParams, TabTooltipContent, WeakItemHandle,
|
||||
ShowCloseButton, ShowDiagnostics, TabContentParams, TabTooltipContent, WeakItemHandle,
|
||||
},
|
||||
move_item,
|
||||
notifications::NotifyResultExt,
|
||||
|
@ -2269,7 +2269,7 @@ impl Pane {
|
|||
|
||||
let settings = ItemSettings::get_global(cx);
|
||||
let close_side = &settings.close_position;
|
||||
let always_show_close_button = settings.always_show_close_button;
|
||||
let show_close_button = &settings.show_close_button;
|
||||
let indicator = render_item_indicator(item.boxed_clone(), cx);
|
||||
let item_id = item.item_id();
|
||||
let is_first_item = ix == 0;
|
||||
|
@ -2373,18 +2373,21 @@ impl Pane {
|
|||
close_pinned: false,
|
||||
};
|
||||
end_slot_tooltip_text = "Close Tab";
|
||||
IconButton::new("close tab", IconName::Close)
|
||||
.when(!always_show_close_button, |button| {
|
||||
button.visible_on_hover("")
|
||||
})
|
||||
.shape(IconButtonShape::Square)
|
||||
.icon_color(Color::Muted)
|
||||
.size(ButtonSize::None)
|
||||
.icon_size(IconSize::XSmall)
|
||||
.on_click(cx.listener(move |pane, _, window, cx| {
|
||||
pane.close_item_by_id(item_id, SaveIntent::Close, window, cx)
|
||||
.detach_and_log_err(cx);
|
||||
}))
|
||||
match show_close_button {
|
||||
ShowCloseButton::Always => IconButton::new("close tab", IconName::Close),
|
||||
ShowCloseButton::Hover => {
|
||||
IconButton::new("close tab", IconName::Close).visible_on_hover("")
|
||||
}
|
||||
ShowCloseButton::Hidden => return this,
|
||||
}
|
||||
.shape(IconButtonShape::Square)
|
||||
.icon_color(Color::Muted)
|
||||
.size(ButtonSize::None)
|
||||
.icon_size(IconSize::XSmall)
|
||||
.on_click(cx.listener(move |pane, _, window, cx| {
|
||||
pane.close_item_by_id(item_id, SaveIntent::Close, window, cx)
|
||||
.detach_and_log_err(cx);
|
||||
}))
|
||||
}
|
||||
.map(|this| {
|
||||
if is_active {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue