Skip to content

Commit

Permalink
v1.10.0 - Add warnings to commands that require a
Browse files Browse the repository at this point in the history
workspace to be open in the event that
no workspace is open.
  • Loading branch information
robole committed Dec 11, 2023
1 parent a19059c commit 978053f
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"detail": "vsce package ."
},
{
"label": "Run webpack on startup",
"label": "Run bundler on startup",
"type": "shell",
"command": "export NODE_OPTIONS=--openssl-legacy-provider;npm run dev",
"command": "npm run dev",
"presentation": {
"reveal": "always",
"panel": "new"
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/-0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.10.0] - 2023-12-12

### Changed

- For `File Bunny: Open File`, `File Bunny: Open File to the Left`, `File Bunny: Open File to the Right`, `File Bunny: Open File Above`, `File Bunny: Open File Below`, `File Bunny: Create New File`, `File Bunny: Move File`, `File Bunny: Duplicate File`, `File Bunny: Delete File`, `File Bunny: Move Active File`, `File Bunny: Duplicate Active File`, `File Bunny: Open Workspace Folder in External Default App`, `File Bunny: Open Folder in External Default App`, `File Bunny: Create New Folder`, `File Bunny: Duplicate Folder`, `File Bunny: Delete Folder` : Give a warning message when no workspace is open because no action will take place. Can consider a different approach for some of these commands in future.
- For `File Bunny: Delete Active File` and `File Bunny: Delete File`: Close the `TextEditor` once the file is deleted.
- Change `MultiStepPicker` and all children to dispose of all disposables when closed. Oddly, when no workspace is open the disposal needs to be done explicitly. When a workspace is open, the `onDidHide` event is taking care of it.

## [1.9.2] - 2023-12-11

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ The following commands can be run from the Command Palette (`Ctrl+Shift+P`). The

### File actions

1. `File Bunny: Open File`: Choose a file to open from the current workspace.
1.
: Choose a file to open from the current workspace.
1. `File Bunny: Open File to the Right`: Choose a file to open from the current workspace, and split it to the right of the active editor.
1. `File Bunny: Open File to the Left`: Choose a file to open from the current workspace, and split it to the left of the active editor.
1. `File Bunny: Open File Above`: Choose a file to open from the current workspace, and split it above the active editor.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"description": "Perform file actions quickly with keyboard-driven file selection. 🐰⌨️",
"icon": "img/logo.png",
"version": "1.9.2",
"version": "1.10.0",
"engines": {
"vscode": "^1.46.0",
"node": ">=12"
Expand Down
10 changes: 9 additions & 1 deletion src/duplicateActiveFilePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class DuplicateActiveFilePicker extends MultiStepPicker {
return;
}

if (this.rootFolder === undefined) {
vscode.window.showWarningMessage(
"You cannot duplicate a file if a workspace is not open."
);
this.close();
return;
}

this.picker.show();

this.picker.busy = true;
Expand Down Expand Up @@ -86,7 +94,7 @@ class DuplicateActiveFilePicker extends MultiStepPicker {

await this.duplicateFile();

this.picker.hide();
this.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/duplicateFilePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class DuplicateFilePicker extends MultiStepPicker {
this.steps[2].value = this.picker.value;

await this.duplicateFile();
this.picker.hide();
this.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/duplicateFolderPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DuplicateFolderPicker extends MultiStepPicker {
vscode.window.showErrorMessage(err.message);
}

this.picker.hide();
this.close();
}
}

Expand Down
49 changes: 44 additions & 5 deletions src/fileAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// eslint-disable-next-line import/no-unresolved, node/no-missing-require
const vscode = require("vscode");
const nodePath = require("path");

const configuration = require("./configuration");
const NewFilePicker = require("./newFilePicker");
const DuplicateFilePicker = require("./duplicateFilePicker");
Expand All @@ -13,6 +14,9 @@ const util = require("./util");

async function createFile() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot create a file if a workspace is not open."
);
return;
}

Expand All @@ -22,6 +26,9 @@ async function createFile() {

async function openFile() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot open a file if a workspace is not open."
);
return;
}

Expand Down Expand Up @@ -66,6 +73,9 @@ async function openActiveFileExternal() {

async function openFileAbove() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot open a file if a workspace is not open."
);
return;
}

Expand All @@ -82,6 +92,9 @@ async function openFileAbove() {

async function openFileBelow() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot open a file if a workspace is not open."
);
return;
}

Expand All @@ -98,6 +111,9 @@ async function openFileBelow() {

async function openFileToRight() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot open a file if a workspace is not open."
);
return;
}

Expand All @@ -114,6 +130,9 @@ async function openFileToRight() {

async function openFileToLeft() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot open a file if a workspace is not open."
);
return;
}

Expand Down Expand Up @@ -165,17 +184,26 @@ async function moveActiveFile() {

let activeDocUri = vscode.window.activeTextEditor.document.uri;
let activeDocFileName = nodePath.basename(activeDocUri.path);
let workspaceFolderPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
let absoluteExcludes = configuration.getAbsoluteExcludes(workspaceFolderPath);

if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot move an active file if a workspace is not open."
);
return;
}

let startingLocation = vscode.workspace.workspaceFolders[0].uri.fsPath;
let absoluteExcludes = configuration.getAbsoluteExcludes(startingLocation);
let topFolderDescription = "Workspace Root";

let pickerItems = await globPicker.getFilesRecursivelyAsPickerItems(
workspaceFolderPath,
startingLocation,
{
showFiles: false,
showFolders: true,
excludes: absoluteExcludes,
includeTopFolder: true,
topFolderDescription: "Workspace Root",
topFolderDescription,
}
);

Expand All @@ -187,7 +215,7 @@ async function moveActiveFile() {

if (selectedFolder !== undefined) {
let newUri = vscode.Uri.file(
nodePath.join(workspaceFolderPath, selectedFolder.name, activeDocFileName)
nodePath.join(startingLocation, selectedFolder.name, activeDocFileName)
);

let exists = await fileSystem.exists(newUri);
Expand Down Expand Up @@ -256,13 +284,17 @@ async function deleteActiveFile() {

let { uri } = vscode.window.activeTextEditor.document;
await vscode.workspace.fs.delete(uri, { useTrash: true });
await util.closeTextEditor(uri);

// give focus to next editor
await vscode.commands.executeCommand("workbench.action.nextEditorInGroup");
}

async function duplicateFile() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot duplicate a file if a workspace is not open."
);
return;
}

Expand All @@ -272,6 +304,9 @@ async function duplicateFile() {

async function moveFile() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot move a file if a workspace is not open."
);
return;
}

Expand All @@ -281,6 +316,9 @@ async function moveFile() {

async function deleteFile() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"You cannot delete a file if a workspace is not open."
);
return;
}

Expand Down Expand Up @@ -308,6 +346,7 @@ async function deleteFile() {
);

await vscode.workspace.fs.delete(selectedFileUri, { useTrash: true });
await util.closeTextEditor(selectedFileUri);

// give focus to next editor
await vscode.commands.executeCommand("workbench.action.nextEditorInGroup");
Expand Down
28 changes: 26 additions & 2 deletions src/folderAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const vscode = require("vscode");
const homeFolder = require("os").homedir();
const configuration = require("./configuration");
const util = require("./util");
const Browser = require("./browser");
const globPicker = require("./globPicker");
const NewFolderPicker = require("./newFolderPicker");
Expand Down Expand Up @@ -61,7 +62,10 @@ async function getStartingLocation() {
}

async function createFolder() {
if (vscode.workspace.workspaceFolders === undefined) {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"Cannot create a new folder. There is no workspace open."
);
return;
}

Expand All @@ -70,7 +74,10 @@ async function createFolder() {
}

async function duplicateFolder() {
if (vscode.workspace.workspaceFolders === undefined) {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"Cannot duplicate a folder. There is no workspace open."
);
return;
}

Expand All @@ -79,6 +86,13 @@ async function duplicateFolder() {
}

async function deleteFolder() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage(
"Cannot delete a folder. There is no workspace open."
);
return;
}

if (vscode.workspace.workspaceFolders) {
let selectedFolder = await selectWorkspaceFolder(false, "Delete Folder");

Expand All @@ -94,6 +108,11 @@ async function deleteFolder() {
}

async function openWorkspaceFolderExternal() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage("There is no workspace open.");
return;
}

if (vscode.workspace.workspaceFolders !== undefined) {
let workspaceFolder = vscode.workspace.workspaceFolders[0];

Expand All @@ -106,6 +125,11 @@ async function openWorkspaceFolderExternal() {
}

async function openFolderExternal() {
if (util.isWorkspaceOpen() === false) {
vscode.window.showWarningMessage("There is no workspace open.");
return;
}

let selectedFolder = await selectWorkspaceFolder(
false,
"Open Workspace Folder in External Default App"
Expand Down
2 changes: 1 addition & 1 deletion src/moveFilePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MoveFilePicker extends MultiStepPicker {
this.steps[1].value = selection;

await this.moveFile();
this.picker.hide();
this.close();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/multiStepPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MultiStepPicker {
this.currentStepNum += 1;
this.setCurrentStep(this.steps[this.currentStepNum - 1]);
} else {
this.picker.hide();
this.close();
this.running = false;
}
}
Expand All @@ -116,6 +116,11 @@ class MultiStepPicker {
});
this.picker.dispose();
}

close() {
this.dispose();
this.picker.hide();
}
}

module.exports = MultiStepPicker;
2 changes: 1 addition & 1 deletion src/newFilePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class NewFilePicker extends MultiStepPicker {
vscode.window.showErrorMessage(err);
}

this.picker.hide();
this.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/newFolderPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NewFolderPicker extends MultiStepPicker {
return;
}

this.picker.hide();
this.close();
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ function hasActiveTextEditor() {
return !(vscode.window.activeTextEditor === undefined);
}

async function closeTextEditor(filepath) {
const tabs = vscode.window.tabGroups.all.map((tg) => tg.tabs).flat();
const index = tabs.findIndex(
(tab) =>
tab.input instanceof vscode.TabInputText &&
tab.input.uri.path === filepath.path
);
if (index !== -1) {
await vscode.window.tabGroups.close(tabs[index]);
}
}

function isRootFolder(p) {
const parentPath = nodePath.join(p, "../");
if (p === parentPath || parentPath === "./" || /\w:\/$/.test(p)) {
Expand Down Expand Up @@ -93,6 +105,7 @@ function createUniqueFileName(fileName, index) {
module.exports = {
isWorkspaceOpen,
isRootFolder,
closeTextEditor,
hasActiveTextEditor,
enableKeyBindings,
disableKeyBindings,
Expand Down
1 change: 1 addition & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
1. Add more tests (refactor).
1. `File Bunny: New Project from Template`?
1. Add multi-root workspace support?
1. `File Bunny: Move Active File`, `File Bunny: Duplicate Active File`, and `File Bunny: Delete File` perform no action when a workspace is not open because it is too slow to index all folders of system. It'd be better to have the dialog version of file picker for this.

## Further ideas

Expand Down

0 comments on commit 978053f

Please sign in to comment.