mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add back "Remove Project" (#17178)
* remove project working with full paths * use relative paths * const * addressing comments
This commit is contained in:
@@ -26,10 +26,10 @@
|
|||||||
{
|
{
|
||||||
"title": "Projects",
|
"title": "Projects",
|
||||||
"properties": {
|
"properties": {
|
||||||
"dataworkspace.projects": {
|
"dataworkspace.excludedProjects": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"default": [],
|
"default": [],
|
||||||
"description": ""
|
"description": "%projects.excludedProjectsDescription%"
|
||||||
},
|
},
|
||||||
"projects.defaultProjectSaveLocation": {
|
"projects.defaultProjectSaveLocation": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -68,6 +68,10 @@
|
|||||||
"category": "",
|
"category": "",
|
||||||
"icon": "$(close)"
|
"icon": "$(close)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "projects.removeProject",
|
||||||
|
"title": "%remove-project-command%"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "projects.manageProject",
|
"command": "projects.manageProject",
|
||||||
"title": "%manage-project-command%"
|
"title": "%manage-project-command%"
|
||||||
@@ -108,6 +112,10 @@
|
|||||||
"command": "dataworkspace.close",
|
"command": "dataworkspace.close",
|
||||||
"when": "false"
|
"when": "false"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "projects.removeProject",
|
||||||
|
"when": "false"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "projects.openExisting"
|
"command": "projects.openExisting"
|
||||||
},
|
},
|
||||||
@@ -121,6 +129,11 @@
|
|||||||
"command": "projects.manageProject",
|
"command": "projects.manageProject",
|
||||||
"when": "view == dataworkspace.views.main && viewItem == databaseProject.itemType.project && azdataAvailable",
|
"when": "view == dataworkspace.views.main && viewItem == databaseProject.itemType.project && azdataAvailable",
|
||||||
"group": "0_projectsFirst@1"
|
"group": "0_projectsFirst@1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "projects.removeProject",
|
||||||
|
"when": "view == dataworkspace.views.main && viewItem == databaseProject.itemType.project",
|
||||||
|
"group": "9_dbProjectsLast@9"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,5 +12,6 @@
|
|||||||
"open-existing-command": "Open existing",
|
"open-existing-command": "Open existing",
|
||||||
"projects.defaultProjectSaveLocation": "Full path to folder where new projects are saved by default.",
|
"projects.defaultProjectSaveLocation": "Full path to folder where new projects are saved by default.",
|
||||||
"projects.showNotAddedProjectsInWorkspacePrompt": "Always show information message when the current workspace folders contain projects that have not been added to the workspace's projects.",
|
"projects.showNotAddedProjectsInWorkspacePrompt": "Always show information message when the current workspace folders contain projects that have not been added to the workspace's projects.",
|
||||||
"manage-project-command": "Manage"
|
"manage-project-command": "Manage",
|
||||||
|
"projects.excludedProjectsDescription": "List of projects in the workspace to exclude from the projects viewlet"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
|
|||||||
return vscode.commands.executeCommand('workbench.action.closeFolder');
|
return vscode.commands.executeCommand('workbench.action.closeFolder');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
context.subscriptions.push(vscode.commands.registerCommand('projects.removeProject', async (treeItem: WorkspaceTreeItem) => {
|
||||||
|
await workspaceService.removeProject(vscode.Uri.file(treeItem.element.project.projectFilePath));
|
||||||
|
}));
|
||||||
|
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('projects.manageProject', async (treeItem: WorkspaceTreeItem) => {
|
context.subscriptions.push(vscode.commands.registerCommand('projects.manageProject', async (treeItem: WorkspaceTreeItem) => {
|
||||||
const dashboard = new ProjectDashboard(workspaceService, treeItem);
|
const dashboard = new ProjectDashboard(workspaceService, treeItem);
|
||||||
await dashboard.showDashboard();
|
await dashboard.showDashboard();
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import { TelemetryReporter, TelemetryViews, TelemetryActions } from '../common/t
|
|||||||
import { Deferred } from '../common/promise';
|
import { Deferred } from '../common/promise';
|
||||||
import { getAzdataApi } from '../common/utils';
|
import { getAzdataApi } from '../common/utils';
|
||||||
|
|
||||||
|
const WorkspaceConfigurationName = 'dataworkspace';
|
||||||
|
const ExcludedProjectsConfigurationName = 'excludedProjects';
|
||||||
|
|
||||||
export class WorkspaceService implements IWorkspaceService {
|
export class WorkspaceService implements IWorkspaceService {
|
||||||
private _onDidWorkspaceProjectsChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
|
private _onDidWorkspaceProjectsChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
|
||||||
readonly onDidWorkspaceProjectsChange: vscode.Event<void> = this._onDidWorkspaceProjectsChange?.event;
|
readonly onDidWorkspaceProjectsChange: vscode.Event<void> = this._onDidWorkspaceProjectsChange?.event;
|
||||||
@@ -93,8 +96,14 @@ export class WorkspaceService implements IWorkspaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. If any new projects are detected, fire event to refresh projects tree
|
// 3. Check if the project was previously excluded and remove it from the list of excluded projects if it was
|
||||||
|
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
|
||||||
|
const updatedExcludedProjects = excludedProjects.filter(excludedProj => !projectFiles.find(newProj => vscode.workspace.asRelativePath(newProj) === excludedProj));
|
||||||
|
if (excludedProjects.length !== updatedExcludedProjects.length) {
|
||||||
|
await this.setWorkspaceConfigurationValue(ExcludedProjectsConfigurationName, updatedExcludedProjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. If any new projects are detected, fire event to refresh projects tree
|
||||||
if (newProjectAdded) {
|
if (newProjectAdded) {
|
||||||
this._onDidWorkspaceProjectsChange.fire();
|
this._onDidWorkspaceProjectsChange.fire();
|
||||||
}
|
}
|
||||||
@@ -127,6 +136,10 @@ export class WorkspaceService implements IWorkspaceService {
|
|||||||
throw new Error(constants.openedProjectsUndefinedAfterRefresh);
|
throw new Error(constants.openedProjectsUndefinedAfterRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove excluded projects specified in workspace file
|
||||||
|
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
|
||||||
|
this.openedProjects = this.openedProjects.filter(project => !excludedProjects.find(excludedProject => excludedProject === vscode.workspace.asRelativePath(project)));
|
||||||
|
|
||||||
// filter by specified extension
|
// filter by specified extension
|
||||||
if (ext) {
|
if (ext) {
|
||||||
return this.openedProjects.filter(p => p.fsPath.toLowerCase().endsWith(ext.toLowerCase()));
|
return this.openedProjects.filter(p => p.fsPath.toLowerCase().endsWith(ext.toLowerCase()));
|
||||||
@@ -257,4 +270,28 @@ export class WorkspaceService implements IWorkspaceService {
|
|||||||
ProjectProviderRegistry.registerProvider(extension.exports, extension.id);
|
ProjectProviderRegistry.registerProvider(extension.exports, extension.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the specified project to list of projects to hide in projects viewlet. This list is kept track of in the workspace file
|
||||||
|
* @param projectFile uri of project to remove from projects viewlet
|
||||||
|
*/
|
||||||
|
async removeProject(projectFile: vscode.Uri): Promise<void> {
|
||||||
|
TelemetryReporter.createActionEvent(TelemetryViews.WorkspaceTreePane, TelemetryActions.ProjectRemovedFromWorkspace)
|
||||||
|
.withAdditionalProperties({
|
||||||
|
projectType: path.extname(projectFile.fsPath)
|
||||||
|
}).send();
|
||||||
|
|
||||||
|
const excludedProjects = this.getWorkspaceConfigurationValue<string[]>(ExcludedProjectsConfigurationName);
|
||||||
|
excludedProjects.push(vscode.workspace.asRelativePath(projectFile.fsPath));
|
||||||
|
await this.setWorkspaceConfigurationValue(ExcludedProjectsConfigurationName, [...new Set(excludedProjects)]);
|
||||||
|
this._onDidWorkspaceProjectsChange.fire();
|
||||||
|
}
|
||||||
|
|
||||||
|
getWorkspaceConfigurationValue<T>(configurationName: string): T {
|
||||||
|
return vscode.workspace.getConfiguration(WorkspaceConfigurationName).get(configurationName) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
async setWorkspaceConfigurationValue(configurationName: string, value: any): Promise<void> {
|
||||||
|
await vscode.workspace.getConfiguration(WorkspaceConfigurationName).update(configurationName, value, vscode.ConfigurationTarget.Workspace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user