main menu available in web version

This commit is contained in:
Jan Prochazka
2022-02-12 08:23:37 +01:00
parent 0c951b4659
commit db6d930d0c
8 changed files with 94 additions and 49 deletions

View File

@@ -2,29 +2,28 @@ module.exports = [
{ {
label: 'File', label: 'File',
submenu: [ submenu: [
{ command: 'new.connection' }, { command: 'new.connection', hideDisabled: true },
{ command: 'new.sqliteDatabase' }, { command: 'new.sqliteDatabase', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'file.open' }, { command: 'file.open', hideDisabled: true },
{ command: 'file.openArchive' }, { command: 'file.openArchive', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'group.save' }, { command: 'group.save', hideDisabled: true },
{ command: 'group.saveAs' }, { command: 'group.saveAs', hideDisabled: true },
{ command: 'database.search' }, { command: 'database.search', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'file.exit', hideDisabled: true },
{ command: 'file.exit' },
], ],
}, },
{ {
label: 'Window', label: 'Window',
submenu: [ submenu: [
{ command: 'new.query' }, { command: 'new.query', hideDisabled: true },
{ command: 'new.modelCompare' }, { command: 'new.modelCompare', hideDisabled: true },
{ command: 'new.freetable' }, { command: 'new.freetable', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'tabs.closeTab' }, { command: 'tabs.closeTab', hideDisabled: true },
{ command: 'tabs.closeAll' }, { command: 'tabs.closeAll', hideDisabled: true },
], ],
}, },
@@ -42,23 +41,23 @@ module.exports = [
{ {
label: 'View', label: 'View',
submenu: [ submenu: [
{ command: 'app.reload' }, { command: 'app.reload', hideDisabled: true },
{ command: 'app.toggleDevTools' }, { command: 'app.toggleDevTools', hideDisabled: true },
{ command: 'app.toggleFullScreen' }, { command: 'app.toggleFullScreen', hideDisabled: true },
{ command: 'app.minimize' }, { command: 'app.minimize', hideDisabled: true },
{ command: 'theme.changeTheme' }, { command: 'theme.changeTheme', hideDisabled: true },
], ],
}, },
{ {
label: 'help', label: 'Help',
submenu: [ submenu: [
{ command: 'app.openDocs' }, { command: 'app.openDocs', hideDisabled: true },
{ command: 'app.openWeb' }, { command: 'app.openWeb', hideDisabled: true },
{ command: 'app.openIssue' }, { command: 'app.openIssue', hideDisabled: true },
{ command: 'app.openSponsoring' }, { command: 'app.openSponsoring', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'tabs.changelog' }, { command: 'tabs.changelog', hideDisabled: true },
{ command: 'about.show' }, { command: 'about.show', hideDisabled: true },
], ],
}, },
]; ];

View File

@@ -12,7 +12,7 @@
(var(--dim-left-panel-width) + var(--dim-splitter-thickness)) (var(--dim-left-panel-width) + var(--dim-splitter-thickness))
); );
--dim-visible-toolbar: 1; /* set from JS */ --dim-visible-toolbar: 0; /* set from JS */
--dim-visible-titlebar: 0; /* set from JS */ --dim-visible-titlebar: 0; /* set from JS */
--dim-toolbar-height: 30px; --dim-toolbar-height: 30px;

View File

@@ -24,22 +24,16 @@
import dragDropFileTarget from './utility/dragDropFileTarget'; import dragDropFileTarget from './utility/dragDropFileTarget';
import TitleBar from './widgets/TitleBar.svelte'; import TitleBar from './widgets/TitleBar.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import getElectron from './utility/getElectron'; import { shouldDrawTitleBar } from './utility/common';
$: currentThemeType = $currentThemeDefinition?.themeType == 'dark' ? 'theme-type-dark' : 'theme-type-light'; $: currentThemeType = $currentThemeDefinition?.themeType == 'dark' ? 'theme-type-dark' : 'theme-type-light';
let domTabs; let domTabs;
let drawTitleBar = false; let drawTitleBar = false;
onMount(async () => { onMount(async () => {
let draw = true; drawTitleBar = await shouldDrawTitleBar();
const electron = getElectron();
if (electron && (await electron.isNativeMenu())) {
draw = false;
}
drawTitleBar = draw;
document.documentElement.style.setProperty('--dim-visible-titlebar', drawTitleBar ? 1 : 0); document.documentElement.style.setProperty('--dim-visible-titlebar', drawTitleBar ? 1 : 0);
console.log('drawTitleBar', drawTitleBar);
}); });
function handleTabsWheel(e) { function handleTabsWheel(e) {
@@ -48,11 +42,13 @@
domTabs.scrollBy({ top: 0, left: e.deltaY < 0 ? -150 : 150, behavior: 'smooth' }); domTabs.scrollBy({ top: 0, left: e.deltaY < 0 ? -150 : 150, behavior: 'smooth' });
} }
} }
$: themeStyle = `<style id="themePlugin">${$currentThemeDefinition?.themeCss}</style>`;
</script> </script>
<svelte:head> <svelte:head>
{#if $currentThemeDefinition?.themeCss} {#if $currentThemeDefinition?.themeCss}
{@html `<style id="themePlugin">${$currentThemeDefinition?.themeCss}</style>`} {@html themeStyle}
{/if} {/if}
</svelte:head> </svelte:head>

View File

@@ -53,11 +53,31 @@
} }
return item; return item;
} }
function filterMenuItems(items) {
const res = [];
let wasDivider = false;
let wasItem = false;
for (const item of items.filter(x => !x.disabled || !x.hideDisabled)) {
if (item.divider) {
if (wasItem) {
wasDivider = true;
}
} else {
if (wasDivider) {
res.push({ divider: true });
}
wasDivider = false;
wasItem = true;
res.push(item);
}
}
return res;
}
</script> </script>
<script> <script>
import _ from 'lodash'; import _ from 'lodash';
import clickOutside from '../utility/clickOutside';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { commandsCustomized, visibleCommandPalette } from '../stores'; import { commandsCustomized, visibleCommandPalette } from '../stores';
@@ -106,7 +126,7 @@
$: extracted = extractMenuItems(items, { targetElement }); $: extracted = extractMenuItems(items, { targetElement });
$: compacted = _.compact(extracted.map(x => mapItem(x, $commandsCustomized))); $: compacted = _.compact(extracted.map(x => mapItem(x, $commandsCustomized)));
$: filtered = compacted.filter(x => !x.disabled || !x.hideDisabled); $: filtered = filterMenuItems(compacted);
const handleClickOutside = event => { const handleClickOutside = event => {
// if (element && !element.contains(event.target) && !event.defaultPrevented) { // if (element && !element.contains(event.target) && !event.defaultPrevented) {

View File

@@ -56,7 +56,8 @@ export const commandsCustomized = derived([commands, commandsSettings], ([$comma
})) }))
); );
export const visibleToolbar = writableWithStorage(true, 'visibleToolbar'); // export const visibleToolbar = writableWithStorage(true, 'visibleToolbar');
export const visibleToolbar = writable(false);
export const zoomKoef = writableWithStorage(1, 'zoomKoef'); export const zoomKoef = writableWithStorage(1, 'zoomKoef');
export const leftPanelWidth = writableWithStorage(300, 'leftPanelWidth'); export const leftPanelWidth = writableWithStorage(300, 'leftPanelWidth');
export const currentDropDownMenu = writable(null); export const currentDropDownMenu = writable(null);
@@ -77,7 +78,7 @@ export const currentThemeDefinition = derived([currentTheme, extensions], ([$cur
); );
subscribeCssVariable(selectedWidget, x => (x ? 1 : 0), '--dim-visible-left-panel'); subscribeCssVariable(selectedWidget, x => (x ? 1 : 0), '--dim-visible-left-panel');
subscribeCssVariable(visibleToolbar, x => (x ? 1 : 0), '--dim-visible-toolbar'); // subscribeCssVariable(visibleToolbar, x => (x ? 1 : 0), '--dim-visible-toolbar');
subscribeCssVariable(leftPanelWidth, x => `${x}px`, '--dim-left-panel-width'); subscribeCssVariable(leftPanelWidth, x => `${x}px`, '--dim-left-panel-width');
let activeTabIdValue = null; let activeTabIdValue = null;

View File

@@ -1,5 +1,6 @@
import { openedTabs } from '../stores'; import { openedTabs } from '../stores';
import _ from 'lodash'; import _ from 'lodash';
import getElectron from './getElectron';
export class LoadingToken { export class LoadingToken {
isCanceled = false; isCanceled = false;
@@ -38,3 +39,14 @@ export async function asyncFilter(arr, predicate) {
return arr.filter((_v, index) => results[index]); return arr.filter((_v, index) => results[index]);
} }
export async function shouldDrawTitleBar() {
const electron = getElectron();
if (!electron) {
return false;
}
if (await electron.isNativeMenu()) {
return true;
}
return false;
}

View File

@@ -1,8 +1,7 @@
class ElectronApi { class ElectronApi {
private ipcRenderer = getIpcRenderer(); private ipcRenderer = getIpcRenderer();
constructor() { constructor() {}
}
send(msg, args = null) { send(msg, args = null) {
this.ipcRenderer.send(msg, args); this.ipcRenderer.send(msg, args);
@@ -28,7 +27,8 @@ class ElectronApi {
} }
async isNativeMenu() { async isNativeMenu() {
await this.ipcRenderer.invoke('isNativeMenu'); const res = await this.ipcRenderer.invoke('isNativeMenu');
return res;
} }
async invoke(route, args) { async invoke(route, args) {

View File

@@ -1,9 +1,12 @@
<script lang="ts"> <script lang="ts">
import { update } from 'lodash'; import { onMount } from 'svelte';
import FontIcon from '../icons/FontIcon.svelte'; import FontIcon from '../icons/FontIcon.svelte';
import { currentDropDownMenu, selectedWidget, visibleCommandPalette, visibleToolbar } from '../stores'; import { currentDropDownMenu, selectedWidget, visibleCommandPalette } from '../stores';
import { shouldDrawTitleBar } from '../utility/common';
import mainMenuDefinition from '../../../../app/src/mainMenuDefinition';
let domSettings; let domSettings;
let domMainMenu;
const widgets = [ const widgets = [
{ {
@@ -63,15 +66,29 @@
function handleSettingsMenu() { function handleSettingsMenu() {
const rect = domSettings.getBoundingClientRect(); const rect = domSettings.getBoundingClientRect();
const left = rect.right; const left = rect.right;
const top = rect.top; const top = rect.bottom;
const items = [{ command: 'settings.commands' }, { command: 'theme.changeTheme' }, { command: 'settings.show' }]; const items = [{ command: 'settings.commands' }, { command: 'theme.changeTheme' }, { command: 'settings.show' }];
currentDropDownMenu.set({ left, top, items }); currentDropDownMenu.set({ left, top, items });
} }
function handleMainMenu() {
const rect = domMainMenu.getBoundingClientRect();
const left = rect.right;
const top = rect.top;
console.log('mainMenuDefinition', mainMenuDefinition);
const items = mainMenuDefinition;
currentDropDownMenu.set({ left, top, items });
}
let showMainMenu = false;
onMount(async () => {
showMainMenu = !(await shouldDrawTitleBar());
});
</script> </script>
<div class="main"> <div class="main">
{#if !$visibleToolbar} {#if showMainMenu}
<div class="wrapper mb-3" on:click={() => ($visibleCommandPalette = 'menu')}> <div class="wrapper mb-3" on:click={handleMainMenu} bind:this={domMainMenu}>
<FontIcon icon="icon menu" /> <FontIcon icon="icon menu" />
</div> </div>
{/if} {/if}