diff --git a/extensions/vscode/src/constants.ts b/extensions/vscode/src/constants.ts index 905b180bd..762aa1560 100644 --- a/extensions/vscode/src/constants.ts +++ b/extensions/vscode/src/constants.ts @@ -32,12 +32,20 @@ const configurationsCommands = { Delete: "posit.publisher.configurations.delete", } as const; +const configurationsContexts = { + TreeItem: "posit.publisher.configurations.tree.item", +} as const; + const credentialsCommands = { Add: "posit.publisher.credentials.add", Delete: "posit.publisher.credentials.delete", Refresh: "posit.publisher.credentials.refresh", } as const; +const credentialsContexts = { + Keychain: "posit.publisher.credentials.tree.item.keychain", +}; + const contentRecordsCommands = { Edit: "posit.publisher.contentRecords.edit", Rename: "posit.publisher.contentRecords.rename", @@ -46,6 +54,12 @@ const contentRecordsCommands = { Refresh: "posit.publisher.contentRecords.refresh", } as const; +const contentRecordsContexts = { + ContentRecord: "posit.publisher.contentRecords.tree.item.contentRecord", + PreContentRecord: "posit.publisher.contentRecords.tree.item.precontentRecord", + DeploymentError: "posit.publisher.contentRecords.tree.item.deploymentError", +} as const; + const filesCommands = { Refresh: "posit.publisher.files.refresh", Exclude: "posit.publisher.files.exclude", @@ -79,11 +93,19 @@ const homeViewCommands = { ShowContentLogs: "posit.publisher.homeView.navigateToDeployment.ContentLog", } as const; +const homeViewContexts = { + Initialized: "posit.publisher.homeView.initialized", +}; + const helpAndFeedbackCommands = { OpenFeedback: "posit.publisher.helpAndFeedback.openFeedback", OpenGettingStarted: "posit.publisher.helpAndFeedback.gettingStarted", } as const; +export const LocalState = { + LastSelectionState: "posit.publisher.homeView.lastSelectionState.v2", +}; + export const Commands = { ...baseCommands, Configurations: configurationsCommands, @@ -95,7 +117,14 @@ export const Commands = { RPackages: rPackagesCommands, HomeView: homeViewCommands, HelpAndFeedback: helpAndFeedbackCommands, -} as const; +}; + +export const Contexts = { + Configurations: configurationsContexts, + ContentRecords: contentRecordsContexts, + Credentials: credentialsContexts, + HomeView: homeViewContexts, +}; export const enum Views { Project = "posit.publisher.project", diff --git a/extensions/vscode/src/views/configurations.ts b/extensions/vscode/src/views/configurations.ts index b82f1331c..592dba5ff 100644 --- a/extensions/vscode/src/views/configurations.ts +++ b/extensions/vscode/src/views/configurations.ts @@ -28,7 +28,7 @@ import { ensureSuffix, fileExists, isValidFilename } from "src/utils/files"; import { untitledConfigurationName } from "src/utils/names"; import { newConfig } from "src/multiStepInputs/newConfig"; import { WatcherManager } from "src/watchers"; -import { Commands, Views } from "src/constants"; +import { Commands, Contexts, Views } from "src/constants"; type ConfigurationEventEmitter = EventEmitter< ConfigurationTreeItem | undefined | void @@ -200,7 +200,7 @@ export class ConfigurationsTreeDataProvider } export class ConfigurationTreeItem extends TreeItem { - contextValue = "posit.publisher.configurations.tree.item"; + contextValue = Contexts.Configurations.TreeItem; constructor( public readonly config: Configuration | ConfigurationError, diff --git a/extensions/vscode/src/views/contentRecords.ts b/extensions/vscode/src/views/contentRecords.ts index 64fc83d40..cc1684315 100644 --- a/extensions/vscode/src/views/contentRecords.ts +++ b/extensions/vscode/src/views/contentRecords.ts @@ -32,7 +32,7 @@ import { getSummaryStringFromError } from "src/utils/errors"; import { ensureSuffix } from "src/utils/files"; import { contentRecordNameValidator } from "src/utils/names"; import { WatcherManager } from "src/watchers"; -import { Commands, Views } from "src/constants"; +import { Commands, Contexts, Views } from "src/constants"; type ContentRecordsEventEmitter = EventEmitter< ContentRecordsTreeItem | undefined | void @@ -226,8 +226,7 @@ export class ContentRecordsTreeItem extends TreeItem { } private initializeContentRecord(contentRecord: ContentRecord) { - this.contextValue = - "posit.publisher.contentRecords.tree.item.contentRecord"; + this.contextValue = Contexts.ContentRecords.ContentRecord; if (!contentRecord.deploymentError) { this.tooltip = `ContentRecord file: ${contentRecord.deploymentPath}\n` + @@ -253,8 +252,7 @@ export class ContentRecordsTreeItem extends TreeItem { } private initializePreContentRecord(precontentRecord: PreContentRecord) { - this.contextValue = - "posit.publisher.contentRecords.tree.item.precontentRecord"; + this.contextValue = Contexts.ContentRecords.PreContentRecord; this.tooltip = `Deployment Record file: ${precontentRecord.deploymentPath}\n` + `\n` + @@ -266,8 +264,7 @@ export class ContentRecordsTreeItem extends TreeItem { } private initializeContentRecordError(deploymentError: ContentRecordError) { - this.contextValue = - "posit.publisher.contentRecords.tree.item.deploymentError"; + this.contextValue = Contexts.ContentRecords.DeploymentError; this.tooltip = `Deployment Record file: ${deploymentError.deploymentPath}\n` + `\n` + diff --git a/extensions/vscode/src/views/credentials.ts b/extensions/vscode/src/views/credentials.ts index 4c0eb2dbe..d478ce2ed 100644 --- a/extensions/vscode/src/views/credentials.ts +++ b/extensions/vscode/src/views/credentials.ts @@ -16,7 +16,7 @@ import { useBus } from "src/bus"; import { confirmDelete } from "src/dialogs"; import { getSummaryStringFromError } from "src/utils/errors"; import { newCredential } from "src/multiStepInputs/newCredential"; -import { Commands, Views } from "src/constants"; +import { Commands, Contexts, Views } from "src/constants"; type CredentialEventEmitter = EventEmitter< CredentialsTreeItem | undefined | void @@ -129,6 +129,6 @@ export class CredentialsTreeItem extends TreeItem { super(cred.name); this.iconPath = new ThemeIcon("key"); this.description = `${cred.url}`; - this.contextValue = `posit.publisher.credentials.tree.item.keychain`; + this.contextValue = Contexts.Credentials.Keychain; } } diff --git a/extensions/vscode/src/views/homeView.ts b/extensions/vscode/src/views/homeView.ts index 28267348b..3fac3629f 100644 --- a/extensions/vscode/src/views/homeView.ts +++ b/extensions/vscode/src/views/homeView.ts @@ -65,17 +65,13 @@ import { selectConfig } from "src/multiStepInputs/selectConfig"; import { RPackage, RVersionConfig } from "src/api/types/packages"; import { calculateTitle } from "src/utils/titles"; import { ConfigWatcherManager, WatcherManager } from "src/watchers"; -import { Commands, Views } from "src/constants"; - -const contextIsHomeViewInitialized = "posit.publisher.homeView.initialized"; +import { Commands, Contexts, LocalState, Views } from "src/constants"; enum HomeViewInitialized { initialized = "initialized", uninitialized = "uninitialized", } -const lastSelectionState = "posit.publisher.homeView.lastSelectionState.v2"; - const fileEventDebounce = 200; export class HomeViewProvider implements WebviewViewProvider, Disposable { @@ -244,7 +240,7 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable { private setInitializationContext(context: HomeViewInitialized) { commands.executeCommand( "setContext", - contextIsHomeViewInitialized, + Contexts.HomeView.Initialized, context, ); } @@ -431,7 +427,7 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable { private _getSelectionState(): HomeViewState { const state = this._context.workspaceState.get( - lastSelectionState, + LocalState.LastSelectionState, { deploymentName: undefined, configurationName: undefined, @@ -462,7 +458,10 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable { } private async _saveSelectionState(state: HomeViewState): Promise { - await this._context.workspaceState.update(lastSelectionState, state); + await this._context.workspaceState.update( + LocalState.LastSelectionState, + state, + ); useBus().trigger( "activeContentRecordChanged",