mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
Revert "Plugins: Adding support for command boolean expressions"
This reverts commitf8f46db910
. Feature was implemented in3a57cfea02
This commit is contained in:
parent
f8f46db910
commit
22dd613660
@ -275,59 +275,4 @@ describe('services_CommandService', function() {
|
||||
expect(propValue).toBe('hello');
|
||||
}));
|
||||
|
||||
it('should allow isEnabled expressions', asyncTest(async () => {
|
||||
const service = newService();
|
||||
|
||||
registerCommand(service, createCommand('test1', {
|
||||
isEnabled: 'selectedNoteCount == 1 && isMarkdownEditor',
|
||||
execute: () => {},
|
||||
}));
|
||||
|
||||
expect(service.isEnabled('test1', null, {
|
||||
selectedNoteCount: 2,
|
||||
isMarkdownEditor: true,
|
||||
})).toBe(false);
|
||||
|
||||
expect(service.isEnabled('test1', null, {
|
||||
selectedNoteCount: 1,
|
||||
isMarkdownEditor: true,
|
||||
})).toBe(true);
|
||||
|
||||
expect(service.isEnabled('test1', null, {
|
||||
selectedNoteCount: 1,
|
||||
isMarkdownEditor: false,
|
||||
})).toBe(false);
|
||||
}));
|
||||
|
||||
it('should enable and disable toolbar buttons depending on boolean expression', asyncTest(async () => {
|
||||
const service = newService();
|
||||
const toolbarButtonUtils = new ToolbarButtonUtils(service);
|
||||
|
||||
const state:any = {
|
||||
selectedNoteIds: ['note1', 'note2'],
|
||||
};
|
||||
|
||||
registerCommand(service, createCommand('test1', {
|
||||
execute: () => {},
|
||||
isEnabled: 'selectedNoteCount == 1 && selectedNoteId == note2',
|
||||
}));
|
||||
|
||||
{
|
||||
const toolbarInfos = toolbarButtonUtils.commandsToToolbarButtons(state, ['test1']);
|
||||
expect(toolbarInfos[0].enabled).toBe(false);
|
||||
}
|
||||
|
||||
{
|
||||
state.selectedNoteIds = ['note1'];
|
||||
const toolbarInfos = toolbarButtonUtils.commandsToToolbarButtons(state, ['test1']);
|
||||
expect(toolbarInfos[0].enabled).toBe(false);
|
||||
}
|
||||
|
||||
{
|
||||
state.selectedNoteIds = ['note2'];
|
||||
const toolbarInfos = toolbarButtonUtils.commandsToToolbarButtons(state, ['test1']);
|
||||
expect(toolbarInfos[0].enabled).toBe(true);
|
||||
}
|
||||
}));
|
||||
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ export const runtime = ():CommandRuntime => {
|
||||
return CommandService.instance().execute('newNote', { template: template, isTodo: true });
|
||||
},
|
||||
isEnabled: () => {
|
||||
return CommandService.instance().isEnabled('newNote', {}, null);
|
||||
return CommandService.instance().isEnabled('newNote', {});
|
||||
},
|
||||
title: () => {
|
||||
return _('New to-do');
|
||||
|
@ -788,7 +788,7 @@ function useMenu(props:Props) {
|
||||
useEffect(() => {
|
||||
for (const commandName in props.menuItemProps) {
|
||||
if (!props.menuItemProps[commandName]) continue;
|
||||
menuItemSetEnabled(commandName, CommandService.instance().isEnabled(commandName, props.menuItemProps[commandName], null));
|
||||
menuItemSetEnabled(commandName, CommandService.instance().isEnabled(commandName, props.menuItemProps[commandName]));
|
||||
}
|
||||
|
||||
const layoutButtonSequenceOptions = Setting.enumOptions('layoutButtonSequence');
|
||||
|
@ -2,15 +2,12 @@ import eventManager from 'lib/eventManager';
|
||||
import markdownUtils, { MarkdownTableHeader, MarkdownTableRow } from 'lib/markdownUtils';
|
||||
import BaseService from 'lib/services/BaseService';
|
||||
import shim from 'lib/shim';
|
||||
import BooleanExpression from './BooleanExpression';
|
||||
|
||||
type LabelFunction = () => string;
|
||||
type IsEnabledFunction = (props:any) => boolean;
|
||||
type IsEnabledExpression = string;
|
||||
|
||||
export interface CommandRuntime {
|
||||
execute(props:any):Promise<any>
|
||||
isEnabled?: IsEnabledFunction | IsEnabledExpression;
|
||||
isEnabled?(props:any):boolean
|
||||
|
||||
// "state" type is "AppState" but in order not to introduce a
|
||||
// dependency to the desktop app (so that the service can
|
||||
@ -200,23 +197,11 @@ export default class CommandService extends BaseService {
|
||||
}, 10);
|
||||
}
|
||||
|
||||
public booleanExpressionContextFromState(state:any) {
|
||||
return {
|
||||
selectedNoteCount: state.selectedNoteIds.length,
|
||||
selectedNoteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
|
||||
};
|
||||
}
|
||||
|
||||
isEnabled(commandName:string, props:any, booleanExpressionContext:any):boolean {
|
||||
isEnabled(commandName:string, props:any):boolean {
|
||||
const command = this.commandByName(commandName);
|
||||
if (!command || !command.runtime) return false;
|
||||
|
||||
if (typeof command.runtime.isEnabled === 'function') {
|
||||
return command.runtime.isEnabled(props);
|
||||
} else {
|
||||
const exp = new BooleanExpression(command.runtime.isEnabled);
|
||||
return exp.evaluate(booleanExpressionContext);
|
||||
}
|
||||
// if (!command.runtime.props) return false;
|
||||
return command.runtime.isEnabled(props);
|
||||
}
|
||||
|
||||
commandMapStateToProps(commandName:string, state:any):any {
|
||||
|
@ -35,13 +35,8 @@ export default class ToolbarButtonUtils {
|
||||
return this.service_;
|
||||
}
|
||||
|
||||
private commandToToolbarButton(commandName:string, props:any, booleanExpressionContext:any):ToolbarButtonInfo {
|
||||
const newEnabled = this.service.isEnabled(commandName, props, booleanExpressionContext);
|
||||
|
||||
if (
|
||||
this.toolbarButtonCache_[commandName] &&
|
||||
!propsHaveChanged(this.toolbarButtonCache_[commandName].props, props) &&
|
||||
this.toolbarButtonCache_[commandName].info.enabled === newEnabled) {
|
||||
private commandToToolbarButton(commandName:string, props:any):ToolbarButtonInfo {
|
||||
if (this.toolbarButtonCache_[commandName] && !propsHaveChanged(this.toolbarButtonCache_[commandName].props, props)) {
|
||||
return this.toolbarButtonCache_[commandName].info;
|
||||
}
|
||||
|
||||
@ -51,7 +46,7 @@ export default class ToolbarButtonUtils {
|
||||
name: commandName,
|
||||
tooltip: this.service.label(commandName),
|
||||
iconName: command.declaration.iconName,
|
||||
enabled: newEnabled,
|
||||
enabled: this.service.isEnabled(commandName, props),
|
||||
onClick: async () => {
|
||||
this.service.execute(commandName, props);
|
||||
},
|
||||
@ -72,8 +67,6 @@ export default class ToolbarButtonUtils {
|
||||
public commandsToToolbarButtons(state:any, commandNames:string[]):ToolbarButtonInfo[] {
|
||||
const output:ToolbarButtonInfo[] = [];
|
||||
|
||||
const booleanExpressionContext = this.service.booleanExpressionContextFromState(state);
|
||||
|
||||
for (const commandName of commandNames) {
|
||||
if (commandName === '-') {
|
||||
output.push(separatorItem as any);
|
||||
@ -81,7 +74,7 @@ export default class ToolbarButtonUtils {
|
||||
}
|
||||
|
||||
const props = this.service.commandMapStateToProps(commandName, state);
|
||||
output.push(this.commandToToolbarButton(commandName, props, booleanExpressionContext));
|
||||
output.push(this.commandToToolbarButton(commandName, props));
|
||||
}
|
||||
|
||||
return stateUtils.selectArrayShallow({ array: output }, commandNames.join('_'));
|
||||
|
@ -87,7 +87,7 @@ function filterLogs(logs, platform) {
|
||||
if (platform === 'android' && prefix.indexOf('android') >= 0) addIt = true;
|
||||
if (platform === 'ios' && prefix.indexOf('ios') >= 0) addIt = true;
|
||||
if (platform === 'desktop' && prefix.indexOf('desktop') >= 0) addIt = true;
|
||||
if (platform === 'desktop' && (prefix.indexOf('desktop') >= 0 || prefix.indexOf('api') >= 0 || prefix.indexOf('plugins') >= 0)) addIt = true;
|
||||
if (platform === 'desktop' && (prefix.indexOf('desktop') >= 0 || prefix.indexOf('api') >= 0)) addIt = true;
|
||||
if (platform === 'cli' && prefix.indexOf('cli') >= 0) addIt = true;
|
||||
if (platform === 'clipper' && prefix.indexOf('clipper') >= 0) addIt = true;
|
||||
|
||||
@ -121,7 +121,7 @@ function formatCommitMessage(msg, author, options) {
|
||||
const isPlatformPrefix = prefix => {
|
||||
prefix = prefix.split(',').map(p => p.trim().toLowerCase());
|
||||
for (const p of prefix) {
|
||||
if (['android', 'mobile', 'ios', 'desktop', 'cli', 'clipper', 'all', 'api', 'plugins'].indexOf(p) >= 0) return true;
|
||||
if (['android', 'mobile', 'ios', 'desktop', 'cli', 'clipper', 'all', 'api'].indexOf(p) >= 0) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
@ -129,7 +129,6 @@ function formatCommitMessage(msg, author, options) {
|
||||
if (splitted.length) {
|
||||
const platform = splitted[0].trim().toLowerCase();
|
||||
if (platform === 'api') subModule = 'api';
|
||||
if (platform === 'plugins') subModule = 'plugins';
|
||||
if (isPlatformPrefix(platform)) {
|
||||
splitted.splice(0, 1);
|
||||
}
|
||||
|
@ -360,8 +360,7 @@
|
||||
"CliClient/tests/support/plugins/settings/**/node_modules/": true,
|
||||
"CliClient/tests/support/plugins/selected_text/dist/*": true,
|
||||
"CliClient/tests/support/plugins/selected_text/**/node_modules/": true,
|
||||
"**/CliClient/build/": true,
|
||||
"**/*.js": {"when": "$(basename).ts"},
|
||||
"**/CliClient/build/": true
|
||||
},
|
||||
"spellright.language": [
|
||||
"en"
|
||||
|
Loading…
Reference in New Issue
Block a user