Files
RuneStone/src/lib/layout/WorkbenchHeader.svelte
T
Knotty Wyvern c8cf56b224 Keep global actions visible and follow each platform's title bar
Phase 5-4.

- The workspace button sits at the left end of the header. It shows
  the workspace name and opens the workspace list below it.
- The left ribbon is always present: plugin views at the top, Help and
  Settings at the bottom. The left pane footer is gone.
- Tabs keep 120 pixels and scroll. Fades show tabs out of view, and a
  list button names all tabs, with pinned and unsaved marks. The
  active tab now scrolls into view with its close button.
- A drag area of 120 pixels follows the tabs. In a narrow header, the
  tabs shrink first, and the drag area keeps at least 48 pixels.
- Caption buttons are square, 46 pixels wide, and full height. When the
  pointer rests on maximize, the new window_snap_layouts command opens
  Snap Layouts with Win+Z for the focused window.
- macOS keeps its native traffic lights: tauri.macos.conf.json and the
  runtime window builders use an overlay title bar. Title bars leave
  --rs-titlebar-inset-start free for the traffic lights.
- 3 new catalog rows and 1 removed row, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-050, the user guide, and ui-design.md.

Tests: the new layout/titleBar. Tests that used the left pane footer,
the rounded caption buttons, the 600-pixel theme editor pane, or a
ribbon of no width now follow the new layout.
2026-10-28 20:21:20 -07:00

176 lines
7.4 KiB
Svelte

<script lang="ts">
// The workbench header: the workspace button, the side pane buttons, the working tabs, the actions, and the window controls.
import type { ComponentProps } from "svelte";
import { t } from "$lib/i18n";
import Icon from "$lib/ui/Icon.svelte";
import IconButton from "$lib/ui/IconButton.svelte";
import { attachTooltip } from "$lib/ui/tooltip";
import WindowControls from "$lib/ui/WindowControls.svelte";
import PluginTools from "$lib/plugins/PluginTools.svelte";
import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte";
import { openPluginView, pluginSidebar } from "$lib/plugins/external";
import TabBar from "./TabBar.svelte";
import { commandShortcut } from "./workbenchKeys";
type LeftView = "files" | "search" | "bookmarks";
type Props = {
detached: boolean;
desktop: boolean;
workspaceName: string | null;
workspaceAnchor?: HTMLButtonElement;
onChooseWorkspace: () => void;
leftOpen: boolean;
leftView: LeftView;
sidebarNavigation: { owner: string; id: string; title: string; icon?: string }[];
onSelectLeft: (view: LeftView) => void;
tabBar: ComponentProps<typeof TabBar>;
onNewTab: () => void;
canOpenBrowser: boolean;
browserOpening: boolean;
onOpenBrowser: () => void;
saveDisabled: boolean;
onSave: () => void;
terminalEnabled: boolean;
terminalOpen: boolean;
onToggleTerminal: () => void;
rightOpen: boolean;
onToggleRight: () => void;
onError: (message: string) => void;
};
let { detached, desktop, workspaceName, workspaceAnchor = $bindable(), onChooseWorkspace, leftOpen, leftView, sidebarNavigation, onSelectLeft, tabBar, onNewTab, canOpenBrowser, browserOpening, onOpenBrowser,
saveDisabled, onSave, terminalEnabled, terminalOpen, onToggleTerminal, rightOpen, onToggleRight, onError }: Props = $props();
function tooltip(node: HTMLElement, text: string) {
let current = text;
const dispose = attachTooltip(node, () => current);
return { update(value: string) { current = value; }, destroy: dispose };
}
</script>
<header class="header" data-tauri-drag-region>
<div class="header-left" data-tauri-drag-region>
{#if !detached}
<!-- The workspace button names the window and opens the workspace list. -->
<button class="workspace-button" bind:this={workspaceAnchor} onclick={onChooseWorkspace}
use:tooltip={$t("Open folder ({shortcut})", { shortcut: commandShortcut("open-workspace") })}>
<Icon icon="folder-open" /><span class="ws">{workspaceName ?? $t("Open folder")}</span><Icon icon="chevron-down" />
</button>
<IconButton icon="files" label={$t("Files")} active={leftOpen && !$pluginSidebar && leftView === "files"} onclick={() => onSelectLeft("files")} />
<IconButton icon="search" label={$t("Search")} active={leftOpen && !$pluginSidebar && leftView === "search"} onclick={() => onSelectLeft("search")} />
<IconButton icon="bookmark" label={$t("Bookmarks")} active={leftOpen && !$pluginSidebar && leftView === "bookmarks"} onclick={() => onSelectLeft("bookmarks")} />
{#each sidebarNavigation as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" || item.icon === "git" ? item.icon : "puzzle"}
label={item.title}
active={leftOpen && $pluginSidebar?.owner === item.owner && $pluginSidebar?.id === item.id}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
{/if}
</div>
<div class="header-center" data-tauri-drag-region>
<TabBar {...tabBar} />
<IconButton icon="plus" label={$t("New tab ({shortcut})", { shortcut: commandShortcut("new-tab") })} onclick={onNewTab} />
{#if desktop}<div class="window-drag-space" data-tauri-drag-region aria-hidden="true"></div>{/if}
</div>
<div class="header-right" data-tauri-drag-region>
{#if canOpenBrowser}<IconButton icon="globe" label={$t("New browser tab")} disabled={browserOpening} onclick={onOpenBrowser} />{/if}
<PluginAccessMenu surface="open" compact />
<PluginTools />
<PluginAccessMenu surface="commands" compact />
<IconButton icon="save" label={$t("Save")} disabled={saveDisabled} onclick={onSave} />
{#if terminalEnabled}<IconButton icon="terminal" label={$t("Terminal")} active={terminalOpen} onclick={onToggleTerminal} />{/if}
{#if !detached}<IconButton icon="panel-right" label={rightOpen ? $t("Hide outline") : $t("Show outline")} active={rightOpen} onclick={onToggleRight} />{/if}
{#if desktop}<WindowControls {onError} />{/if}
</div>
</header>
<style>
.header {
grid-column: 1 / -1;
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 0;
padding: 0;
background: var(--rs-bg-elevated);
box-shadow: inset 0 -1px var(--rs-border);
user-select: none;
}
.header-left,
.header-right {
display: flex;
align-items: center;
justify-content: center;
gap: 2px;
min-width: 0;
padding: 0 4px;
}
/* The macOS traffic lights sit at the start of the header (src/lib/theme/tokens.css). */
.header-left { justify-content: flex-start; padding-left: calc(4px + var(--rs-titlebar-inset-start)); }
.workspace-button {
display: inline-flex;
flex: 0 1 auto;
align-items: center;
gap: 6px;
min-width: 32px;
max-width: 180px;
height: 28px;
margin-right: 4px;
padding: 0 6px;
border: 1px solid transparent;
border-radius: var(--rs-control-radius);
background: transparent;
color: var(--rs-text);
font: 600 12px var(--rs-font-ui);
}
.workspace-button:hover { background: var(--rs-bg-active); border-color: var(--rs-border); }
.workspace-button :global(svg) { width: 16px; height: 16px; flex-shrink: 0; color: var(--rs-text-dim); }
.workspace-button :global(svg:last-child) { width: 12px; height: 12px; }
.ws { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* In a window below the minimum width, the center clips its content instead of drawing under the right group. */
.header-center {
overflow: hidden;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 6px;
min-width: 0;
padding: 0;
border-left: 1px solid var(--rs-border);
border-right: 1px solid var(--rs-border);
}
.header-left, .header-center, .header-right { height: 100%; }
/* The left group spans the ribbon and the open left pane (the shell sets the widths). */
:global(.shell.left-open) .header-left { width: calc(var(--ribbon-width) + var(--left) + 1px); }
.header-left :global(.icon-btn), .header-right :global(.icon-btn) { flex-shrink: 0; }
.header-right { justify-content: flex-end; }
/* A drag area keeps the window movable when the tabs fill the header: 120 pixels, and at least 48 in a narrow header. */
.window-drag-space { flex: 0 1 120px; min-width: 48px; align-self: stretch; }
/* The tab strip keeps room for one readable tab. It shrinks first, so the drag area shrinks only after it. */
.header-center :global(.tabs) {
flex: 0 1000 auto;
align-self: stretch;
min-width: 120px;
min-height: 28px;
background: transparent;
border-bottom: 0;
}
.header-center :global(.tab) {
flex: 0 1 180px;
width: 180px;
min-width: 120px;
max-width: 180px;
background: transparent;
}
.header-center :global(.tab.active) {
background: var(--rs-bg);
}
</style>