feat(tabs): add persistent compact title toggle in tab context menu
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, nextTick } from "vue";
|
||||
import { computed, ref, watch, nextTick } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { X, Pin, ChevronRight, Table2, Code2, TableProperties, Package } from "lucide-vue-next";
|
||||
import { X, Pin, ChevronRight, Table2, Code2, TableProperties, Package, Check } from "lucide-vue-next";
|
||||
import {
|
||||
ContextMenu,
|
||||
ContextMenuContent,
|
||||
@@ -30,6 +30,16 @@ const emit = defineEmits<{
|
||||
const { t } = useI18n();
|
||||
const queryStore = useQueryStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const compactTabTitle = computed({
|
||||
get: () => settingsStore.editorSettings.compactTabTitle,
|
||||
set: (checked: boolean | "indeterminate") => {
|
||||
settingsStore.updateEditorSettings({ compactTabTitle: checked === true });
|
||||
},
|
||||
});
|
||||
|
||||
function toggleCompactTabTitle() {
|
||||
compactTabTitle.value = !compactTabTitle.value;
|
||||
}
|
||||
|
||||
const tabsContainerRef = ref<HTMLElement | null>(null);
|
||||
const { canScrollLeft, canScrollRight, updateScrollButtons, scrollTabs } = useTabScroll(tabsContainerRef);
|
||||
@@ -196,6 +206,11 @@ function tabIconClass(tab: QueryTab) {
|
||||
</ContextMenuTrigger>
|
||||
|
||||
<ContextMenuContent class="w-44">
|
||||
<ContextMenuItem @click="toggleCompactTabTitle">
|
||||
<Check class="w-3.5 h-3.5 mr-2" :class="compactTabTitle ? 'opacity-100' : 'opacity-0'" />
|
||||
{{ t("contextMenu.compactTabTitle") }}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem @click="queryStore.togglePinnedTab(tab.id)">
|
||||
<Pin class="w-3.5 h-3.5 mr-2" :class="{ 'fill-current': tab.pinned }" />
|
||||
{{ tab.pinned ? t("contextMenu.unpin") : t("contextMenu.pin") }}
|
||||
|
||||
@@ -679,6 +679,7 @@ export default {
|
||||
pin: "Pin",
|
||||
unpin: "Unpin",
|
||||
refreshTab: "Refresh Data",
|
||||
compactTabTitle: "Shorten Tab Titles",
|
||||
closeTab: "Close Tab",
|
||||
closeOtherTabs: "Close Other Tabs",
|
||||
closeAllTabs: "Close All Tabs",
|
||||
|
||||
@@ -663,6 +663,7 @@ export default {
|
||||
pin: "置顶",
|
||||
unpin: "取消置顶",
|
||||
refreshTab: "刷新数据",
|
||||
compactTabTitle: "缩短标签标题",
|
||||
closeTab: "关闭标签页",
|
||||
closeOtherTabs: "关闭其他标签页",
|
||||
closeAllTabs: "关闭全部标签页",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import type { QueryTab } from "@/types/database";
|
||||
|
||||
export function connectionDisplayName(connectionId: string): string {
|
||||
@@ -28,22 +29,32 @@ export function isPreviewTab(tab: QueryTab): boolean {
|
||||
|
||||
export function tabDisplayTitle(tab: QueryTab): string {
|
||||
const database = databaseDisplayNameForTab(tab.connectionId, tab.database);
|
||||
const settingsStore = useSettingsStore();
|
||||
const compact = settingsStore.editorSettings.compactTabTitle;
|
||||
if (isPreviewTab(tab)) return tab.title;
|
||||
if (tab.mode === "data" && tab.tableMeta?.tableName) {
|
||||
const suffix = tab.tableMeta.schema ? `@${database}.${tab.tableMeta.schema}` : `@${database}`;
|
||||
if (compact) return tab.tableMeta.tableName;
|
||||
const suffix =
|
||||
tab.tableMeta.schema && tab.tableMeta.schema !== tab.database
|
||||
? `@${database}.${tab.tableMeta.schema}`
|
||||
: `@${database}`;
|
||||
return `${tab.tableMeta.tableName}${suffix}`;
|
||||
}
|
||||
if (tab.mode === "query") {
|
||||
if (compact) return connectionDisplayName(tab.connectionId);
|
||||
return `${connectionDisplayName(tab.connectionId)}@${database}`;
|
||||
}
|
||||
if (tab.mode === "mongo" && tab.sql) {
|
||||
if (compact) return tab.sql;
|
||||
return `${tab.sql}@${database}`;
|
||||
}
|
||||
if (tab.mode === "redis") {
|
||||
if (compact) return connectionDisplayName(tab.connectionId);
|
||||
return `${connectionDisplayName(tab.connectionId)}@${database}`;
|
||||
}
|
||||
if (tab.mode === "objects") {
|
||||
const schema = tab.objectBrowser?.schema;
|
||||
if (compact) return schema || tab.title;
|
||||
return schema ? `${schema}@${database}` : `${tab.title}@${database}`;
|
||||
}
|
||||
return tab.title;
|
||||
|
||||
@@ -163,6 +163,7 @@ export interface EditorSettings {
|
||||
theme: EditorTheme;
|
||||
executeMode: "all" | "current";
|
||||
wordWrap: boolean;
|
||||
compactTabTitle: boolean;
|
||||
appLayout: "separated" | "classic";
|
||||
pageSize: number;
|
||||
redisScanPageSize: number;
|
||||
@@ -201,6 +202,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
|
||||
theme: "one-dark",
|
||||
executeMode: "all",
|
||||
wordWrap: false,
|
||||
compactTabTitle: false,
|
||||
appLayout: "classic",
|
||||
pageSize: 100,
|
||||
redisScanPageSize: 1000,
|
||||
@@ -241,6 +243,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>): Edit
|
||||
theme: settings.theme ?? DEFAULT_EDITOR_SETTINGS.theme,
|
||||
executeMode: settings.executeMode ?? DEFAULT_EDITOR_SETTINGS.executeMode,
|
||||
wordWrap: settings.wordWrap ?? DEFAULT_EDITOR_SETTINGS.wordWrap,
|
||||
compactTabTitle: settings.compactTabTitle ?? DEFAULT_EDITOR_SETTINGS.compactTabTitle,
|
||||
appLayout: settings.appLayout ?? DEFAULT_EDITOR_SETTINGS.appLayout,
|
||||
pageSize: normalizeResultPageSize(settings.pageSize),
|
||||
redisScanPageSize: settings.redisScanPageSize ?? DEFAULT_EDITOR_SETTINGS.redisScanPageSize,
|
||||
|
||||
Reference in New Issue
Block a user