Skip to content

Commit 93e2082

Browse files
author
Akos Kitta
committed
fix: context key match when pulling/pushing
Signed-off-by: Akos Kitta <[email protected]>
1 parent cd12e96 commit 93e2082

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

Diff for: arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
12
import {
23
ContextMenuRenderer,
34
RenderContextMenuOptions,
@@ -60,6 +61,8 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
6061
private readonly configServiceClient: ConfigServiceClient;
6162
@inject(ApplicationConnectionStatusContribution)
6263
private readonly connectionStatus: ApplicationConnectionStatusContribution;
64+
@inject(ContextKeyService)
65+
private readonly contextKeyService: ContextKeyService;
6366

6467
private readonly onDidChangeToolbarEmitter = new Emitter<void>();
6568
private readonly toDisposeBeforeNewContextMenu = new DisposableCollection();
@@ -79,6 +82,17 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
7982
}),
8083
this.createFeatures.onDidChangeSession(() => this.fireToolbarChange()),
8184
this.createFeatures.onDidChangeEnabled(() => this.fireToolbarChange()),
85+
this.contextKeyService.onDidChange((event) => {
86+
if (
87+
event.affects({
88+
has(candidate: string) {
89+
return candidate === 'cloudSketchState';
90+
},
91+
})
92+
) {
93+
this.fireToolbarChange();
94+
}
95+
}),
8296
]);
8397
}
8498

@@ -101,13 +115,15 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
101115
tooltip: CloudSketchbookCommands.PULL_SKETCH__TOOLBAR.label,
102116
priority: -2,
103117
onDidChange: this.onDidChangeToolbar,
118+
when: 'cloudSketchState != pulling && cloudSketchState != pushing',
104119
});
105120
registry.registerItem({
106121
id: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.id,
107122
command: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.id,
108123
tooltip: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.label,
109124
priority: -1,
110125
onDidChange: this.onDidChangeToolbar,
126+
when: 'cloudSketchState != pulling && cloudSketchState != pushing',
111127
});
112128
}
113129

Diff for: arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-tree.ts

+30-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import {
3737
pullingSketch,
3838
pushingSketch,
3939
} from '../../contributions/cloud-contribution';
40+
import {
41+
ContextKey,
42+
ContextKeyService,
43+
} from '@theia/core/lib/browser/context-key-service';
4044

4145
const MESSAGE_TIMEOUT = 5 * 1000;
4246
const deepmerge = require('deepmerge').default;
@@ -63,10 +67,19 @@ export class CloudSketchbookTree extends SketchbookTree {
6367
@inject(ApplicationConnectionStatusContribution)
6468
private readonly connectionStatus: ApplicationConnectionStatusContribution;
6569

70+
@inject(ContextKeyService)
71+
private readonly contextKeyService: ContextKeyService;
72+
73+
private cloudSketchState: ContextKey<string> | undefined;
74+
6675
protected override init(): void {
6776
this.toDispose.push(
6877
this.connectionStatus.onOfflineStatusDidChange(() => this.refresh())
6978
);
79+
this.cloudSketchState = this.contextKeyService.createKey<string>(
80+
'cloudSketchState',
81+
undefined
82+
);
7083
super.init();
7184
}
7285

@@ -343,18 +356,23 @@ export class CloudSketchbookTree extends SketchbookTree {
343356
task: (node: CloudSketchbookTree.CloudSketchDirNode) => MaybePromise<T>,
344357
noProgress = false
345358
): Promise<T> {
346-
const result = await (noProgress
347-
? task(node)
348-
: ExecuteWithProgress.withProgress(
349-
this.taskMessage(state, node.uri.path.name),
350-
this.messageService,
351-
async (progress) => {
352-
progress.report({ work: { done: 0, total: NaN } });
353-
return task(node);
354-
}
355-
));
356-
await this.refresh(node);
357-
return result;
359+
this.cloudSketchState?.set(state);
360+
try {
361+
const result = await (noProgress
362+
? task(node)
363+
: ExecuteWithProgress.withProgress(
364+
this.taskMessage(state, node.uri.path.name),
365+
this.messageService,
366+
async (progress) => {
367+
progress.report({ work: { done: 0, total: NaN } });
368+
return task(node);
369+
}
370+
));
371+
await this.refresh(node);
372+
return result;
373+
} finally {
374+
this.cloudSketchState?.set(undefined);
375+
}
358376
}
359377

360378
private taskMessage(

0 commit comments

Comments
 (0)