本文整理匯總了TypeScript中@phosphor/commands.CommandRegistry.addCommand方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CommandRegistry.addCommand方法的具體用法?TypeScript CommandRegistry.addCommand怎麽用?TypeScript CommandRegistry.addCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@phosphor/commands.CommandRegistry
的用法示例。
在下文中一共展示了CommandRegistry.addCommand方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should resolve an exact match of partial match time out', (done) => {
let called1 = false;
let called2 = false;
registry.addCommand('test1', {
execute: () => { called1 = true; }
});
registry.addCommand('test2', {
execute: () => { called2 = true; }
});
registry.addKeyBinding({
keys: ['D', 'D'],
selector: `#${elem.id}`,
command: 'test1'
});
registry.addKeyBinding({
keys: ['D'],
selector: `#${elem.id}`,
command: 'test2'
});
let event = generate('keydown', { keyCode: 68 });
elem.dispatchEvent(event);
expect(called1).to.equal(false);
expect(called2).to.equal(false);
setTimeout(() => {
expect(called1).to.equal(false);
expect(called2).to.equal(true);
done();
}, 1300);
});
示例2: it
it('should stop routing if returned by a routed command', done => {
const wanted = ['a', 'b'];
const recorded: string[] = [];
commands.addCommand('a', {
execute: () => {
recorded.push('a');
}
});
commands.addCommand('b', {
execute: () => {
recorded.push('b');
}
});
commands.addCommand('c', { execute: () => router.stop });
commands.addCommand('d', {
execute: () => {
recorded.push('d');
}
});
router.register({ command: 'a', pattern: /.*/, rank: 10 });
router.register({ command: 'b', pattern: /.*/, rank: 20 });
router.register({ command: 'c', pattern: /.*/, rank: 30 });
router.register({ command: 'd', pattern: /.*/, rank: 40 });
router.routed.connect(() => {
expect(recorded).to.deep.equal(wanted);
done();
});
router.route();
});
示例3: it
it('should stop routing if returned by a routed command', async () => {
const wanted = ['a', 'b'];
const recorded: string[] = [];
commands.addCommand('a', {
execute: () => {
recorded.push('a');
}
});
commands.addCommand('b', {
execute: () => {
recorded.push('b');
}
});
commands.addCommand('c', { execute: () => router.stop });
commands.addCommand('d', {
execute: () => {
recorded.push('d');
}
});
router.register({ command: 'a', pattern: /.*/, rank: 10 });
router.register({ command: 'b', pattern: /.*/, rank: 20 });
router.register({ command: 'c', pattern: /.*/, rank: 30 });
router.register({ command: 'd', pattern: /.*/, rank: 40 });
let promise = signalToPromise(router.routed);
await router.route();
await promise;
expect(recorded).to.deep.equal(wanted);
});
示例4: addDefaultCommands
function addDefaultCommands(tracker: ITerminalTracker, commands: CommandRegistry) {
/**
* Whether there is an active terminal.
*/
function hasWidget(): boolean {
return tracker.currentWidget !== null;
}
commands.addCommand('terminal:increase-font', {
label: 'Increase Terminal Font Size',
execute: () => {
let options = TerminalWidget.defaultOptions;
if (options.fontSize < 72) {
options.fontSize++;
tracker.forEach(widget => { widget.fontSize = options.fontSize; });
}
},
isEnabled: hasWidget
});
commands.addCommand('terminal:decrease-font', {
label: 'Decrease Terminal Font Size',
execute: () => {
let options = TerminalWidget.defaultOptions;
if (options.fontSize > 9) {
options.fontSize--;
tracker.forEach(widget => { widget.fontSize = options.fontSize; });
}
},
isEnabled: hasWidget
});
commands.addCommand('terminal:toggle-theme', {
label: 'Toggle Terminal Theme',
caption: 'Switch Terminal Background and Font Colors',
execute: () => {
let options = TerminalWidget.defaultOptions;
if (options.background === 'black') {
options.background = 'white';
options.color = 'black';
} else {
options.background = 'black';
options.color = 'white';
}
tracker.forEach(widget => {
widget.background = options.background;
widget.color = options.color;
});
},
isEnabled: hasWidget
});
}
示例5: addDefaultCommands
function addDefaultCommands(tracker: IImageTracker, commands: CommandRegistry) {
commands.addCommand('imagewidget:zoom-in', {
execute: zoomIn,
label: 'Zoom In'
});
commands.addCommand('imagewidget:zoom-out', {
execute: zoomOut,
label: 'Zoom Out'
});
commands.addCommand('imagewidget:reset-zoom', {
execute: resetZoom,
label: 'Reset Zoom'
});
function zoomIn(): void {
let widget = tracker.currentWidget;
if (!widget) {
return;
}
if (widget.scale > 1) {
widget.scale += .5;
} else {
widget.scale *= 2;
}
}
function zoomOut(): void {
let widget = tracker.currentWidget;
if (!widget) {
return;
}
if (widget.scale > 1) {
widget.scale -= .5;
} else {
widget.scale /= 2;
}
}
function resetZoom(): void {
let widget = tracker.currentWidget;
if (!widget) {
return;
}
widget.scale = 1;
}
}
示例6: it
it('should restore the widgets in a tracker', done => {
let tracker = new InstanceTracker<Widget>({
namespace: 'foo-widget',
shell: new ApplicationShell()
});
let registry = new CommandRegistry();
let state = new StateDB({ namespace: NAMESPACE });
let ready = new PromiseDelegate<void>();
let restorer = new LayoutRestorer({
first: ready.promise, registry, state
});
let called = false;
let key = `${tracker.namespace}:${tracker.namespace}`;
registry.addCommand(tracker.namespace, {
execute: () => { called = true; }
});
state.save(key, { data: null }).then(() => {
return restorer.restore(tracker, {
args: () => null,
name: () => tracker.namespace,
command: tracker.namespace
});
}).catch(done);
ready.resolve(void 0);
restorer.restored.then(() => { expect(called).to.be(true); })
.then(() => state.remove(key))
.then(() => { done(); })
.catch(done);
});
示例7: before
before(() => {
commands = new CommandRegistry();
bkoMenu = new BkoMenu({ commands });
commands.addCommand('test', { execute: () => {} });
bkoMenu.addItem({command: 'test', submenu: bkoMenu, type: 'submenu'});
});