Skip to content

Commit adf6f66

Browse files
committed
Add ability to rename database in database tree
1 parent 21500f0 commit adf6f66

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

extensions/ql-vscode/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
"command": "codeQLDatabases.upgradeDatabase",
207207
"title": "Upgrade Database"
208208
},
209+
{
210+
"command": "codeQLDatabases.renameDatabase",
211+
"title": "Rename Database"
212+
},
209213
{
210214
"command": "codeQL.checkForUpdatesToCLI",
211215
"title": "CodeQL: Check for CLI Updates"
@@ -275,6 +279,11 @@
275279
"group": "9_qlCommands",
276280
"when": "view == codeQLDatabases"
277281
},
282+
{
283+
"command": "codeQLDatabases.renameDatabase",
284+
"group": "9_qlCommands",
285+
"when": "view == codeQLDatabases"
286+
},
278287
{
279288
"command": "codeQLQueryHistory.openQuery",
280289
"group": "9_qlCommands",

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class DatabaseUI extends DisposableObject {
144144
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.setCurrentDatabase', this.handleMakeCurrentDatabase));
145145
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.removeDatabase', this.handleRemoveDatabase));
146146
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.upgradeDatabase', this.handleUpgradeDatabase));
147+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.renameDatabase', this.handleRenameDatabase));
147148
}
148149

149150
private handleMakeCurrentDatabase = async (databaseItem: DatabaseItem): Promise<void> => {
@@ -220,6 +221,17 @@ export class DatabaseUI extends DisposableObject {
220221
this.databaseManager.removeDatabaseItem(databaseItem);
221222
}
222223

224+
private handleRenameDatabase = async (databaseItem: DatabaseItem): Promise<void> => {
225+
const newName = await window.showInputBox({
226+
prompt: 'Choose new database name',
227+
value: databaseItem.name
228+
});
229+
230+
if (newName) {
231+
this.databaseManager.renameDatabaseItem(databaseItem, newName);
232+
}
233+
}
234+
223235
/**
224236
* Return the current database directory. If we don't already have a
225237
* current database, ask the user for one, and return that, or

extensions/ql-vscode/src/databases.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export interface DatabaseItem {
201201
/** The URI of the database */
202202
readonly databaseUri: vscode.Uri;
203203
/** The name of the database to be displayed in the UI */
204-
readonly name: string;
204+
name: string;
205205
/** The URI of the database's source archive, or `undefined` if no source archive is to be used. */
206206
readonly sourceArchive: vscode.Uri | undefined;
207207
/**
@@ -279,6 +279,10 @@ class DatabaseItemImpl implements DatabaseItem {
279279
}
280280
}
281281

282+
public set name(newName: string) {
283+
this.options.displayName = newName;
284+
}
285+
282286
public get sourceArchive(): vscode.Uri | undefined {
283287
if (this.options.ignoreSourceArchive || (this._contents === undefined)) {
284288
return undefined;
@@ -449,6 +453,7 @@ function eventFired<T>(event: vscode.Event<T>, timeoutMs = 1000): Promise<T | un
449453
export class DatabaseManager extends DisposableObject {
450454
private readonly _onDidChangeDatabaseItem =
451455
this.push(new vscode.EventEmitter<DatabaseItem | undefined>());
456+
452457
readonly onDidChangeDatabaseItem = this._onDidChangeDatabaseItem.event;
453458

454459
private readonly _onDidChangeCurrentDatabaseItem =
@@ -617,6 +622,12 @@ export class DatabaseManager extends DisposableObject {
617622
this._onDidChangeDatabaseItem.fire(undefined);
618623
}
619624

625+
public async renameDatabaseItem(item: DatabaseItem, newName: string) {
626+
item.name = newName;
627+
this.updatePersistedDatabaseList();
628+
this._onDidChangeDatabaseItem.fire(item);
629+
}
630+
620631
public removeDatabaseItem(item: DatabaseItem) {
621632
if (this._currentDatabaseItem == item)
622633
this._currentDatabaseItem = undefined;

0 commit comments

Comments
 (0)