mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 01:25:38 -05:00
Add back "Remove Project" (#17178)
* remove project working with full paths * use relative paths * const * addressing comments
This commit is contained in:
@@ -62,6 +62,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
|
||||
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) => {
|
||||
const dashboard = new ProjectDashboard(workspaceService, treeItem);
|
||||
await dashboard.showDashboard();
|
||||
|
||||
@@ -16,6 +16,9 @@ import { TelemetryReporter, TelemetryViews, TelemetryActions } from '../common/t
|
||||
import { Deferred } from '../common/promise';
|
||||
import { getAzdataApi } from '../common/utils';
|
||||
|
||||
const WorkspaceConfigurationName = 'dataworkspace';
|
||||
const ExcludedProjectsConfigurationName = 'excludedProjects';
|
||||
|
||||
export class WorkspaceService implements IWorkspaceService {
|
||||
private _onDidWorkspaceProjectsChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
|
||||
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) {
|
||||
this._onDidWorkspaceProjectsChange.fire();
|
||||
}
|
||||
@@ -127,6 +136,10 @@ export class WorkspaceService implements IWorkspaceService {
|
||||
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
|
||||
if (ext) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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