1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Menus and keyboard shortcuts

This commit is contained in:
Romein van Buren 2023-01-23 14:12:14 +01:00
parent 4cefc33bd4
commit 29e93dcab1
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
4 changed files with 37 additions and 21 deletions

View File

@ -8,6 +8,7 @@
import Remove from './remove.svelte';
import Stats from './stats.svelte';
import Update from './update.svelte';
import { EventsOn } from '../../../../wailsjs/runtime/runtime';
export let collection;
export let hostKey;
@ -23,6 +24,8 @@
collection.key = collectionKey;
}
EventsOn('OpenCollectionTab', name => (tab = name || tab));
async function catchQuery(event) {
tab = 'find';
await tick();

View File

@ -8,6 +8,7 @@
import CollectionDetail from './collection/index.svelte';
import HostDetail from './hostdetail.svelte';
import Icon from '../../components/icon.svelte';
import { EventsOn } from '../../../wailsjs/runtime/runtime';
export let hosts = {};
export let activeHostKey = '';
@ -72,6 +73,9 @@
busy.end();
}
EventsOn('CreateHost', createHost);
EventsOn('CreateDatabase', () => newDb = {});
EventsOn('CreateCollection', () => newColl = {});
onMount(getHosts);
</script>

View File

@ -1,7 +1,7 @@
import {defineConfig} from 'vite'
import {svelte} from '@sveltejs/vite-plugin-svelte'
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()]
})
plugins: [ svelte() ],
});

View File

@ -21,34 +21,43 @@ func (a *App) Startup(ctx context.Context) {
a.ctx = ctx
}
func menuEventEmitter(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
return func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, eventName, data...)
}
}
func (a *App) Menu() *menu.Menu {
appMenu := menu.NewMenu()
aboutMenu := appMenu.AddSubmenu("About")
aboutMenu.AddText("About…", nil, func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, "OpenAboutModal")
})
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, "OpenPrefrences")
})
aboutMenu.AddText("About…", nil, menuEventEmitter(a, "OpenAboutModal"))
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), menuEventEmitter(a, "OpenPrefrences"))
aboutMenu.AddSeparator()
aboutMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) {
wailsRuntime.Quit(a.ctx)
})
// fileMenu := appMenu.AddSubmenu("File")
// fileMenu.AddText("Hosts…", keys.CmdOrCtrl("k"), func(cd *menu.CallbackData) {
// wailsRuntime.EventsEmit(a.ctx, "OpenHostsModal")
// })
aboutMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
if runtime.GOOS == "darwin" {
appMenu.Append(menu.EditMenu())
}
hostMenu := appMenu.AddSubmenu("Host")
hostMenu.AddText("New host", keys.CmdOrCtrl("y"), menuEventEmitter(a, "CreateHost"))
databaseMenu := appMenu.AddSubmenu("Database")
databaseMenu.AddText("New database", keys.CmdOrCtrl("u"), menuEventEmitter(a, "CreateDatabase"))
collectionMenu := appMenu.AddSubmenu("Collection")
collectionMenu.AddText("New collection", keys.CmdOrCtrl("i"), menuEventEmitter(a, "CreateCollection"))
collectionMenu.AddSeparator()
collectionMenu.AddText("Stats", keys.Combo("h", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "stats"))
collectionMenu.AddText("Find", keys.Combo("f", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "find"))
collectionMenu.AddText("Insert", keys.Combo("i", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "insert"))
collectionMenu.AddText("Update", keys.Combo("u", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "update"))
collectionMenu.AddText("Remove", keys.Combo("r", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "remove"))
collectionMenu.AddText("Indexes", keys.Combo("x", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "indexes"))
helpMenu := appMenu.AddSubmenu("Help")
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) {
wailsRuntime.BrowserOpenURL(a.ctx, "")
})
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
return appMenu
}