mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-17 14:19:29 +00:00
implemented copy to forum.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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'
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user