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.d.ts
|
||||||
packages/app-desktop/gui/MainScreen/MainScreen.js
|
packages/app-desktop/gui/MainScreen/MainScreen.js
|
||||||
packages/app-desktop/gui/MainScreen/MainScreen.js.map
|
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.d.ts
|
||||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
||||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
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.d.ts
|
||||||
packages/app-desktop/gui/MainScreen/MainScreen.js
|
packages/app-desktop/gui/MainScreen/MainScreen.js
|
||||||
packages/app-desktop/gui/MainScreen/MainScreen.js.map
|
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.d.ts
|
||||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
packages/app-desktop/gui/MainScreen/commands/editAlarm.js
|
||||||
packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
packages/app-desktop/gui/MainScreen/commands/editAlarm.js.map
|
||||||
|
@ -46,6 +46,7 @@ const commands = [
|
|||||||
require('./gui/MainScreen/commands/editAlarm'),
|
require('./gui/MainScreen/commands/editAlarm'),
|
||||||
require('./gui/MainScreen/commands/exportPdf'),
|
require('./gui/MainScreen/commands/exportPdf'),
|
||||||
require('./gui/MainScreen/commands/gotoAnything'),
|
require('./gui/MainScreen/commands/gotoAnything'),
|
||||||
|
require('./gui/MainScreen/commands/commandPalette'),
|
||||||
require('./gui/MainScreen/commands/hideModalMessage'),
|
require('./gui/MainScreen/commands/hideModalMessage'),
|
||||||
require('./gui/MainScreen/commands/moveToFolder'),
|
require('./gui/MainScreen/commands/moveToFolder'),
|
||||||
require('./gui/MainScreen/commands/newFolder'),
|
require('./gui/MainScreen/commands/newFolder'),
|
||||||
|
@ -16,16 +16,12 @@ const getLabel = (commandName: string): string => {
|
|||||||
return _('Quit');
|
return _('Quit');
|
||||||
case 'zoomActualSize':
|
case 'zoomActualSize':
|
||||||
return _('Actual Size');
|
return _('Actual Size');
|
||||||
case 'gotoAnything':
|
|
||||||
return _('Goto Anything...');
|
|
||||||
case 'help':
|
case 'help':
|
||||||
return _('Website and documentation');
|
return _('Website and documentation');
|
||||||
case 'hideApp':
|
case 'hideApp':
|
||||||
return _('Hide Joplin');
|
return _('Hide Joplin');
|
||||||
case 'closeWindow':
|
case 'closeWindow':
|
||||||
return _('Close Window');
|
return _('Close Window');
|
||||||
case 'commandPalette':
|
|
||||||
return _('Command palette');
|
|
||||||
case 'config':
|
case 'config':
|
||||||
return shim.isMac() ? _('Preferences') : _('Options');
|
return shim.isMac() ? _('Preferences') : _('Options');
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ const commands = [
|
|||||||
require('./commands/editAlarm'),
|
require('./commands/editAlarm'),
|
||||||
require('./commands/exportPdf'),
|
require('./commands/exportPdf'),
|
||||||
require('./commands/gotoAnything'),
|
require('./commands/gotoAnything'),
|
||||||
|
require('./commands/commandPalette'),
|
||||||
require('./commands/hideModalMessage'),
|
require('./commands/hideModalMessage'),
|
||||||
require('./commands/moveToFolder'),
|
require('./commands/moveToFolder'),
|
||||||
require('./commands/newFolder'),
|
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');
|
const PluginManager = require('@joplin/lib/services/PluginManager');
|
||||||
|
|
||||||
|
export enum UiType {
|
||||||
|
GotoAnything = 'gotoAnything',
|
||||||
|
CommandPalette = 'commandPalette',
|
||||||
|
ControlledApi = 'controlledApi',
|
||||||
|
}
|
||||||
|
|
||||||
export const declaration: CommandDeclaration = {
|
export const declaration: CommandDeclaration = {
|
||||||
name: 'gotoAnything',
|
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 => {
|
export const runtime = (): CommandRuntime => {
|
||||||
return {
|
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) => {
|
return new Promise((resolve: Function, reject: Function) => {
|
||||||
const menuItem = PluginManager.instance().menuItems().find((i: any) => i.id === 'controlledApi');
|
const menuItem = PluginManager.instance().menuItems().find((i: any) => i.id === 'controlledApi');
|
||||||
menuItem.userData = {
|
menuItem.userData = {
|
||||||
@ -15,6 +36,7 @@ export const runtime = (): CommandRuntime => {
|
|||||||
};
|
};
|
||||||
menuItem.click();
|
menuItem.click();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,6 @@ import { reg } from '@joplin/lib/registry';
|
|||||||
const packageInfo = require('../packageInfo.js');
|
const packageInfo = require('../packageInfo.js');
|
||||||
const { clipboard } = require('electron');
|
const { clipboard } = require('electron');
|
||||||
const Menu = bridge().Menu;
|
const Menu = bridge().Menu;
|
||||||
const PluginManager = require('@joplin/lib/services/PluginManager');
|
|
||||||
|
|
||||||
const menuUtils = new MenuUtils(CommandService.instance());
|
const menuUtils = new MenuUtils(CommandService.instance());
|
||||||
|
|
||||||
@ -751,16 +750,8 @@ function useMenu(props: Props) {
|
|||||||
rootMenus[key].submenu = cleanUpSeparators(rootMenus[key].submenu);
|
rootMenus[key].submenu = cleanUpSeparators(rootMenus[key].submenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
rootMenus.go.submenu.push(menuItemDic.gotoAnything);
|
||||||
// This is for GotoAnything only - should be refactored since this plugin manager is not used otherwise
|
rootMenus.tools.submenu.push(menuItemDic.commandPalette);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const view of props.pluginMenuItems) {
|
for (const view of props.pluginMenuItems) {
|
||||||
const location: MenuItemLocation = view.location;
|
const location: MenuItemLocation = view.location;
|
||||||
|
@ -47,5 +47,7 @@ export default function() {
|
|||||||
'toggleSafeMode',
|
'toggleSafeMode',
|
||||||
'showShareNoteDialog',
|
'showShareNoteDialog',
|
||||||
'showShareFolderDialog',
|
'showShareFolderDialog',
|
||||||
|
'gotoAnything',
|
||||||
|
'commandPalette',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -416,6 +416,8 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.userCallback_) {
|
if (this.userCallback_) {
|
||||||
|
logger.info('gotoItem: user callback', item);
|
||||||
|
|
||||||
this.userCallback_.resolve({
|
this.userCallback_.resolve({
|
||||||
type: this.state.listType,
|
type: this.state.listType,
|
||||||
item: { ...item },
|
item: { ...item },
|
||||||
@ -424,6 +426,7 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === BaseModel.TYPE_COMMAND) {
|
if (item.type === BaseModel.TYPE_COMMAND) {
|
||||||
|
logger.info('gotoItem: execute command', item);
|
||||||
void CommandService.instance().execute(item.id, ...item.commandArgs);
|
void CommandService.instance().execute(item.id, ...item.commandArgs);
|
||||||
void focusEditorIfEditorCommand(item.id, CommandService.instance());
|
void focusEditorIfEditorCommand(item.id, CommandService.instance());
|
||||||
return;
|
return;
|
||||||
@ -442,6 +445,8 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.listType === BaseModel.TYPE_NOTE) {
|
if (this.state.listType === BaseModel.TYPE_NOTE) {
|
||||||
|
logger.info('gotoItem: note', item);
|
||||||
|
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'FOLDER_AND_NOTE_SELECT',
|
type: 'FOLDER_AND_NOTE_SELECT',
|
||||||
folderId: item.parent_id,
|
folderId: item.parent_id,
|
||||||
@ -450,11 +455,15 @@ class Dialog extends React.PureComponent<Props, State> {
|
|||||||
|
|
||||||
CommandService.instance().scheduleExecute('focusElement', 'noteBody');
|
CommandService.instance().scheduleExecute('focusElement', 'noteBody');
|
||||||
} else if (this.state.listType === BaseModel.TYPE_TAG) {
|
} else if (this.state.listType === BaseModel.TYPE_TAG) {
|
||||||
|
logger.info('gotoItem: tag', item);
|
||||||
|
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'TAG_SELECT',
|
type: 'TAG_SELECT',
|
||||||
id: item.id,
|
id: item.id,
|
||||||
});
|
});
|
||||||
} else if (this.state.listType === BaseModel.TYPE_FOLDER) {
|
} else if (this.state.listType === BaseModel.TYPE_FOLDER) {
|
||||||
|
logger.info('gotoItem: folder', item);
|
||||||
|
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'FOLDER_SELECT',
|
type: 'FOLDER_SELECT',
|
||||||
id: item.id,
|
id: item.id,
|
||||||
@ -602,6 +611,7 @@ GotoAnything.manifest = {
|
|||||||
name: PLUGIN_NAME,
|
name: PLUGIN_NAME,
|
||||||
menuItems: [
|
menuItems: [
|
||||||
{
|
{
|
||||||
|
id: 'gotoAnything',
|
||||||
name: 'main',
|
name: 'main',
|
||||||
parent: 'go',
|
parent: 'go',
|
||||||
label: _('Goto Anything...'),
|
label: _('Goto Anything...'),
|
||||||
@ -609,6 +619,7 @@ GotoAnything.manifest = {
|
|||||||
screens: ['Main'],
|
screens: ['Main'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: 'commandPalette',
|
||||||
name: 'main',
|
name: 'main',
|
||||||
parent: 'tools',
|
parent: 'tools',
|
||||||
label: _('Command palette'),
|
label: _('Command palette'),
|
||||||
|
Loading…
Reference in New Issue
Block a user