mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-15 16:46:32 +00:00
implemented a few more edit contributions.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
c0cadf2b9b
commit
540a6215e4
@ -96,9 +96,7 @@ import { SaveSketch } from './contributions/save-sketch';
|
|||||||
import { VerifySketch } from './contributions/verify-sketch';
|
import { VerifySketch } from './contributions/verify-sketch';
|
||||||
import { UploadSketch } from './contributions/upload-sketch';
|
import { UploadSketch } from './contributions/upload-sketch';
|
||||||
import { CommonFrontendContribution } from './customization/core/common-frontend-contribution';
|
import { CommonFrontendContribution } from './customization/core/common-frontend-contribution';
|
||||||
import { CopyToForum } from './contributions/copy-to-forum';
|
import { EditContributions } from './contributions/edit-contributions';
|
||||||
import { GoToLine } from './contributions/go-to-line';
|
|
||||||
import { ToggleComment } from './contributions/toggle-comment';
|
|
||||||
|
|
||||||
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
||||||
|
|
||||||
@ -327,7 +325,5 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
|
|||||||
Contribution.configure(bind, SaveAsSketch);
|
Contribution.configure(bind, SaveAsSketch);
|
||||||
Contribution.configure(bind, VerifySketch);
|
Contribution.configure(bind, VerifySketch);
|
||||||
Contribution.configure(bind, UploadSketch);
|
Contribution.configure(bind, UploadSketch);
|
||||||
Contribution.configure(bind, CopyToForum);
|
Contribution.configure(bind, EditContributions);
|
||||||
Contribution.configure(bind, GoToLine);
|
|
||||||
Contribution.configure(bind, ToggleComment);
|
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@ export class CloseSketch extends SketchContribution {
|
|||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
|
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
|
||||||
execute: async () => {
|
execute: async () => {
|
||||||
const sketch = await this.getCurrentSketch();
|
const sketch = await this.currentSketch();
|
||||||
if (!sketch) {
|
if (!sketch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/li
|
|||||||
import { Command, CommandRegistry, CommandContribution, CommandService } from '@theia/core/lib/common/command';
|
import { Command, CommandRegistry, CommandContribution, CommandService } from '@theia/core/lib/common/command';
|
||||||
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
|
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
|
||||||
import { EditorMode } from '../editor-mode';
|
import { EditorMode } from '../editor-mode';
|
||||||
import { EditorManager } from '@theia/editor/lib/browser';
|
|
||||||
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
|
||||||
|
|
||||||
export { Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, URI, Sketch };
|
export { Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, URI, Sketch };
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ export abstract class SketchContribution extends Contribution {
|
|||||||
@inject(SketchesService)
|
@inject(SketchesService)
|
||||||
protected readonly sketchService: SketchesService;
|
protected readonly sketchService: SketchesService;
|
||||||
|
|
||||||
protected async getCurrentSketch(): Promise<Sketch | undefined> {
|
protected async currentSketch(): Promise<Sketch | undefined> {
|
||||||
const sketches = (await Promise.all(this.workspaceService.tryGetRoots().map(({ uri }) => this.sketchService.getSketchFolder(uri)))).filter(notEmpty);
|
const sketches = (await Promise.all(this.workspaceService.tryGetRoots().map(({ uri }) => this.sketchService.getSketchFolder(uri)))).filter(notEmpty);
|
||||||
if (!sketches.length) {
|
if (!sketches.length) {
|
||||||
return;
|
return;
|
||||||
@ -76,29 +74,6 @@ export abstract class SketchContribution extends Contribution {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export abstract class EditorContribution extends Contribution {
|
|
||||||
|
|
||||||
@inject(EditorManager)
|
|
||||||
protected readonly editorManager: EditorManager;
|
|
||||||
|
|
||||||
protected async current(): Promise<MonacoEditor | undefined> {
|
|
||||||
const editor = this.editorManager.currentEditor?.editor;
|
|
||||||
return editor instanceof MonacoEditor ? editor : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async run(commandId: string): Promise<any> {
|
|
||||||
const editor = await this.current();
|
|
||||||
if (editor) {
|
|
||||||
const action = editor.getControl().getAction(commandId);
|
|
||||||
if (action) {
|
|
||||||
return action.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace Contribution {
|
export namespace Contribution {
|
||||||
export function configure<T>(bind: interfaces.Bind, serviceIdentifier: interfaces.ServiceIdentifier<T>): void {
|
export function configure<T>(bind: interfaces.Bind, serviceIdentifier: interfaces.ServiceIdentifier<T>): void {
|
||||||
bind(serviceIdentifier).toSelf().inSingletonScope();
|
bind(serviceIdentifier).toSelf().inSingletonScope();
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
|
||||||
import { EditorContribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
|
||||||
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class CopyToForum extends EditorContribution {
|
|
||||||
|
|
||||||
@inject(ClipboardService)
|
|
||||||
protected readonly clipboardService: ClipboardService;
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
|
||||||
registry.registerCommand(CopyToForum.Commands.COPY_TO_FORUM, {
|
|
||||||
execute: () => this.copyToForum()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: CopyToForum.Commands.COPY_TO_FORUM.id,
|
|
||||||
label: 'Copy to Forum',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: CopyToForum.Commands.COPY_TO_FORUM.id,
|
|
||||||
keybinding: 'CtrlCmd+Shift+C'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async copyToForum(): Promise<void> {
|
|
||||||
const editor = await this.current();
|
|
||||||
if (editor) {
|
|
||||||
const value = editor.getControl().getModel()?.getValue();
|
|
||||||
if (value !== undefined) {
|
|
||||||
return this.clipboardService.writeText(`[code]
|
|
||||||
${value}
|
|
||||||
[/code]`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace CopyToForum {
|
|
||||||
export namespace Commands {
|
|
||||||
export const COPY_TO_FORUM: Command = {
|
|
||||||
id: 'arduino-copy-to-forum'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,141 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { EditorManager } from '@theia/editor/lib/browser';
|
||||||
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
||||||
|
import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
||||||
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class EditContributions extends Contribution {
|
||||||
|
|
||||||
|
@inject(ClipboardService)
|
||||||
|
protected readonly clipboardService: ClipboardService;
|
||||||
|
|
||||||
|
@inject(EditorManager)
|
||||||
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(EditContributions.Commands.GO_TO_LINE, { execute: () => this.run('editor.action.gotoLine') });
|
||||||
|
registry.registerCommand(EditContributions.Commands.TOGGLE_COMMENT, { execute: () => this.run('editor.action.commentLine') });
|
||||||
|
registry.registerCommand(EditContributions.Commands.INDENT_LINES, { execute: () => this.run('editor.action.indentLines') });
|
||||||
|
registry.registerCommand(EditContributions.Commands.OUTDENT_LINES, { execute: () => this.run('editor.action.outdentLines') });
|
||||||
|
registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, {
|
||||||
|
execute: async () => {
|
||||||
|
const value = await this.currentValue();
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.clipboardService.writeText(`[code]
|
||||||
|
${value}
|
||||||
|
[/code]`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
registry.registerCommand(EditContributions.Commands.COPY_FOR_MARKDOWN, {
|
||||||
|
execute: async () => {
|
||||||
|
const value = await this.currentValue();
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.clipboardService.writeText(`\`\`\`cpp
|
||||||
|
${value}
|
||||||
|
\`\`\``)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.COPY_FOR_FORUM.id,
|
||||||
|
label: 'Copy for Forum',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.COPY_FOR_MARKDOWN.id,
|
||||||
|
label: 'Copy for GitHub [Markdown]',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.GO_TO_LINE.id,
|
||||||
|
label: 'Go to Line...',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.TOGGLE_COMMENT.id,
|
||||||
|
label: 'Comment/Uncomment',
|
||||||
|
order: '0'
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.INDENT_LINES.id,
|
||||||
|
label: 'Increase Indent',
|
||||||
|
order: '1'
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.OUTDENT_LINES.id,
|
||||||
|
label: 'Decrease Indent',
|
||||||
|
order: '2'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.COPY_FOR_FORUM.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+C'
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.GO_TO_LINE.id,
|
||||||
|
keybinding: 'CtrlCmd+L'
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.TOGGLE_COMMENT.id,
|
||||||
|
keybinding: 'CtrlCmd+/'
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.INDENT_LINES.id,
|
||||||
|
keybinding: 'Tab'
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.OUTDENT_LINES.id,
|
||||||
|
keybinding: 'Shift+Tab'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async current(): Promise<MonacoEditor | undefined> {
|
||||||
|
const editor = this.editorManager.currentEditor?.editor;
|
||||||
|
return editor instanceof MonacoEditor ? editor : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async currentValue(): Promise<string | undefined> {
|
||||||
|
return this.editorManager.currentEditor?.editor.document.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async run(commandId: string): Promise<any> {
|
||||||
|
const editor = await this.current();
|
||||||
|
if (editor) {
|
||||||
|
const action = editor.getControl().getAction(commandId);
|
||||||
|
if (action) {
|
||||||
|
return action.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace EditContributions {
|
||||||
|
export namespace Commands {
|
||||||
|
export const COPY_FOR_FORUM: Command = {
|
||||||
|
id: 'arduino-copy-for-forum'
|
||||||
|
};
|
||||||
|
export const COPY_FOR_MARKDOWN: Command = {
|
||||||
|
id: 'arduino-copy-for-markdown'
|
||||||
|
};
|
||||||
|
export const GO_TO_LINE: Command = {
|
||||||
|
id: 'arduino-go-to-line'
|
||||||
|
};
|
||||||
|
export const TOGGLE_COMMENT: Command = {
|
||||||
|
id: 'arduino-toggle-comment'
|
||||||
|
};
|
||||||
|
export const INDENT_LINES: Command = {
|
||||||
|
id: 'arduino-indent-lines'
|
||||||
|
};
|
||||||
|
export const OUTDENT_LINES: Command = {
|
||||||
|
id: 'arduino-outdent-lines'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,41 +0,0 @@
|
|||||||
import { injectable } from 'inversify';
|
|
||||||
import { EditorContribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class GoToLine extends EditorContribution {
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
|
||||||
registry.registerCommand(GoToLine.Commands.GO_TO_LINE, {
|
|
||||||
execute: () => this.goToLine()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: GoToLine.Commands.GO_TO_LINE.id,
|
|
||||||
label: 'Go to Line...',
|
|
||||||
order: '6'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: GoToLine.Commands.GO_TO_LINE.id,
|
|
||||||
keybinding: 'CtrlCmd+L'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async goToLine(): Promise<void> {
|
|
||||||
return this.run('editor.action.gotoLine');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace GoToLine {
|
|
||||||
export namespace Commands {
|
|
||||||
export const GO_TO_LINE: Command = {
|
|
||||||
id: 'arduino-go-to-line'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,7 +32,7 @@ export class SaveAsSketch extends SketchContribution {
|
|||||||
* Resolves `true` if the sketch was successfully saved as something.
|
* Resolves `true` if the sketch was successfully saved as something.
|
||||||
*/
|
*/
|
||||||
async saveAs({ execOnlyIfTemp, openAfterMove }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<boolean> {
|
async saveAs({ execOnlyIfTemp, openAfterMove }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<boolean> {
|
||||||
const sketch = await this.getCurrentSketch();
|
const sketch = await this.currentSketch();
|
||||||
if (!sketch) {
|
if (!sketch) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import { injectable } from 'inversify';
|
|
||||||
import { EditorContribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class ToggleComment extends EditorContribution {
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
|
||||||
registry.registerCommand(ToggleComment.Commands.TOGGLE_COMMENT, {
|
|
||||||
execute: () => this.toggleComment()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
|
||||||
commandId: ToggleComment.Commands.TOGGLE_COMMENT.id,
|
|
||||||
label: 'Comment/Uncomment',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: ToggleComment.Commands.TOGGLE_COMMENT.id,
|
|
||||||
keybinding: 'CtrlCmd+L'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleComment(): Promise<void> {
|
|
||||||
return this.run('editor.action.commentLine');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace ToggleComment {
|
|
||||||
export namespace Commands {
|
|
||||||
export const TOGGLE_COMMENT: Command = {
|
|
||||||
id: 'arduino-toggle-comment'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -57,7 +57,7 @@ export class UploadSketch extends SketchContribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async uploadSketch(): Promise<void> {
|
async uploadSketch(): Promise<void> {
|
||||||
const sketch = await this.getCurrentSketch();
|
const sketch = await this.currentSketch();
|
||||||
if (!sketch) {
|
if (!sketch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ export class VerifySketch extends SketchContribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifySketch(): Promise<void> {
|
async verifySketch(): Promise<void> {
|
||||||
const sketch = await this.getCurrentSketch();
|
const sketch = await this.currentSketch();
|
||||||
if (!sketch) {
|
if (!sketch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user