feat(tabs): configurable tab bar position, grouping and sorting
This commit is contained in:
18 files changed
+728
-353
No files matched your search
@@ -733,6 +733,16 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const t = getI18nT();
|
||||
const settingsStore = useSettingsStore();
|
||||
const tabs = ref<QueryTab[]>([]);
|
||||
// New tabs are created by many feature-specific entry points. Tracking id
|
||||
// changes here gives every one a stable timestamp without duplicating the
|
||||
// field at each call site; restored legacy tabs retain their saved order.
|
||||
function ensureTabCreationTimes() {
|
||||
const migrationBase = Date.now() - tabs.value.length;
|
||||
tabs.value.forEach((tab, index) => {
|
||||
if (typeof tab.createdAt !== "number" || !Number.isFinite(tab.createdAt)) tab.createdAt = migrationBase + index;
|
||||
});
|
||||
}
|
||||
watch(() => tabs.value.map((tab) => tab.id), ensureTabCreationTimes, { immediate: true, flush: "sync" });
|
||||
// Default auto-commit for a fresh query tab follows the user's global
|
||||
// "默认事务提交方式" setting (Settings > Editor), not a hard-coded constant.
|
||||
const defaultAutoCommitForDbTypeWithSetting = (dbType?: string) => defaultAutoCommitForDbType(dbType, settingsStore.editorSettings.defaultTransactionMode);
|
||||
@@ -2858,20 +2868,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
);
|
||||
}
|
||||
|
||||
function closeLeftTabs(id: string, onComplete?: () => void) {
|
||||
const target = tabs.value.find((tab) => tab.id === id);
|
||||
if (!target) return;
|
||||
|
||||
const groupedTabs = tabs.value.filter((tab) => Boolean(tab.pinned) === Boolean(target.pinned));
|
||||
const targetIndex = groupedTabs.findIndex((tab) => tab.id === id);
|
||||
const ids = groupedTabs.slice(0, targetIndex).map((tab) => tab.id);
|
||||
if (ids.length === 0) {
|
||||
onComplete?.();
|
||||
return;
|
||||
}
|
||||
|
||||
const finalActiveTabId = activeTabId.value && !ids.includes(activeTabId.value) ? activeTabId.value : id;
|
||||
beginBatchClose(ids, finalActiveTabId, onComplete);
|
||||
function closeTabsByIds(ids: Iterable<string>, finalActiveTabId?: string | null, onComplete?: () => void) {
|
||||
beginBatchClose([...ids], finalActiveTabId, onComplete);
|
||||
}
|
||||
|
||||
function closeRightTabs(id: string, onComplete?: () => void) {
|
||||
@@ -2887,7 +2885,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
|
||||
const finalActiveTabId = activeTabId.value && !ids.includes(activeTabId.value) ? activeTabId.value : id;
|
||||
beginBatchClose(ids, finalActiveTabId, onComplete);
|
||||
closeTabsByIds(ids, finalActiveTabId, onComplete);
|
||||
}
|
||||
|
||||
function finalActiveTabAfterClosing(ids: string[]) {
|
||||
@@ -6852,7 +6850,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
discardTabChanges,
|
||||
requestAppCloseConfirmation,
|
||||
closeOtherTabs,
|
||||
closeLeftTabs,
|
||||
closeTabsByIds,
|
||||
closeRightTabs,
|
||||
closeOtherRegularTabs,
|
||||
closeRegularTabs,
|
||||
|
||||
@@ -476,6 +476,12 @@ const CELL_DETAIL_PANEL_LAYOUTS = ["bottom", "right"] as const;
|
||||
export type CellDetailPanelLayout = (typeof CELL_DETAIL_PANEL_LAYOUTS)[number];
|
||||
const TAB_LAYOUT_MODES = ["scroll", "wrap"] as const;
|
||||
export type TabLayoutMode = (typeof TAB_LAYOUT_MODES)[number];
|
||||
const TAB_PLACEMENTS = ["top", "bottom", "left", "right"] as const;
|
||||
export type TabPlacement = (typeof TAB_PLACEMENTS)[number];
|
||||
const TAB_GROUP_MODES = ["none", "database-type", "connection"] as const;
|
||||
export type TabGroupMode = (typeof TAB_GROUP_MODES)[number];
|
||||
const TAB_SORT_MODES = ["manual", "created-asc", "title-asc"] as const;
|
||||
export type TabSortMode = (typeof TAB_SORT_MODES)[number];
|
||||
const DATA_GRID_RENDER_MODES = ["dom", "canvas"] as const;
|
||||
export type DataGridRenderMode = (typeof DATA_GRID_RENDER_MODES)[number];
|
||||
const DATA_GRID_SEARCH_MODES = ["filter", "highlight"] as const;
|
||||
@@ -607,6 +613,9 @@ export interface EditorSettings {
|
||||
savedSqlOpenTargetMode: SavedSqlOpenTargetMode;
|
||||
compactTabTitle: boolean;
|
||||
tabLayout: TabLayoutMode;
|
||||
tabPlacement: TabPlacement;
|
||||
tabGroupMode: TabGroupMode;
|
||||
tabSortMode: TabSortMode;
|
||||
appLayout: "separated" | "classic";
|
||||
pageSize: number;
|
||||
tableOpenPageSize: number;
|
||||
@@ -829,6 +838,9 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
|
||||
savedSqlOpenTargetMode: "saved",
|
||||
compactTabTitle: false,
|
||||
tabLayout: "scroll",
|
||||
tabPlacement: "top",
|
||||
tabGroupMode: "none",
|
||||
tabSortMode: "manual",
|
||||
appLayout: "classic",
|
||||
pageSize: 100,
|
||||
tableOpenPageSize: 100,
|
||||
@@ -970,6 +982,18 @@ function normalizeTabLayout(value: unknown): TabLayoutMode {
|
||||
return TAB_LAYOUT_MODES.includes(value as TabLayoutMode) ? (value as TabLayoutMode) : DEFAULT_EDITOR_SETTINGS.tabLayout;
|
||||
}
|
||||
|
||||
function normalizeTabPlacement(value: unknown): TabPlacement {
|
||||
return TAB_PLACEMENTS.includes(value as TabPlacement) ? (value as TabPlacement) : DEFAULT_EDITOR_SETTINGS.tabPlacement;
|
||||
}
|
||||
|
||||
function normalizeTabGroupMode(value: unknown): TabGroupMode {
|
||||
return TAB_GROUP_MODES.includes(value as TabGroupMode) ? (value as TabGroupMode) : DEFAULT_EDITOR_SETTINGS.tabGroupMode;
|
||||
}
|
||||
|
||||
function normalizeTabSortMode(value: unknown): TabSortMode {
|
||||
return TAB_SORT_MODES.includes(value as TabSortMode) ? (value as TabSortMode) : DEFAULT_EDITOR_SETTINGS.tabSortMode;
|
||||
}
|
||||
|
||||
function normalizeCellDetailPanelLayout(value: unknown): CellDetailPanelLayout {
|
||||
return CELL_DETAIL_PANEL_LAYOUTS.includes(value as CellDetailPanelLayout) ? (value as CellDetailPanelLayout) : DEFAULT_EDITOR_SETTINGS.cellDetailPanelLayout;
|
||||
}
|
||||
@@ -1240,6 +1264,9 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
savedSqlOpenTargetMode: settings.savedSqlOpenTargetMode === "current" ? "current" : DEFAULT_EDITOR_SETTINGS.savedSqlOpenTargetMode,
|
||||
compactTabTitle: settings.compactTabTitle ?? DEFAULT_EDITOR_SETTINGS.compactTabTitle,
|
||||
tabLayout: normalizeTabLayout(settings.tabLayout),
|
||||
tabPlacement: normalizeTabPlacement(settings.tabPlacement),
|
||||
tabGroupMode: normalizeTabGroupMode(settings.tabGroupMode),
|
||||
tabSortMode: normalizeTabSortMode(settings.tabSortMode),
|
||||
appLayout: settings.appLayout ?? DEFAULT_EDITOR_SETTINGS.appLayout,
|
||||
pageSize: normalizeResultPageSize(settings.pageSize),
|
||||
tableOpenPageSize: normalizeResultPageSize(settings.tableOpenPageSize, DEFAULT_EDITOR_SETTINGS.tableOpenPageSize),
|
||||
@@ -1864,6 +1891,9 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
if (partial.savedSqlOpenTargetMode !== undefined) editorSettings.value.savedSqlOpenTargetMode = partial.savedSqlOpenTargetMode === "current" ? "current" : "saved";
|
||||
if (partial.compactTabTitle !== undefined) editorSettings.value.compactTabTitle = partial.compactTabTitle;
|
||||
if (partial.tabLayout !== undefined) editorSettings.value.tabLayout = normalizeTabLayout(partial.tabLayout);
|
||||
if (partial.tabPlacement !== undefined) editorSettings.value.tabPlacement = normalizeTabPlacement(partial.tabPlacement);
|
||||
if (partial.tabGroupMode !== undefined) editorSettings.value.tabGroupMode = normalizeTabGroupMode(partial.tabGroupMode);
|
||||
if (partial.tabSortMode !== undefined) editorSettings.value.tabSortMode = normalizeTabSortMode(partial.tabSortMode);
|
||||
if (partial.appLayout !== undefined) editorSettings.value.appLayout = partial.appLayout;
|
||||
if (partial.pageSize !== undefined) editorSettings.value.pageSize = normalizeResultPageSize(partial.pageSize);
|
||||
if (partial.tableOpenPageSize !== undefined) editorSettings.value.tableOpenPageSize = normalizeResultPageSize(partial.tableOpenPageSize, DEFAULT_EDITOR_SETTINGS.tableOpenPageSize);
|
||||
|
||||
Reference in new issue
Block a user