fix: remote sketch creation if tree is not active

Closes #1715

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2022-11-28 09:52:28 +01:00 committed by Akos Kitta
parent 81195431b0
commit c0488d1f64
2 changed files with 24 additions and 5 deletions

View File

@ -202,11 +202,12 @@ export class NewCloudSketch extends Contribution {
private treeModelFrom(
widget: SketchbookWidget
): CloudSketchbookTreeModel | undefined {
const treeWidget = widget.getTreeWidget();
if (treeWidget instanceof CloudSketchbookTreeWidget) {
const model = treeWidget.model;
if (model instanceof CloudSketchbookTreeModel) {
return model;
for (const treeWidget of widget.getTreeWidgets()) {
if (treeWidget instanceof CloudSketchbookTreeWidget) {
const model = treeWidget.model;
if (model instanceof CloudSketchbookTreeModel) {
return model;
}
}
}
return undefined;

View File

@ -53,10 +53,28 @@ export class SketchbookWidget extends BaseWidget {
);
}
/**
* The currently selected sketchbook tree widget inside the view.
*/
getTreeWidget(): SketchbookTreeWidget {
return this.sketchbookCompositeWidget.treeWidget;
}
/**
* An array of all sketchbook tree widgets managed by the view.
*/
getTreeWidgets(): SketchbookTreeWidget[] {
return toArray(this.sketchbookTreesContainer.widgets()).reduce(
(acc, curr) => {
if (curr instanceof BaseSketchbookCompositeWidget) {
acc.push(curr.treeWidget);
}
return acc;
},
[] as SketchbookTreeWidget[]
);
}
activeTreeWidgetId(): string | undefined {
const selectedTreeWidgets = toArray(
this.sketchbookTreesContainer.selectedWidgets()