Skip to content

AI-native design editor. Open-source Figma alternative.

feat: follow the tab in front in the menus and tab icons (#1687)

Danila Poyarkov09824d45b2c8
diff --git a/changes/1687/changed.md b/changes/1687/changed.md
new file mode 100644
index 000000000..a2f616f8c
--- /dev/null
+++ b/changes/1687/changed.md
@@ -0,0 +1,2 @@
+- The menus follow the tab in front: on Home and in a New file tab they leave out Object, Text, and Arrange and the items that need a document, and in the desktop app items that cannot act, such as Group with nothing selected, are greyed out, as in Figma.
+- Document tabs show what kind of file they hold, with the pen and sticky note Home uses for designs and boards.
diff --git a/changes/1687/fixed.md b/changes/1687/fixed.md
new file mode 100644
index 000000000..ca0305e9a
--- /dev/null
+++ b/changes/1687/fixed.md
@@ -0,0 +1 @@
+- A design or board saved to disk in the desktop app appears in recent files on Home, as a file opened from disk does.
diff --git a/desktop/AGENTS.md b/desktop/AGENTS.md
index 0d1504612..7fd0bf168 100644
--- a/desktop/AGENTS.md
+++ b/desktop/AGENTS.md
@@ -11,7 +11,8 @@ Check `desktop/Cargo.toml`, `desktop/capabilities/**`, and `desktop/tauri.conf.j
- The Software Update window is a second webview labelled `updater` that loads `updater.html` (`src/updater.ts`), never the editor's `index.html`; its own capability, `desktop/capabilities/updater.json`, grants only checking, installing, restarting, closing, and opening links. It owns no documents, so before a restart or a Windows install it asks the editor window over `updater:restart-request` to run the Quit approval (`src/app/shell/updater/approvals.ts`, `tests/app/shell/updater/session.test.ts`).
- Never click Install in a `tauri dev` build: the updater unpacks the release next to the running binary, which there is `desktop/target/debug`.
- `desktop/generated/menu.json` is produced by `bun run generate:tauri-menu` from `src/app/shell/menu/schema.ts`; do not edit or import it directly.
-- A menu entry with a `feature` in the schema is built only while the frontend names that feature through `set_native_menu_features` (`src/app/shell/menu/features.ts`); every rebuild keeps the check states the menu had (`desktop/src/menu/mod.rs`).
+- A menu or menu entry with a `feature` in the schema is built only while the frontend names that feature through `set_native_menu_features` (`src/app/shell/menu/features.ts`); `document` hides what needs an open document on Home and a New file tab. Every rebuild keeps the check states the menu had (`desktop/src/menu/mod.rs`).
+- Command items are greyed out while their editor command is unavailable: the frontend sends their ids through `set_native_menu_disabled`, which updates the items in place instead of rebuilding (`src/app/shell/menu/editor.ts`).
- Run `bun run generate:icons --target desktop` before direct Cargo checks; native icons are generated, not committed.
- `build_fig_file` performs full `.fig` export on desktop at the level it is given, on a blocking thread, since high levels take seconds; saves that patch an opened archive compress in the web worker (`packages/fig/AGENTS.md`).
- The embedded WebDriver plugin compiles only with the `native-test` Cargo feature and must never be enabled in development or production binaries. Native tests use `bun run test:native` (`tests/AGENTS.md`).
diff --git a/desktop/generated/menu.json b/desktop/generated/menu.json
index 2d39222bd..184a38633 100644
--- a/desktop/generated/menu.json
+++ b/desktop/generated/menu.json
@@ -35,16 +35,19 @@
{
"id": "save",
"label": "Save",
- "accelerator": "CmdOrCtrl+S"
+ "accelerator": "CmdOrCtrl+S",
+ "feature": "document"
},
{
"id": "save-as",
"label": "Save As…",
- "accelerator": "CmdOrCtrl+Shift+S"
+ "accelerator": "CmdOrCtrl+Shift+S",
+ "feature": "document"
},
{
"id": "save-to",
- "label": "Save To…"
+ "label": "Save To…",
+ "feature": "document"
},
{
"id": "save-version",
@@ -64,6 +67,7 @@
"id": "export-selection",
"label": "Export Selection",
"accelerator": "CmdOrCtrl+Shift+E",
+ "feature": "document",
"sub": [
{
"id": "export-png",
@@ -99,7 +103,8 @@
{
"id": "close",
"label": "Close Tab",
- "accelerator": "CmdOrCtrl+W"
+ "accelerator": "CmdOrCtrl+W",
+ "feature": "document"
},
{
"id": "previous-tab",
@@ -127,12 +132,14 @@
{
"id": "edit.undo",
"label": "Undo",
- "accelerator": "CmdOrCtrl+Z"
+ "accelerator": "CmdOrCtrl+Z",
+ "feature": "document"
},
{
"id": "edit.redo",
"label": "Redo",
- "accelerator": "CmdOrCtrl+Shift+Z"
+ "accelerator": "CmdOrCtrl+Shift+Z",
+ "feature": "document"
},
{
"type": "separator"
@@ -155,22 +162,26 @@
{
"id": "paste-to-replace",
"label": "Paste to replace",
- "accelerator": "CmdOrCtrl+Shift+R"
+ "accelerator": "CmdOrCtrl+Shift+R",
+ "feature": "document"
},
{
"id": "selection.duplicate",
"label": "Duplicate",
- "accelerator": "CmdOrCtrl+D"
+ "accelerator": "CmdOrCtrl+D",
+ "feature": "document"
},
{
"id": "selection.delete",
"label": "Delete",
- "accelerator": "Backspace"
+ "accelerator": "Backspace",
+ "feature": "document"
},
{
"id": "selection.rename",
"label": "Rename Selection…",
- "accelerator": "CmdOrCtrl+R"
+ "accelerator": "CmdOrCtrl+R",
+ "feature": "document"
},
{
"type": "separator"
@@ -178,12 +189,14 @@
{
"id": "selection.selectAll",
"label": "Select All",
- "accelerator": "CmdOrCtrl+A"
+ "accelerator": "CmdOrCtrl+A",
+ "feature": "document"
},
{
"id": "selection.selectInverse",
"label": "Select Inverse",
- "accelerator": "CmdOrCtrl+Shift+A"
+ "accelerator": "CmdOrCtrl+Shift+A",
+ "feature": "document"
}
]
},
@@ -193,27 +206,32 @@
{
"id": "view.zoom100",
"label": "Zoom to 100%",
- "accelerator": "CmdOrCtrl+0"
+ "accelerator": "CmdOrCtrl+0",
+ "feature": "document"
},
{
"id": "view.zoomFit",
"label": "Zoom to Fit",
- "accelerator": "Shift+1"
+ "accelerator": "Shift+1",
+ "feature": "document"
},
{
"id": "view.zoomSelection",
"label": "Zoom to Selection",
- "accelerator": "Shift+2"
+ "accelerator": "Shift+2",
+ "feature": "document"
},
{
"id": "zoom-in",
"label": "Zoom In",
- "accelerator": "CmdOrCtrl+="
+ "accelerator": "CmdOrCtrl+=",
+ "feature": "document"
},
{
"id": "zoom-out",
"label": "Zoom Out",
- "accelerator": "CmdOrCtrl+-"
+ "accelerator": "CmdOrCtrl+-",
+ "feature": "document"
},
{
"type": "separator"
@@ -221,40 +239,47 @@
{
"id": "view.zoomPreviousFrame",
"label": "Zoom to Previous Frame",
- "accelerator": "Shift+N"
+ "accelerator": "Shift+N",
+ "feature": "document"
},
{
"id": "view.zoomNextFrame",
"label": "Zoom to Next Frame",
- "accelerator": "N"
+ "accelerator": "N",
+ "feature": "document"
},
{
"id": "view.previousPage",
"label": "Previous Page",
- "accelerator": "PageUp"
+ "accelerator": "PageUp",
+ "feature": "document"
},
{
"id": "view.nextPage",
"label": "Next Page",
- "accelerator": "PageDown"
+ "accelerator": "PageDown",
+ "feature": "document"
},
{
"type": "separator"
},
{
"id": "view-split-right",
- "label": "Split Right"
+ "label": "Split Right",
+ "feature": "document"
},
{
"id": "view-split-down",
- "label": "Split Down"
+ "label": "Split Down",
+ "feature": "document"
},
{
"type": "separator"
},
{
"id": "variables",
- "label": "Variables…"
+ "label": "Variables…",
+ "feature": "document"
},
{
"type": "separator"
@@ -263,30 +288,35 @@
"id": "view-rulers",
"label": "Rulers",
"accelerator": "Shift+R",
- "checkbox": true
+ "checkbox": true,
+ "feature": "document"
},
{
"id": "view-pixel-grid",
"label": "Pixel Grid",
"accelerator": "Shift+'",
- "checkbox": true
+ "checkbox": true,
+ "feature": "document"
},
{
"id": "view-multiplayer-cursors",
"label": "Multiplayer Cursors",
"accelerator": "Alt+CmdOrCtrl+\\",
- "checkbox": true
+ "checkbox": true,
+ "feature": "document"
},
{
"id": "view-design-issues",
"label": "Design Issues",
- "checkbox": true
+ "checkbox": true,
+ "feature": "document"
},
{
"id": "view-comments",
"label": "Comments",
"accelerator": "Shift+C",
- "checkbox": true
+ "checkbox": true,
+ "feature": "document"
},
{
"type": "separator"
@@ -343,12 +373,14 @@
{
"id": "toggle-ui",
"label": "Toggle UI",
- "accelerator": "CmdOrCtrl+\\"
+ "accelerator": "CmdOrCtrl+\\",
+ "feature": "document"
},
{
"id": "toggle-preview",
"label": "Preview",
- "accelerator": "CmdOrCtrl+Alt+Enter"
+ "accelerator": "CmdOrCtrl+Alt+Enter",
+ "feature": "document"
},
{
"type": "separator"
@@ -362,6 +394,7 @@
},
{
"label": "Object",
+ "feature": "document",
"items": [
{
"id": "selection.group",
@@ -513,6 +546,7 @@
},
{
"label": "Text",
+ "feature": "document",
"items": [
{
"id": "text.bold",
@@ -533,6 +567,7 @@
},
{
"label": "Arrange",
+ "feature": "document",
"items": [
{
"id": "selection.wrapInAutoLayout",
diff --git a/desktop/src/lib.rs b/desktop/src/lib.rs
index a9810389c..e9e10dc1b 100644
--- a/desktop/src/lib.rs
+++ b/desktop/src/lib.rs
@@ -16,8 +16,8 @@ use fonts::{list_system_fonts, load_system_font};
use launch::args;
use menu::events::handle_menu_event;
use menu::{
- install_app_menu, native_menu_checked, set_native_menu_checked, set_native_menu_features,
- NativeMenuInputs, NativeMenuState,
+ install_app_menu, native_menu_checked, set_native_menu_checked, set_native_menu_disabled,
+ set_native_menu_features, NativeMenuInputs, NativeMenuState,
};
use network::http::{cancel_http_request, proxy_http_request, ProxyHttpRequests};
use std::sync::Mutex;
@@ -94,6 +94,7 @@ pub fn run() {
cancel_http_request,
files::recent::set_recent_files,
set_native_menu_features,
+ set_native_menu_disabled,
native_menu_checked,
set_native_menu_checked,
launch::take_pending_open,
diff --git a/desktop/src/menu/mod.rs b/desktop/src/menu/mod.rs
index ca04e0c6f..ffe2fe7f8 100644
--- a/desktop/src/menu/mod.rs
+++ b/desktop/src/menu/mod.rs
@@ -1,7 +1,7 @@
pub mod events;
use serde::Deserialize;
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::sync::Mutex;
use tauri::menu::{
@@ -14,6 +14,8 @@ use tauri::menu::PredefinedMenuItem;
#[derive(Deserialize)]
struct MenuGroup {
label: String,
+ /// A feature the frontend turns on before the whole menu shows (`set_native_menu_features`).
+ feature: Option<String>,
items: Vec<MenuEntry>,
}
@@ -32,11 +34,13 @@ struct MenuEntry {
sub: Vec<MenuEntry>,
}
-/// What the schema menu is built from besides the schema: recent files and enabled features.
+/// What the schema menu is built from besides the schema: recent files, enabled features, and
+/// the items whose editor command is unavailable, such as Group with nothing selected.
#[derive(Default)]
pub struct NativeMenuInputs {
pub recent_files: Vec<String>,
pub features: Vec<String>,
+ pub disabled: HashSet<String>,
}
pub struct NativeMenuState(pub Mutex<NativeMenuInputs>);
@@ -73,10 +77,16 @@ fn app_menu_file() -> tauri::Result<AppMenuFile> {
))?)
}
-/// The macOS application menu holds Settings…, so the schema's copy is left out there, along
-/// with a separator it would leave at the end of its menu.
+fn is_separator(entry: &MenuEntry) -> bool {
+ entry.r#type.as_deref() == Some("separator")
+}
+
+/// The entries a menu shows. Items whose feature is off are left out, as is the schema's
+/// Settings… on macOS, where the application menu holds it, along with the separators they
+/// would leave at either end of the menu or next to each other.
fn platform_entries<'a>(items: &'a [MenuEntry], features: &[String]) -> Vec<&'a MenuEntry> {
- let mut entries: Vec<&MenuEntry> = items
+ let mut entries: Vec<&MenuEntry> = Vec::new();
+ for entry in items
.iter()
.filter(|entry| !(cfg!(target_os = "macos") && entry.id.as_deref() == Some("settings")))
.filter(|entry| {
@@ -85,16 +95,22 @@ fn platform_entries<'a>(items: &'a [MenuEntry], features: &[String]) -> Vec<&'a
.as_ref()
.is_none_or(|feature| features.contains(feature))
})
- .collect();
- while entries
- .last()
- .is_some_and(|entry| entry.r#type.as_deref() == Some("separator"))
{
+ if is_separator(entry) && entries.last().is_none_or(|last| is_separator(last)) {
+ continue;
+ }
+ entries.push(entry);
+ }
+ if entries.last().is_some_and(|entry| is_separator(entry)) {
entries.pop();
}
entries
}
+fn item_enabled(entry: &MenuEntry, disabled: &HashSet<String>) -> bool {
+ entry.id.as_ref().is_none_or(|id| !disabled.contains(id))
+}
+
fn build_submenu<R: tauri::Runtime>(
app: &tauri::AppHandle<R>,
label: &str,
@@ -104,7 +120,7 @@ fn build_submenu<R: tauri::Runtime>(
let mut builder = SubmenuBuilder::new(app, label);
for entry in platform_entries(items, &build.inputs.features) {
- if entry.r#type.as_deref() == Some("separator") {
+ if is_separator(entry) {
builder = builder.separator();
continue;
}
@@ -147,7 +163,9 @@ fn build_submenu<R: tauri::Runtime>(
.as_ref()
.and_then(|id| build.checked.get(id).copied())
.unwrap_or(true);
- let mut item = CheckMenuItemBuilder::new(label).checked(checked);
+ let mut item = CheckMenuItemBuilder::new(label)
+ .checked(checked)
+ .enabled(item_enabled(entry, &build.inputs.disabled));
if let Some(id) = &entry.id {
item = item.id(id);
}
@@ -158,7 +176,8 @@ fn build_submenu<R: tauri::Runtime>(
continue;
}
- let mut item = MenuItemBuilder::new(label);
+ let mut item =
+ MenuItemBuilder::new(label).enabled(item_enabled(entry, &build.inputs.disabled));
if let Some(id) = &entry.id {
item = item.id(id);
}
@@ -222,6 +241,12 @@ fn build_schema_menus<R: tauri::Runtime>(
let groups: Vec<MenuGroup> = serde_json::from_str(include_str!("../../generated/menu.json"))?;
groups
.iter()
+ .filter(|group| {
+ group
+ .feature
+ .as_ref()
+ .is_none_or(|feature| build.inputs.features.contains(feature))
+ })
.map(|group| build_submenu(app, &group.label, &group.items, build))
.collect()
}
@@ -400,3 +425,119 @@ pub fn set_native_menu_features<R: tauri::Runtime>(
) -> Result<(), String> {
update_app_menu(&app, |inputs| inputs.features = features)
}
+
+/// Sets the enabled state of the items among `changed`, wherever they sit in the menu.
+fn apply_disabled_changes<R: tauri::Runtime>(
+ items: Vec<MenuItemKind<R>>,
+ disabled: &HashSet<String>,
+ changed: &HashSet<String>,
+) {
+ for item in items {
+ if let MenuItemKind::Submenu(submenu) = &item {
+ if let Ok(children) = submenu.items() {
+ apply_disabled_changes(children, disabled, changed);
+ }
+ continue;
+ }
+ let id = &item.id().0;
+ if !changed.contains(id) {
+ continue;
+ }
+ let enabled = !disabled.contains(id);
+ match &item {
+ MenuItemKind::MenuItem(menu_item) => {
+ let _ = menu_item.set_enabled(enabled);
+ }
+ MenuItemKind::Check(check) => {
+ let _ = check.set_enabled(enabled);
+ }
+ _ => {}
+ }
+ }
+}
+
+/// Greys out the items whose editor command is unavailable and enables the rest. It changes the
+/// items in place, since it follows every selection change; a rebuild keeps the same state.
+#[tauri::command]
+pub fn set_native_menu_disabled<R: tauri::Runtime>(
+ app: tauri::AppHandle<R>,
+ ids: Vec<String>,
+) -> Result<(), String> {
+ let state = tauri::Manager::state::<NativeMenuState>(&app);
+ let mut inputs = state
+ .0
+ .lock()
+ .map_err(|_| "Menu state is unavailable".to_string())?;
+ let previous = std::mem::replace(&mut inputs.disabled, ids.into_iter().collect());
+ let changed: HashSet<String> = previous
+ .symmetric_difference(&inputs.disabled)
+ .cloned()
+ .collect();
+ if changed.is_empty() {
+ return Ok(());
+ }
+ if let Some(items) = editor_menu(&app).and_then(|menu| menu.items().ok()) {
+ apply_disabled_changes(items, &inputs.disabled, &changed);
+ }
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn groups() -> Vec<MenuGroup> {
+ serde_json::from_str(include_str!("../../generated/menu.json")).expect("menu.json")
+ }
+
+ fn shown(group: &MenuGroup, features: &[String]) -> Vec<String> {
+ platform_entries(&group.items, features)
+ .iter()
+ .map(|entry| entry.id.clone().unwrap_or_else(|| "---".into()))
+ .collect()
+ }
+
+ // Home holds no document: the items that need one are gone, and so are the separators they
+ // would leave at the ends of a menu or next to each other.
+ #[test]
+ fn leaves_no_stray_separators_without_a_document() {
+ for group in groups() {
+ let ids = shown(&group, &[]);
+ assert_ne!(
+ ids.first().map(String::as_str),
+ Some("---"),
+ "{}",
+ group.label
+ );
+ assert_ne!(
+ ids.last().map(String::as_str),
+ Some("---"),
+ "{}",
+ group.label
+ );
+ assert!(
+ !ids.windows(2)
+ .any(|pair| pair[0] == "---" && pair[1] == "---"),
+ "{}: {ids:?}",
+ group.label
+ );
+ }
+ }
+
+ #[test]
+ fn hides_document_menus_until_a_document_is_in_front() {
+ let document_menus: Vec<String> = groups()
+ .into_iter()
+ .filter(|group| group.feature.as_deref() == Some("document"))
+ .map(|group| group.label)
+ .collect();
+ assert_eq!(document_menus, ["Object", "Text", "Arrange"]);
+
+ let file = groups()
+ .into_iter()
+ .find(|group| group.label == "File")
+ .expect("File menu");
+ assert!(!shown(&file, &[]).contains(&"save".to_string()));
+ assert!(shown(&file, &["document".to_string()]).contains(&"save".to_string()));
+ }
+}
diff --git a/src/app/document/io/save/actions.ts b/src/app/document/io/save/actions.ts
index a60bd4a06..6bc68eafc 100644
--- a/src/app/document/io/save/actions.ts
+++ b/src/app/document/io/save/actions.ts
@@ -7,6 +7,7 @@ import { documentFileName, documentNameFromFigPath } from '@/app/document/io/nam
import { chooseBrowserFigSaveHandle, chooseTauriFigSavePath } from '@/app/document/io/save/targets'
import type { DocumentSourceAccess } from '@/app/document/io/types'
import { createDocumentWriter } from '@/app/document/io/write'
+import { rememberRecentFile } from '@/app/recent-files'
import { IS_TAURI } from '@/constants'
type SaveDocumentState = EditorState & { documentName: string }
@@ -87,7 +88,11 @@ export function createSaveActions({
setFileHandle(null)
state.documentName = documentNameFromFigPath(path)
const wrote = await writeFile(data, version)
- if (wrote) setSourceIdentity({ handle: null, path })
+ if (wrote) {
+ setSourceIdentity({ handle: null, path })
+ // A file saved to disk is listed on Home like one opened from there.
+ rememberRecentFile(path, state.documentKind)
+ }
startWatchingFile()
return wrote
}
diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.ts
index 9d477077f..7282c4419 100644
--- a/src/app/shell/menu/app-menu.ts
+++ b/src/app/shell/menu/app-menu.ts
@@ -35,6 +35,7 @@ import {
import { appPreferences } from '@/app/settings/preferences/store'
import { createSharedEditorMenuActions } from '@/app/shell/menu/actions/editor'
import { createSelectionMenuActions } from '@/app/shell/menu/actions/selection'
+import { visibleMenuEntries } from '@/app/shell/menu/entry'
import { menuFeatureAvailable } from '@/app/shell/menu/features'
import { createSaveMenuActions } from '@/app/shell/menu/save-actions'
import type {
@@ -344,7 +345,7 @@ export function useAppMenu() {
disabled: disabled(entry),
checked: checked(entry),
onCheckedChange: onCheckedChange(entry),
- sub: entry.sub?.map(buildEntry).filter((item): item is MenuEntry => item !== null)
+ sub: entry.sub ? visibleMenuEntries(entry.sub.map(buildEntry)) : undefined
}
}
@@ -358,7 +359,7 @@ export function useAppMenu() {
return {
label: groupLabel(group),
paletteIcon: group.paletteIcon ? APP_MENU_ICONS[group.paletteIcon] : undefined,
- items: group.items.map(buildEntry).filter((item): item is MenuEntry => item !== null)
+ items: visibleMenuEntries(group.items.map(buildEntry))
}
}
diff --git a/src/app/shell/menu/editor.ts b/src/app/shell/menu/editor.ts
index 8def1a8f9..04a6c16ef 100644
--- a/src/app/shell/menu/editor.ts
+++ b/src/app/shell/menu/editor.ts
@@ -1,4 +1,11 @@
-import { useEditorCommands, type EditorCommandId } from '@open-pencil/vue/editor/commands'
+import { invoke } from '@tauri-apps/api/core'
+import { computed, watch } from 'vue'
+
+import {
+ useEditorCommands,
+ type EditorCommand,
+ type EditorCommandId
+} from '@open-pencil/vue/editor/commands'
import { useEditorStore } from '@/app/editor/active-store'
import { clearRecentFiles, forgetRecentFile, recentLocalFileAt } from '@/app/recent-files'
@@ -28,6 +35,30 @@ const COMMAND_MENU_IDS = new Set<EditorCommandId>(
APP_MENU_SCHEMA.flatMap((group) => commandMenuIds(group.items))
)
+/**
+ * Greys out the desktop menu's command items while their command is unavailable, such as Group
+ * with nothing selected, as the browser menu does. Item ids are their command ids.
+ */
+function watchNativeMenuDisabled(commands: Record<EditorCommandId, EditorCommand>) {
+ // A joined key, so the watcher fires when the set changes rather than on every recompute.
+ const disabled = computed(() =>
+ [...COMMAND_MENU_IDS]
+ .filter((id) => !commands[id].enabled.value)
+ .sort()
+ .join('\n')
+ )
+ watch(
+ disabled,
+ (key) => {
+ const ids = key ? key.split('\n') : []
+ invoke('set_native_menu_disabled', { ids }).catch((error: unknown) => {
+ console.warn('[Menu] Failed to update the native menu', error)
+ })
+ },
+ { immediate: true }
+ )
+}
+
export function useEditorMenu() {
if (!isTauri()) return
@@ -35,7 +66,8 @@ export function useEditorMenu() {
watchNativeMenuFeatures()
const { setTheme } = useAppTheme()
- const { runCommand } = useEditorCommands()
+ const { commands, runCommand } = useEditorCommands()
+ watchNativeMenuDisabled(commands)
const actions: Partial<Record<string, () => void>> = {
new: () => createTab(),
diff --git a/src/app/shell/menu/entry.ts b/src/app/shell/menu/entry.ts
index 8d79577af..6112c644e 100644
--- a/src/app/shell/menu/entry.ts
+++ b/src/app/shell/menu/entry.ts
@@ -8,6 +8,23 @@ export function isMenuAction(entry: MenuEntry): entry is MenuActionNode {
return !isMenuSeparator(entry)
}
+/**
+ * The entries a menu shows, without the separators that hidden items leave at its ends or next
+ * to each other, as on Home, where the document's items are gone.
+ */
+export function visibleMenuEntries(entries: readonly (MenuEntry | null)[]): MenuEntry[] {
+ const result: MenuEntry[] = []
+ for (const entry of entries) {
+ if (entry === null) continue
+ const previous = result.at(-1)
+ if (isMenuSeparator(entry) && (previous === undefined || isMenuSeparator(previous))) continue
+ result.push(entry)
+ }
+ const last = result.at(-1)
+ if (last !== undefined && isMenuSeparator(last)) result.pop()
+ return result
+}
+
export function menuLabel(entry: MenuEntry) {
return isMenuAction(entry) ? entry.label : ''
}
diff --git a/src/app/shell/menu/features.ts b/src/app/shell/menu/features.ts
index a2e08cfba..f530f21be 100644
--- a/src/app/shell/menu/features.ts
+++ b/src/app/shell/menu/features.ts
@@ -3,6 +3,7 @@ import { computed, watch } from 'vue'
import { isCloudBinding } from '@/app/cloud/integration'
import { useEditorStore } from '@/app/editor/active-store'
+import { showsDocument } from '@/app/tabs'
import { isTauri } from '@/app/tauri/env'
import type { AppMenuFeature } from './schema'
@@ -10,6 +11,8 @@ import type { AppMenuFeature } from './schema'
const store = useEditorStore()
const available: Record<AppMenuFeature, () => boolean> = {
+ // Home and a New file tab hold no document, so they leave out what edits or shows one.
+ document: () => showsDocument(),
// Cloud and storage documents always save; auto-save is a choice only for a file on disk.
'local-file': () => store.hasWritableSource() && !store.getStorageBinding(),
// Version history lives on the Cloud server that keeps the document.
diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema/index.ts
similarity index 82%
rename from src/app/shell/menu/schema.ts
rename to src/app/shell/menu/schema/index.ts
index 7278836bf..60b1848d0 100644
--- a/src/app/shell/menu/schema.ts
+++ b/src/app/shell/menu/schema/index.ts
@@ -1,71 +1,17 @@
-import type { EditorCommandId } from '@open-pencil/vue/editor/commands'
+import type { AppMenuActionItem, AppMenuGroupSchema } from './types'
-export type AppMenuTarget = 'all' | 'browser' | 'native'
-
-export type AppMenuIcon =
- | 'download'
- | 'eye'
- | 'file'
- | 'folder-open'
- | 'layers'
- | 'pencil'
- | 'redo'
- | 'save'
- | 'settings'
- | 'type'
- | 'variables'
- | 'undo'
- | 'zoom-in'
- | 'zoom-out'
-
-export type AppMenuPaletteLabel =
- | 'exportSelectionAsPNG'
- | 'exportSelectionAsSVG'
- | 'exportSelectionAsPPTX'
- | 'exportSelectionAsDrawIO'
- | 'exportSelectionAsFig'
-
-export interface AppMenuPaletteMetadata {
- icon?: AppMenuIcon
- label?: AppMenuPaletteLabel
- description?: string
- keywords?: string[]
-}
-
-export type AppMenuHandler = 'editor' | 'shell'
-
-/** A feature an item waits for: it shows only while the feature is available (`./features`). */
-/** Items shown only for a document backed by a file on disk. */
-export type AppMenuFeature = 'local-file' | 'cloud-document'
-
-export interface AppMenuActionItem {
- type?: 'item'
- id: string
- label: string
- shortcut?: string
- accelerator?: string
- command?: EditorCommandId
- checkbox?: boolean
- target?: AppMenuTarget
- handler?: AppMenuHandler
- feature?: AppMenuFeature
- palette?: AppMenuPaletteMetadata
- sub?: AppMenuEntry[]
-}
-
-export interface AppMenuSeparatorItem {
- type: 'separator'
- target?: AppMenuTarget
-}
-
-export type AppMenuEntry = AppMenuActionItem | AppMenuSeparatorItem
-
-export interface AppMenuGroupSchema {
- label: string
- target?: AppMenuTarget
- paletteIcon?: AppMenuIcon
- items: AppMenuEntry[]
-}
+export type {
+ AppMenuTarget,
+ AppMenuIcon,
+ AppMenuPaletteLabel,
+ AppMenuPaletteMetadata,
+ AppMenuHandler,
+ AppMenuFeature,
+ AppMenuActionItem,
+ AppMenuSeparatorItem,
+ AppMenuEntry,
+ AppMenuGroupSchema
+} from './types'
/** Settings…, where each platform expects it: the macOS application menu, otherwise File. */
const SETTINGS_MENU_ITEM = {
@@ -92,9 +38,9 @@ export const APP_MENU_SCHEMA = [
palette: { keywords: ['log', 'report', 'bug', 'problem', 'troubleshoot'] }
},
{ type: 'separator' },
- { id: 'save', label: 'Save', shortcut: 'MOD+S' },
- { id: 'save-as', label: 'Save As…', shortcut: 'MOD+SHIFT+S' },
- { id: 'save-to', label: 'Save To…' },
+ { id: 'save', feature: 'document', label: 'Save', shortcut: 'MOD+S' },
+ { id: 'save-as', feature: 'document', label: 'Save As…', shortcut: 'MOD+SHIFT+S' },
+ { id: 'save-to', feature: 'document', label: 'Save To…' },
{
id: 'save-version',
label: 'Save to Version History…',
@@ -105,6 +51,7 @@ export const APP_MENU_SCHEMA = [
{ type: 'separator' },
{
id: 'export-selection',
+ feature: 'document',
label: 'Export Selection',
palette: { icon: 'download' },
shortcut: 'MOD+SHIFT+E',
@@ -138,7 +85,7 @@ export const APP_MENU_SCHEMA = [
},
{ type: 'separator' },
{ id: 'autosave', label: 'Autosave', checkbox: true, feature: 'local-file' },
- { id: 'close', label: 'Close Tab', shortcut: 'MOD+W' },
+ { id: 'close', feature: 'document', label: 'Close Tab', shortcut: 'MOD+W' },
// ⌃Tab on every platform, as in Figma's desktop app, so it is not a MOD shortcut.
{ id: 'previous-tab', label: 'Select Previous Tab', accelerator: 'Ctrl+Shift+Tab' },
{ id: 'next-tab', label: 'Select Next Tab', accelerator: 'Ctrl+Tab' },
@@ -153,11 +100,13 @@ export const APP_MENU_SCHEMA = [
items: [
{
id: 'edit.undo',
+ feature: 'document',
label: 'Undo',
command: 'edit.undo'
},
{
id: 'edit.redo',
+ feature: 'document',
label: 'Redo',
command: 'edit.redo'
},
@@ -165,26 +114,40 @@ export const APP_MENU_SCHEMA = [
{ id: 'copy', label: 'Copy', shortcut: 'MOD+C' },
{ id: 'cut', label: 'Cut', shortcut: 'MOD+X' },
{ id: 'paste', label: 'Paste', shortcut: 'MOD+V' },
- { id: 'paste-to-replace', label: 'Paste to replace', shortcut: 'MOD+SHIFT+R' },
+ {
+ id: 'paste-to-replace',
+ feature: 'document',
+ label: 'Paste to replace',
+ shortcut: 'MOD+SHIFT+R'
+ },
{
id: 'selection.duplicate',
+ feature: 'document',
label: 'Duplicate',
command: 'selection.duplicate'
},
{
id: 'selection.delete',
+ feature: 'document',
label: 'Delete',
command: 'selection.delete'
},
- { id: 'selection.rename', label: 'Rename Selection…', shortcut: 'MOD+R' },
+ {
+ id: 'selection.rename',
+ feature: 'document',
+ label: 'Rename Selection…',
+ shortcut: 'MOD+R'
+ },
{ type: 'separator' },
{
id: 'selection.selectAll',
+ feature: 'document',
label: 'Select All',
command: 'selection.selectAll'
},
{
id: 'selection.selectInverse',
+ feature: 'document',
label: 'Select Inverse',
command: 'selection.selectInverse'
}
@@ -196,36 +159,51 @@ export const APP_MENU_SCHEMA = [
items: [
{
id: 'view.zoom100',
+ feature: 'document',
label: 'Zoom to 100%',
command: 'view.zoom100'
},
{
id: 'view.zoomFit',
+ feature: 'document',
label: 'Zoom to Fit',
command: 'view.zoomFit'
},
{
id: 'view.zoomSelection',
+ feature: 'document',
label: 'Zoom to Selection',
command: 'view.zoomSelection'
},
- { id: 'zoom-in', label: 'Zoom In', shortcut: 'MOD+=' },
- { id: 'zoom-out', label: 'Zoom Out', shortcut: 'MOD+-' },
+ { id: 'zoom-in', feature: 'document', label: 'Zoom In', shortcut: 'MOD+=' },
+ { id: 'zoom-out', feature: 'document', label: 'Zoom Out', shortcut: 'MOD+-' },
{ type: 'separator' },
{
id: 'view.zoomPreviousFrame',
+ feature: 'document',
label: 'Zoom to Previous Frame',
command: 'view.zoomPreviousFrame'
},
- { id: 'view.zoomNextFrame', label: 'Zoom to Next Frame', command: 'view.zoomNextFrame' },
- { id: 'view.previousPage', label: 'Previous Page', command: 'view.previousPage' },
- { id: 'view.nextPage', label: 'Next Page', command: 'view.nextPage' },
+ {
+ id: 'view.zoomNextFrame',
+ feature: 'document',
+ label: 'Zoom to Next Frame',
+ command: 'view.zoomNextFrame'
+ },
+ {
+ id: 'view.previousPage',
+ feature: 'document',
+ label: 'Previous Page',
+ command: 'view.previousPage'
+ },
+ { id: 'view.nextPage', feature: 'document', label: 'Next Page', command: 'view.nextPage' },
{ type: 'separator' },
- { id: 'view-split-right', label: 'Split Right' },
- { id: 'view-split-down', label: 'Split Down' },
+ { id: 'view-split-right', feature: 'document', label: 'Split Right' },
+ { id: 'view-split-down', feature: 'document', label: 'Split Down' },
{ type: 'separator' },
{
id: 'variables',
+ feature: 'document',
label: 'Variables…',
palette: {
icon: 'variables',
@@ -233,17 +211,42 @@ export const APP_MENU_SCHEMA = [
}
},
{ type: 'separator' },
- { id: 'view-rulers', label: 'Rulers', checkbox: true, shortcut: 'SHIFT+R' },
+ {
+ id: 'view-rulers',
+ feature: 'document',
+ label: 'Rulers',
+ checkbox: true,
+ shortcut: 'SHIFT+R'
+ },
// Figma's View › Pixel grid, shown once zoomed in far enough.
- { id: 'view-pixel-grid', label: 'Pixel Grid', checkbox: true, shortcut: "SHIFT+'" },
+ {
+ id: 'view-pixel-grid',
+ feature: 'document',
+ label: 'Pixel Grid',
+ checkbox: true,
+ shortcut: "SHIFT+'"
+ },
{
id: 'view-multiplayer-cursors',
+ feature: 'document',
label: 'Multiplayer Cursors',
checkbox: true,
shortcut: 'ALT+MOD+\\'
},
- { id: 'view-design-issues', label: 'Design Issues', checkbox: true, handler: 'shell' },
- { id: 'view-comments', label: 'Comments', checkbox: true, shortcut: 'SHIFT+C' },
+ {
+ id: 'view-design-issues',
+ feature: 'document',
+ label: 'Design Issues',
+ checkbox: true,
+ handler: 'shell'
+ },
+ {
+ id: 'view-comments',
+ feature: 'document',
+ label: 'Comments',
+ checkbox: true,
+ shortcut: 'SHIFT+C'
+ },
{ type: 'separator' },
{
id: 'theme',
@@ -282,8 +285,8 @@ export const APP_MENU_SCHEMA = [
]
},
{ type: 'separator' },
- { id: 'toggle-ui', label: 'Toggle UI', shortcut: 'MOD+\\' },
- { id: 'toggle-preview', label: 'Preview', shortcut: 'MOD+ALT+↩' },
+ { id: 'toggle-ui', feature: 'document', label: 'Toggle UI', shortcut: 'MOD+\\' },
+ { id: 'toggle-preview', feature: 'document', label: 'Preview', shortcut: 'MOD+ALT+↩' },
{ type: 'separator' },
{ id: 'profiler', label: 'Profiler', checkbox: true, target: 'browser' },
{
@@ -296,6 +299,7 @@ export const APP_MENU_SCHEMA = [
},
{
label: 'Object',
+ feature: 'document',
paletteIcon: 'layers',
items: [
{
@@ -449,6 +453,7 @@ export const APP_MENU_SCHEMA = [
},
{
label: 'Text',
+ feature: 'document',
paletteIcon: 'type',
items: [
{ id: 'text.bold', label: 'Bold', shortcut: 'MOD+B' },
@@ -458,6 +463,7 @@ export const APP_MENU_SCHEMA = [
},
{
label: 'Arrange',
+ feature: 'document',
paletteIcon: 'layers',
items: [
{
diff --git a/src/app/shell/menu/schema/types.ts b/src/app/shell/menu/schema/types.ts
new file mode 100644
index 000000000..09b115649
--- /dev/null
+++ b/src/app/shell/menu/schema/types.ts
@@ -0,0 +1,73 @@
+import type { EditorCommandId } from '@open-pencil/vue/editor/commands'
+
+export type AppMenuTarget = 'all' | 'browser' | 'native'
+
+export type AppMenuIcon =
+ | 'download'
+ | 'eye'
+ | 'file'
+ | 'folder-open'
+ | 'layers'
+ | 'pencil'
+ | 'redo'
+ | 'save'
+ | 'settings'
+ | 'type'
+ | 'variables'
+ | 'undo'
+ | 'zoom-in'
+ | 'zoom-out'
+
+export type AppMenuPaletteLabel =
+ | 'exportSelectionAsPNG'
+ | 'exportSelectionAsSVG'
+ | 'exportSelectionAsPPTX'
+ | 'exportSelectionAsDrawIO'
+ | 'exportSelectionAsFig'
+
+export interface AppMenuPaletteMetadata {
+ icon?: AppMenuIcon
+ label?: AppMenuPaletteLabel
+ description?: string
+ keywords?: string[]
+}
+
+export type AppMenuHandler = 'editor' | 'shell'
+
+/**
+ * A feature an item or a whole menu waits for: it shows only while the feature is available
+ * (`./features`). `document`: the tab in front holds a document, not Home or a New file tab;
+ * `local-file`: that document is backed by a file on disk; `cloud-document`: it is kept by a
+ * Cloud server.
+ */
+export type AppMenuFeature = 'document' | 'local-file' | 'cloud-document'
+
+export interface AppMenuActionItem {
+ type?: 'item'
+ id: string
+ label: string
+ shortcut?: string
+ accelerator?: string
+ command?: EditorCommandId
+ checkbox?: boolean
+ target?: AppMenuTarget
+ handler?: AppMenuHandler
+ feature?: AppMenuFeature
+ palette?: AppMenuPaletteMetadata
+ sub?: AppMenuEntry[]
+}
+
+export interface AppMenuSeparatorItem {
+ type: 'separator'
+ target?: AppMenuTarget
+}
+
+export type AppMenuEntry = AppMenuActionItem | AppMenuSeparatorItem
+
+export interface AppMenuGroupSchema {
+ label: string
+ target?: AppMenuTarget
+ feature?: AppMenuFeature
+ paletteIcon?: AppMenuIcon
+ items: AppMenuEntry[]
+}
diff --git a/src/app/tabs/index.ts b/src/app/tabs/index.ts
index 11ab2cfa9..9b8f368d6 100644
--- a/src/app/tabs/index.ts
+++ b/src/app/tabs/index.ts
@@ -88,6 +88,8 @@ export const allTabs = computed(() =>
isHome: t.kind === 'home',
isNewFile: t.kind === 'new-file',
isDirty: t.kind === 'document' && t.store.hasUnsavedChanges(),
+ // What kind of file the tab holds, for its icon, as Home marks its files.
+ fileKind: t.kind === 'document' ? t.store.state.documentKind : undefined,
isPreparing: t.store.state.preparation !== null,
preparationProgress: t.store.state.preparation?.progress ?? null,
isActive: t.id === activeTabId.value
diff --git a/src/components/TabBar.vue b/src/components/TabBar.vue
index d4dc12230..366fa4686 100644
--- a/src/components/TabBar.vue
+++ b/src/components/TabBar.vue
@@ -7,6 +7,7 @@ import { useI18n } from '@open-pencil/vue/i18n'
import { animationsEnabled } from '@/app/shell/motion'
import { openNewFileTab, useTabsStore } from '@/app/tabs'
+import { DOCUMENT_KIND_ICONS } from '@/components/document/kinds'
import PreparationIndicator from '@/components/preparation/tab/PreparationIndicator.vue'
import { useScrollOverflow } from '@/components/ui/list/useScrollOverflow'
import Tip from '@/components/ui/overlay/Tip.vue'
@@ -99,6 +100,11 @@ function onClose(e: MouseEvent, tabId: string) {
>
<icon-lucide-house v-if="tab.isHome" :class="baseStyles.icon()" />
<PreparationIndicator v-else-if="tab.isPreparing" :progress="tab.preparationProgress" />
+ <component
+ :is="DOCUMENT_KIND_ICONS[tab.fileKind]"
+ v-else-if="tab.fileKind"
+ :class="baseStyles.icon()"
+ />
<icon-lucide-file v-else :class="baseStyles.icon()" />
<span v-if="!tab.isHome" :class="baseStyles.label()">{{
tab.isNewFile ? files.newFile : tab.name
diff --git a/src/components/home/document/kinds.ts b/src/components/document/kinds.ts
similarity index 73%
rename from src/components/home/document/kinds.ts
rename to src/components/document/kinds.ts
index 45bf980a6..8021cc153 100644
--- a/src/components/home/document/kinds.ts
+++ b/src/components/document/kinds.ts
@@ -3,7 +3,10 @@ import IconLucideStickyNote from '~icons/lucide/sticky-note'
import type { DocumentKind } from '@open-pencil/scene-graph'
-/** The icon each kind of document shows, on Home's create buttons and before its files' names. */
+/**
+ * The icon each kind of document shows: on Home's create buttons, before its files' names, and on
+ * its tab.
+ */
export const DOCUMENT_KIND_ICONS = {
design: IconLucidePenTool,
board: IconLucideStickyNote
diff --git a/src/components/home/document/DocumentEntry.vue b/src/components/home/document/DocumentEntry.vue
index 6181ca38b..e75d1299d 100644
--- a/src/components/home/document/DocumentEntry.vue
+++ b/src/components/home/document/DocumentEntry.vue
@@ -17,7 +17,7 @@ import { computed, normalizeClass, type HTMLAttributes } from 'vue'
import type { DocumentKind } from '@open-pencil/scene-graph'
import { useI18n } from '@open-pencil/vue/i18n'
-import { DOCUMENT_KIND_ICONS } from '@/components/home/document/kinds'
+import { DOCUMENT_KIND_ICONS } from '@/components/document/kinds'
import { useMenuUI } from '@/components/ui/menu/menu'
import MenuScrollArea from '@/components/ui/menu/MenuScrollArea.vue'
import iconButtonTheme from '@/theme/button/icon-button'
diff --git a/src/components/home/search/HomeSearchActions.vue b/src/components/home/search/HomeSearchActions.vue
index 8e8b02fd6..73df725da 100644
--- a/src/components/home/search/HomeSearchActions.vue
+++ b/src/components/home/search/HomeSearchActions.vue
@@ -8,7 +8,7 @@ import { useI18n } from '@open-pencil/vue/i18n'
import { openFileDialog } from '@/app/shell/menu/use'
import { activeTab } from '@/app/tabs'
-import { DOCUMENT_KIND_ICONS } from '@/components/home/document/kinds'
+import { DOCUMENT_KIND_ICONS } from '@/components/document/kinds'
import AppButton from '@/components/ui/button/AppButton.vue'
import AppInput from '@/components/ui/input/AppInput.vue'
import Tip from '@/components/ui/overlay/Tip.vue'
diff --git a/tests/app/shell/menu/entry.test.ts b/tests/app/shell/menu/entry.test.ts
new file mode 100644
index 000000000..da91b6fef
--- /dev/null
+++ b/tests/app/shell/menu/entry.test.ts
@@ -0,0 +1,28 @@
+import { expect, test } from 'bun:test'
+
+import type { MenuEntry } from '@open-pencil/vue/editor/menu-model'
+
+import { visibleMenuEntries } from '@/app/shell/menu/entry'
+
+const separator: MenuEntry = { separator: true }
+const item = (label: string): MenuEntry => ({ label })
+
+test('drops the separators hidden items leave at the ends and next to each other', () => {
+ expect(
+ visibleMenuEntries([
+ separator,
+ null,
+ item('New'),
+ separator,
+ null,
+ separator,
+ item('Settings'),
+ separator,
+ null
+ ])
+ ).toEqual([item('New'), separator, item('Settings')])
+})
+
+test('leaves a menu of only separators empty', () => {
+ expect(visibleMenuEntries([separator, null, separator])).toEqual([])
+})
diff --git a/tests/engine/app/shell/menu/schema.test.ts b/tests/engine/app/shell/menu/schema.test.ts
index ff3c35ff1..9db2dbdf7 100644
--- a/tests/engine/app/shell/menu/schema.test.ts
+++ b/tests/engine/app/shell/menu/schema.test.ts
@@ -84,6 +84,35 @@ describe('APP_MENU_SCHEMA', () => {
)
})
+ // Home and a New file tab hold no document: the menus keep what starts, opens, and switches
+ // documents, and the app's own settings, and leave out what edits or shows one.
+ test('shows only document-free menus and items while no document is in front', () => {
+ const shownIds = (items: readonly AppMenuEntry[]) =>
+ items.flatMap((entry) =>
+ entry.type === 'separator' || entry.feature === 'document' ? [] : [entry.id]
+ )
+ const shown = new Map(
+ APP_MENU_SCHEMA.filter((group) => group.feature !== 'document').map((group) => [
+ group.label,
+ shownIds(group.items)
+ ])
+ )
+
+ expect([...shown.keys()]).toEqual(['File', 'Edit', 'View'])
+ expect(shown.get('File')).toEqual(expect.arrayContaining(['new', 'open', 'settings']))
+ expect(shown.get('Edit')).toEqual(expect.arrayContaining(['copy', 'cut', 'paste']))
+ const shownAnywhere = [...shown.values()].flat()
+ for (const id of [
+ 'save',
+ 'export-selection',
+ 'edit.undo',
+ 'selection.selectAll',
+ 'view.zoomFit'
+ ]) {
+ expect(shownAnywhere).not.toContain(id)
+ }
+ })
+
test('keeps move-to-page destination selection in the browser menu', () => {
const objectMenu = APP_MENU_SCHEMA.find((group) => group.label === 'Object')
const entries = objectMenu ? actionItems(objectMenu.items) : []
diff --git a/tools/generate/tauri-menu/src/menu.ts b/tools/generate/tauri-menu/src/menu.ts
index 91aefc234..5c18b5d20 100644
--- a/tools/generate/tauri-menu/src/menu.ts
+++ b/tools/generate/tauri-menu/src/menu.ts
@@ -36,6 +36,7 @@ function cleanGroup(group: AppMenuGroupSchema): unknown | null {
if (!isNativeVisible(group)) return null
return {
label: group.label,
+ feature: group.feature,
items: compact(group.items.map(cleanEntry))
}
}