Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

tabular_data_preview: Move settings into popup (refine UI) (#62812)

Oleksandr Kholiavkoe0f913b07d6a
diff --git a/crates/tabular_data_preview/src/renderer/preview_view.rs b/crates/tabular_data_preview/src/renderer/preview_view.rs
index 6d093525ae0..e8c4822523f 100644
--- a/crates/tabular_data_preview/src/renderer/preview_view.rs
+++ b/crates/tabular_data_preview/src/renderer/preview_view.rs
@@ -4,6 +4,8 @@ use ui::{SpinnerLabel, div, prelude::*};
use crate::TabularDataPreviewPane;
+use super::settings::settings_popover_menu;
+
impl Render for TabularDataPreviewPane {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();
@@ -21,27 +23,39 @@ impl Render for TabularDataPreviewPane {
.size_full()
.bg(theme.colors().editor_background)
.track_focus(&self.focus_handle)
- .child(self.render_settings_panel(window, cx))
.child({
let is_parsing = self.is_parsing;
if is_parsing || self.engine.contents.number_of_cols == 0 {
- div()
- .flex()
- .items_center()
- .justify_center()
- .h_32()
- .text_ui(cx)
- .font_buffer(cx)
- .text_color(cx.theme().colors().text_muted)
- .when(is_parsing, |div| {
- div.child(
- h_flex()
- .gap_2()
- .child(SpinnerLabel::new())
- .child("Loading…"),
- )
- })
- .when(!is_parsing, |div| div.child("No data to display"))
+ v_flex()
+ .size_full()
+ .child(
+ // Settings stay reachable even before the table (and its own
+ // header-embedded settings trigger) has anything to render.
+ h_flex()
+ .w_full()
+ .justify_end()
+ .p_1()
+ .child(settings_popover_menu(cx.entity())),
+ )
+ .child(
+ div()
+ .flex()
+ .flex_1()
+ .items_center()
+ .justify_center()
+ .text_ui(cx)
+ .font_buffer(cx)
+ .text_color(cx.theme().colors().text_muted)
+ .when(is_parsing, |div| {
+ div.child(
+ h_flex()
+ .gap_2()
+ .child(SpinnerLabel::new())
+ .child("Loading…"),
+ )
+ })
+ .when(!is_parsing, |div| div.child("No data to display")),
+ )
.into_any_element()
} else {
self.create_table(&self.column_widths.widths, cx)
diff --git a/crates/tabular_data_preview/src/renderer/row_identifiers.rs b/crates/tabular_data_preview/src/renderer/row_identifiers.rs
index 0a3fcae4bcd..bf1c69c6655 100644
--- a/crates/tabular_data_preview/src/renderer/row_identifiers.rs
+++ b/crates/tabular_data_preview/src/renderer/row_identifiers.rs
@@ -1,20 +1,21 @@
-use ui::{
- ActiveTheme as _, AnyElement, Button, ButtonCommon as _, ButtonSize, ButtonStyle,
- Clickable as _, Context, ElementId, IntoElement as _, ParentElement as _, SharedString,
- Styled as _, StyledTypography as _, Tooltip, div,
-};
-
use crate::{
TabularDataPreviewPane,
settings::RowIdentifiers,
types::{DataRow, DisplayRow, LineNumber},
};
+use ui::{
+ ActiveTheme as _, AnyElement, ButtonCommon as _, ButtonSize, Clickable, Context,
+ FluentBuilder as _, IconButton, IconButtonShape, IconName, IconSize, IntoElement as _,
+ ParentElement as _, SharedString, Styled as _, StyledTypography as _, Tooltip, div, h_flex,
+};
+
+use super::settings::settings_popover_menu;
pub enum RowIdentDisplayMode {
/// E.g
/// ```text
/// 1
- /// ...
+ /// -
/// 5
/// ```
Vertical,
@@ -106,38 +107,49 @@ impl TabularDataPreviewPane {
&self,
cx: &mut Context<'_, TabularDataPreviewPane>,
) -> AnyElement {
- // First column: row identifier (clickable to toggle between Lines and Rows)
- let row_identifier_text = match self.settings.numbering_type {
- RowIdentifiers::SrcLines => "Lines",
- RowIdentifiers::RowNum => "Rows",
- };
+ let has_line_numbers = !self.engine.contents.line_numbers.is_empty();
- let view = cx.entity();
- let value = div()
- .font_buffer(cx)
- .child(
- Button::new(
- ElementId::Name("row-identifier-toggle".into()),
- row_identifier_text,
+ h_flex()
+ .size_full()
+ .items_center()
+ .justify_center()
+ .gap_1()
+ .when(has_line_numbers, |row| {
+ // A dedicated toggle (rather than only exposing this in the settings popover) so
+ // toggling shows its effect on the row identifier column immediately, instead of
+ // being hidden behind the open popover until it's dismissed.
+ let (icon, tooltip_text) = match self.settings.numbering_type {
+ RowIdentifiers::SrcLines => (
+ IconName::Code,
+ "Showing file line numbers.\nClick to show sequential row numbers.",
+ ),
+ RowIdentifiers::RowNum => (
+ IconName::Hash,
+ "Showing sequential row numbers.\nClick to show file line numbers.",
+ ),
+ };
+
+ let view = cx.entity();
+ row.child(
+ IconButton::new("row-identifier-toggle", icon)
+ .shape(IconButtonShape::Square)
+ .icon_size(IconSize::Small)
+ .size(ButtonSize::Compact)
+ .tooltip(Tooltip::text(tooltip_text))
+ .on_click(move |_event, _window, cx| {
+ view.update(cx, |this, cx| {
+ this.settings.numbering_type = match this.settings.numbering_type {
+ RowIdentifiers::SrcLines => RowIdentifiers::RowNum,
+ RowIdentifiers::RowNum => RowIdentifiers::SrcLines,
+ };
+ this.sync_column_widths(cx);
+ cx.notify();
+ });
+ }),
)
- .style(ButtonStyle::Subtle)
- .size(ButtonSize::Compact)
- .tooltip(Tooltip::text(
- "Toggle between: file line numbers or sequential row numbers",
- ))
- .on_click(move |_event, _window, cx| {
- view.update(cx, |this, cx| {
- this.settings.numbering_type = match this.settings.numbering_type {
- RowIdentifiers::SrcLines => RowIdentifiers::RowNum,
- RowIdentifiers::RowNum => RowIdentifiers::SrcLines,
- };
- this.sync_column_widths(cx);
- cx.notify();
- });
- }),
- )
- .into_any_element();
- value
+ })
+ .child(settings_popover_menu(cx.entity()))
+ .into_any_element()
}
pub(crate) fn create_row_identifier_cell(
diff --git a/crates/tabular_data_preview/src/renderer/settings.rs b/crates/tabular_data_preview/src/renderer/settings.rs
index 3b39b4240cc..81b20d080fb 100644
--- a/crates/tabular_data_preview/src/renderer/settings.rs
+++ b/crates/tabular_data_preview/src/renderer/settings.rs
@@ -1,256 +1,163 @@
+use gpui::{Anchor, Entity};
use ui::{
- ActiveTheme as _, AnyElement, ButtonSize, Checkbox, Context, ContextMenu, DropdownMenu,
- ElementId, IntoElement as _, ParentElement as _, Styled as _, ToggleState, Tooltip, Window,
- div, h_flex,
+ ContextMenu, ContextMenuEntry, DocumentationSide, IconButton, IconName, IconPosition, IconSize,
+ Label, PopoverMenu, Tooltip, prelude::*,
};
use crate::{
TabularDataPreviewPane,
- settings::{FilterSortOrder, VerticalAlignment},
+ settings::{FilterSortOrder, TabularDataPreviewSettings, VerticalAlignment},
};
///// Settings related /////
-impl TabularDataPreviewPane {
- /// Render settings panel above the table
- pub(crate) fn render_settings_panel(
- &self,
- window: &mut Window,
- cx: &mut Context<Self>,
- ) -> AnyElement {
- let current_alignment_text = match self.settings.vertical_alignment {
- VerticalAlignment::Top => "Top",
- VerticalAlignment::Center => "Center",
- };
- let current_filter_sort_text = match self.settings.filter_sort_order {
- FilterSortOrder::AlphaThenCount => "A-Z, then Count",
- FilterSortOrder::CountThenAlpha => "Count, then A-Z",
- };
-
- let view = cx.entity();
- let alignment_dropdown_menu = ContextMenu::build(window, cx, |menu, _window, _cx| {
- menu.entry("Top", None, {
- let view = view.clone();
- move |_window, cx| {
- view.update(cx, |this, cx| {
- this.settings.vertical_alignment = VerticalAlignment::Top;
- cx.notify();
- });
- }
- })
- .entry("Center", None, {
- let view = view.clone();
- move |_window, cx| {
- view.update(cx, |this, cx| {
- this.settings.vertical_alignment = VerticalAlignment::Center;
- cx.notify();
- });
- }
- })
+/// Adds a toggleable entry that applies `set` to the pane's settings when clicked. `description`,
+/// when given, shows as a documentation aside explaining what the entry does.
+fn toggle_entry(
+ menu: ContextMenu,
+ label: &'static str,
+ description: Option<&'static str>,
+ selected: bool,
+ view_entity: &Entity<TabularDataPreviewPane>,
+ set: impl Fn(&mut TabularDataPreviewSettings) + 'static,
+) -> ContextMenu {
+ let view_entity = view_entity.clone();
+ let entry = ContextMenuEntry::new(label)
+ .toggleable(IconPosition::Start, selected)
+ .handler(move |_, cx| {
+ view_entity.update(cx, |this, cx| {
+ set(&mut this.settings);
+ cx.notify();
+ });
});
+ let entry = if let Some(description) = description {
+ entry.documentation_aside(DocumentationSide::Right, move |_| {
+ Label::new(description).into_any_element()
+ })
+ } else {
+ entry
+ };
+ menu.item(entry)
+}
- let filter_sort_dropdown_menu = ContextMenu::build(window, cx, |menu, _window, _cx| {
- menu.entry("A-Z, then Count", None, {
- let view = view.clone();
- move |_window, cx| {
- view.update(cx, |this, cx| {
- this.settings.filter_sort_order = FilterSortOrder::AlphaThenCount;
- cx.notify();
- });
- }
- })
- .entry("Count, then A-Z", None, {
- let view = view.clone();
- move |_window, cx| {
- view.update(cx, |this, cx| {
- this.settings.filter_sort_order = FilterSortOrder::CountThenAlpha;
- cx.notify();
- });
- }
- })
- });
+pub(crate) fn settings_popover_menu(
+ view_entity: Entity<TabularDataPreviewPane>,
+) -> PopoverMenu<ContextMenu> {
+ PopoverMenu::new("table-settings-menu")
+ .trigger_with_tooltip(
+ IconButton::new("table-settings-trigger", IconName::Filter)
+ .icon_size(IconSize::Small)
+ .size(ButtonSize::Compact),
+ Tooltip::text("Table Settings"),
+ )
+ .anchor(Anchor::TopRight)
+ .menu(move |window, cx| {
+ let view_entity = view_entity.clone();
+ Some(ContextMenu::build_persistent(
+ window,
+ cx,
+ move |menu, _window, cx| {
+ let settings = view_entity.read(cx).settings.clone();
- let panel = h_flex()
- .gap_4()
- .p_2()
- .bg(cx.theme().colors().surface_background)
- .border_b_1()
- .border_color(cx.theme().colors().border)
- .flex_wrap()
- .child(
- h_flex()
- .gap_2()
- .items_center()
- .child(
- div()
- .text_sm()
- .text_color(cx.theme().colors().text_muted)
- .child("Text Alignment:"),
- )
- .child(
- DropdownMenu::new(
- ElementId::Name("vertical-alignment-dropdown".into()),
- current_alignment_text,
- alignment_dropdown_menu,
- )
- .trigger_size(ButtonSize::Compact)
- .trigger_tooltip(Tooltip::text(
- "Choose vertical text alignment within cells",
- )),
- ),
- )
- .child(
- h_flex()
- .gap_2()
- .items_center()
- .child(
- div()
- .text_sm()
- .text_color(cx.theme().colors().text_muted)
- .child("Filter Sort:"),
- )
- .child(
- DropdownMenu::new(
- ElementId::Name("filter-sort-order-dropdown".into()),
- current_filter_sort_text,
- filter_sort_dropdown_menu,
- )
- .trigger_size(ButtonSize::Compact)
- .trigger_tooltip(Tooltip::text(
- "Choose how filter values are sorted in the filter menu",
- )),
- ),
- );
+ let menu = toggle_entry(
+ menu.header("Text Alignment"),
+ "Top",
+ Some("Choose vertical text alignment within cells"),
+ matches!(settings.vertical_alignment, VerticalAlignment::Top),
+ &view_entity,
+ |settings| settings.vertical_alignment = VerticalAlignment::Top,
+ );
+ let menu = toggle_entry(
+ menu,
+ "Center",
+ None,
+ matches!(settings.vertical_alignment, VerticalAlignment::Center),
+ &view_entity,
+ |settings| settings.vertical_alignment = VerticalAlignment::Center,
+ );
- let multiline_enabled = self.settings.multiline_cells_enabled;
- let panel = panel.child({
- let view = view.clone();
- Checkbox::new(
- ElementId::Name("multiline-rows-checkbox".into()),
- if multiline_enabled {
- ToggleState::Selected
- } else {
- ToggleState::Unselected
- },
- )
- .label("Display multiline rows")
- .tooltip(Tooltip::text(
- "When enabled, row height grows to show all content. \
- When disabled, only the first line is visible — hover a cell to see the rest.",
- ))
- .on_click(move |_state, _window, cx| {
- view.update(cx, |this, cx| {
- this.settings.multiline_cells_enabled = !this.settings.multiline_cells_enabled;
- cx.notify();
- });
- })
- });
+ let menu = menu.separator().header("Filter Sort");
+ let menu = toggle_entry(
+ menu,
+ "A-Z, then Count",
+ Some("Choose how filter values are sorted in the filter menu"),
+ settings.filter_sort_order == FilterSortOrder::AlphaThenCount,
+ &view_entity,
+ |settings| settings.filter_sort_order = FilterSortOrder::AlphaThenCount,
+ );
+ let menu = toggle_entry(
+ menu,
+ "Count, then A-Z",
+ None,
+ settings.filter_sort_order == FilterSortOrder::CountThenAlpha,
+ &view_entity,
+ |settings| settings.filter_sort_order = FilterSortOrder::CountThenAlpha,
+ );
- #[cfg(feature = "dev-tools")]
- let panel = panel.child(
- h_flex()
- .gap_2()
- .items_center()
- .child(
- div()
- .text_sm()
- .text_color(cx.theme().colors().text_muted)
- .child("Dev-only:"),
- )
- .child(create_dev_only_popover_menu(cx)),
- );
+ let menu = toggle_entry(
+ menu.separator(),
+ "Display multiline rows",
+ Some(
+ "When enabled, row height grows to show all content. \
+ When disabled, only the first line is visible — hover a cell to see the rest.",
+ ),
+ settings.multiline_cells_enabled,
+ &view_entity,
+ |settings| settings.multiline_cells_enabled = !settings.multiline_cells_enabled,
+ );
- panel.into_any_element()
- }
+ #[cfg(feature = "dev-tools")]
+ let menu = append_dev_only_entries(menu, &view_entity, &settings);
+
+ menu
+ },
+ ))
+ })
}
#[cfg(feature = "dev-tools")]
-fn create_dev_only_popover_menu(
- cx: &mut Context<'_, TabularDataPreviewPane>,
-) -> ui::PopoverMenu<ContextMenu> {
+fn append_dev_only_entries(
+ menu: ContextMenu,
+ view_entity: &Entity<TabularDataPreviewPane>,
+ settings: &TabularDataPreviewSettings,
+) -> ContextMenu {
use crate::settings::RowRenderMechanism;
- use ui::{IconButton, IconName, IconPosition, IconSize, PopoverMenu};
- PopoverMenu::new("debug-options-menu")
- .trigger_with_tooltip(
- IconButton::new("debug-options-trigger", IconName::Settings).icon_size(IconSize::Small),
- Tooltip::text(
- "Dev-only section used for debugging purposes.\nWill be removed on public release of the tabular data preview feature"
- ),
- )
- .menu({
- let view_entity = cx.entity();
- move |window, cx| {
- let view = view_entity.read(cx);
- let settings = view.settings.clone();
- Some(ContextMenu::build(window, cx, |menu, _, _| {
- menu.header("Rendering Mode")
- .toggleable_entry(
- "Variable Height",
- settings.rendering_with == RowRenderMechanism::VariableList,
- IconPosition::Start,
- None,
- {
- let view_entity = view_entity.clone();
- move |_w, cx| {
- view_entity.update(cx, |view, cx| {
- view.settings.rendering_with =
- RowRenderMechanism::VariableList;
- cx.notify();
- })
- }
- },
- )
- .toggleable_entry(
- "Uniform Height",
- settings.rendering_with == RowRenderMechanism::UniformList,
- IconPosition::Start,
- None,
- {
- let view_entity = view_entity.clone();
- move |_w, cx| {
- view_entity.update(cx, |view, cx| {
- view.settings.rendering_with =
- RowRenderMechanism::UniformList;
- cx.notify();
- })
- }
- },
- )
- .separator()
- .toggleable_entry(
- "Show perf metrics",
- settings.show_perf_metrics_overlay,
- IconPosition::Start,
- None,
- {
- let view_entity = view_entity.clone();
- move |_w, cx| {
- view_entity.update(cx, |view, cx| {
- view.settings.show_perf_metrics_overlay =
- !view.settings.show_perf_metrics_overlay;
- cx.notify();
- })
- }
- },
- )
- .toggleable_entry(
- "Show cell positions",
- settings.show_debug_info,
- IconPosition::Start,
- None,
- {
- let view_entity = view_entity.clone();
- move |_, cx| {
- view_entity.update(cx, |view, cx| {
- view.settings.show_debug_info =
- !view.settings.show_debug_info;
- cx.notify();
- })
- }
- },
- )
- }))
- }
- })
+ let menu = menu.separator().header("Dev-only: Rendering Mode");
+ let menu = toggle_entry(
+ menu,
+ "Variable Height",
+ Some(
+ "Dev-only section used for debugging purposes.\n\
+ Will be removed on public release of the tabular data preview feature",
+ ),
+ settings.rendering_with == RowRenderMechanism::VariableList,
+ view_entity,
+ |settings| settings.rendering_with = RowRenderMechanism::VariableList,
+ );
+ let menu = toggle_entry(
+ menu,
+ "Uniform Height",
+ None,
+ settings.rendering_with == RowRenderMechanism::UniformList,
+ view_entity,
+ |settings| settings.rendering_with = RowRenderMechanism::UniformList,
+ );
+
+ let menu = toggle_entry(
+ menu.separator(),
+ "Show perf metrics",
+ None,
+ settings.show_perf_metrics_overlay,
+ view_entity,
+ |settings| settings.show_perf_metrics_overlay = !settings.show_perf_metrics_overlay,
+ );
+ toggle_entry(
+ menu,
+ "Show cell positions",
+ None,
+ settings.show_debug_info,
+ view_entity,
+ |settings| settings.show_debug_info = !settings.show_debug_info,
+ )
}