|
| 1 | +import * as React from "react"; |
| 2 | +import { |
| 3 | + injectable, |
| 4 | + postConstruct, |
| 5 | + inject, |
| 6 | +} from "@theia/core/shared/inversify"; |
| 7 | +import { AlertMessage } from "@theia/core/lib/browser/widgets/alert-message"; |
| 8 | +import { ReactWidget } from "@theia/core/lib/browser/widgets/react-widget"; |
| 9 | +import { MessageService } from "@theia/core"; |
| 10 | +import { Message, QuickInputService, InputBox } from "@theia/core/lib/browser"; |
| 11 | +import { AbstractViewContribution } from "@theia/core/lib/browser"; |
| 12 | +import { Command, CommandRegistry } from "@theia/core/lib/common/command"; |
| 13 | +import { crdebug } from "./cr-logger"; |
| 14 | + |
| 15 | +import { QuickFileSelectService } from "@theia/file-search/lib/browser/quick-file-select-service"; |
| 16 | +import { MonacoQuickInputService } from "@theia/monaco/lib/browser/monaco-quick-input-service"; |
| 17 | + |
| 18 | +/** |
| 19 | + * since this is registered in theia's WidgetManager / WidgetFactory it is part of the inversify container (hence injectable) |
| 20 | + */ |
| 21 | +@injectable() |
| 22 | +export class CodeRibbonFuzzyFileOpenerWidget extends ReactWidget { |
| 23 | + static readonly ID = "coderibbon:fuzzy-file-opener"; |
| 24 | + static readonly LABEL = "CodeRibbon Fuzzy File Finder"; |
| 25 | + |
| 26 | + // protected current_search?: string = undefined; |
| 27 | + // TODO this should be the monaco input / quick open equivalent |
| 28 | + // protected inputElement?: HTMLInputElement; |
| 29 | + protected inputElementRef: React.RefObject<HTMLInputElement>; |
| 30 | + |
| 31 | + @inject(QuickInputService) |
| 32 | + protected readonly quickInputService: QuickInputService; |
| 33 | + |
| 34 | + @inject(QuickFileSelectService) |
| 35 | + protected readonly quickFileSelectService: QuickFileSelectService; |
| 36 | + |
| 37 | + @inject(MonacoQuickInputService) |
| 38 | + protected readonly monacoQuickInputService: MonacoQuickInputService; |
| 39 | + |
| 40 | + @inject(MessageService) |
| 41 | + protected readonly messageService!: MessageService; |
| 42 | + |
| 43 | + @postConstruct() |
| 44 | + protected init(): void { |
| 45 | + crdebug("CRFFO postConstruct"); |
| 46 | + this.id = CodeRibbonFuzzyFileOpenerWidget.ID; |
| 47 | + this.title.label = CodeRibbonFuzzyFileOpenerWidget.LABEL; |
| 48 | + this.title.caption = CodeRibbonFuzzyFileOpenerWidget.LABEL; |
| 49 | + this.title.closable = true; |
| 50 | + this.title.iconClass = "fa fa-window-maximize"; // example widget icon. |
| 51 | + |
| 52 | + this.inputElementRef = React.createRef(); |
| 53 | + // TODO how? |
| 54 | + // this.inputBox = this.quickInputService.createInputBox(); |
| 55 | + this.update(); |
| 56 | + } |
| 57 | + |
| 58 | + activate(): void { |
| 59 | + this.inputElementRef.current?.focus(); |
| 60 | + } |
| 61 | + |
| 62 | + render(): React.ReactElement { |
| 63 | + const header = `Does not work yet. Eventually this should be the same UI as Ctrl-P.`; |
| 64 | + const show_fuzzy_search: boolean = true; |
| 65 | + return ( |
| 66 | + <div id="widget-container"> |
| 67 | + <AlertMessage type="INFO" header={header} /> |
| 68 | + {/* <button |
| 69 | + className="theia-button secondary" |
| 70 | + title="Display Message" |
| 71 | + onClick={(_a) => this.displayMessage()} |
| 72 | + > |
| 73 | + Display Message |
| 74 | + </button> */} |
| 75 | + <input |
| 76 | + ref={this.inputElementRef} |
| 77 | + name="search" |
| 78 | + placeholder="search project files..." |
| 79 | + autoComplete="off" |
| 80 | + /> |
| 81 | + </div> |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + protected displayMessage(): void { |
| 86 | + this.messageService.info( |
| 87 | + "Congratulations: My Widget Successfully Created!", |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +export const TestOpenFFOCommand: Command = { id: "coderibbon:test-ffo" }; |
| 93 | + |
| 94 | +@injectable() |
| 95 | +export class CodeRibbonFuzzyFileOpenerContribution extends AbstractViewContribution<CodeRibbonFuzzyFileOpenerWidget> { |
| 96 | + constructor() { |
| 97 | + super({ |
| 98 | + widgetId: CodeRibbonFuzzyFileOpenerWidget.ID, |
| 99 | + widgetName: CodeRibbonFuzzyFileOpenerWidget.LABEL, |
| 100 | + defaultWidgetOptions: { area: "main" }, |
| 101 | + toggleCommandId: TestOpenFFOCommand.id, |
| 102 | + }); |
| 103 | + } |
| 104 | + |
| 105 | + registerCommands(commands: CommandRegistry): void { |
| 106 | + commands.registerCommand(TestOpenFFOCommand, { |
| 107 | + execute: () => { |
| 108 | + crdebug("command: TestOpenFFOCommand executes"); |
| 109 | + super.openView({ activate: false, reveal: true }); |
| 110 | + }, |
| 111 | + }); |
| 112 | + } |
| 113 | + |
| 114 | + // registerMenus(menus:) |
| 115 | +} |
0 commit comments