diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index ec0b301be..4743f3f84 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -23,7 +23,7 @@ import { SketchesService, SketchesServicePath, } from '../common/protocol/sketches-service'; -import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl'; +import { SketchesServiceClientImpl } from './sketches-service-client-impl'; import { CoreService, CoreServicePath } from '../common/protocol/core-service'; import { BoardsListWidget } from './boards/boards-list-widget'; import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution'; diff --git a/arduino-ide-extension/src/browser/contributions/add-file.ts b/arduino-ide-extension/src/browser/contributions/add-file.ts index 5605ba7d5..dacbd4e86 100644 --- a/arduino-ide-extension/src/browser/contributions/add-file.ts +++ b/arduino-ide-extension/src/browser/contributions/add-file.ts @@ -11,7 +11,7 @@ import { } from './contribution'; import { FileDialogService } from '@theia/filesystem/lib/browser'; import { nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; @injectable() export class AddFile extends SketchContribution { diff --git a/arduino-ide-extension/src/browser/contributions/archive-sketch.ts b/arduino-ide-extension/src/browser/contributions/archive-sketch.ts index e10893729..1f69bb3da 100644 --- a/arduino-ide-extension/src/browser/contributions/archive-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/archive-sketch.ts @@ -9,7 +9,7 @@ import { MenuModelRegistry, } from './contribution'; import { nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; @injectable() export class ArchiveSketch extends SketchContribution { diff --git a/arduino-ide-extension/src/browser/contributions/close.ts b/arduino-ide-extension/src/browser/contributions/close.ts index 6b9d0149b..b6d8f91ec 100644 --- a/arduino-ide-extension/src/browser/contributions/close.ts +++ b/arduino-ide-extension/src/browser/contributions/close.ts @@ -20,7 +20,7 @@ import { URI, } from './contribution'; import { Dialog } from '@theia/core/lib/browser/dialogs'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { SaveAsSketch } from './save-as-sketch'; /** diff --git a/arduino-ide-extension/src/browser/contributions/contribution.ts b/arduino-ide-extension/src/browser/contributions/contribution.ts index 0bf830c2d..3260ab7b9 100644 --- a/arduino-ide-extension/src/browser/contributions/contribution.ts +++ b/arduino-ide-extension/src/browser/contributions/contribution.ts @@ -41,7 +41,7 @@ import { SettingsService } from '../dialogs/settings/settings'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../common/protocol/sketches-service-client-impl'; +} from '../sketches-service-client-impl'; import { SketchesService, FileSystemExt, diff --git a/arduino-ide-extension/src/browser/contributions/create-contribution.ts b/arduino-ide-extension/src/browser/contributions/create-contribution.ts index 76d11535e..5add704f5 100644 --- a/arduino-ide-extension/src/browser/contributions/create-contribution.ts +++ b/arduino-ide-extension/src/browser/contributions/create-contribution.ts @@ -1,13 +1,10 @@ import { CompositeTreeNode } from '@theia/core/lib/browser'; import { nls } from '@theia/core/lib/common/nls'; -import URI from '@theia/core/lib/common/uri'; import { inject, injectable } from '@theia/core/shared/inversify'; -import { Sketch } from '../../common/protocol'; import { CreateApi } from '../create/create-api'; import { CreateFeatures } from '../create/create-features'; import { CreateUri } from '../create/create-uri'; import { Create, isNotFound } from '../create/typings'; -import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider'; import { CloudSketchbookTree } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree'; import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model'; import { CloudSketchbookTreeWidget } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-widget'; @@ -51,8 +48,6 @@ export function pushingSketch(input: string): string { @injectable() export abstract class CloudSketchContribution extends SketchContribution { - @inject(LocalCacheFsProvider) - private readonly localCacheFsProvider: LocalCacheFsProvider; @inject(SketchbookWidgetContribution) private readonly widgetContribution: SketchbookWidgetContribution; @inject(CreateApi) @@ -60,19 +55,6 @@ export abstract class CloudSketchContribution extends SketchContribution { @inject(CreateFeatures) protected readonly createFeatures: CreateFeatures; - protected cloudUri(sketch: Sketch): URI | undefined { - return this.localCacheFsProvider.from(new URI(sketch.uri)); - } - - protected localCacheUri(cloudUri: URI): URI | undefined { - if (cloudUri.scheme !== CreateUri.scheme) { - throw new Error( - `Expected '${CreateUri.scheme}'. Got ${cloudUri.toString()}` - ); - } - return this.localCacheFsProvider.to(cloudUri); - } - protected async treeModel(): Promise< (CloudSketchbookTreeModel & { root: CompositeTreeNode }) | undefined > { diff --git a/arduino-ide-extension/src/browser/contributions/debug.ts b/arduino-ide-extension/src/browser/contributions/debug.ts index f2a2b97f7..f43f00426 100644 --- a/arduino-ide-extension/src/browser/contributions/debug.ts +++ b/arduino-ide-extension/src/browser/contributions/debug.ts @@ -18,7 +18,7 @@ import { TabBarToolbarRegistry, } from './contribution'; import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { ArduinoMenus } from '../menu/arduino-menus'; const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug'; diff --git a/arduino-ide-extension/src/browser/contributions/delete-sketch.ts b/arduino-ide-extension/src/browser/contributions/delete-sketch.ts index 66dcff6ce..7fd3d4535 100644 --- a/arduino-ide-extension/src/browser/contributions/delete-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/delete-sketch.ts @@ -59,7 +59,7 @@ export class DeleteSketch extends CloudSketchContribution { if (!willNavigateAway) { return this.sketchesService.deleteSketch(sketch); } - const cloudUri = this.cloudUri(sketch); // TODO: warn user that it's a cloud sketch + const cloudUri = this.createFeatures.cloudUri(sketch); // TODO: warn user that it's a cloud sketch if (willNavigateAway !== 'force') { const { response } = await remote.dialog.showMessageBox({ title: nls.localizeByDefault('Delete'), diff --git a/arduino-ide-extension/src/browser/contributions/include-library.ts b/arduino-ide-extension/src/browser/contributions/include-library.ts index 0efe114d7..a8a2f3f4b 100644 --- a/arduino-ide-extension/src/browser/contributions/include-library.ts +++ b/arduino-ide-extension/src/browser/contributions/include-library.ts @@ -17,7 +17,7 @@ import { SketchContribution, Command, CommandRegistry } from './contribution'; import { NotificationCenter } from '../notification-center'; import { nls } from '@theia/core/lib/common'; import * as monaco from '@theia/monaco-editor-core'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; @injectable() export class IncludeLibrary extends SketchContribution { diff --git a/arduino-ide-extension/src/browser/contributions/ino-language.ts b/arduino-ide-extension/src/browser/contributions/ino-language.ts index 6a783b494..c5096e64f 100644 --- a/arduino-ide-extension/src/browser/contributions/ino-language.ts +++ b/arduino-ide-extension/src/browser/contributions/ino-language.ts @@ -8,7 +8,7 @@ import { ExecutableService, sanitizeFqbn, } from '../../common/protocol'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { BoardsConfig } from '../boards/boards-config'; import { BoardsServiceProvider } from '../boards/boards-service-provider'; import { HostedPluginEvents } from '../hosted-plugin-events'; diff --git a/arduino-ide-extension/src/browser/contributions/save-as-sketch.ts b/arduino-ide-extension/src/browser/contributions/save-as-sketch.ts index 6110055d6..bf7a45092 100644 --- a/arduino-ide-extension/src/browser/contributions/save-as-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/save-as-sketch.ts @@ -8,7 +8,7 @@ import { nls } from '@theia/core/lib/common/nls'; import { inject, injectable } from '@theia/core/shared/inversify'; import { WorkspaceInput } from '@theia/workspace/lib/browser/workspace-service'; import * as dateFormat from 'dateformat'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { StartupTask } from '../../electron-common/startup-task'; import { ArduinoMenus } from '../menu/arduino-menus'; import { @@ -71,7 +71,7 @@ export class SaveAsSketch extends CloudSketchContribution { } let destinationUri: string | undefined; - const cloudUri = this.cloudUri(sketch); + const cloudUri = this.createFeatures.cloudUri(sketch); if (cloudUri) { destinationUri = await this.createCloudCopy({ cloudUri, sketch }); } else { diff --git a/arduino-ide-extension/src/browser/contributions/save-sketch.ts b/arduino-ide-extension/src/browser/contributions/save-sketch.ts index e02b7bff7..d05a47982 100644 --- a/arduino-ide-extension/src/browser/contributions/save-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/save-sketch.ts @@ -10,7 +10,7 @@ import { KeybindingRegistry, } from './contribution'; import { nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; @injectable() export class SaveSketch extends SketchContribution { diff --git a/arduino-ide-extension/src/browser/contributions/sketch-control.ts b/arduino-ide-extension/src/browser/contributions/sketch-control.ts index 7d285e187..a8805f440 100644 --- a/arduino-ide-extension/src/browser/contributions/sketch-control.ts +++ b/arduino-ide-extension/src/browser/contributions/sketch-control.ts @@ -18,7 +18,7 @@ import { open, } from './contribution'; import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { nls } from '@theia/core/lib/common'; @injectable() diff --git a/arduino-ide-extension/src/browser/contributions/sketch-files-tracker.ts b/arduino-ide-extension/src/browser/contributions/sketch-files-tracker.ts index 15f90dfa2..d7c1c68d6 100644 --- a/arduino-ide-extension/src/browser/contributions/sketch-files-tracker.ts +++ b/arduino-ide-extension/src/browser/contributions/sketch-files-tracker.ts @@ -3,7 +3,7 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable'; import { inject, injectable } from '@theia/core/shared/inversify'; import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution'; import { FileChangeType } from '@theia/filesystem/lib/common/files'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { Sketch, SketchContribution } from './contribution'; import { OpenSketchFiles } from './open-sketch-files'; diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 3bef23f62..034ea87d3 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -12,7 +12,7 @@ import { CoreServiceContribution, } from './contribution'; import { deepClone, nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import type { VerifySketchParams } from './verify-sketch'; import { UserFields } from './user-fields'; diff --git a/arduino-ide-extension/src/browser/contributions/validate-sketch.ts b/arduino-ide-extension/src/browser/contributions/validate-sketch.ts index c79839485..bc0f22f18 100644 --- a/arduino-ide-extension/src/browser/contributions/validate-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/validate-sketch.ts @@ -4,7 +4,7 @@ import { nls } from '@theia/core/lib/common/nls'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { injectable } from '@theia/core/shared/inversify'; import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { Sketch, SketchContribution, URI } from './contribution'; import { SaveAsSketch } from './save-as-sketch'; diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 2090c7590..bd6b60ff8 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -11,7 +11,7 @@ import { TabBarToolbarRegistry, } from './contribution'; import { nls } from '@theia/core/lib/common'; -import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; +import { CurrentSketch } from '../sketches-service-client-impl'; import { CoreService } from '../../common/protocol'; import { CoreErrorHandler } from './core-error-handler'; diff --git a/arduino-ide-extension/src/browser/create/create-features.ts b/arduino-ide-extension/src/browser/create/create-features.ts index 2a56eb07b..a88f8fac5 100644 --- a/arduino-ide-extension/src/browser/create/create-features.ts +++ b/arduino-ide-extension/src/browser/create/create-features.ts @@ -5,6 +5,8 @@ import { inject, injectable } from '@theia/core/shared/inversify'; import { AuthenticationSession } from '../../node/auth/types'; import { ArduinoPreferences } from '../arduino-preferences'; import { AuthenticationClientService } from '../auth/authentication-client-service'; +import { Sketch, URI } from '../contributions/contribution'; +import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider'; @injectable() export class CreateFeatures implements FrontendApplicationContribution { @@ -12,6 +14,8 @@ export class CreateFeatures implements FrontendApplicationContribution { private readonly preferences: ArduinoPreferences; @inject(AuthenticationClientService) private readonly authenticationService: AuthenticationClientService; + @inject(LocalCacheFsProvider) + private readonly localCacheFsProvider: LocalCacheFsProvider; private readonly onDidChangeSessionEmitter = new Emitter< AuthenticationSession | undefined @@ -66,4 +70,11 @@ export class CreateFeatures implements FrontendApplicationContribution { get session(): AuthenticationSession | undefined { return this._session; } + + cloudUri(sketch: Sketch): URI | undefined { + if (!this.session) { + return undefined; + } + return this.localCacheFsProvider.from(new URI(sketch.uri)); + } } diff --git a/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts b/arduino-ide-extension/src/browser/sketches-service-client-impl.ts similarity index 97% rename from arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts rename to arduino-ide-extension/src/browser/sketches-service-client-impl.ts index 59e88d740..9f603a55c 100644 --- a/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts +++ b/arduino-ide-extension/src/browser/sketches-service-client-impl.ts @@ -10,13 +10,17 @@ import { DisposableCollection, } from '@theia/core/lib/common/disposable'; import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application'; -import { Sketch, SketchesService } from '.'; -import { ConfigServiceClient } from '../../browser/config/config-service-client'; -import { SketchContainer, SketchesError, SketchRef } from './sketches-service'; +import { Sketch, SketchesService } from '../common/protocol'; +import { ConfigServiceClient } from './config/config-service-client'; +import { + SketchContainer, + SketchesError, + SketchRef, +} from '../common/protocol/sketches-service'; import { ARDUINO_CLOUD_FOLDER, REMOTE_SKETCHBOOK_FOLDER, -} from '../../browser/utils/constants'; +} from './utils/constants'; import * as monaco from '@theia/monaco-editor-core'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; diff --git a/arduino-ide-extension/src/browser/theia/core/widget-manager.ts b/arduino-ide-extension/src/browser/theia/core/widget-manager.ts index 038b046a1..1ab8a2921 100644 --- a/arduino-ide-extension/src/browser/theia/core/widget-manager.ts +++ b/arduino-ide-extension/src/browser/theia/core/widget-manager.ts @@ -10,7 +10,7 @@ import { OutputWidget } from '@theia/output/lib/browser/output-widget'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; @injectable() export class WidgetManager extends TheiaWidgetManager { diff --git a/arduino-ide-extension/src/browser/theia/debug/debug-configuration-manager.ts b/arduino-ide-extension/src/browser/theia/debug/debug-configuration-manager.ts index 2523c99c8..eda81804b 100644 --- a/arduino-ide-extension/src/browser/theia/debug/debug-configuration-manager.ts +++ b/arduino-ide-extension/src/browser/theia/debug/debug-configuration-manager.ts @@ -14,7 +14,7 @@ import { SketchesService } from '../../../common/protocol'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { DebugConfigurationModel } from './debug-configuration-model'; import { FileOperationError, diff --git a/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts b/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts index 3df32188c..14016c167 100644 --- a/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts +++ b/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts @@ -6,7 +6,7 @@ import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/l import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { SketchesService, Sketch } from '../../../common/protocol'; import { nls } from '@theia/core/lib/common'; diff --git a/arduino-ide-extension/src/browser/theia/monaco/monaco-editor-provider.ts b/arduino-ide-extension/src/browser/theia/monaco/monaco-editor-provider.ts index b93036a3c..2718b0579 100644 --- a/arduino-ide-extension/src/browser/theia/monaco/monaco-editor-provider.ts +++ b/arduino-ide-extension/src/browser/theia/monaco/monaco-editor-provider.ts @@ -6,7 +6,7 @@ import { } from '@theia/core/lib/common/disposable'; import { EditorServiceOverrides, MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; import { MonacoEditorProvider as TheiaMonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider'; -import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { SketchesServiceClientImpl } from '../../sketches-service-client-impl'; import * as monaco from '@theia/monaco-editor-core'; import type { ReferencesModel } from '@theia/monaco-editor-core/esm/vs/editor/contrib/gotoSymbol/browser/referencesModel'; diff --git a/arduino-ide-extension/src/browser/theia/monaco/monaco-text-model-service.ts b/arduino-ide-extension/src/browser/theia/monaco/monaco-text-model-service.ts index 7a8ece561..ec775685a 100644 --- a/arduino-ide-extension/src/browser/theia/monaco/monaco-text-model-service.ts +++ b/arduino-ide-extension/src/browser/theia/monaco/monaco-text-model-service.ts @@ -6,14 +6,16 @@ import { EditorPreferences } from '@theia/editor/lib/browser/editor-preferences' import { MonacoToProtocolConverter } from '@theia/monaco/lib/browser/monaco-to-protocol-converter'; import { ProtocolToMonacoConverter } from '@theia/monaco/lib/browser/protocol-to-monaco-converter'; import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; -import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { SketchesServiceClientImpl } from '../../sketches-service-client-impl'; @injectable() export class MonacoTextModelService extends TheiaMonacoTextModelService { @inject(SketchesServiceClientImpl) protected readonly sketchesServiceClient: SketchesServiceClientImpl; - protected override async createModel(resource: Resource): Promise { + protected override async createModel( + resource: Resource + ): Promise { const factory = this.factories .getContributions() .find(({ scheme }) => resource.uri.scheme === scheme); diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts index 6d936a515..eeae7fcf7 100644 --- a/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts @@ -12,21 +12,28 @@ import { WorkspaceCommandContribution as TheiaWorkspaceCommandContribution, WorkspaceCommands, } from '@theia/workspace/lib/browser/workspace-commands'; -import { Sketch, SketchesService } from '../../../common/protocol'; +import { Sketch } from '../../../common/protocol'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; +import { CreateFeatures } from '../../create/create-features'; import { WorkspaceInputDialog } from './workspace-input-dialog'; +interface ValidationContext { + sketch: Sketch; + cloudUri: URI | undefined; +} + @injectable() export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribution { @inject(CommandService) private readonly commandService: CommandService; - @inject(SketchesService) - private readonly sketchService: SketchesService; @inject(SketchesServiceClientImpl) private readonly sketchesServiceClient: SketchesServiceClientImpl; + @inject(CreateFeatures) + private readonly createFeatures: CreateFeatures; + private validationContext: ValidationContext | undefined; override registerCommands(registry: CommandRegistry): void { super.registerCommands(registry); @@ -65,7 +72,7 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut this.labelProvider ); - const name = await dialog.open(); + const name = await this.openDialog(dialog, parentUri); if (!name) { return; } @@ -93,7 +100,9 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut } let errorMessage: string | undefined = undefined; if (Sketch.Extensions.CODE_FILES.includes(extension)) { - errorMessage = Sketch.validateSketchFolderName(name); + errorMessage = this.validationContext?.cloudUri + ? Sketch.validateCloudSketchFolderName(name) + : Sketch.validateSketchFolderName(name); } return errorMessage ?? super.validateFileName(userInput, parent, recursive); } @@ -123,10 +132,7 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut } // file belongs to another sketch, do not allow rename - const parentSketch = await this.sketchService.getSketchFolder( - uri.toString() - ); - if (parentSketch && parentSketch.uri !== sketch.uri) { + if (!Sketch.isInSketch(uri, sketch)) { return; } @@ -166,7 +172,7 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut }, this.labelProvider ); - const name = await dialog.open(); + const name = await this.openDialog(dialog, uri); if (!name) { return; } @@ -175,6 +181,34 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut const newUri = uri.parent.resolve(nameWithExt); return this.fileService.move(oldUri, newUri); } + + private async openDialog( + dialog: WorkspaceInputDialog, + uri: URI + ): Promise { + try { + this.setValidationContext(uri); + const name = await dialog.open(); + return name; + } finally { + this.resetValidationContext(); + } + } + + private setValidationContext(uri: URI): void { + const sketch = this.sketchesServiceClient.tryGetCurrentSketch(); + if ( + CurrentSketch.isValid(sketch) && + new URI(sketch.uri).isEqualOrParent(uri) + ) { + const cloudUri = this.createFeatures.cloudUri(sketch); + this.validationContext = { sketch, cloudUri }; + } + } + + private resetValidationContext(): void { + this.validationContext = undefined; + } } export function invalidExtension( diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts index 1400fb01a..f234f3b5a 100644 --- a/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts @@ -5,7 +5,7 @@ import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/wo import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { DeleteSketch } from '../../contributions/delete-sketch'; @injectable() diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-variable-contribution.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-variable-contribution.ts index 2f9c88800..c14027791 100644 --- a/arduino-ide-extension/src/browser/theia/workspace/workspace-variable-contribution.ts +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-variable-contribution.ts @@ -9,7 +9,7 @@ import { Sketch } from '../../../common/protocol'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { DisposableCollection } from '@theia/core/lib/common/disposable'; @injectable() diff --git a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts index fbe41be50..80971f04d 100644 --- a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts +++ b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts @@ -26,7 +26,7 @@ import { SketchbookCommands } from '../sketchbook/sketchbook-commands'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { Contribution } from '../../contributions/contribution'; import { ArduinoPreferences } from '../../arduino-preferences'; import { MainMenuManager } from '../../../common/main-menu-manager'; diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-model.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-model.ts index 34263df8a..df1d52964 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-model.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-model.ts @@ -1,4 +1,8 @@ -import { inject, injectable, postConstruct } from '@theia/core/shared/inversify'; +import { + inject, + injectable, + postConstruct, +} from '@theia/core/shared/inversify'; import URI from '@theia/core/lib/common/uri'; import { FileNode, FileTreeModel } from '@theia/filesystem/lib/browser'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; @@ -13,7 +17,10 @@ import { } from '@theia/core/lib/browser/tree'; import { SketchbookCommands } from './sketchbook-commands'; import { OpenerService, open } from '@theia/core/lib/browser'; -import { CurrentSketch, SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { + CurrentSketch, + SketchesServiceClientImpl, +} from '../../sketches-service-client-impl'; import { CommandRegistry } from '@theia/core/lib/common/command'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; @@ -195,7 +202,10 @@ export class SketchbookTreeModel extends FileTreeModel { /** * Move the given source file or directory to the given target directory. */ - override async move(source: TreeNode, target: TreeNode): Promise { + override async move( + source: TreeNode, + target: TreeNode + ): Promise { if (source.parent && WorkspaceRootNode.is(source)) { // do not support moving a root folder return undefined; diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx index 599cac893..1c3323227 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx @@ -21,7 +21,7 @@ import { ArduinoPreferences } from '../../arduino-preferences'; import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { SelectableTreeNode } from '@theia/core/lib/browser/tree/tree-selection'; import { Sketch } from '../../contributions/contribution'; import { nls } from '@theia/core/lib/common'; diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts index 74b782887..ba3794233 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts @@ -26,7 +26,7 @@ import { import { CurrentSketch, SketchesServiceClientImpl, -} from '../../../common/protocol/sketches-service-client-impl'; +} from '../../sketches-service-client-impl'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { URI } from '../../contributions/contribution'; import { WorkspaceInput } from '@theia/workspace/lib/browser'; diff --git a/arduino-ide-extension/src/test/browser/workspace-commands.test.ts b/arduino-ide-extension/src/test/browser/workspace-commands.test.ts index 5d0321a1e..8ec223051 100644 --- a/arduino-ide-extension/src/test/browser/workspace-commands.test.ts +++ b/arduino-ide-extension/src/test/browser/workspace-commands.test.ts @@ -33,7 +33,7 @@ import { WorkspaceCommandContribution, } from '../../browser/theia/workspace/workspace-commands'; import { Sketch, SketchesService } from '../../common/protocol'; -import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl'; +import { SketchesServiceClientImpl } from '../../browser/sketches-service-client-impl'; disableJSDOM();