8000 feat: rename, deletion, and validation support · arduino/arduino-ide@31cc604 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31cc604

Browse files
author
Akos Kitta
committed
feat: rename, deletion, and validation support
Closes #1599 Closes #1825 Closes #1826 Co-authored-by: Akos Kitta <a.kitta@arduino.cc> Co-authored-by: per1234 <accounts@perglass.com> Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent f5621db commit 31cc604
  • create
  • local-cache
  • theia
  • utils
  • widgets
  • common/protocol
  • node
  • test
  • docs
  • i18n
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    63 files changed

    +2261
    -725
    lines changed

    arduino-ide-extension/package.json

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -67,6 +67,7 @@
    6767
    "auth0-js": "^9.14.0",
    6868
    "btoa": "^1.2.1",
    6969
    "classnames": "^2.3.1",
    70+
    "cross-fetch": "^3.1.5",
    7071
    "dateformat": "^3.0.3",
    7172
    "deepmerge": "2.0.1",
    7273
    "electron-updater": "^4.6.5",

    arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

    Lines changed: 8 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -23,7 +23,7 @@ import {
    2323
    SketchesService,
    2424
    SketchesServicePath,
    2525
    } from '../common/protocol/sketches-service';
    26-
    import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
    26+
    import { SketchesServiceClientImpl } from './sketches-service-client-impl';
    2727
    import { CoreService, CoreServicePath } from '../common/protocol/core-service';
    2828
    import { BoardsListWidget } from './boards/boards-list-widget';
    2929
    import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution';
    @@ -344,6 +344,9 @@ import { DebugViewModel } from '@theia/debug/lib/browser/view/debug-view-model';
    344344
    import { DebugSessionWidget } from '@theia/debug/lib/browser/view/debug-session-widget';
    345345
    import { DebugConfigurationWidget } from '@theia/debug/lib/browser/view/debug-configuration-widget';
    346346
    import { ConfigServiceClient } from './config/config-service-client';
    347+
    import { ValidateSketch } from './contributions/validate-sketch';
    348+
    import { RenameCloudSketch } from './contributions/rename-cloud-sketch';
    349+
    import { CreateFeatures } from './create/create-features';
    347350

    348351
    export default new ContainerModule((bind, unbind, isBound, rebind) => {
    349352
    // Commands and toolbar items
    @@ -729,6 +732,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
    729732
    Contribution.configure(bind, UpdateIndexes);
    730733
    Contribution.configure(bind, InterfaceScale);
    731734
    Contribution.configure(bind, NewCloudSketch);
    735+
    Contribution.configure(bind, ValidateSketch);
    736+
    Contribution.configure(bind, RenameCloudSketch);
    732737

    733738
    bindContributionProvider(bind, StartupTaskProvider);
    734739
    bind(StartupTaskProvider).toService(BoardsServiceProvider); // to reuse the boards config in another window
    @@ -889,6 +894,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
    889894
    );
    890895
    bind(CreateApi).toSelf().inSingletonScope();
    891896
    bind(SketchCache).toSelf().inSingletonScope();
    897+
    bind(CreateFeatures).toSelf().inSingletonScope();
    898+
    bind(FrontendApplicationContribution).toService(CreateFeatures);
    892899

    893900
    bind(ShareSketchDialog).toSelf().inSingletonScope();
    894901
    bind(AuthenticationClientService).toSelf().inSingletonScope();

    arduino-ide-extension/src/browser/contributions/add-file.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -11,7 +11,7 @@ import {
    1111
    } from './contribution';
    1212
    import { FileDialogService } from '@theia/filesystem/lib/browser';
    1313
    import { nls } from '@theia/core/lib/common';
    14-
    import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
    14+
    import { CurrentSketch } from '../sketches-service-client-impl';
    1515

    1616
    @injectable()
    1717
    export class AddFile extends SketchContribution {

    arduino-ide-extension/src/browser/contributions/archive-sketch.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,7 +9,7 @@ import {< F438 /div>
    99
    MenuModelRegistry,
    1010
    } from './contribution';
    1111
    import { nls } from '@theia/core/lib/common';
    12-
    import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
    12+
    import { CurrentSketch } from '../sketches-service-client-impl';
    1313

    1414
    @injectable()
    1515
    export class ArchiveSketch extends SketchContribution {
    @@ -56,7 +56,7 @@ export class ArchiveSketch extends SketchContribution {
    5656
    if (!destinationUri) {
    5757
    return;
    5858
    }
    59-
    await this.sketchService.archive(sketch, destinationUri.toString());
    59+
    await this.sketchesService.archive(sketch, destinationUri.toString());
    6060
    this.messageService.info(
    6161
    nls.localize(
    6262
    'arduino/sketch/createdArchive',

    arduino-ide-extension/src/browser/contributions/close.ts

    Lines changed: 2 additions & 2 deletions
    < 10000 td data-grid-cell-id="diff-d75767495b70f0c6a10456f6a08ea71728c0b74709a2b697e88b9b50f6890177-188-187-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">188
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@ import {
    2020
    URI,
    2121
    } from './contribution';
    2222
    import { Dialog } from '@theia/core/lib/browser/dialogs';
    23-
    import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
    23+
    import { CurrentSketch } from '../sketches-service-client-impl';
    2424
    import { SaveAsSketch } from './save-as-sketch';
    2525

    2626
    /**
    @@ -185,7 +185,7 @@ export class Close extends SketchContribution {
    185185
    private async isCurrentSketchTemp(): Promise<false | Sketch> {
    186186
    const currentSketch = await this.sketchServiceClient.currentSketch();
    187187
    if (CurrentSketch.isValid(currentSketch)) {
    -
    const isTemp = await this.sketchService.isTemp(currentSketch);
    188+
    const isTemp = await this.sketchesService.isTemp(currentSketch);
    189189
    if (isTemp) {
    190190
    return currentSketch;
    191191
    }

    arduino-ide-extension/src/browser/contributions/contribution.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -41,7 +41,7 @@ import { SettingsService } from '../dialogs/settings/settings';
    4141
    import {
    4242
    CurrentSketch,
    4343
    SketchesServiceClientImpl,
    44-
    } from '../../common/protocol/sketches-service-client-impl';
    44+
    } from '../sketches-service-client-impl';
    4545
    import {
    4646
    SketchesService,
    4747
    FileSystemExt,
    @@ -147,7 +147,7 @@ export abstract class SketchContribution extends Contribution {
    147147
    protected readonly configService: ConfigServiceClient;
    148148

    149149
    @inject(SketchesService)
    150-
    protected readonly sketchService: SketchesService;
    150+
    protected readonly sketchesService: SketchesService;
    151151

    152152
    @inject(OpenerService)
    153153
    protected readonly openerService: OpenerService;
    Lines changed: 121 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,121 @@
    1+
    import { CompositeTreeNode } from '@theia/core/lib/browser';
    2+
    import { nls } from '@theia/core/lib/common/nls';
    3+
    import { inject, injectable } from '@theia/core/shared/inversify';
    4+
    import { CreateApi } from '../create/create-api';
    5+
    import { CreateFeatures } from '../create/create-features';
    6+
    import { CreateUri } from '../create/create-uri';
    7+
    import { Create, isNotFound } from '../create/typings';
    8+
    import { CloudSketchbookTree } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree';
    9+
    import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model';
    10+
    import { CloudSketchbookTreeWidget } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-widget';
    11+
    import { SketchbookWidget } from '../widgets/sketchbook/sketchbook-widget';
    12+
    import { SketchbookWidgetContribution } from '../widgets/sketchbook/sketchbook-widget-contribution';
    13+
    import { SketchContribution } from './contribution';
    14+
    15+
    export function sketchAlreadyExists(input: string): string {
    16+
    return nls.localize(
    17+
    'arduino/cloudSketch/alreadyExists',
    18+
    "Cloud sketch '{0}' already exists.",
    19+
    input
    20+
    );
    21+
    }
    22+
    export function sketchNotFound(input: string): string {
    23+
    return nls.localize(
    24+
    'arduino/cloudSketch/notFound',
    25+
    "Could not pull the cloud sketch '{0}'. It does not exist.",
    26+
    input
    27+
    );
    28+
    }
    29+
    export const synchronizingSketchbook = nls.localize(
    30+
    'arduino/cloudSketch/synchronizingSketchbook',
    31+
    'Synchronizing sketchbook...'
    32+
    );
    33+
    export function pullingSketch(input: string): string {
    34+
    return nls.localize(
    35+
    'arduino/cloudSketch/pulling',
    36+
    "Synchronizing sketchbook, pulling '{0}'...",
    37+
    input
    38+
    );
    39+
    }
    40+
    export function pushingSketch(input: string): string {
    41+
    return nls.localize(
    42+
    'arduino/cloudSketch/pushing',
    43+
    "Synchronizing sketchbook, pushing '{0}'...",
    44+
    input
    45+
    );
    46+
    }
    47+
    48+
    @injectable()
    49+
    export abstract class CloudSketchContribution extends SketchContribution {
    50+
    @inject(SketchbookWidgetContribution)
    51+
    private readonly widgetContribution: SketchbookWidgetContribution;
    52+
    @inject(CreateApi)
    53+
    protected readonly createApi: CreateApi;
    54+
    @inject(CreateFeatures)
    55+
    protected readonly createFeatures: CreateFeatures;
    56+
    57+
    protected async treeModel(): Promise<
    58+
    (CloudSketchbookTreeModel & { root: CompositeTreeNode }) | undefined
    59+
    > {
    60+
    const { enabled, session } = this.createFeatures;
    61+
    if (enabled && session) {
    62+
    const widget = await this.widgetContribution.widget;
    63+
    const treeModel = this.treeModelFrom(widget);
    64+
    if (treeModel) {
    65+
    const root = treeModel.root;
    66+
    if (CompositeTreeNode.is(root)) {
    67+
    return treeModel as CloudSketchbookTreeModel & {
    68+
    root: CompositeTreeNode;
    69+
    };
    70+
    }
    71+
    }
    72+
    }
    73+
    return undefined;
    74+
    }
    75+
    76+
    protected async pull(
    77+
    sketch: Create.Sketch
    78+
    ): Promise<CloudSketchbookTree.CloudSketchDirNode | undefined> {
    79+
    const treeModel = await this.treeModel();
    80+
    if (!treeModel) {
    81+
    return undefined;
    82+
    }
    83+
    const id = CreateUri.toUri(sketch).path.toString();
    84+
    const node = treeModel.getNode(id);
    85+
    if (!node) {
    86+
    throw new Error(
    87+
    `Could not find cloud sketchbook tree node with ID: ${id}.`
    88+
    );
    89+
    }
    90+
    if (!CloudSketchbookTree.CloudSketchDirNode.is(node)) {
    91+
    throw new Error(
    92+
    `Cloud sketchbook tree node expected to represent a directory but it did not. Tree node ID: ${id}.`
    93+
    );
    94+
    }
    95+
    try {
    96+
    await treeModel.sketchbookTree().pull({ node });
    97+
    return node;
    98+
    } catch (err) {
    99+
    if (isNotFound(err)) {
    100+
    await treeModel.refresh();
    101+
    this.messageService.error(sketchNotFound(sketch.name));
    102+
    return undefined;
    103+
    }
    104+
    throw err;
    105+
    }
    106+
    }
    107+
    108+
    private treeModelFrom(
    109+
    widget: SketchbookWidget
    110+
    ): CloudSketchbookTreeModel | undefined {
    111+
    for (const treeWidget of widget.getTreeWidgets()) {
    112+
    if (treeWidget instanceof CloudSketchbookTreeWidget) {
    113+
    const model = treeWidget.model;
    114+
    if (model instanceof CloudSketchbookTreeModel) {
    115+
    return model;
    116+
    }
    117+
    }
    118+
    }
    119+
    return undefined;
    120+
    }
    121+
    }

    arduino-ide-extension/src/browser/contributions/debug.ts

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@ import {
    1818
    TabBarToolbarRegistry,
    1919
    } from './contribution';
    2020
    import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common';
    21-
    import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
    21+
    import { CurrentSketch } from '../sketches-service-client-impl';
    2222
    import { ArduinoMenus } from '../menu/arduino-menus';
    2323

    2424
    const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
    @@ -187,7 +187,7 @@ export class Debug extends SketchContribution {
    187187
    if (!CurrentSketch.isValid(sketch)) {
    188188
    return;
    189189
    }
    190-
    const ideTempFolderUri = await this.sketchService.getIdeTempFolderUri(
    190+
    const ideTempFolderUri = await this.sketchesService.getIdeTempFolderUri(
    191191
    sketch
    192192
    );
    193193
    const [cliPath, sketchPath, configPath] = await Promise.all([
    @@ -246,7 +246,7 @@ export class Debug extends SketchContribution {
    246246
    ): Promise<boolean> {
    247247
    if (err instanceof Error) {
    248248
    try {
    249-
    const tempBuildPaths = await this.sketchService.tempBuildPath(sketch);
    249+
    const tempBuildPaths = await this.sketchesService.tempBuildPath(sketch);
    250250
    return tempBuildPaths.some((tempBuildPath) =>
    251251
    err.message.includes(tempBuildPath)
    252252
    );

    0 commit comments

    Comments
     (0)
    0