implemented copy to forum.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-18 14:22:54 +02:00
parent e0d4634f32
commit 33af9b6005
4 changed files with 76 additions and 0 deletions

View File

@ -96,6 +96,7 @@ import { SaveSketch } from './contributions/save-sketch';
import { VerifySketch } from './contributions/verify-sketch';
import { UploadSketch } from './contributions/upload-sketch';
import { CommonFrontendContribution } from './customization/core/common-frontend-contribution';
import { CopyToForum } from './contributions/copy-to-forum';
const ElementQueries = require('css-element-queries/src/ElementQueries');
@ -324,4 +325,5 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
Contribution.configure(bind, SaveAsSketch);
Contribution.configure(bind, VerifySketch);
Contribution.configure(bind, UploadSketch);
Contribution.configure(bind, CopyToForum);
});

View File

@ -11,6 +11,8 @@ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/li
import { Command, CommandRegistry, CommandContribution, CommandService } from '@theia/core/lib/common/command';
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
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 };
@ -74,6 +76,19 @@ 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;
}
}
export namespace Contribution {
export function configure<T>(bind: interfaces.Bind, serviceIdentifier: interfaces.ServiceIdentifier<T>): void {
bind(serviceIdentifier).toSelf().inSingletonScope();

View File

@ -0,0 +1,53 @@
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'
};
}
}

View File

@ -8,6 +8,12 @@ export namespace ArduinoMenus {
export const FILE__SKETCH_GROUP = [...CommonMenus.FILE, '0_sketch'];
export const FILE__PRINT_GROUP = [...CommonMenus.FILE, '1_print'];
// Edit
export const EDIT__TEXT_CONTROL_GROUP = [...CommonMenus.EDIT, '1_text_control']; // `Copy`, `Copy to Forum`, `Paste`, etc.
export const EDIT__CODE_CONTROL_GROUP = [...CommonMenus.EDIT, '2_code_control']; // `Comment/Uncomment`, etc.
export const EDIT__FONT_CONTROL_GROUP = [...CommonMenus.EDIT, '3_font_control'];
export const EDIT__FIND_GROUP = [...CommonMenus.EDIT, '4_find'];
// Sketch
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
export const SKETCH__MAIN_GROUP = [...SKETCH, '0_main'];