mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #5184: GotoAnything is not working on first try
This commit is contained in:
parent
0cec4753d8
commit
4f5ad86028
@ -228,6 +228,9 @@ packages/app-desktop/gui/KeymapConfig/utils/useKeymap.js.map
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.d.ts
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.js
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.js
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -213,6 +213,9 @@ packages/app-desktop/gui/KeymapConfig/utils/useKeymap.js.map
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.d.ts
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.js
|
||||
packages/app-desktop/gui/MainScreen/MainScreen.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.js
|
||||
packages/app-desktop/gui/MainScreen/commands/commandPalette.js.map
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.d.ts
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
||||
|
@ -46,6 +46,7 @@ const commands = [
|
||||
require('./gui/MainScreen/commands/editAlarm'),
|
||||
require('./gui/MainScreen/commands/exportPdf'),
|
||||
require('./gui/MainScreen/commands/gotoAnything'),
|
||||
require('./gui/MainScreen/commands/commandPalette'),
|
||||
require('./gui/MainScreen/commands/hideModalMessage'),
|
||||
require('./gui/MainScreen/commands/moveToFolder'),
|
||||
require('./gui/MainScreen/commands/newFolder'),
|
||||
|
@ -16,16 +16,12 @@ const getLabel = (commandName: string): string => {
|
||||
return _('Quit');
|
||||
case 'zoomActualSize':
|
||||
return _('Actual Size');
|
||||
case 'gotoAnything':
|
||||
return _('Goto Anything...');
|
||||
case 'help':
|
||||
return _('Website and documentation');
|
||||
case 'hideApp':
|
||||
return _('Hide Joplin');
|
||||
case 'closeWindow':
|
||||
return _('Close Window');
|
||||
case 'commandPalette':
|
||||
return _('Command palette');
|
||||
case 'config':
|
||||
return shim.isMac() ? _('Preferences') : _('Options');
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ const commands = [
|
||||
require('./commands/editAlarm'),
|
||||
require('./commands/exportPdf'),
|
||||
require('./commands/gotoAnything'),
|
||||
require('./commands/commandPalette'),
|
||||
require('./commands/hideModalMessage'),
|
||||
require('./commands/moveToFolder'),
|
||||
require('./commands/newFolder'),
|
||||
|
@ -0,0 +1,16 @@
|
||||
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
import { UiType } from './gotoAnything';
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'commandPalette',
|
||||
label: () => _('Command palette...'),
|
||||
};
|
||||
|
||||
export const runtime = (): CommandRuntime => {
|
||||
return {
|
||||
execute: async (_context: CommandContext) => {
|
||||
void CommandService.instance().execute('gotoAnything', UiType.CommandPalette);
|
||||
},
|
||||
};
|
||||
};
|
@ -1,13 +1,34 @@
|
||||
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
|
||||
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
const PluginManager = require('@joplin/lib/services/PluginManager');
|
||||
|
||||
export enum UiType {
|
||||
GotoAnything = 'gotoAnything',
|
||||
CommandPalette = 'commandPalette',
|
||||
ControlledApi = 'controlledApi',
|
||||
}
|
||||
|
||||
export const declaration: CommandDeclaration = {
|
||||
name: 'gotoAnything',
|
||||
label: () => _('Goto Anything...'),
|
||||
};
|
||||
|
||||
function menuItemById(id: string) {
|
||||
return PluginManager.instance().menuItems().find((i: any) => i.id === id);
|
||||
}
|
||||
|
||||
// The way this command is implemented is a bit hacky due to the PluginManager
|
||||
// layer. This manager is no longer needed but hasn't been refactored yet, so in
|
||||
// the meantime we access the GotoAnything actions by grabbing the menu item
|
||||
// calling the click() handler.
|
||||
export const runtime = (): CommandRuntime => {
|
||||
return {
|
||||
execute: async () => {
|
||||
execute: async (_context: CommandContext, uiType: UiType = UiType.GotoAnything) => {
|
||||
if (uiType === UiType.GotoAnything) {
|
||||
menuItemById('gotoAnything').click();
|
||||
} else if (uiType === UiType.CommandPalette) {
|
||||
menuItemById('commandPalette').click();
|
||||
} else if (uiType === UiType.ControlledApi) {
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
const menuItem = PluginManager.instance().menuItems().find((i: any) => i.id === 'controlledApi');
|
||||
menuItem.userData = {
|
||||
@ -15,6 +36,7 @@ export const runtime = (): CommandRuntime => {
|
||||
};
|
||||
menuItem.click();
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -24,7 +24,6 @@ import { reg } from '@joplin/lib/registry';
|
||||
const packageInfo = require('../packageInfo.js');
|
||||
const { clipboard } = require('electron');
|
||||
const Menu = bridge().Menu;
|
||||
const PluginManager = require('@joplin/lib/services/PluginManager');
|
||||
|
||||
const menuUtils = new MenuUtils(CommandService.instance());
|
||||
|
||||
@ -751,16 +750,8 @@ function useMenu(props: Props) {
|
||||
rootMenus[key].submenu = cleanUpSeparators(rootMenus[key].submenu);
|
||||
}
|
||||
|
||||
{
|
||||
// This is for GotoAnything only - should be refactored since this plugin manager is not used otherwise
|
||||
const pluginMenuItems = PluginManager.instance().menuItems();
|
||||
for (const item of pluginMenuItems) {
|
||||
if (!item.parent) continue;
|
||||
const itemParent = rootMenus[item.parent] ? rootMenus[item.parent] : 'tools';
|
||||
itemParent.submenu.push(separator());
|
||||
itemParent.submenu.push(item);
|
||||
}
|
||||
}
|
||||
rootMenus.go.submenu.push(menuItemDic.gotoAnything);
|
||||
rootMenus.tools.submenu.push(menuItemDic.commandPalette);
|
||||
|
||||
for (const view of props.pluginMenuItems) {
|
||||
const location: MenuItemLocation = view.location;
|
||||
|
@ -47,5 +47,7 @@ export default function() {
|
||||
'toggleSafeMode',
|
||||
'showShareNoteDialog',
|
||||
'showShareFolderDialog',
|
||||
'gotoAnything',
|
||||
'commandPalette',
|
||||
];
|
||||
}
|
||||
|
@ -416,6 +416,8 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
});
|
||||
|
||||
if (this.userCallback_) {
|
||||
logger.info('gotoItem: user callback', item);
|
||||
|
||||
this.userCallback_.resolve({
|
||||
type: this.state.listType,
|
||||
item: { ...item },
|
||||
@ -424,6 +426,7 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
if (item.type === BaseModel.TYPE_COMMAND) {
|
||||
logger.info('gotoItem: execute command', item);
|
||||
void CommandService.instance().execute(item.id, ...item.commandArgs);
|
||||
void focusEditorIfEditorCommand(item.id, CommandService.instance());
|
||||
return;
|
||||
@ -442,6 +445,8 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
if (this.state.listType === BaseModel.TYPE_NOTE) {
|
||||
logger.info('gotoItem: note', item);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'FOLDER_AND_NOTE_SELECT',
|
||||
folderId: item.parent_id,
|
||||
@ -450,11 +455,15 @@ class Dialog extends React.PureComponent<Props, State> {
|
||||
|
||||
CommandService.instance().scheduleExecute('focusElement', 'noteBody');
|
||||
} else if (this.state.listType === BaseModel.TYPE_TAG) {
|
||||
logger.info('gotoItem: tag', item);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'TAG_SELECT',
|
||||
id: item.id,
|
||||
});
|
||||
} else if (this.state.listType === BaseModel.TYPE_FOLDER) {
|
||||
logger.info('gotoItem: folder', item);
|
||||
|
||||
this.props.dispatch({
|
||||
type: 'FOLDER_SELECT',
|
||||
id: item.id,
|
||||
@ -602,6 +611,7 @@ GotoAnything.manifest = {
|
||||
name: PLUGIN_NAME,
|
||||
menuItems: [
|
||||
{
|
||||
id: 'gotoAnything',
|
||||
name: 'main',
|
||||
parent: 'go',
|
||||
label: _('Goto Anything...'),
|
||||
@ -609,6 +619,7 @@ GotoAnything.manifest = {
|
||||
screens: ['Main'],
|
||||
},
|
||||
{
|
||||
id: 'commandPalette',
|
||||
name: 'main',
|
||||
parent: 'tools',
|
||||
label: _('Command palette'),
|
||||
|
Loading…
Reference in New Issue
Block a user