Skip to content

Commit ca049a9

Browse files
author
Akos Kitta
committed
removed open prompt
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent e5336cf commit ca049a9

File tree

2 files changed

+34
-132
lines changed

2 files changed

+34
-132
lines changed

arduino-ide-extension/src/browser/arduino-preferences.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,6 @@ export namespace ErrorRevealStrategy {
4040
export const Default: ErrorRevealStrategy = 'centerIfOutsideViewport';
4141
}
4242

43-
export const CloudSketchOpenStrategyLiterals = [
44-
'Ask',
45-
'Never',
46-
'Always',
47-
] as const;
48-
export type CloudSketchOpenStrategy =
49-
typeof CloudSketchOpenStrategyLiterals[number];
50-
export namespace CloudSketchOpenStrategy {
51-
export const Default: CloudSketchOpenStrategy = 'Ask';
52-
export function labelOf(strategy: CloudSketchOpenStrategy): string {
53-
return CloudSketchOpenStrategyLabels[strategy];
54-
}
55-
const CloudSketchOpenStrategyLabels: Record<CloudSketchOpenStrategy, string> =
56-
{
57-
Ask: nls.localize(
58-
'arduino/preferences/cloud.sketchOpenStrategy.ask',
59-
'Ask'
60-
),
61-
Never: nls.localize(
62-
'arduino/preferences/cloud.sketchOpenStrategy.never',
63-
'Never'
64-
),
65-
Always: nls.localize(
66-
'arduino/preferences/cloud.sketchOpenStrategy.always',
67-
'Always'
68-
),
69-
};
70-
}
71-
7243
export const ArduinoConfigSchema: PreferenceSchema = {
7344
type: 'object',
7445
properties: {
@@ -190,29 +161,6 @@ export const ArduinoConfigSchema: PreferenceSchema = {
190161
),
191162
default: true,
192163
},
193-
'arduino.cloud.sketchOpenStrategy': {
194-
enum: [...CloudSketchOpenStrategyLiterals],
195-
enumDescriptions: [
196-
nls.localize(
197-
'arduino/preferences/cloud.sketchOpenStrategy.ask.description',
198-
'IDE asks users whether to pull the remote sketch and open it in a new window.'
199-
),
200-
nls.localize(
201-
'arduino/preferences/cloud.sketchOpenStrategy.never.description',
202-
'IDE neither pulls nor opens the remote sketch after creating it. Users can manually pull the remote sketch.'
203-
),
204-
nls.localize(
205-
'arduino/preferences/cloud.sketchOpenStrategy.always.description',
206-
'IDE automatically pulls and opens the remote sketch in a new window.'
207-
),
208-
],
209-
markdownDescription: nls.localize(
210-
'arduino/preferences/cloud.sketchOpenStrategy',
211-
'Configures what IDE does after creating a new remote sketch. The default value is `"{0}"`.',
212-
CloudSketchOpenStrategy.labelOf('Ask')
213-
),
214-
default: CloudSketchOpenStrategy.Default,
215-
},
216164
'arduino.cloud.pull.warn': {
217165
type: 'boolean',
218166
description: nls.localize(
@@ -328,7 +276,6 @@ export interface ArduinoConfiguration {
328276
'arduino.board.certificates': string;
329277
'arduino.sketchbook.showAllFiles': boolean;
330278
'arduino.cloud.enabled': boolean;
331-
'arduino.cloud.sketchOpenStrategy': CloudSketchOpenStrategy;
332279
'arduino.cloud.pull.warn': boolean;
333280
'arduino.cloud.push.warn': boolean;
334281
'arduino.cloud.pushpublic.warn': boolean;

arduino-ide-extension/src/browser/contributions/new-cloud-sketch.ts

Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { MenuModelRegistry } from '@theia/core';
2-
import {
3-
PreferenceScope,
4-
PreferenceService,
5-
} from '@theia/core/lib/browser/preferences/preference-service';
62
import { CompositeTreeNode } from '@theia/core/lib/browser/tree';
73
import { DisposableCollection } from '@theia/core/lib/common/disposable';
84
import { nls } from '@theia/core/lib/common/nls';
95
import { inject, injectable } from '@theia/core/shared/inversify';
106
import { MainMenuManager } from '../../common/main-menu-manager';
117
import type { AuthenticationSession } from '../../node/auth/types';
12-
import { CloudSketchOpenStrategy } from '../arduino-preferences';
138
import { AuthenticationClientService } from '../auth/authentication-client-service';
149
import { CreateApi } from '../create/create-api';
1510
import { CreateUri } from '../create/create-uri';
@@ -34,13 +29,10 @@ export class NewCloudSketch extends Contribution {
3429
private readonly authenticationService: AuthenticationClientService;
3530
@inject(MainMenuManager)
3631
private readonly mainMenuManager: MainMenuManager;
37-
@inject(PreferenceService)
38-
private readonly preferenceService: PreferenceService;
3932

4033
private readonly toDispose = new DisposableCollection();
4134
private _session: AuthenticationSession | undefined;
4235
private _enabled: boolean;
43-
private _strategy: CloudSketchOpenStrategy;
4436

4537
override onReady(): void {
4638
this.toDispose.pushAll([
@@ -52,23 +44,15 @@ export class NewCloudSketch extends Contribution {
5244
}
5345
}),
5446
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
55-
switch (preferenceName) {
56-
case 'arduino.cloud.sketchOpenStrategy': {
57-
this._strategy = newValue as CloudSketchOpenStrategy;
58-
break;
59-
}
60-
case 'arduino.cloud.enabled': {
61-
const oldEnabled = this._enabled;
62-
this._enabled = Boolean(newValue);
63-
if (this._enabled !== oldEnabled) {
64-
this.mainMenuManager.update();
65-
}
66-
break;
47+
if (preferenceName === 'arduino.cloud.enabled') {
48+
const oldEnabled = this._enabled;
49+
this._enabled = Boolean(newValue);
50+
if (this._enabled !== oldEnabled) {
51+
this.mainMenuManager.update();
6752
}
6853
}
6954
}),
7055
]);
71-
this._strategy = this.preferences['arduino.cloud.sketchOpenStrategy'];
7256
this._enabled = this.preferences['arduino.cloud.enabled'];
7357
this._session = this.authenticationService.session;
7458
if (this._session) {
@@ -136,77 +120,48 @@ export class NewCloudSketch extends Contribution {
136120
}
137121

138122
if (result) {
139-
return this.maybeOpen(treeModel, result);
123+
return this.open(treeModel, result);
140124
}
141125
return undefined;
142126
}
143127

144-
private async maybeOpen(
128+
private async open(
145129
treeModel: CloudSketchbookTreeModel,
146130
newSketch: Create.Sketch
147131
): Promise<URI | undefined> {
148-
if (this._strategy === 'Never') {
149-
return undefined;
132+
const id = CreateUri.toUri(newSketch).path.toString();
133+
const node = treeModel.getNode(id);
134+
if (!node) {
135+
throw new Error(
136+
`Could not find remote sketchbook tree node with Tree node ID: ${id}.`
137+
);
150138
}
151-
if (this._strategy === 'Ask') {
152-
const yes = nls.localize('vscode/extensionsUtils/yes', 'Yes');
153-
const never = CloudSketchOpenStrategy.labelOf('Never');
154-
const always = CloudSketchOpenStrategy.labelOf('Always');
155-
const answer = await this.messageService.info(
156-
nls.localize(
157-
'arduino/newCloudSketch/openNewSketch',
158-
"Do you want to pull the new remote sketch '{0}' and open it in a new window?",
159-
newSketch.name
160-
),
161-
never,
162-
yes,
163-
always
139+
if (!CloudSketchbookTree.CloudSketchDirNode.is(node)) {
140+
throw new Error(
141+
`Remote sketchbook tree node expected to represent a directory but it did not. Tree node ID: ${id}.`
164142
);
165-
if (!answer) {
166-
return undefined;
167-
}
168-
if (answer === never) {
169-
await this.preferenceService.set(
170-
'arduino.cloud.sketchOpenStrategy',
171-
'Never',
172-
PreferenceScope.User
143+
}
144+
try {
145+
await treeModel.sketchbookTree().pull({ node });
146+
} catch (err) {
147+
if (isNotFound(err)) {
148+
await treeModel.updateRoot();
149+
await treeModel.refresh();
150+
this.messageService.error(
151+
nls.localize(
152+
'arduino/newCloudSketch/notFound',
153+
"Could not pull the remote sketch '{0}'. It does not exist.",
154+
newSketch.name
155+
)
173156
);
174157
return undefined;
175-
} else if (answer === always) {
176-
await this.preferenceService.set(
177-
'arduino.cloud.sketchOpenStrategy',
178-
'Always',
179-
PreferenceScope.User
180-
);
181158
}
159+
throw err;
182160
}
183-
const node = treeModel.getNode(CreateUri.toUri(newSketch).path.toString());
184-
if (!node) {
185-
return undefined;
186-
}
187-
if (CloudSketchbookTree.CloudSketchDirNode.is(node)) {
188-
try {
189-
await treeModel.sketchbookTree().pull({ node });
190-
} catch (err) {
191-
if (isNotFound(err)) {
192-
await treeModel.updateRoot();
193-
await treeModel.refresh();
194-
this.messageService.error(
195-
nls.localize(
196-
'arduino/newCloudSketch/notFound',
197-
"Could not pull the remote sketch '{0}'. It does not exist.",
198-
newSketch.name
199-
)
200-
);
201-
return undefined;
202-
}
203-
throw err;
204-
}
205-
return this.commandService.executeCommand(
206-
SketchbookCommands.OPEN_NEW_WINDOW.id,
207-
{ node }
208-
);
209-
}
161+
return this.commandService.executeCommand(
162+
SketchbookCommands.OPEN_NEW_WINDOW.id,
163+
{ node }
164+
);
210165
}
211166

212167
private treeModelFrom(

0 commit comments

Comments
 (0)