From c0811392eea42479c95b755ca7adeb74c3bae09e Mon Sep 17 00:00:00 2001 From: Gruntfuggly Date: Tue, 16 Apr 2019 14:58:30 +0100 Subject: [PATCH] Add "scan open files only"/"scan workspace" toggle button --- README.md | 7 ++- extension.js | 15 +++++++ package.json | 53 ++++++++++++++++++----- resources/icons/dark/scan-open-files.svg | 5 +++ resources/icons/dark/scan-workspace.svg | 6 +++ resources/icons/light/scan-open-files.svg | 5 +++ resources/icons/light/scan-workspace.svg | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 resources/icons/dark/scan-open-files.svg create mode 100644 resources/icons/dark/scan-workspace.svg create mode 100644 resources/icons/light/scan-open-files.svg create mode 100644 resources/icons/light/scan-workspace.svg diff --git a/README.md b/README.md index 1155b65..9c70a38 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ The source code is available on GitHub [here](https://github.com/Gruntfuggly/tod ## Controls -The tree view header contains the following buttons: +The tree view header can contain the following buttons: - Collapse all tree nodes
- Expand all tree nodes
@@ -92,7 +92,9 @@ The tree view header contains the following buttons: - Organise the TODOs by file (default)
- Only show items in the tree which match the entered filter text
- Remove any active filter
- - Rebuild the tree + - Rebuild the tree
+ - Show tags from open files only
+ - Show tags from workspace
## Commands @@ -137,6 +139,7 @@ The extension can be customised as follows: | todo-tree.statusBar | none | What to show in the status bar - nothing (none), total count (total), counts per tag (tags) or the counts for the top three tags (top three) | | todo-tree.showCountsInTree | false | Set to true to show counts of TODOs in the tree | | todo-tree.labelFormat | ${tag} ${after} | Format of the TODO item labels. Available placeholders are ${line}, ${column}, ${tag}, ${before} (text from before the tag), ${after} (text from after the tag) and ${filename}. | +| todo-tree.showScanOpenFilesOrWorkspaceButton | false | Show a button on the tree view header to toggle between scanning open files only, or the whole workspace | * Only applies to new workspaces. Once the view has been changed in the workspace, the current state is stored. diff --git a/extension.js b/extension.js index f8795ac..68fc3a3 100644 --- a/extension.js +++ b/extension.js @@ -404,6 +404,9 @@ function activate( context ) vscode.commands.executeCommand( 'setContext', 'todo-tree-filtered', context.workspaceState.get( 'filtered', false ) ); vscode.commands.executeCommand( 'setContext', 'todo-tree-collapsible', isCollapsible ); + vscode.commands.executeCommand( 'setContext', 'todo-tree-show-scan-open-files-or-workspace-button', c.get( 'showScanOpenFilesOrWorkspaceButton', false ) ); + vscode.commands.executeCommand( 'setContext', 'todo-tree-scan-open-files-only', c.get( 'showTagsFromOpenFilesOnly', false ) ); + var children = provider.getChildren(); var empty = children.length === 1 && children[ 0 ].empty === true; @@ -574,6 +577,16 @@ function activate( context ) } ); } + function scanOpenFilesOnly() + { + vscode.workspace.getConfiguration( 'todo-tree' ).update( 'showTagsFromOpenFilesOnly', true, false ); + } + + function scanWorkspace() + { + vscode.workspace.getConfiguration( 'todo-tree' ).update( 'showTagsFromOpenFilesOnly', false, false ); + } + function register() { function migrateSettings() @@ -676,6 +689,8 @@ function activate( context ) context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.addTag', addTag ) ); context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.removeTag', removeTag ) ); context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.toggleStatusBar', toggleStatusBar ) ); + context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.scanOpenFilesOnly', scanOpenFilesOnly ) ); + context.subscriptions.push( vscode.commands.registerCommand( 'todo-tree.scanWorkspace', scanWorkspace ) ); context.subscriptions.push( vscode.window.onDidChangeActiveTextEditor( function( e ) { diff --git a/package.json b/package.json index 9dbf297..f8fbbee 100644 --- a/package.json +++ b/package.json @@ -52,55 +52,65 @@ }, "menus": { "view/title": [ + { + "command": "todo-tree.scanOpenFilesOnly", + "when": "view =~ /todo-tree/ && todo-tree-scan-open-files-only == false && todo-tree-show-scan-open-files-or-workspace-button == true", + "group": "navigation@1" + }, + { + "command": "todo-tree.scanWorkspace", + "when": "view =~ /todo-tree/ && todo-tree-scan-open-files-only == true && todo-tree-show-scan-open-files-or-workspace-button == true", + "group": "navigation@1" + }, { "command": "todo-tree.expand", "when": "view =~ /todo-tree/ && todo-tree-expanded == false && todo-tree-collapsible", - "group": "navigation@1" + "group": "navigation@2" }, { "command": "todo-tree.collapse", "when": "view =~ /todo-tree/ && todo-tree-expanded == true && todo-tree-collapsible", - "group": "navigation@1" + "group": "navigation@2" }, { "command": "todo-tree.showFlatView", "when": "view =~ /todo-tree/ && todo-tree-flat == false && todo-tree-tags-only == false", - "group": "navigation@2" + "group": "navigation@3" }, { "command": "todo-tree.showTagsOnlyView", "when": "view =~ /todo-tree/ && todo-tree-flat == true && todo-tree-tags-only == false", - "group": "navigation@2" + "group": "navigation@3" }, { "command": "todo-tree.showTreeView", "when": "view =~ /todo-tree/ && todo-tree-flat == false && todo-tree-tags-only == true", - "group": "navigation@2" + "group": "navigation@3" }, { "command": "todo-tree.groupByTag", "when": "view =~ /todo-tree/ && todo-tree-grouped == false", - "group": "navigation@3" + "group": "navigation@4" }, { "command": "todo-tree.ungroupByTag", "when": "view =~ /todo-tree/ && todo-tree-grouped == true", - "group": "navigation@3" + "group": "navigation@4" }, { "command": "todo-tree.filter", "when": "view =~ /todo-tree/ && todo-tree-filtered == false", - "group": "navigation@4" + "group": "navigation@5" }, { "command": "todo-tree.filterClear", "when": "view =~ /todo-tree/ && todo-tree-filtered == true", - "group": "navigation@4" + "group": "navigation@5" }, { "command": "todo-tree.refresh", "when": "view =~ /todo-tree/", - "group": "navigation@5" + "group": "navigation@6" } ] }, @@ -195,6 +205,24 @@ "light": "resources/icons/light/notag.svg" } }, + { + "command": "todo-tree.scanOpenFilesOnly", + "title": "Scan Open Files Only", + "category": "Todo Tree", + "icon": { + "dark": "resources/icons/dark/scan-open-files.svg", + "light": "resources/icons/light/scan-open-files.svg" + } + }, + { + "command": "todo-tree.scanWorkspace", + "title": "Scan Workspace", + "category": "Todo Tree", + "icon": { + "dark": "resources/icons/dark/scan-workspace.svg", + "light": "resources/icons/light/scan-workspace.svg" + } + }, { "command": "todo-tree.addTag", "title": "Add Tag", @@ -374,6 +402,11 @@ "type": "boolean", "default": false, "markdownDescription": "When opening new workspaces, show only tag elements in tree" + }, + "todo-tree.showScanOpenFilesOrWorkspaceButton": { + "type": "boolean", + "default":false, + "markdownDescription":"Show a button on the tree view header to toggle between scanning open files only, or the whole workspace" } } } diff --git a/resources/icons/dark/scan-open-files.svg b/resources/icons/dark/scan-open-files.svg new file mode 100644 index 0000000..675406b --- /dev/null +++ b/resources/icons/dark/scan-open-files.svg @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/resources/icons/dark/scan-workspace.svg b/resources/icons/dark/scan-workspace.svg new file mode 100644 index 0000000..93257ac --- /dev/null +++ b/resources/icons/dark/scan-workspace.svg @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/resources/icons/light/scan-open-files.svg b/resources/icons/light/scan-open-files.svg new file mode 100644 index 0000000..f574a27 --- /dev/null +++ b/resources/icons/light/scan-open-files.svg @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/resources/icons/light/scan-workspace.svg b/resources/icons/light/scan-workspace.svg new file mode 100644 index 0000000..a898b95 --- /dev/null +++ b/resources/icons/light/scan-workspace.svg @@ -0,0 +1,6 @@ + + + \ No newline at end of file