diff --git a/.changeset/shaggy-drinks-develop.md b/.changeset/shaggy-drinks-develop.md new file mode 100644 index 0000000..b59b699 --- /dev/null +++ b/.changeset/shaggy-drinks-develop.md @@ -0,0 +1,5 @@ +--- +"terminal-keeper": patch +--- + +fix: warn if the folder is not opened before using Terminal Keeper. diff --git a/src/commands/generateAsync.ts b/src/commands/generateAsync.ts index 54fb140..59343be 100644 --- a/src/commands/generateAsync.ts +++ b/src/commands/generateAsync.ts @@ -1,11 +1,30 @@ -import { window } from 'vscode'; +import { commands, window } from 'vscode'; import { Configuration } from '../configuration/configuration'; import { configurationTemplate } from '../configuration/template'; -import { constants } from '../utils/constants'; -import { showErrorMessageWithDetail, showTextDocument } from '../utils/utils'; +import { constants, sysCommands } from '../utils/constants'; +import { isWorkspaceOpened, showErrorMessageWithDetail, showTextDocument } from '../utils/utils'; export const generateAsync = async (): Promise => { try { + // Check workspace is opened + if (!isWorkspaceOpened()) { + window + .showInformationMessage( + constants.openWorkspace, + constants.openFolderButton, + constants.openWorkspaceButton + ) + .then(async (selection) => { + if (selection === constants.openFolderButton) { + await commands.executeCommand(sysCommands.openFolder); + } + if (selection === constants.openWorkspaceButton) { + await commands.executeCommand(sysCommands.openWorkspace); + } + }); + return; + } + // Write configuration file const configInstance = Configuration.instance(); const isDefinedSessionFile = await configInstance.isDefinedSessionFile(); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 5025515..63ab4d3 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -12,12 +12,18 @@ export const extCommands = { activeTerminalActivity: 'terminal-keeper.active-terminal-activity' }; +export const sysCommands = { + openFolder: 'workbench.action.files.openFolder', + openWorkspace: 'workbench.action.openWorkspace' +}; + export const constants = { // Common defaultSession: 'default', // Open the configuration file openConfigurationFailed: 'Failed to open the configuration file!', + openWorkspace: 'Please make sure to open a workspace folder before using Terminal Keeper!', // Generate the configuration file generateConfigurationTitle: 'Would you like to generate the configuration?', @@ -66,5 +72,7 @@ export const constants = { noButton: 'No', newSession: 'Create a new session...', viewConfigurationButton: 'View Configuration', + openWorkspaceButton: 'Open Workspace', + openFolderButton: 'Open Folder', viewError: 'View Error' }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5728235..83472be 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -113,3 +113,8 @@ export const showGenerateConfiguration = async (): Promise => { await commands.executeCommand(extCommands.generate); } }; + +export const isWorkspaceOpened = (): boolean => { + // The name of the workspace. undefined when no workspace has been opened. + return workspace.name !== undefined; +};