forked from arduino/arduino-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboards-widget-frontend-contribution.ts
98 lines (90 loc) · 2.88 KB
/
boards-widget-frontend-contribution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { MenuPath } from '@theia/core';
import { Command } from '@theia/core/lib/common/command';
import { nls } from '@theia/core/lib/common/nls';
import { inject, injectable } from '@theia/core/shared/inversify';
import { Type as TypeLabel } from '../../common/nls';
import {
BoardSearch,
BoardsPackage,
} from '../../common/protocol/boards-service';
import { URI } from '../contributions/contribution';
import { MenuActionTemplate, SubmenuTemplate } from '../menu/register-menu';
import { ListWidgetFrontendContribution } from '../widgets/component-list/list-widget-frontend-contribution';
import {
BoardsListWidget,
BoardsListWidgetSearchOptions,
} from './boards-list-widget';
@injectable()
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution<
BoardsPackage,
BoardSearch
> {
@inject(BoardsListWidgetSearchOptions)
protected readonly searchOptions: BoardsListWidgetSearchOptions;
constructor() {
super({
widgetId: BoardsListWidget.WIDGET_ID,
widgetName: BoardsListWidget.WIDGET_LABEL,
defaultWidgetOptions: {
area: 'left',
rank: 2,
},
toggleCommandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
toggleKeybinding: 'CtrlCmd+Shift+B',
});
}
protected canParse(uri: URI): boolean {
try {
BoardSearch.UriParser.parse(uri);
return true;
} catch {
return false;
}
}
protected parse(uri: URI): BoardSearch | undefined {
return BoardSearch.UriParser.parse(uri);
}
protected buildFilterMenuGroup(
menuPath: MenuPath
): Array<MenuActionTemplate | SubmenuTemplate> {
const typeSubmenuPath = [...menuPath, TypeLabel];
return [
{
submenuPath: typeSubmenuPath,
menuLabel: `${TypeLabel}: "${
BoardSearch.TypeLabels[this.searchOptions.options.type]
}"`,
options: { order: String(0) },
},
...this.buildMenuActions<BoardSearch.Type>(
typeSubmenuPath,
BoardSearch.TypeLiterals.slice(),
(type) => this.searchOptions.options.type === type,
(type) => this.searchOptions.update({ type }),
(type) => BoardSearch.TypeLabels[type]
),
];
}
protected get showViewFilterContextMenuCommand(): Command & {
label: string;
} {
return BoardsListWidgetFrontendContribution.Commands
.SHOW_BOARDS_LIST_WIDGET_FILTER_CONTEXT_MENU;
}
protected get showInstalledCommandId(): string {
return 'arduino-show-installed-boards';
}
protected get showUpdatesCommandId(): string {
return 'arduino-show-boards-updates';
}
}
export namespace BoardsListWidgetFrontendContribution {
export namespace Commands {
export const SHOW_BOARDS_LIST_WIDGET_FILTER_CONTEXT_MENU: Command & {
label: string;
} = {
id: 'arduino-boards-list-widget-show-filter-context-menu',
label: nls.localize('arduino/boards/filterBoards', 'Filter Boards...'),
};
}
}