-
-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: rename, deletion, and validation support #1833
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
arduino-ide-extension/src/browser/contributions/cloud-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { CompositeTreeNode } from '@theia/core/lib/browser/tree'; | ||
import { nls } from '@theia/core/lib/common/nls'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
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 { 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'; | ||
import { SketchbookWidget } from '../widgets/sketchbook/sketchbook-widget'; | ||
import { SketchbookWidgetContribution } from '../widgets/sketchbook/sketchbook-widget-contribution'; | ||
import { SketchContribution } from './contribution'; | ||
|
||
export function sketchAlreadyExists(input: string): string { | ||
return nls.localize( | ||
'arduino/cloudSketch/alreadyExists', | ||
"Cloud sketch '{0}' already exists.", | ||
input | ||
); | ||
} | ||
export function sketchNotFound(input: string): string { | ||
return nls.localize( | ||
'arduino/cloudSketch/notFound', | ||
"Could not pull the cloud sketch '{0}'. It does not exist.", | ||
input | ||
); | ||
} | ||
export const synchronizingSketchbook = nls.localize( | ||
'arduino/cloudSketch/synchronizingSketchbook', | ||
'Synchronizing sketchbook...' | ||
); | ||
export function pullingSketch(input: string): string { | ||
return nls.localize( | ||
'arduino/cloudSketch/pulling', | ||
"Synchronizing sketchbook, pulling '{0}'...", | ||
input | ||
); | ||
} | ||
export function pushingSketch(input: string): string { | ||
return nls.localize( | ||
'arduino/cloudSketch/pushing', | ||
"Synchronizing sketchbook, pushing '{0}'...", | ||
input | ||
); | ||
} | ||
|
||
@injectable() | ||
export abstract class CloudSketchContribution extends SketchContribution { | ||
@inject(SketchbookWidgetContribution) | ||
private readonly widgetContribution: SketchbookWidgetContribution; | ||
@inject(CreateApi) | ||
protected readonly createApi: CreateApi; | ||
@inject(CreateFeatures) | ||
protected readonly createFeatures: CreateFeatures; | ||
|
||
protected async treeModel(): Promise< | ||
(CloudSketchbookTreeModel & { root: CompositeTreeNode }) | undefined | ||
> { | ||
const { enabled, session } = this.createFeatures; | ||
if (enabled && session) { | ||
const widget = await this.widgetContribution.widget; | ||
const treeModel = this.treeModelFrom(widget); | ||
if (treeModel) { | ||
const root = treeModel.root; | ||
if (CompositeTreeNode.is(root)) { | ||
return treeModel as CloudSketchbookTreeModel & { | ||
root: CompositeTreeNode; | ||
}; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
protected async pull( | ||
sketch: Create.Sketch | ||
): Promise<CloudSketchbookTree.CloudSketchDirNode | undefined> { | ||
const treeModel = await this.treeModel(); | ||
if (!treeModel) { | ||
return undefined; | ||
} | ||
const id = CreateUri.toUri(sketch).path.toString(); | ||
const node = treeModel.getNode(id); | ||
if (!node) { | ||
throw new Error( | ||
`Could not find cloud sketchbook tree node with ID: ${id}.` | ||
); | ||
} | ||
if (!CloudSketchbookTree.CloudSketchDirNode.is(node)) { | ||
throw new Error( | ||
`Cloud sketchbook tree node expected to represent a directory but it did not. Tree node ID: ${id}.` | ||
); | ||
} | ||
try { | ||
await treeModel.sketchbookTree().pull({ node }); | ||
return node; | ||
} catch (err) { | ||
if (isNotFound(err)) { | ||
await treeModel.refresh(); | ||
this.messageService.error(sketchNotFound(sketch.name)); | ||
return undefined; | ||
} | ||
throw err; | ||
} | ||
} | ||
|
||
private treeModelFrom( | ||
widget: SketchbookWidget | ||
): CloudSketchbookTreeModel | undefined { | ||
for (const treeWidget of widget.getTreeWidgets()) { | ||
if (treeWidget instanceof CloudSketchbookTreeWidget) { | ||
const model = treeWidget.model; | ||
if (model instanceof CloudSketchbookTreeModel) { | ||
return model; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should "cloud" be capitalized?
I'm not a fan of the recent trend I've observed of sometimes capitalizing "sketch" in sentences, since that is not a proper noun, but if "cloud" is short for the "Arduino Cloud" service (as opposed to being a reference to the general concept of "the cloud"), then this is a proper noun and so should be capitalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will leave this decision to you. Whichever you think is the best.
I found the following translations from this PR where the "sketch" is capitalized in a sentence. (I hope I did not leave out anything):
These have not changed in this PR or recently:
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-tree.ts
Line 107 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/dialogs/cloud-share-sketch-dialog.tsx
Line 66 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/dialogs/cloud-share-sketch-dialog.tsx
Line 75 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/dialogs/cloud-share-sketch-dialog.tsx
Line 86 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-tree.ts
Line 70 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/dialogs/firmware-uploader/firmware-uploader-component.tsx
Line 187 in 9a3b107
These have not changed, and the sentence starts with "sketch":
arduino-ide/arduino-ide-extension/src/browser/contributions/debug.ts
Line 215 in 9a3b107
These are command or menu labels, so capitalized "sketch" is expected:
arduino-ide/arduino-ide-extension/src/browser/contributions/new-sketch.ts
Line 24 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx
Line 59 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/contributions/open-sketch-external.ts
Line 25 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts
Line 15 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx
Line 161 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/contributions/open-sketch.ts
Line 93 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/contributions/archive-sketch.ts
Line 25 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts
Line 78 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts
Line 87 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/contributions/new-cloud-sketch.ts
Line 55 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-composite-widget.tsx
Line 84 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts
Line 217 in 9a3b107
These are new and were requested in the design doc:
arduino-ide/arduino-ide-extension/src/browser/contributions/rename-cloud-sketch.ts
Line 85 in 9a3b107
arduino-ide/arduino-ide-extension/src/browser/contributions/new-cloud-sketch.ts
Line 100 in 9a3b107
Let me know what to do. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I surveyed the Arduino Cloud-related content on arduino.cc and found that "Cloud" is capitalized in contexts equivalent to "Cloud sketch". So I think it should be capitalized.
Yes, in cases where the work occurs at the start of a sentence or contexts where the standard for capitalization style is "title case", there is no question that "Sketch" is correct.
Then I guess I would have to request the input of the designers.
@91volt @gmarchiarduino please provide clear rules for when "sketch" should and should not be capitalized. As I've said several times in the past, it would be very helpful to have this sort of thing documented in a style guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is something I cannot control, so I moved it to its dedicated task: #1884.