diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d37933..9a6ee58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the "AddFolderToWorkspace" extension will be documented in this file. +## [1.1.1] + +`AddFolderToWorkspace: Add manually a directory...` - Paths can be added manually from now on. After that, the new workspace can be saved directly in the settings.s + +Fixed bug - when a workspace has already been added. + ## [1.1.0] ### AddFolderToWorkspace diff --git a/RELEASE.md b/RELEASE.md index 4ec8b0f..33befce 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,15 +1,4 @@ -# [1.1.0] +# [1.1.1] -## AddFolderToWorkspace - -This Function provides a searchable list of folders (Workspaces) that can be added **simultaneous** to the current VSC Workspace. All configured folders will be displayed. - -**Shortcut:** ```strg + alt + k, p```
-**Command:** ```AddFolderToWorkspace: Add Folder to Workspace.``` - -## RemoveFolderFromWorkspace - -This Function provides a searchable list of folders (Workspaces) that can be removed **simultaneous** from the current VSC Workspace. All current open folders are displayed. - -**Shortcut:** ```strg + alt + k, shift + p```
-**Command:** ```AddFolderToWorkspace: Remove Folder from Workspace.``` +- `AddFolderToWorkspace: Add manually a directory...` - Paths can be added manually from now on. After that, the new workspace can be saved directly in the settings. +- Fixed bug - when a workspace has already been added. \ No newline at end of file diff --git a/package.json b/package.json index 3703c55..694b463 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "AddFolderToWorkspace", "displayName": "Add Folder To Workspace", "description": "This extension adds / removes the selected folder (multiple) to / from the workspace (VSC Workspace).", - "version": "1.1.0", + "version": "1.1.1", "publisher": "dennykorsukewitz", "icon": "doc/images/icon.png", "license": "SEE LICENSE IN LICENSE", diff --git a/src/extension.js b/src/extension.js index 0548a8b..d781edc 100644 --- a/src/extension.js +++ b/src/extension.js @@ -24,7 +24,11 @@ function initAddFolderToWorkspace(context) { const addFolderToWorkspaceId = 'addFolderToWorkspace'; context.subscriptions.push(vscode.commands.registerCommand(addFolderToWorkspaceId, async () => { - let workspaceDirectories = []; + let workspaceDirectories = [], + newWorkspaceFound = 0, + manualWorkspace = '', + manualDirectoryString = '-- Add manually a directory --'; + let config = vscode.workspace.getConfiguration('addFolderToWorkspace'); // Check if workspaces are defined. @@ -50,26 +54,75 @@ function initAddFolderToWorkspace(context) { return; } + if (workspaceDirectories.length && !workspaceDirectories.includes(manualDirectoryString)) { + workspaceDirectories.unshift(manualDirectoryString); + } + // Open QuickPick and add selected Folder (Directory to VSC Workspace). let workspaces = await vscode.window.showQuickPick(workspaceDirectories, { title: 'AddFolderToWorkspace', placeHolder: 'AddFolderToWorkspace: Select a folder...', canPickMany: true, }) + if (!workspaces) return; + + if (workspaces.length && workspaces.includes(manualDirectoryString)) { + workspaces.shift(manualDirectoryString); + newWorkspaceFound = 1; + + manualWorkspace = await vscode.window.showInputBox({ + title: 'AddFolderToWorkspace', + placeHolder: 'AddFolderToWorkspace: Add manually a directory...', + }); + + if (manualWorkspace){ + workspaces.push(manualWorkspace); + } + } if (!workspaces) return; let workspaceURIs = []; for await (const workspace of workspaces) { // Get URI of selected directory. - let URI = vscode.Uri.file(workspace); + let URI = vscode.Uri.file(workspace), + URIexists = 0; + if (!URI) return; - workspaceURIs.push({ uri: URI }); + + vscode.workspace.workspaceFolders.sort().forEach(function (workspaceFolder) { + + if (URI.path == workspaceFolder.uri.path){ + URIexists = 1; + } + }) + + if (!URIexists){ + workspaceURIs.push({ uri: URI }); + } } if (!workspaceURIs.length) return; + if (newWorkspaceFound) { + let addNewWorkspaceToConfig = await vscode.window.showQuickPick(['yes','no'], { + title: 'AddFolderToWorkspace (New Workspace)', + placeHolder: 'AddFolderToWorkspace: Should I save the new workspace in the settings?', + canPickMany: false, + }); + + if (addNewWorkspaceToConfig == 'yes'){ + + if (!manualWorkspace.endsWith("/")){ + manualWorkspace += '/'; + } + + config.workspaces.push(manualWorkspace); + await vscode.workspace.getConfiguration().update('addFolderToWorkspace.workspaces', config.workspaces); + } + } + // Add selected Folder to Workspace. await updateWorkspaceAndWait(0, null, workspaceURIs);