Skip to content
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

Allow TreeItems to have optional checkboxes #116141

Closed
TylerLeonhardt opened this issue Feb 8, 2021 · 18 comments · Fixed by #158250 or #185846
Closed

Allow TreeItems to have optional checkboxes #116141

TylerLeonhardt opened this issue Feb 8, 2021 · 18 comments · Fixed by #158250 or #185846
Assignees
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan tree-views Extension tree view issues
Milestone

Comments

@TylerLeonhardt
Copy link
Member

I'm all for trying to avoid webviews as much as possible, especially when tree views are hard to make work in a webview. This proposal allows for treeviews to have checkboxes:

image
(but better styling of course 😄)

Scenarios

  • To-do list extensions
  • Applying filters where an 'Edit' button drops you into the experience above where checkboxes show up
  • Crafting .gitignore's or other 'ignores' where you go down the filesystem and uncheck the files you want to ignore

Proposal

  • TreeItem has new optional property called checkboxState similar to collapsibleState which takes in a TreeItemCheckBoxState:
        export class TreeItem {
            // ...

            /**
             * [TreeItemCheckboxState](#TreeItemCheckboxState) of the tree item.
             */
            checkboxState?: TreeItemCheckboxState;

            // ...
        }

       /**
	 * Checkbox state of the tree item
	 */
        export enum TreeItemCheckboxState{
		/**
		 * Determines an item can be neither checked nor unchecked. Implies it has no checkbox.
		 */
		None = 0,
		/**
		 * Determines an item is checked
		 */
		Checked = 1,
		/**
		 * Determines an item is unchecked
		 */
		Unchecked = 2
	}
  • TreeDataProvider will have a new optional event onDidChangeTreeCheckbox which will fire when the checkbox of a TreeItem is checked or unchecked:
        /**
	 * A data provider that provides tree data
	 */
	export interface TreeDataProvider<T> {
                // ...

                /**
		 * An optional event to signal that an element or root has either been checked or unchecked.
		 */
		onDidChangeTreeCheckbox?: Event<ChangeTreeCheckboxEvent<T>>;

                // ...
        }

        export interface ChangeTreeCheckboxEvent {
                /**
		 * The item that was checked or unchecked.
		 */
		readonly item: <T>;

		/**
		 * Removed workspace folders.
		 */
		readonly newState: TreeItemCheckboxState;
        }
@TylerLeonhardt TylerLeonhardt added tree-widget Tree widget issues feature-request Request for new features or functionality api-proposal labels Feb 8, 2021
@TylerLeonhardt
Copy link
Member Author

btw, this is essentially an alternative to #115365

@TylerLeonhardt TylerLeonhardt self-assigned this Feb 8, 2021
@TylerLeonhardt TylerLeonhardt removed their assignment Jun 10, 2021
@joaomoreno joaomoreno removed the tree-widget Tree widget issues label Nov 5, 2021
@joaomoreno joaomoreno added the tree-views Extension tree view issues label Jun 29, 2022
@joaomoreno
Copy link
Member

Interesting that some internal tree usages already do something similar:

image

@albertelo
Copy link

@daviddossett @misolori Hi folks, this feature request has come up for some of our extension authors. Since the last update was more than a year ago, I was wondering if you had this in your pipeline for the near future?

@alexr00
Copy link
Member

alexr00 commented Aug 2, 2022

You should see this appear on our August iteration plan :). We'll start looking into it then.

@benibenj
Copy link
Contributor

API Proposal: #158250

@benibenj benibenj linked a pull request Aug 16, 2022 that will close this issue
@benibenj benibenj modified the milestones: August 2022, September 2022 Aug 22, 2022
@alexr00
Copy link
Member

alexr00 commented Sep 6, 2022

Re-opening to track API proposal.

@alexr00 alexr00 reopened this Sep 6, 2022
@alexr00
Copy link
Member

alexr00 commented May 12, 2023

  1. checkbox is not rendered if initial state is Unchecked.

@Eskibear I'm not able to reproduce this. Are you able to reproduce this by adding a checkbox to tree items in the [tree view sample](https://github.com/microsoft/vscode-extension-samples/blob/f7b27a91779e770b8f8f0e6791bcefc5d9c64035/tree-view-sample/src/testView.ts#L50-L51}.

  1. by check/uncheck, context value is not updated unless I signal the element has changed

As you say, this can be accomplished with onDidChangeTreeData. For now, this is by design. We will revisit as part of the finalization process.

do we need indeterminate state for the checkbox?

We have discussed this, and it would be nice to have. However, the major use cases we have seen so far for the checkbox can live without it. We will revisit during finalization, but I think the outcome will be that we should have only 2 states for now and make sure the API is designed in such a way that if we want to add a third state later we can.

alexr00 added a commit that referenced this issue May 17, 2023
alexr00 added a commit to microsoft/vscode-pull-request-github that referenced this issue May 17, 2023
@alexr00
Copy link
Member

alexr00 commented May 17, 2023

Starting tomorrow, child and parent checkbox state will be managed by VS Code by default. This can be overridden:

/**
* Options for creating a {@link TreeView}
*/
export interface TreeViewOptions<T> {
/**
* By default, when the children of a tree item have already been fetched, child checkboxes are automatically managed based on the checked state of the parent tree item.
* If the tree item is collapsed by default (meaning that the children haven't yet been fetched) then child checkboxes will not be updated.
* To override this behavior and manage child and parent checkbox state in the extension, set this to `true`.
*/
manuallyManageCheckboxSelection?: boolean;
}

We also have a new accessibilityInformation:

export class TreeItem2 extends TreeItem {
/**
* {@link TreeItemCheckboxState TreeItemCheckboxState} of the tree item.
* {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} should be fired when {@link TreeItem2.checkboxState checkboxState} changes.
*/
checkboxState?: TreeItemCheckboxState | { readonly state: TreeItemCheckboxState; readonly tooltip?: string; readonly accessibilityInformation?: AccessibilityInformation };
}

alexr00 added a commit that referenced this issue May 17, 2023
alexr00 added a commit to microsoft/vscode-pull-request-github that referenced this issue May 17, 2023
@Eskibear
Copy link
Member

@alexr00 I still can produce it.

Latest Insiders, Commit: f6be5461f8bc69013a605f5baea834651c6589fb

image

I made some changes, and expect all items ending with "a" to have a checked box, and otherwise an unchecked box. See item "ab", "b" and "bb".

Code change based on the sample.
https://github.com/microsoft/vscode-extension-samples/compare/main...Eskibear:vscode-extension-samples:checkbox?expand=1#diff-c9867a60c64266b038de2193e5a755121ab3e04c2597c19a1cee9ba77ed3a0d4R82

@alexr00
Copy link
Member

alexr00 commented May 25, 2023

Thanks for the example @Eskibear! I was using the readonly state: TreeItemCheckboxState; readonly tooltip?: string;} type for checkboxState, which is why I failed to repro.

@alexr00 alexr00 modified the milestones: May 2023, June 2023 May 26, 2023
@alexr00 alexr00 mentioned this issue May 26, 2023
2 tasks
alexr00 added a commit that referenced this issue Jun 22, 2023
alexr00 added a commit that referenced this issue Jun 22, 2023
* Finalize tree checkbox API
Fixes #116141

* Remove TODO
@VSCodeTriageBot VSCodeTriageBot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jun 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan tree-views Extension tree view issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants