Browse Source

Use system::openFolder() for certain menu items.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
6886360c3b
4 changed files with 54 additions and 12 deletions
  1. +1
    -0
      include/system.hpp
  2. +25
    -4
      src/app/ModuleWidget.cpp
  3. +14
    -6
      src/app/Toolbar.cpp
  4. +14
    -2
      src/system.cpp

+ 1
- 0
include/system.hpp View File

@@ -36,6 +36,7 @@ Shell injection is possible, so make sure the URL is trusted or hard coded.
May block, so open in a new thread.
*/
void openBrowser(const std::string &url);
void openFolder(const std::string &path);


} // namespace system


+ 25
- 4
src/app/ModuleWidget.cpp View File

@@ -29,6 +29,16 @@ struct ModuleUrlItem : ui::MenuItem {
}
};


struct ModuleFolderItem : ui::MenuItem {
std::string path;
void onAction(const event::Action &e) override {
std::thread t(system::openFolder, path);
t.detach();
}
};


struct ModulePluginItem : ui::MenuItem {
plugin::Plugin *plugin;
ui::Menu *createChildMenu() override {
@@ -80,11 +90,10 @@ struct ModulePluginItem : ui::MenuItem {
menu->addChild(donateItem);
}

// TODO open folder location with file explorer instead of browser
if (!plugin->path.empty()) {
ModuleUrlItem *pathItem = new ModuleUrlItem;
pathItem->text = "Open folder";
pathItem->url = plugin->path;
ModuleFolderItem *pathItem = new ModuleFolderItem;
pathItem->text = "Open plugin folder";
pathItem->path = plugin->path;
menu->addChild(pathItem);
}

@@ -92,6 +101,7 @@ struct ModulePluginItem : ui::MenuItem {
}
};


struct ModuleDisconnectItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -99,6 +109,7 @@ struct ModuleDisconnectItem : ui::MenuItem {
}
};


struct ModuleResetItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -106,6 +117,7 @@ struct ModuleResetItem : ui::MenuItem {
}
};


struct ModuleRandomizeItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -113,6 +125,7 @@ struct ModuleRandomizeItem : ui::MenuItem {
}
};


struct ModuleCopyItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -120,6 +133,7 @@ struct ModuleCopyItem : ui::MenuItem {
}
};


struct ModulePasteItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -127,6 +141,7 @@ struct ModulePasteItem : ui::MenuItem {
}
};


struct ModuleSaveItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -134,6 +149,7 @@ struct ModuleSaveItem : ui::MenuItem {
}
};


struct ModuleLoadItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -141,6 +157,7 @@ struct ModuleLoadItem : ui::MenuItem {
}
};


struct ModulePresetItem : ui::MenuItem {
ModuleWidget *moduleWidget;
std::string presetPath;
@@ -149,6 +166,7 @@ struct ModulePresetItem : ui::MenuItem {
}
};


struct ModuleListPresetsItem : ui::MenuItem {
ModuleWidget *moduleWidget;
ui::Menu *createChildMenu() override {
@@ -167,6 +185,7 @@ struct ModuleListPresetsItem : ui::MenuItem {
}
};


struct ModuleCloneItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -174,6 +193,7 @@ struct ModuleCloneItem : ui::MenuItem {
}
};


struct ModuleBypassItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
@@ -181,6 +201,7 @@ struct ModuleBypassItem : ui::MenuItem {
}
};


struct ModuleDeleteItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {


+ 14
- 6
src/app/Toolbar.cpp View File

@@ -577,9 +577,7 @@ struct PluginsButton : MenuButton {

struct ManualItem : ui::MenuItem {
void onAction(const event::Action &e) override {
std::thread t([&]() {
system::openBrowser("https://vcvrack.com/manual/");
});
std::thread t(system::openBrowser, "https://vcvrack.com/manual/");
t.detach();
}
};
@@ -587,9 +585,7 @@ struct ManualItem : ui::MenuItem {

struct WebsiteItem : ui::MenuItem {
void onAction(const event::Action &e) override {
std::thread t([&]() {
system::openBrowser("https://vcvrack.com/");
});
std::thread t(system::openBrowser, "https://vcvrack.com/");
t.detach();
}
};
@@ -602,6 +598,14 @@ struct CheckVersionItem : ui::MenuItem {
};


struct UserFolderItem : ui::MenuItem {
void onAction(const event::Action &e) override {
std::thread t(system::openFolder, asset::user(""));
t.detach();
}
};


struct HelpButton : MenuButton {
void onAction(const event::Action &e) override {
ui::Menu *menu = createMenu();
@@ -621,6 +625,10 @@ struct HelpButton : MenuButton {
checkVersionItem->text = "Check version on launch";
checkVersionItem->rightText = CHECKMARK(settings.checkVersion);
menu->addChild(checkVersionItem);

UserFolderItem *folderItem = new UserFolderItem;
folderItem->text = "Open user folder";
menu->addChild(folderItem);
}
};



+ 14
- 2
src/system.cpp View File

@@ -9,6 +9,7 @@
#include <pthread.h>
#include <sched.h>
#include <execinfo.h> // for backtrace and backtrace_symbols
#include <unistd.h> // for execl
#endif

#if defined ARCH_WIN
@@ -150,11 +151,11 @@ std::string getStackTrace() {

void openBrowser(const std::string &url) {
#if defined ARCH_LIN
std::string command = "xdg-open " + url;
std::string command = "xdg-open \"" + url + "\"";
(void) std::system(command.c_str());
#endif
#if defined ARCH_MAC
std::string command = "open " + url;
std::string command = "open \"" + url + "\"";
std::system(command.c_str());
#endif
#if defined ARCH_WIN
@@ -162,6 +163,17 @@ void openBrowser(const std::string &url) {
#endif
}

void openFolder(const std::string &path) {
#if defined ARCH_LIN
std::string command = "xdg-open \"" + path + "\"";
(void) std::system(command.c_str());
#endif
#if defined ARCH_WIN
ShellExecute(NULL, "explorer", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
#endif
}



} // namespace system
} // namespace rack

Loading…
Cancel
Save