-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add support for sub heading in extension views #9909
Add support for sub heading in extension views #9909
Conversation
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.
Thank you for your contribution, the changes look good to me so far. The description property does its job.
FYI the title of your PR is a bit misleading, as you're adding support for the description property for views contributed by extensions, not only for outlines.
I have a few remarks before approving.
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 noticed a couple of things:
- the commit message needs to be updated, we mention
outline-view
but I believe we mean all view-container-parts. - the description is only visible if the view-container-part is currently expanded in vscode - I believe we should align.
export interface DescriptionWidget { | ||
description: string; | ||
onDescriptionChange: Emitter<void>; | ||
} | ||
|
||
export namespace DescriptionWidget { | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
export function is(arg: any): arg is DescriptionWidget { | ||
return arg !== undefined && !!arg['onDescriptionChange']; | ||
} |
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 wasn't so sure the file was necessary, and instead it could be directly added to the tree-view
.
Adding it under shell/
is also a bit awkward.
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'm now moved this file into view-container.ts
as it only really applies to the container widgets
packages/plugin-ext/src/main/browser/view/plugin-view-widget.ts
Outdated
Show resolved
Hide resolved
packages/plugin-ext/src/main/browser/view/plugin-view-widget.ts
Outdated
Show resolved
Hide resolved
packages/plugin-ext/src/main/browser/view/plugin-view-widget.ts
Outdated
Show resolved
Hide resolved
bc50b40
to
929d152
Compare
thanks for the feedback! Have updated the commit message and the subheading now hides and shows when the panel is collapsed/expanded respectively. |
929d152
to
4466fc2
Compare
if (DescriptionWidget.is(this.wrapped) && !this.collapsed) { | ||
subHeading.innerText = !!this.wrapped.description ? this.wrapped.description : ''; | ||
} else { | ||
subHeading.innerText = ''; | ||
} |
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.
Nitpick: We can simplify this
if (DescriptionWidget.is(this.wrapped) && !this.collapsed) { | |
subHeading.innerText = !!this.wrapped.description ? this.wrapped.description : ''; | |
} else { | |
subHeading.innerText = ''; | |
} | |
subHeading.innerText = DescriptionWidget.is(this.wrapped) && !this.collapsed && this.wrapped.description || ''; |
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.
👍
@@ -47,6 +47,17 @@ export class ViewContainerIdentifier { | |||
progressLocationId?: string; | |||
} | |||
|
|||
export interface DescriptionWidget { | |||
description: string; | |||
onDescriptionChange: Emitter<void>; |
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.
Given our coding guidelines, the event name should be renamed to something like:
onDescriptionChange: Emitter<void>; | |
onDidChangeDescription: Emitter<void>; |
protected readonly onSubHeadingChangedEmitter = new Emitter<void>(); | ||
readonly onSubHeadingChanged = this.onSubHeadingChangedEmitter.event; |
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.
Similarly to the above comment, the event name should be renamed:
protected readonly onSubHeadingChangedEmitter = new Emitter<void>(); | |
readonly onSubHeadingChanged = this.onSubHeadingChangedEmitter.event; | |
protected readonly onDidChangeSubHeadingEmitter = new Emitter<void>(); | |
readonly onDidChangeSubHeading = this.onDidChangeSubHeadingEmitter.event; |
I understand we have onTitleChanged
but I believe that example is legacy, perhaps before we put in place the guideline.
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.
👍
@@ -699,6 +712,12 @@ export class ViewContainerPart extends BaseWidget { | |||
this.wrapped.title.changed.connect(fireTitleChanged); | |||
this.toDispose.push(Disposable.create(() => this.wrapped.title.changed.disconnect(fireTitleChanged))); | |||
|
|||
if (DescriptionWidget.is(this.wrapped)) { | |||
const fireSubHeadingChanged = () => this.onSubHeadingChangedEmitter.fire(undefined); | |||
const sub = (this.wrapped as DescriptionWidget)?.onDescriptionChange.event(fireSubHeadingChanged); |
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.
Update to a more meaningful name than sub
?
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.
Removed as it was only really used for debug anyway
flex: 1; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
padding-left: 12px; |
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.
We should compute this value I believe rather than hardcoding.
Example:
padding-left: var(--theia-ui-padding); |
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.
Great suggestion, thanks!
4466fc2
to
37ef12f
Compare
protected readonly onDidSubHeadingChangedEmitter = new Emitter<void>(); | ||
readonly onDidSubHeadingChanged = this.onDidSubHeadingChangedEmitter.event; |
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 think onDidChangeSubHeading(Emitter)
would conform more closely to the guidelines on event naming.
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.
No probs, have updated all of these references!
if (DescriptionWidget.is(this.wrapped)) { | ||
const fireSubHeadingChanged = () => this.onDidSubHeadingChangedEmitter.fire(undefined); | ||
this.toDispose.push((this.wrapped as DescriptionWidget)?.onDidDescriptionChange.event(fireSubHeadingChanged)); |
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.
Since you've performed a type check already, you shouldn't need the as
cast or the ?.
conditional accessor.
Why the change in terminology here from onDidChangeDescription
to onDidChangeSubHeading
? I think I'd prefer that we use the description
-type names throughout and leave the fact that they're rendered as a subheading as an implementation detail.
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.
👍
@@ -50,6 +52,8 @@ export class PluginViewWidget extends Panel implements StatefulWidget { | |||
this.node.style.height = '100%'; | |||
} | |||
|
|||
public onDidDescriptionChange: Emitter<void> = new Emitter<void>(); |
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.
public onDidDescriptionChange: Emitter<void> = new Emitter<void>(); | |
onDidChangeDescription: Emitter<void> = new Emitter<void>(); |
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.
👍 +
Signed-off-by: Aaron Rhodes <aaron.rhodes@arm.com>
37ef12f
to
d880c0e
Compare
thanks @colin-grant-work - have addressed feedback |
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 is working well for me. I was surprised to find that if the ViewContainerPart is the only widget in its ViewContainer, the title bar is not updated:
Only child:
With sibling:
But it looks like that's the same behavior as in VSCode:
In other contexts, I've remarked that it would be nice to extend Phosphor's Title
to handle additional fields not foreseen by Phosphor (pinning, descriptions). There are also two existing fields that we currently treat as more or less interchangeable: label and caption. Arguably, caption
could be used for description
, but we'd have to check all existing code to ensure we're not relying on caption
and label
being interchangeable. Unfortunately, extending the Title
wouldn't be trivial, as it's assigned in a somewhat eccentric way in Phosphor. I think this PR achieves its objectives effectively given the means available, but I wanted to remark on some of the problem areas that it touches for future reference.
What it does
Adds the description field to TreeView from the vscode API.
resolves #9903
How to test
Add a plugin that utilises the TreeView description field.
There is a modified version of the vscode tree-view-sample available in the following repo:
https://github.com/aaronrhodes/vscode-extension-samples
build, and copy or symlink this example into the plugins directory and select a file using the "file explorer" panel in the explorer tab.
Review checklist
Reminder for reviewers