Skip to content

Commit

Permalink
fix: warn if the folder is not opened before using Terminal Keeper.
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Sep 30, 2024
1 parent 02045c9 commit 05e2741
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-drinks-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

fix: warn if the folder is not opened before using Terminal Keeper.
25 changes: 22 additions & 3 deletions src/commands/generateAsync.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
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();
Expand Down
8 changes: 8 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down Expand Up @@ -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'
};
5 changes: 5 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ export const showGenerateConfiguration = async (): Promise<void> => {
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;
};

0 comments on commit 05e2741

Please sign in to comment.