diff --git a/src/config.ts b/src/config.ts index f8bbe267..d4d5cc75 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,6 +7,7 @@ import { JobManagerView } from "./views/jobManager/jobManagerView"; import Configuration from "./configuration"; import { ConfigManager } from "./views/jobManager/ConfigManager"; import { Examples, ServiceInfoLabel } from "./views/examples"; +import { updateStatusBar } from "./views/jobManager/statusBar"; interface IBMiLevels { version: number; @@ -30,6 +31,8 @@ export async function onConnectOrServerInstall(): Promise { await ServerComponent.checkForUpdate(); + updateStatusBar(); + if (ServerComponent.isInstalled()) { JobManagerView.setVisible(true); @@ -38,7 +41,7 @@ export async function onConnectOrServerInstall(): Promise { switch (newJob) { case `ask`: - return await askAboutNewJob(); + return await askAboutNewJob(true); case `new`: await commands.executeCommand(`vscode-db2i.jobManager.newJob`); @@ -67,7 +70,8 @@ export function setupConfig(context: ExtensionContext) { getInstance().onEvent(`disconnected`, async () => { JobManagerView.setVisible(false); - await JobManager.endAll(); + JobManager.endAll(); + updateStatusBar(); // Remove old service examples delete Examples[ServiceInfoLabel]; @@ -101,15 +105,28 @@ export async function fetchSystemInfo() { } } -export async function askAboutNewJob(): Promise { - const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, `Yes`, `Always`, `No`); - if (chosen === `Yes` || chosen === `Always`) { - if (chosen === `Always`) { - await Configuration.set(`alwaysStartSQLJob`, `new`); - } +export async function askAboutNewJob(startup?: boolean): Promise { + const instance = getInstance(); + const connection = instance.getConnection(); + + if (connection) { + const options = startup ? [`Yes`, `Always`, `No`, `Never`] : [`Yes`, `No`]; + + const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, ...options); + switch (chosen) { + case `Yes`: + case `Always`: + if (chosen === `Always`) { + await Configuration.set(`alwaysStartSQLJob`, `new`); + } - await commands.executeCommand(`vscode-db2i.jobManager.newJob`); - return true; + await commands.executeCommand(`vscode-db2i.jobManager.newJob`); + return true; + + case `Never`: + await Configuration.set(`alwaysStartSQLJob`, `never`); + break; + } } return false; diff --git a/src/connection/manager.ts b/src/connection/manager.ts index 281e3917..baddaa5b 100644 --- a/src/connection/manager.ts +++ b/src/connection/manager.ts @@ -38,7 +38,7 @@ export class SQLJobManager { this.totalJobs += 1; this.jobs.push({ - name: `${name || 'New job'} ${this.totalJobs}`, + name: `${name || 'New job'} (${this.totalJobs})`, job: newJob }); diff --git a/src/views/jobManager/ConfigManager.ts b/src/views/jobManager/ConfigManager.ts index 2c1b5f4c..d71c9324 100644 --- a/src/views/jobManager/ConfigManager.ts +++ b/src/views/jobManager/ConfigManager.ts @@ -1,7 +1,7 @@ import { Disposable, ProgressLocation, ThemeIcon, TreeItem, TreeItemCollapsibleState, commands, window } from "vscode"; import Configuration from "../../configuration"; import { JDBCOptions } from "../../connection/types"; -import { SQLJobItem } from "./jobManagerView"; +import { JobManagerView, SQLJobItem } from "./jobManagerView"; import { JobManager } from "../../config"; import { SQLJob } from "../../connection/sqlJob"; import { editJobUi } from "./editJob"; @@ -42,16 +42,7 @@ export class ConfigManager { const options = this.getConfig(name); if (options) { - await window.withProgress({ location: ProgressLocation.Window }, async (progress) => { - try { - progress.report({ message: `Spinning up SQL job...` }); - await JobManager.newJob(new SQLJob(options), name); - } catch (e) { - window.showErrorMessage(e.message); - } - - this.refresh(); - }); + commands.executeCommand(`vscode-db2i.jobManager.newJob`, options, name); } }), @@ -108,7 +99,8 @@ export class ConfigManager { } static getConfig(name: string): JDBCOptions | undefined { - return this.getSavedConfigs()[name]; + const configs = this.getSavedConfigs(); // Returns a proxy + return Object.assign({}, configs[name]); } private static storeConfig(name: string, options: JDBCOptions) { diff --git a/src/views/jobManager/jobManagerView.ts b/src/views/jobManager/jobManagerView.ts index fb03cbba..25ccbfaf 100644 --- a/src/views/jobManager/jobManagerView.ts +++ b/src/views/jobManager/jobManagerView.ts @@ -3,7 +3,7 @@ import { JobManager } from "../../config"; import { JobInfo } from "../../connection/manager"; import { ServerComponent } from "../../connection/serverComponent"; import { SQLJob, TransactionEndType } from "../../connection/sqlJob"; -import { ServerTraceDest, ServerTraceLevel } from "../../connection/types"; +import { JDBCOptions, ServerTraceDest, ServerTraceLevel } from "../../connection/types"; import { ConfigGroup, ConfigManager } from "./ConfigManager"; import { editJobUi } from "./editJob"; import { displayJobLog } from "./jobLog"; @@ -26,17 +26,18 @@ export class JobManagerView implements TreeDataProvider { ...ConfigManager.initialiseSaveCommands(), - vscode.commands.registerCommand(`vscode-db2i.jobManager.newJob`, async (predefinedJob?: SQLJob, name?: string) => { - await window.withProgress({ location: ProgressLocation.Window }, async (progress) => { - try { - progress.report({ message: `Spinning up SQL job...` }); - await JobManager.newJob(predefinedJob, name); - } catch (e) { - window.showErrorMessage(e.message); - } + vscode.commands.registerCommand(`vscode-db2i.jobManager.newJob`, async (options?: JDBCOptions, name?: string) => { + try { + updateStatusBar({newJob: true}); + await JobManager.newJob( + (options ? new SQLJob(options) : undefined), + name + ); + } catch (e) { + window.showErrorMessage(e.message); + } - this.refresh(); - }); + this.refresh(); }), vscode.commands.registerCommand(`vscode-db2i.jobManager.closeJob`, async (node?: SQLJobItem) => { diff --git a/src/views/jobManager/statusBar.ts b/src/views/jobManager/statusBar.ts index eef440e5..6616dab0 100644 --- a/src/views/jobManager/statusBar.ts +++ b/src/views/jobManager/statusBar.ts @@ -1,20 +1,24 @@ import { MarkdownString, StatusBarAlignment, ThemeColor, languages, window } from "vscode"; import { ServerComponent } from "../../connection/serverComponent"; -import { SQLJobManager } from "../../connection/manager"; import { JobManager } from "../../config"; - -const statusItem = languages.createLanguageStatusItem(`sqlStatus`, {language: `sql`}); +import { getInstance } from "../../base"; const item = window.createStatusBarItem(`sqlJob`, StatusBarAlignment.Left); -export async function updateStatusBar() { - if (ServerComponent.isInstalled()) { +export async function updateStatusBar(options: {newJob?: boolean} = {}) { + const instance = getInstance(); + const connection = instance.getConnection(); + + if (connection && ServerComponent.isInstalled()) { const selected = JobManager.getSelection(); let text; let backgroundColour: ThemeColor|undefined = undefined; let toolTipItems = []; + if (options.newJob) { + text = `$(sync~spin) Spinning up job...`; + } else if (selected) { text = `$(database) ${selected.name}`; @@ -39,11 +43,13 @@ export async function updateStatusBar() { toolTipItems.push(`[Start Job](command:vscode-db2i.jobManager.newJob)`); } - const toolTip = new MarkdownString(toolTipItems.join(`\n\n---\n\n`), true); - toolTip.isTrusted = true; + if (toolTipItems.length > 0) { + const toolTip = new MarkdownString(toolTipItems.join(`\n\n---\n\n`), true); + toolTip.isTrusted = true; + item.tooltip = toolTip; + } item.text = text; - item.tooltip = toolTip; item.backgroundColor = backgroundColour; item.show();