mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
# Conflicts: # crates/automation/Cargo.toml # crates/automation/src/client.rs # crates/automation/src/control.rs # crates/automation/src/screenshot.rs # crates/automation/src/synthetic.rs # crates/automation/tests/it/main.rs # crates/automation/tests/it/synthetic.rs # crates/color-ui/src/palette.rs # crates/color-ui/src/ui/area.rs # crates/color-ui/src/ui/disc/stories.rs # crates/color-ui/src/ui/mod.rs # crates/color-ui/src/ui/paint_chip.rs # crates/color-ui/src/ui/pair/stories.rs # crates/color-ui/src/ui/palette/stories.rs # crates/color-ui/src/ui/panel.rs # crates/color-ui/src/ui/picker/stories.rs # crates/color-ui/src/ui/picker_dialog.rs # crates/color-ui/src/ui/swatches/library.rs # crates/color-ui/src/ui/swatches/panel.rs # crates/color-ui/src/ui/swatches/stories.rs # crates/color-ui/src/ui/wheel/stories.rs # crates/color-ui/tests/it/main.rs # crates/color-ui/tests/it/panels.rs # crates/color-ui/tests/it/picker.rs # crates/dialogs/src/lib.rs # crates/dialogs/src/native.rs # crates/dialogs/src/portal.rs # crates/dialogs/src/service.rs # crates/draw/src/ui/brush_presets/panel.rs # crates/draw/src/ui/brush_presets/picker.rs # crates/draw/src/ui/brush_presets/stories.rs # crates/draw/src/ui/gradient/palette/mod.rs # crates/draw/src/ui/pattern/editor.rs # crates/draw/src/ui/pen/stories.rs # crates/draw/src/ui/transform/mod.rs # crates/draw/src/ui/transform/transform_box.rs # crates/draw/src/ui/transform/transform_box/stories.rs # crates/draw/src/ui/transform/transform_fields.rs # crates/draw/tests/it/brush_presets.rs # crates/draw/tests/it/main.rs # crates/draw/tests/it/transform_box.rs # crates/font-manager/src/axes.rs # crates/font-manager/src/picker.rs # crates/font-manager/src/picker/rows.rs # crates/font-manager/src/picker/stories.rs # crates/font-manager/tests/it/main.rs # crates/font-manager/tests/it/picker.rs # crates/host/src/files.rs # crates/i18n/src/lib.rs # crates/imaging/src/ui/layer_style/styles.rs # crates/keymap/src/keymap.rs # crates/keymap/src/matcher.rs # crates/layers/src/ui/filter/mod.rs # crates/layers/src/ui/filter/stories.rs # crates/layers/src/ui/mock.rs # crates/layers/src/ui/panel/mod.rs # crates/layers/src/ui/panel/stories.rs # crates/layers/src/ui/tree.rs # crates/layers/tests/it/panel_drag_menu.rs # crates/layers/tests/it/panel_filter.rs # crates/menu/src/bar.rs # crates/menu/src/driver.rs # crates/menu/src/model.rs # crates/menu/src/shortcuts/pages.rs # crates/menu/src/shortcuts/state.rs # crates/menu/src/shortcuts/stories.rs # crates/menu/src/shortcuts/view.rs # crates/menu/tests/it/main.rs # crates/menu/tests/it/native.rs # crates/menu/tests/it/shortcuts/mod.rs # crates/pages/src/ui/mod.rs # crates/pages/src/ui/view.rs # crates/platform/README.md # crates/platform/src/clipboard_tests.rs # crates/platform/src/open.rs # crates/print/src/ui/stories.rs # crates/text/src/ui/character.rs # crates/text/src/ui/character/stories.rs # crates/text/src/ui/find.rs # crates/text/src/ui/find/dialog.rs # crates/text/src/ui/find/stories.rs # crates/text/src/ui/ruler.rs # crates/text/src/ui/ruler/paint.rs # crates/text/src/ui/ruler/run.rs # crates/text/tests/it/main.rs # crates/text/tests/it/ruler.rs # crates/ui-canvas/src/canvas/mod.rs # crates/ui-canvas/src/canvas/tool.rs # crates/ui-canvas/src/canvas/tool_host.rs # crates/ui-canvas/src/canvas_controls/grid/mod.rs # crates/ui-canvas/src/canvas_controls/grid/stories.rs # crates/ui-canvas/src/canvas_controls/guides/stories.rs # crates/ui-canvas/src/canvas_controls/task_bar.rs # crates/ui-canvas/src/canvas_controls/task_bar/stories.rs # crates/ui-canvas/tests/it/canvas/navigate.rs # crates/ui-canvas/tests/it/canvas/rulers.rs # crates/ui-canvas/tests/it/canvas/tool.rs # crates/ui-canvas/tests/it/canvas_controls/grid.rs # crates/ui-contract/src/contract/body/presses.rs # crates/ui-contract/src/contract/items/drag.rs # crates/ui-contract/src/contract/items/hooks.rs # crates/ui-contract/src/contract/items/lead.rs # crates/ui-contract/src/contract/overlay/placement.rs # crates/ui-contract/src/contract/overlay/props.rs # crates/ui-contract/src/contract/overlay/ui.rs # crates/ui-contract/src/contract/steps/label.rs # crates/ui-contract/src/contract/text.rs # crates/ui-contract/src/contract/tooltip.rs # crates/ui-contract/src/layout/body.rs # crates/ui-contract/src/primitives/draw.rs # crates/ui-contract/src/primitives/icon.rs # crates/ui-contract/src/primitives/mod.rs # crates/ui-contract/src/primitives/textures/thumbnails.rs # crates/ui-contract/src/runtime/commands/board.rs # crates/ui-contract/src/runtime/commands/mod.rs # crates/ui-contract/src/runtime/drag.rs # crates/ui-contract/src/runtime/egui/input.rs # crates/ui-contract/src/runtime/egui/plugin.rs # crates/ui-contract/src/runtime/frame.rs # crates/ui-contract/src/runtime/keys.rs # crates/ui-contract/src/runtime/keys/input.rs # crates/ui-contract/src/runtime/keys/route.rs # crates/ui-contract/src/runtime/pointer.rs # crates/ui-contract/src/runtime/wheel.rs # crates/ui-contract/src/runtime/windows.rs # crates/ui-contract/src/runtime/windows/viewport.rs # crates/ui-contract/src/style/cx.rs # crates/ui-contract/src/style/span.rs # crates/ui-contract/src/testing/access.rs # crates/ui-contract/src/testing/icon_trials.rs # crates/ui-contract/tests/it/body/mod.rs # crates/ui-contract/tests/it/runtime/mod.rs # crates/ui-contract/tests/it/runtime/wheel.rs # crates/ui-contract/tests/it/runtime/windows.rs # crates/ui-contract/tests/it/text/editor.rs # crates/ui-gallery/src/mock/panels.rs # crates/ui-panels/src/dialog/mod.rs # crates/ui-panels/src/docking/group.rs # crates/ui-panels/src/rails/drawer/stories.rs # crates/ui-panels/src/rails/tool.rs # crates/ui-panels/src/rails/tool/stories.rs # crates/ui-panels/src/rails/tool/trials.rs # crates/ui-panels/src/sections/footer.rs # crates/ui-panels/tests/it/dialogs.rs # crates/ui-patterns/src/patterns/dock/hide.rs # crates/ui-patterns/src/patterns/dock/panes.rs # crates/ui-patterns/src/patterns/form_dialogs/dialog.rs # crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/list_manager.rs # crates/ui-patterns/src/patterns/form_dialogs/list_manager/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/mod.rs # crates/ui-patterns/src/patterns/form_dialogs/new_document.rs # crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs # crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs # crates/ui-patterns/src/patterns/form_dialogs/param.rs # crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs # crates/ui-patterns/src/patterns/form_dialogs/pdf_export/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/report.rs # crates/ui-patterns/src/patterns/form_dialogs/report/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/rows.rs # crates/ui-patterns/src/patterns/form_dialogs/save_for_web.rs # crates/ui-patterns/src/patterns/form_dialogs/save_for_web/hosted.rs # crates/ui-patterns/src/patterns/form_dialogs/save_for_web/model.rs # crates/ui-patterns/src/patterns/form_dialogs/save_for_web/options.rs # crates/ui-patterns/src/patterns/form_dialogs/save_for_web/stories.rs # crates/ui-patterns/src/patterns/panels/palette.rs # crates/ui-patterns/src/patterns/panels/palette/stories.rs # crates/ui-patterns/src/patterns/preferences/document/model.rs # crates/ui-patterns/src/patterns/preferences/page.rs # crates/ui-patterns/src/patterns/preferences/window.rs # crates/ui-patterns/src/patterns/preferences/window/stories.rs # crates/ui-patterns/src/patterns/presets/browser.rs # crates/ui-patterns/src/patterns/presets/browser/stories.rs # crates/ui-patterns/src/patterns/presets/manager.rs # crates/ui-patterns/src/patterns/presets/mod.rs # crates/ui-patterns/src/patterns/presets/named.rs # crates/ui-patterns/src/patterns/presets/picker.rs # crates/ui-patterns/tests/it/docking/drop_session.rs # crates/ui-patterns/tests/it/docking/native.rs # crates/ui-patterns/tests/it/form_dialogs/hosted.rs # crates/ui-patterns/tests/it/form_dialogs/list_manager.rs # crates/ui-patterns/tests/it/form_dialogs/mod.rs # crates/ui-patterns/tests/it/form_dialogs/params.rs # crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs # crates/ui-patterns/tests/it/panels/palette.rs # crates/ui-patterns/tests/it/presets/browser.rs # crates/ui-shell/src/shell/app_shell.rs # crates/ui-shell/src/shell/app_shell/stories.rs # crates/ui-shell/src/shell/mod.rs # crates/ui-shell/src/shell/start.rs # crates/ui-shell/src/shell/start/stories.rs # crates/ui-shell/tests/it/commands/mod.rs # crates/ui-shell/tests/it/shell/app_shell.rs # crates/ui-shell/tests/it/shell/mod.rs # crates/ui-widgets/src/bars/bar.rs # crates/ui-widgets/src/buttons/button.rs # crates/ui-widgets/src/buttons/face.rs # crates/ui-widgets/src/buttons/mod.rs # crates/ui-widgets/src/buttons/stories.rs # crates/ui-widgets/src/choice/mod.rs # crates/ui-widgets/src/choice/swatch.rs # crates/ui-widgets/src/choice/swatch/stories.rs # crates/ui-widgets/src/choice/swatch_table.rs # crates/ui-widgets/src/choice/swatch_table/stories.rs # crates/ui-widgets/src/display/text.rs # crates/ui-widgets/src/list/row.rs # crates/ui-widgets/src/list/row/paint.rs # crates/ui-widgets/src/list/stories.rs # crates/ui-widgets/src/list/view_stories.rs # crates/ui-widgets/src/menu/bar.rs # crates/ui-widgets/src/menu/item.rs # crates/ui-widgets/src/menu/search.rs # crates/ui-widgets/src/menu/stories.rs # crates/ui-widgets/src/pickers/mod.rs # crates/ui-widgets/src/pickers/reference_point.rs # crates/ui-widgets/src/pickers/reference_point/stories.rs # crates/ui-widgets/src/tabs/strip.rs # crates/ui-widgets/src/text/number.rs # crates/ui-widgets/src/text/number/stories.rs # crates/ui-widgets/src/tile_grid/grid.rs # crates/ui-widgets/tests/it/buttons.rs # crates/ui-widgets/tests/it/label/mod.rs # crates/ui-widgets/tests/it/label/tooltip.rs # crates/ui-widgets/tests/it/main.rs # crates/ui-widgets/tests/it/menu/bar.rs # crates/ui-widgets/tests/it/menu/mod.rs # crates/ui-widgets/tests/it/menu/rows.rs # crates/ui-widgets/tests/it/menu/search.rs # crates/ui-widgets/tests/it/pickers/select_list.rs # crates/ui-widgets/tests/it/text/mod.rs
329 lines
13 KiB
Rust
329 lines
13 KiB
Rust
//! `DocumentTabs`: the tab strip of one document group. Tabs reorder within the strip, drop into another group's
|
|
//! strip through the drag session, and tear off when released over no strip; the host areas at both ends of the strip
|
|
//! are the caller's closures. Files from the OS drop between the tabs when the host takes them.
|
|
|
|
#[cfg(feature = "suite")]
|
|
pub(crate) mod stories;
|
|
|
|
use super::{Tab, TabStrip};
|
|
use crate::contract::{
|
|
CollectionEvent, ContextMenuRequest, DropAt, DropKind, DropPlace, ListDrag, OsFiles, ReorderRule, ShowCollection as _, ShowContainer as _,
|
|
};
|
|
use crate::layout_components::Row;
|
|
use crate::runtime::drag::OsFile;
|
|
use crate::runtime::env::Label;
|
|
use craft_behavior::{EditEvent, SelectionChange, keyed};
|
|
use egui::{Pos2, Response, Ui};
|
|
use std::borrow::Cow;
|
|
use std::hash::Hash;
|
|
|
|
/// A document as its tab shows it.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub struct DocumentTab<D> {
|
|
/// Identifies the document in events.
|
|
pub id: D,
|
|
/// The tab's text.
|
|
pub label: Label,
|
|
/// Unsaved changes: the tab shows the modified mark.
|
|
pub modified: bool,
|
|
/// The tab shows a close button.
|
|
pub closable: bool,
|
|
/// How far the document has opened, between 0 and 1; `None` for a document that is open.
|
|
pub progress: Option<f32>,
|
|
/// A second line of text the tab shows, such as the opening step.
|
|
pub detail: Option<Label>,
|
|
/// The accessible name of the close button, for a tab whose close cancels the opening.
|
|
pub close_label: Option<Label>,
|
|
}
|
|
|
|
impl<D> DocumentTab<D> {
|
|
/// A closable, unmodified tab for document `id` named `label`.
|
|
pub fn new(id: D, label: impl Into<Label>) -> Self {
|
|
DocumentTab { id, label: label.into(), modified: false, closable: true, progress: None, detail: None, close_label: None }
|
|
}
|
|
|
|
/// Unsaved changes.
|
|
#[must_use]
|
|
pub fn modified(mut self, on: bool) -> Self {
|
|
self.modified = on;
|
|
self
|
|
}
|
|
|
|
/// Whether the tab can be closed.
|
|
#[must_use]
|
|
pub fn closable(mut self, on: bool) -> Self {
|
|
self.closable = on;
|
|
self
|
|
}
|
|
|
|
/// How far the document has opened; a tab with progress is a document still opening, and its close cancels.
|
|
#[must_use]
|
|
pub fn progress(mut self, fraction: Option<f32>) -> Self {
|
|
self.progress = fraction;
|
|
self
|
|
}
|
|
|
|
/// A second line of text the tab shows.
|
|
#[must_use]
|
|
pub fn detail(mut self, text: impl Into<Label>) -> Self {
|
|
self.detail = Some(text.into());
|
|
self
|
|
}
|
|
|
|
/// The accessible name of the close button.
|
|
#[must_use]
|
|
pub fn close_label(mut self, label: impl Into<Label>) -> Self {
|
|
self.close_label = Some(label.into());
|
|
self
|
|
}
|
|
}
|
|
|
|
/// What the tabs of a group did this pass, in the order they happened.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub enum DocumentTabsEvent<D> {
|
|
/// The tab was selected: a click, Space or Enter, or a drag of another payload resting over the tab.
|
|
Selected(D),
|
|
/// The tab was activated: Enter, or a double click.
|
|
Activated(D),
|
|
/// The tab's close button was pressed, or the tab was middle-clicked.
|
|
CloseRequested(D),
|
|
/// The tab was picked in the overflow menu: the host shows it.
|
|
Picked(D),
|
|
/// The tabs moved within the strip: now before `before`, or last when `None`.
|
|
#[non_exhaustive]
|
|
Reordered {
|
|
/// The moved documents in display order.
|
|
documents: Vec<D>,
|
|
/// The tab they now sit before.
|
|
before: Option<D>,
|
|
},
|
|
/// Tabs of another group dropped on this strip, on the tab `over`.
|
|
#[non_exhaustive]
|
|
DroppedInto {
|
|
/// The dropped documents in the order they had.
|
|
documents: Vec<D>,
|
|
/// The tab the drop landed on.
|
|
over: D,
|
|
},
|
|
/// The tab was dragged out and released over no strip: float it at `at`.
|
|
#[non_exhaustive]
|
|
TornOff {
|
|
/// The documents the drag carried.
|
|
documents: Vec<D>,
|
|
/// The pointer when the drag was released, in screen points.
|
|
at: Pos2,
|
|
},
|
|
/// The tab's context menu is asked for.
|
|
ContextMenu(ContextMenuRequest<D>),
|
|
/// Files dropped from the operating system on the strip, before the tab `before` (last when `None`).
|
|
#[non_exhaustive]
|
|
FilesDropped {
|
|
/// The dropped files.
|
|
files: Vec<OsFile>,
|
|
/// The tab they go before.
|
|
before: Option<D>,
|
|
},
|
|
/// The strip's empty room after the tabs was double-clicked: the host opens a new document there.
|
|
EmptyDoubleClick,
|
|
}
|
|
|
|
/// What `DocumentTabs::show` returns.
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
#[must_use = "the host applies the group's events"]
|
|
pub struct DocumentTabsOutput<D> {
|
|
/// The strip's response.
|
|
pub response: Response,
|
|
/// What happened, in order.
|
|
pub events: Vec<DocumentTabsEvent<D>>,
|
|
/// The tab under the pointer this pass, also while another component holds the press: the Move tool's transfer reads it.
|
|
pub hovered: Option<D>,
|
|
}
|
|
|
|
type Area<'a> = Box<dyn FnOnce(&mut Ui) + 'a>;
|
|
|
|
/// The tab strip of one document group. Give the strips of all groups the same `accepts` rule (the default takes
|
|
/// every group) and a tab dropped from one reaches the other as `DroppedInto`.
|
|
#[must_use = "show the tabs with `show`"]
|
|
#[derive(crate::contract::Pattern)]
|
|
#[pattern(probe(DocumentTabs<'static, usize>))]
|
|
pub struct DocumentTabs<'a, D: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> {
|
|
label: Label,
|
|
tabs: &'a [DocumentTab<D>],
|
|
selected: Option<D>,
|
|
reorderable: bool,
|
|
tear_off: bool,
|
|
large: bool,
|
|
takes_files: bool,
|
|
leading: Option<Area<'a>>,
|
|
trailing: Option<Area<'a>>,
|
|
}
|
|
|
|
impl<'a, D: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> DocumentTabs<'a, D> {
|
|
/// The tabs of a group named `label`, in the host's order.
|
|
pub fn new(label: impl Into<Label>, tabs: &'a [DocumentTab<D>]) -> Self {
|
|
DocumentTabs {
|
|
label: label.into(),
|
|
tabs,
|
|
selected: None,
|
|
reorderable: false,
|
|
tear_off: false,
|
|
large: false,
|
|
takes_files: false,
|
|
leading: None,
|
|
trailing: None,
|
|
}
|
|
}
|
|
|
|
/// The document the group shows.
|
|
pub fn selected(mut self, document: D) -> Self {
|
|
self.selected = Some(document);
|
|
self
|
|
}
|
|
|
|
/// Tabs reorder by drag and by Cmd+] and Cmd+[ (Ctrl off macOS; Shift to the ends).
|
|
pub fn reorderable(mut self, on: bool) -> Self {
|
|
self.reorderable = on;
|
|
self
|
|
}
|
|
|
|
/// A tab released over no strip is reported as `TornOff`.
|
|
pub fn tear_off(mut self, on: bool) -> Self {
|
|
self.tear_off = on;
|
|
self
|
|
}
|
|
|
|
/// Every tab takes the strip's taller form.
|
|
pub fn large(mut self, on: bool) -> Self {
|
|
self.large = on;
|
|
self
|
|
}
|
|
|
|
/// The strip takes files dragged from the operating system and reports them as `FilesDropped`.
|
|
pub fn takes_files(mut self, on: bool) -> Self {
|
|
self.takes_files = on;
|
|
self
|
|
}
|
|
|
|
/// Host content before the tabs, at the reading start, as wide as it measures.
|
|
pub fn leading(mut self, area: impl FnOnce(&mut Ui) + 'a) -> Self {
|
|
self.leading = Some(Box::new(area));
|
|
self
|
|
}
|
|
|
|
/// Host content after the tabs, at the reading end, as wide as it measures.
|
|
pub fn trailing(mut self, area: impl FnOnce(&mut Ui) + 'a) -> Self {
|
|
self.trailing = Some(Box::new(area));
|
|
self
|
|
}
|
|
|
|
/// Shows the group's strip.
|
|
pub fn show(self, ui: &mut Ui) -> DocumentTabsOutput<D> {
|
|
let DocumentTabs { label, tabs, selected, reorderable, tear_off, leading, trailing, large, takes_files } = self;
|
|
let source = keyed(tabs, |tab: &DocumentTab<D>| tab.id.clone()).with_text(|tab| Cow::Borrowed(tab.label.as_str()));
|
|
let mut strip = TabStrip::new(label).takes_drop(DropKind::new(DropPlace::Between, |_: &ListDrag<D>, _| true));
|
|
if takes_files {
|
|
strip = strip.takes_drop(DropKind::new(DropPlace::Between, |_: &OsFiles, _| true));
|
|
}
|
|
if tear_off {
|
|
strip = strip.tear_off();
|
|
}
|
|
if large {
|
|
strip = strip.large();
|
|
}
|
|
if let Some(document) = selected {
|
|
strip = strip.shown(document);
|
|
}
|
|
if reorderable {
|
|
strip = strip.reorder(ReorderRule::new());
|
|
}
|
|
let hovered = std::cell::RefCell::new(None);
|
|
let show_strip = |ui: &mut Ui, strip: TabStrip<'_, D>| {
|
|
strip.show_items(ui, &source, &mut |key, cx| {
|
|
if cx.row.pointer_over {
|
|
*hovered.borrow_mut() = Some(key.clone());
|
|
}
|
|
let Some(document) = tabs.iter().find(|tab| &tab.id == key) else {
|
|
return Tab::new(Label::default()).closable(false);
|
|
};
|
|
let mut tab = Tab::new(document.label.clone()).closable(document.closable);
|
|
if document.modified {
|
|
tab = tab.modified();
|
|
}
|
|
if let Some(fraction) = document.progress {
|
|
tab = tab.progress(fraction);
|
|
}
|
|
if let Some(detail) = &document.detail {
|
|
tab = tab.detail(detail.clone());
|
|
}
|
|
if let Some(close) = &document.close_label {
|
|
tab = tab.close_label(close.clone());
|
|
}
|
|
tab
|
|
})
|
|
};
|
|
let shown = if leading.is_none() && trailing.is_none() {
|
|
Ok(show_strip(ui, strip))
|
|
} else {
|
|
let (mut strip, mut leading, mut trailing) = (Some(strip), leading, trailing);
|
|
let mut shown = None;
|
|
let row = Row::new().show(ui, |ui, _| {
|
|
if let Some(area) = leading.take() {
|
|
area(ui);
|
|
}
|
|
if let Some(strip) = strip.take() {
|
|
shown = Some(show_strip(ui, strip));
|
|
}
|
|
if let Some(area) = trailing.take() {
|
|
area(ui);
|
|
}
|
|
});
|
|
shown.ok_or(row.output)
|
|
};
|
|
let shown = match shown {
|
|
Ok(shown) => shown,
|
|
Err(response) => return DocumentTabsOutput { response, events: Vec::new(), hovered: None },
|
|
};
|
|
let mut events = Vec::new();
|
|
let response = shown.response.response.clone();
|
|
for event in shown.response.events {
|
|
match event {
|
|
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => {
|
|
events.extend(keys.last().cloned().map(DocumentTabsEvent::Selected))
|
|
}
|
|
CollectionEvent::Activate(key) => events.push(DocumentTabsEvent::Activated(key)),
|
|
CollectionEvent::Reorder(edit) => {
|
|
if let (Some(moved), true) = (edit.value(), matches!(edit, EditEvent::Set { .. } | EditEvent::Commit { .. })) {
|
|
let remaining: Vec<&D> = tabs.iter().map(|tab| &tab.id).filter(|id| !moved.keys.contains(id)).collect();
|
|
events.push(DocumentTabsEvent::Reordered {
|
|
documents: moved.keys.clone(),
|
|
before: remaining.get(moved.to).map(|id| (*id).clone()),
|
|
});
|
|
}
|
|
}
|
|
CollectionEvent::Dropped { at: DropAt::Gap { key, insert, .. }, payload, .. } => {
|
|
// The gap's `key` is the tab under the pointer; `insert` is the display position the files land
|
|
// before, so the tab at `insert` is the one they go before.
|
|
if let Some(files) = payload.get::<OsFiles>() {
|
|
events
|
|
.push(DocumentTabsEvent::FilesDropped { files: files.files.clone(), before: tabs.get(insert).map(|tab| tab.id.clone()) });
|
|
} else if let (Some(drag), Some(over)) = (payload.get::<ListDrag<D>>(), key) {
|
|
events.push(DocumentTabsEvent::DroppedInto { documents: drag.keys.clone(), over });
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
events.extend(shown.closed.into_iter().map(DocumentTabsEvent::CloseRequested));
|
|
events.extend(shown.menu.map(DocumentTabsEvent::ContextMenu));
|
|
events.extend(shown.picked.map(DocumentTabsEvent::Picked));
|
|
events.extend(shown.torn_off.map(|torn| DocumentTabsEvent::TornOff { documents: torn.keys, at: torn.pointer }));
|
|
if shown.empty_double {
|
|
events.push(DocumentTabsEvent::EmptyDoubleClick);
|
|
}
|
|
DocumentTabsOutput { response, events, hovered: hovered.into_inner() }
|
|
}
|
|
}
|