mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
show selected tab in multitab
This commit is contained in:
parent
d283429f40
commit
f5d41c89e6
@ -1,42 +1,28 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { currentDatabase, lockedDatabaseMode, openedTabs, TabDefinition } from '../stores';
|
import { openedTabs } from '../stores';
|
||||||
import TabContent from './TabContent.svelte';
|
import TabContent from './TabContent.svelte';
|
||||||
import tabs from '../tabs';
|
import tabs from '../tabs';
|
||||||
import { shouldShowTab } from './TabsPanel.svelte';
|
|
||||||
|
|
||||||
export let multiTabIndex;
|
export let multiTabIndex;
|
||||||
|
export let shownTab;
|
||||||
|
|
||||||
let mountedTabs = {};
|
let mountedTabs = {};
|
||||||
|
|
||||||
function findShownTab(tabs: TabDefinition[], multiTabIndex, lockedDbMode, currentDb) {
|
|
||||||
const selectedTab = tabs.find(x => x.selected && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex);
|
|
||||||
if (selectedTab) {
|
|
||||||
return selectedTab;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectedIndex = _.findLastIndex(
|
|
||||||
tabs,
|
|
||||||
x => (x.multiTabIndex || 0) == multiTabIndex && shouldShowTab(x, lockedDbMode, currentDb)
|
|
||||||
);
|
|
||||||
|
|
||||||
return tabs[selectedIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
$: shownTab = findShownTab($openedTabs, multiTabIndex, $lockedDatabaseMode, $currentDatabase);
|
|
||||||
|
|
||||||
// cleanup closed tabs
|
// cleanup closed tabs
|
||||||
$: {
|
$: {
|
||||||
if (
|
if (
|
||||||
_.difference(
|
_.difference(
|
||||||
_.keys(mountedTabs),
|
_.keys(mountedTabs),
|
||||||
_.map(
|
_.map(
|
||||||
$openedTabs.filter(x => x.closedTime == null),
|
$openedTabs.filter(x => x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex),
|
||||||
'tabid'
|
'tabid'
|
||||||
)
|
)
|
||||||
).length > 0
|
).length > 0
|
||||||
) {
|
) {
|
||||||
mountedTabs = _.pickBy(mountedTabs, (v, k) => $openedTabs.find(x => x.tabid == k && x.closedTime == null));
|
mountedTabs = _.pickBy(mountedTabs, (v, k) =>
|
||||||
|
$openedTabs.find(x => x.tabid == k && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
<script lang='ts'>
|
<script lang="ts">
|
||||||
import TabRegister from './TabRegister.svelte';
|
import TabRegister from './TabRegister.svelte';
|
||||||
import TabsPanel from './TabsPanel.svelte';
|
import TabsPanel from './TabsPanel.svelte';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import { currentDatabase, lockedDatabaseMode, openedTabs, TabDefinition } from '../stores';
|
||||||
|
import { shouldShowTab } from './TabsPanel.svelte';
|
||||||
|
|
||||||
export let multiTabIndex;
|
export let multiTabIndex;
|
||||||
|
|
||||||
|
function findShownTab(tabs: TabDefinition[], multiTabIndex, lockedDbMode, currentDb) {
|
||||||
|
const selectedTab = tabs.find(x => x.selected && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex);
|
||||||
|
if (selectedTab) {
|
||||||
|
return selectedTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedIndex = _.findLastIndex(
|
||||||
|
tabs,
|
||||||
|
x => (x.multiTabIndex || 0) == multiTabIndex && shouldShowTab(x, lockedDbMode, currentDb)
|
||||||
|
);
|
||||||
|
|
||||||
|
return tabs[selectedIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
$: shownTab = findShownTab($openedTabs, multiTabIndex, $lockedDatabaseMode, $currentDatabase);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<TabsPanel {multiTabIndex} />
|
<TabsPanel {multiTabIndex} {shownTab} />
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<TabRegister {multiTabIndex} />
|
<TabRegister {multiTabIndex} {shownTab} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -281,6 +281,7 @@
|
|||||||
import CloseTabModal from '../modals/CloseTabModal.svelte';
|
import CloseTabModal from '../modals/CloseTabModal.svelte';
|
||||||
|
|
||||||
export let multiTabIndex;
|
export let multiTabIndex;
|
||||||
|
export let shownTab;
|
||||||
|
|
||||||
$: showTabFilterFunc = tab =>
|
$: showTabFilterFunc = tab =>
|
||||||
shouldShowTab(tab, $lockedDatabaseMode, $currentDatabase) && (tab.multiTabIndex || 0) == multiTabIndex;
|
shouldShowTab(tab, $lockedDatabaseMode, $currentDatabase) && (tab.multiTabIndex || 0) == multiTabIndex;
|
||||||
@ -517,7 +518,9 @@
|
|||||||
<div
|
<div
|
||||||
id={`file-tab-item-${tab.tabid}`}
|
id={`file-tab-item-${tab.tabid}`}
|
||||||
class="file-tab-item"
|
class="file-tab-item"
|
||||||
class:selected={$draggingTab || $draggingDbGroup ? tab.tabid == $draggingTabTarget?.tabid : tab.selected}
|
class:selected={$draggingTab || $draggingDbGroup
|
||||||
|
? tab.tabid == $draggingTabTarget?.tabid
|
||||||
|
: tab.tabid == shownTab?.tabid}
|
||||||
on:click={e => handleTabClick(e, tab.tabid)}
|
on:click={e => handleTabClick(e, tab.tabid)}
|
||||||
on:mouseup={e => handleMouseUp(e, tab.tabid)}
|
on:mouseup={e => handleMouseUp(e, tab.tabid)}
|
||||||
use:contextMenu={getContextMenu(tab)}
|
use:contextMenu={getContextMenu(tab)}
|
||||||
|
Loading…
Reference in New Issue
Block a user