Skip to content

Add "Open with VS Code" option to file/folder context menu #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

quinn-p-mchugh
Copy link
Contributor

@quinn-p-mchugh quinn-p-mchugh commented Nov 2, 2024

This pull request is to satisfy feature request #14 (Add "Open in VS Code" to folder context menu).

New Behavior

  • When the user right-clicks a file or folder in the Obsidian file tree, a new option will be available in the context menu titled "Open with VS Code".
  • Clicking this option will open the selected file/folder in VS Code, based on the CLI command they specified in their plugin settings (Template for executing the "code" command)
  • Opening a file/folder in VS Code using this context menu simply overrides the {{filepath}} and {{folderpath}} variables used in the above setting with the path of the selected file/folder.

Code Changes

  • Added a function called fileMenuHandler to add the new context menu item when the user right-clicks a file/folder.
  • Clicking this menu item will execute the openVSCode function with a new input parameter called fileContextMenuPath (the path of the file/folder that was right-clicked).
  • To achieve the desired functionality, I added an if statement to the openVSCode function to set the filePath and folderPath variables to the fileContextMenuPath variable instead of the path/folder of the currently open file.

Future Work

  • Since this change simply modifies the underlying behavior of the openVSCode function and relies on the same CLI command (Template for executing the "code" command) used by the existing "VSCode" command button, this update might result in some confusion for users looking to achieve different behavior when opening VS Code using the "VSCode" command button v.s. the file/folder context menu item.
  • To address this, it may be beneficial to split the Template for executing the code` setting into two: one that is evoked when clicking the VS Code command button and the other that is evoked when clicking the file/folder context menu item.

@NomarCub
Copy link
Owner

NomarCub commented Nov 5, 2024

Hey @quinn-p-mchugh!
I did some modifications to your code and a bunch of maintenance. Would you please run this new version to see if it works the same on your end? And also take a look at my changes as both a user of the plugin and a developer?

@NomarCub
Copy link
Owner

@quinn-p-mchugh I'll merge this in a week, with some modification to your code and a logo change. If you have anything you want to change you have until then, or you can do it in a new PR later.

@quinn-p-mchugh
Copy link
Contributor Author

quinn-p-mchugh commented Nov 13, 2024

Hi @NomarCub, thanks for your patience here. I just tested the changes in a basic Obsidian vault and everything works great. Please feel free to merge when you get the chance.

Also, thanks for refactoring and fixing the menu item icon. Adding a file input parameter that defaults to the active file makes the code much more readable.

@NomarCub NomarCub merged commit 0134e7b into NomarCub:main Nov 14, 2024
@NomarCub
Copy link
Owner

Just made a release with this in https://github.com/NomarCub/obsidian-open-vscode/releases/tag/1.3.0, thank you for your contribution!

@quinn-p-mchugh
Copy link
Contributor Author

@NomarCub
Wonderful! Thank you for enhancing and merging.

Looking forward to taking advantage of this small but handy feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants