Skip to content

Commit 7f5cf05

Browse files
author
Tom Saunders
committed
1.6.0
* When workspace storage directory has not been entered the notification dialog will now provide an option to choose the workspace by opening a file dialog. * Updated Change Icon to force reload icons that are overwritten by the user
1 parent 9b021e2 commit 7f5cf05

File tree

9 files changed

+2591
-42
lines changed

9 files changed

+2591
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to the "vscode-workspace-explorer" extension will be documented in this file.
33

4+
## 1.6.0
5+
* When workspace storage directory has not been entered the notification dialog will now provide an option to choose the workspace by opening a file dialog.
6+
* Updated Change Icon to force reload icons that are overwritten by the user
7+
48
## 1.5.0
59
* Added Container Development Environment
610
* Enabled multi-select in Open Workspace Storage Directory dialog.

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ Workspace Explorer contributes the following settings:
181181

182182
# Release Notes
183183

184+
## 1.6.0
185+
* When workspace storage directory has not been entered the notification dialog will now provide an option to choose the workspace by opening a file dialog.
186+
* Updated Change Icon to force reload icons that are overwritten by the user
187+
184188
## 1.5.0
185189
* Added Experimantal Create Workspace right click option.
186190
* Added Experimental Create Workspace button on the Workspace Explorer navigation menu.
@@ -238,12 +242,6 @@ the initial version of the code for this feature.
238242

239243
# Development Roadmap
240244
## Proposed Features:
241-
* Add the ability to create a new sub-folder.
242-
* **Feature Built** Waiting for tree view drag and drop API to be stable in VSCode.
243-
* A button would be added to the title bar indicating a new folder.
244-
* The default location of the new folder would be in the
245-
**Workspace Storage Directory**, but a **sub-folder** in the Workspace
246-
Explorer could be selected before clicking the button.
247245
* Add the ability to open the Additional Custom Icon Directory from the Workspace Explorer
248246
* Add a button the the title bar that would open a file explorer
249247
at the Additional Custom Icon Directory.

package-lock.json

Lines changed: 2495 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-workspace-explorer",
33
"displayName": "Workspace Explorer",
44
"description": "An explorer panel that allows you to list your collection of workspaces and load them one at a time into the IDE or open a new window with the selected workspace.",
5-
"version": "1.5.0",
5+
"version": "1.6.0",
66
"icon": "resources/icons/icon.png",
77
"publisher": "tomsaunders",
88
"author": {
-349 KB
Loading
-145 KB
Loading

src/changeIcon.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,10 @@ const changeIcon = async (context, treeDataProvider) => {
9999
// Copy the file to the Workspace Storage Directory.
100100
await vscode.workspace.fs.copy(inputResults[0], destinationUri);
101101

102-
// Refresh Tree
103-
treeDataProvider.refresh();
104-
105-
// VSCode does not reload image resources with same URI.
106-
if (conflictingFile) {
107-
const response = await vscode.window.showInformationMessage(
108-
'VSCode requires a reload for images with the same name',
109-
...['Reload Now', 'Do it Later'],
110-
);
111-
if (response === 'Reload Now') {
112-
vscode.commands.executeCommand('workbench.action.reloadWindow');
113-
}
114-
}
102+
// Refresh Tree and send URI to force VSCode to relaod
103+
// with dummy query args.
104+
treeDataProvider.refresh(conflictingFile);
105+
115106
} catch (err) {
116107
vscode.window.showErrorMessage(`ERROR: ${err}`);
117108
}

src/workspaceTreeDataProvider.js

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,59 @@ class WorkspaceTreeDataProvider {
8383
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
8484
this.extensionConfig;
8585
this.workspaceStorageDirectory;
86+
this.targetIconUri;
8687
this.getConfigs();
8788
}
8889

8990
// Gets user set configuration values.
90-
getConfigs() {
91-
this.extensionConfig = vscode.workspace.getConfiguration(
92-
'workspaceExplorer',
93-
);
94-
if (this.extensionConfig.workspaceStorageDirectory === '') {
95-
vscode.window.showWarningMessage(
96-
'Workspace Explorer: You must set the workspace '
97-
+ 'storage directory in your vscode settings. Copy this to your '
98-
+ 'clipboard: workspaceExplorer.workspaceStorageDirectory. Then '
99-
+ 'click Open Settings and paste it in the search window.',
100-
...['Open Settings'],
101-
).then((results) => {
102-
if (results === 'Open Settings') {
103-
vscode.commands.executeCommand('workbench.action.openSettings2');
104-
}
105-
});
106-
} else {
107-
this.workspaceStorageDirectory = (
108-
this.extensionConfig.workspaceStorageDirectory
91+
async getConfigs() {
92+
try {
93+
this.extensionConfig = vscode.workspace.getConfiguration(
94+
'workspaceExplorer',
10995
);
96+
if (this.extensionConfig.workspaceStorageDirectory === '') {
97+
const results = await vscode.window.showWarningMessage(
98+
'Workspace Explorer: You must set the workspace '
99+
+ 'storage directory to use the Workspace Explorer. '
100+
+ 'This is the directory where you want to keep your '
101+
+ 'workspace configuration files.',
102+
...['Choose a Directory'],
103+
);
104+
if (results === 'Choose a Directory') {
105+
const config = vscode.workspace.getConfiguration(
106+
'workspaceExplorer',
107+
);
108+
const userFolder = await vscode.window.showOpenDialog(
109+
{
110+
canSelectFiles: false,
111+
canSelectFolders: true,
112+
canSelectMany: false,
113+
},
114+
);
115+
if (userFolder) {
116+
await config.update(
117+
'workspaceStorageDirectory',
118+
userFolder[0].fsPath,
119+
vscode.ConfigurationTarget.Global,
120+
);
121+
this.refresh();
122+
}
123+
}
124+
} else {
125+
this.workspaceStorageDirectory = (
126+
this.extensionConfig.workspaceStorageDirectory
127+
);
128+
}
129+
} catch (err) {
130+
vscode.window.showErrorMessage(err);
110131
}
111132
}
112133

113134
// Rebuilds the Tree of workspaces and sub-folders.
114135
// Repopulates the Workspace Explorer view.
115-
refresh() {
136+
refresh(targetIconUri) {
116137
this.getConfigs();
138+
this.targetIconUri = targetIconUri;
117139
this._onDidChangeTreeData.fire();
118140
}
119141

@@ -124,12 +146,36 @@ class WorkspaceTreeDataProvider {
124146

125147
// Gets vscode Tree Items representing a workspace or folder.
126148
getTreeItem(element) {
127-
return new WorkspaceTreeItem(
149+
// Check if item is using an icon that must be force reloaded due
150+
// to a change icon action initiated by the user who overwrote the
151+
// original icon file.
152+
let useNewUri = false;
153+
if (this.targetIconUri) {
154+
const partialIconPath = this.targetIconUri.fsPath.replace(
155+
path.extname(this.targetIconUri.fsPath),
156+
'',
157+
);
158+
const partialWorkspacePath = element.workspaceFileNameAndFilePath.replace(
159+
path.extname(element.workspaceFileNameAndFilePath),
160+
'',
161+
);
162+
if (partialIconPath === partialWorkspacePath) {
163+
useNewUri = true;
164+
}
165+
}
166+
const treeItem = new WorkspaceTreeItem(
128167
element.label,
129168
element.workspaceFileNameAndFilePath,
130169
element.collapsableState,
131170
this.extensionConfig,
171+
useNewUri,
132172
);
173+
174+
if (useNewUri) {
175+
this.targetIconUri = '';
176+
}
177+
178+
return treeItem;
133179
}
134180

135181
// This runs on activation and any time a collapsed item is expanded.

src/workspaceTreeItem.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,33 @@ class WorkspaceTreeItem extends vscode.TreeItem {
102102
workspaceFileNameAndFilePath,
103103
collapsableState,
104104
extensionConfig,
105+
useNewUri,
105106
) {
106107
super(label, collapsableState);
107108
this.workspaceFileNameAndFilePath = workspaceFileNameAndFilePath;
108109

109110
// Look for custom icons if configuration setting is enabled.
110111
// Else, get defaults.
111112
if (extensionConfig.enableCustomIconSearch === true) {
112-
this.iconPath = getCustomWorkspaceIcons(
113+
const icons = getCustomWorkspaceIcons(
113114
workspaceFileNameAndFilePath,
114115
collapsableState,
115116
extensionConfig,
116117
);
118+
if (useNewUri) {
119+
// Create dummy query args to force reload of icon that has
120+
// been overwritten by the user.
121+
this.iconPath = {
122+
light: vscode.Uri.file(icons.light).with(
123+
{ query: `x=${Math.random()}` },
124+
),
125+
dark: vscode.Uri.file(icons.dark).with(
126+
{ query: `x=${Math.random()}` },
127+
),
128+
};
129+
} else {
130+
this.iconPath = icons;
131+
}
117132
} else {
118133
this.iconPath = getDefaultWorkspaceIcons(collapsableState);
119134
}

0 commit comments

Comments
 (0)