Skip to content

Commit

Permalink
feat: open in os file explorer option in tauri
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Oct 27, 2023
1 parent aa2301b commit 06da479
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

/*global Phoenix*/

/**
* Initializes the default brackets menu items.
*/
Expand Down Expand Up @@ -55,7 +57,8 @@ define(function (require, exports, module) {
if (err) {
return err;
}
_setContextMenuItemsVisible(isPresent, [Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE]);
_setContextMenuItemsVisible(isPresent, [Commands.FILE_RENAME,
Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS]);
});
}
}
Expand Down Expand Up @@ -287,6 +290,9 @@ define(function (require, exports, module) {
project_cmenu.addMenuItem(Commands.CMD_REPLACE_IN_SUBTREE);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.FILE_REFRESH);
if(Phoenix.browser.isTauri){
project_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
}

var editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
// editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
Expand Down
16 changes: 15 additions & 1 deletion src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,15 @@ define(function (require, exports, module) {
});
}

/** Show the selected sidebar (tree or workingset) item in Finder/Explorer */
function handleShowInOS() {
var entry = ProjectManager.getSelectedItem();
if (entry) {
brackets.app.openPathInFileBrowser(entry.fullPath)
.catch(err=>console.error("Error showing '" + entry.fullPath + "' in OS folder:", err));
}
}

/**
* Does a full reload of the browser window
* @param {string} href The url to reload into the window
Expand Down Expand Up @@ -1907,9 +1916,13 @@ define(function (require, exports, module) {
exports._parseDecoratedPath = _parseDecoratedPath;

// Set some command strings
var quitString = Strings.CMD_QUIT;
var quitString = Strings.CMD_QUIT,
showInOS = Strings.CMD_SHOW_IN_OS;
if (brackets.platform === "win") {
quitString = Strings.CMD_EXIT;
showInOS = Strings.CMD_SHOW_IN_EXPLORER;
} else if (brackets.platform === "mac") {
showInOS = Strings.CMD_SHOW_IN_FINDER;
}

// Define public API
Expand Down Expand Up @@ -1948,6 +1961,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_PREV_DOC_LIST_ORDER, Commands.NAVIGATE_PREV_DOC_LIST_ORDER, handleGoPrevDocListOrder);

// Special Commands
CommandManager.register(showInOS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS);
CommandManager.register(Strings.CMD_NEW_BRACKETS_WINDOW, Commands.FILE_NEW_WINDOW, handleFileNewWindow);
CommandManager.register(quitString, Commands.FILE_QUIT, handleFileQuit);
CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree);
Expand Down
20 changes: 15 additions & 5 deletions src/extensions/default/DebugCommands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define(function (require, exports, module) {
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
Locales = brackets.getModule("nls/strings"),
ProjectManager = brackets.getModule("project/ProjectManager"),
ExtensionLoader = brackets.getModule("utils/ExtensionLoader"),
extensionDevelopment = require("extensionDevelopment"),
PerfDialogTemplate = require("text!htmlContent/perf-dialog.html"),
LanguageDialogTemplate = require("text!htmlContent/language-dialog.html");
Expand Down Expand Up @@ -72,6 +73,7 @@ define(function (require, exports, module) {
DEBUG_ENABLE_LOGGING = "debug.enableLogging",
DEBUG_LIVE_PREVIEW_LOGGING = "debug.livePreviewLogging",
DEBUG_OPEN_VFS = "debug.openVFS",
DEBUG_OPEN_EXTENSION_FOLDER = "debug.openExtensionFolders",
DEBUG_OPEN_VIRTUAL_SERVER = "debug.openVirtualServer",
DEBUG_OPEN_PREFERENCES_IN_SPLIT_VIEW = "debug.openPrefsInSplitView";

Expand Down Expand Up @@ -708,6 +710,10 @@ define(function (require, exports, module) {
ProjectManager.openProject("/");
}

function _openExtensionsFolder() {
Phoenix.app.openPathInFileBrowser(ExtensionLoader.getUserExtensionPath());
}

function _openVirtualServer() {
const virtualServingURL = Phoenix.VFS.getVirtualServingURLForPath("/");
if(!virtualServingURL) {
Expand Down Expand Up @@ -745,6 +751,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_ENABLE_LOGGING, DEBUG_ENABLE_LOGGING, _handleLogging);
CommandManager.register(Strings.CMD_ENABLE_LIVE_PREVIEW_LOGS, DEBUG_LIVE_PREVIEW_LOGGING, _handleLivePreviewLogging);
CommandManager.register(Strings.CMD_OPEN_VFS, DEBUG_OPEN_VFS, _openVFS);
CommandManager.register(Strings.CMD_OPEN_EXTENSIONS_FOLDER, DEBUG_OPEN_EXTENSION_FOLDER, _openExtensionsFolder);
CommandManager.register(Strings.CMD_OPEN_VIRTUAL_SERVER, DEBUG_OPEN_VIRTUAL_SERVER, _openVirtualServer);

CommandManager.register(Strings.CMD_OPEN_PREFERENCES, DEBUG_OPEN_PREFERENCES_IN_SPLIT_VIEW, handleOpenPrefsInSplitView);
Expand All @@ -767,17 +774,20 @@ define(function (require, exports, module) {
debugMenu.addMenuItem(DEBUG_LIVE_PREVIEW_LOGGING);
debugMenu.addMenuDivider();
debugMenu.addMenuItem(DEBUG_OPEN_VFS);
debugMenu.addMenuItem(DEBUG_OPEN_EXTENSION_FOLDER, undefined, undefined, undefined, {
hideWhenCommandDisabled: true
});
debugMenu.addMenuItem(DEBUG_OPEN_VIRTUAL_SERVER, undefined, undefined, undefined, {
hideWhenCommandDisabled: true
});

CommandManager.get(DEBUG_UNLOAD_CURRENT_EXTENSION)
.setEnabled(extensionDevelopment.isProjectLoadedAsExtension());
if(window.__TAURI__) {
// in tauri, virtual server doesnt exist, extensions are served by tauri asset urls.
CommandManager.get(DEBUG_OPEN_VIRTUAL_SERVER)
.setEnabled(false);
}
CommandManager.get(DEBUG_OPEN_EXTENSION_FOLDER)
.setEnabled(Phoenix.browser.isTauri); // only show in tauri
CommandManager.get(DEBUG_OPEN_VIRTUAL_SERVER)
.setEnabled(!Phoenix.browser.isTauri); // don't show in tauri as there is no virtual server in tauri

_updateLogToConsoleMenuItemChecked();

const helpMenu = Menus.getMenu(Menus.AppMenuBar.HELP_MENU);
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ define({

// Debug menu commands
"CMD_OPEN_VFS": "Open Virtual File System",
"CMD_OPEN_EXTENSIONS_FOLDER": "Open Extensions Folder\u2026",
"CMD_OPEN_VIRTUAL_SERVER": "Open Virtual Server",

// Help menu commands
Expand Down
20 changes: 20 additions & 0 deletions src/phoenix/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ Phoenix.app = {
}
return window.document.title;
},
openPathInFileBrowser: function (fullVFSPath){
return new Promise((resolve, reject)=>{
if(!window.__TAURI__ ||
!fullVFSPath.startsWith(Phoenix.VFS.getTauriDir())) {
reject("openPathInFileBrowser is only currently supported in Native builds for tauri paths!");
return;
}
if(fullVFSPath.toLowerCase().startsWith("http://")
|| fullVFSPath.toLowerCase().startsWith("https://")
|| fullVFSPath.toLowerCase().startsWith("file://")) {
reject("Please use openPathInFileBrowser API to open URLs");
return;
}
const platformPath = Phoenix.fs.getTauriPlatformPath(fullVFSPath);
window.__TAURI__.tauri
.invoke('show_in_folder', {path: platformPath})
.then(resolve)
.catch(reject);
});
},
openURLInDefaultBrowser: function (url){
return new Promise((resolve, reject)=>{
if(!window.__TAURI__) {
Expand Down

0 comments on commit 06da479

Please sign in to comment.