Browse Source

Added project.open_with_default_application to preferences

pipelines/1486128344
eidheim 2 years ago
parent
commit
cc3ecab010
  1. 2
      CMakeLists.txt
  2. 12
      src/config.cpp
  3. 1
      src/config.hpp
  4. 12
      src/notebook.cpp
  5. 4
      src/window.cpp

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(juci) project(juci)
set(JUCI_VERSION "1.8.0") set(JUCI_VERSION "1.8.0.1")
set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

12
src/config.cpp

@ -189,6 +189,14 @@ void Config::read(const JSON &cfg) {
project.cargo_command = project_json.string("cargo_command"); project.cargo_command = project_json.string("cargo_command");
project.python_command = project_json.string("python_command"); project.python_command = project_json.string("python_command");
project.markdown_command = project_json.string("markdown_command"); project.markdown_command = project_json.string("markdown_command");
std::stringstream ss(project_json.string("open_with_default_application"));
std::string str;
project.open_with_default_application.clear();
while(getline(ss, str, ',')) {
while(!str.empty() && str.front() == ' ')
str.erase(str.begin());
project.open_with_default_application.emplace_back(std::move(str));
}
auto terminal_json = cfg.object("terminal"); auto terminal_json = cfg.object("terminal");
terminal.history_size = terminal_json.integer("history_size", JSON::ParseOptions::accept_string); terminal.history_size = terminal_json.integer("history_size", JSON::ParseOptions::accept_string);
@ -347,7 +355,9 @@ std::string Config::default_config() {
"grep_command": "grep", "grep_command": "grep",
"cargo_command": "cargo", "cargo_command": "cargo",
"python_command": "python -u", "python_command": "python -u",
"markdown_command": "grip -b" "markdown_command": "grip -b",
"open_with_default_application_comment": "Comma-separated list of file extensions that should be opened with system default applications",
"open_with_default_application": ".pdf,.png"
}, },
"keybindings": { "keybindings": {
"preferences": "<primary>comma", "preferences": "<primary>comma",

1
src/config.hpp

@ -54,6 +54,7 @@ public:
std::string cargo_command; std::string cargo_command;
std::string python_command; std::string python_command;
std::string markdown_command; std::string markdown_command;
std::vector<boost::filesystem::path> open_with_default_application;
}; };
class Source { class Source {

12
src/notebook.cpp

@ -149,6 +149,18 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
auto file_path = filesystem::get_normal_path(file_path_); auto file_path = filesystem::get_normal_path(file_path_);
if(std::any_of(Config::get().project.open_with_default_application.begin(), Config::get().project.open_with_default_application.end(), [&file_path](const boost::filesystem::path &extension) {
return extension == file_path.extension();
})) {
#ifdef __APPLE__
Terminal::get().async_process("open " + filesystem::escape_argument(file_path.string()), "", nullptr, true);
#else
Terminal::get().async_process("xdg-open " + filesystem::escape_argument(file_path.string()), "", nullptr, true);
#endif
Directories::get().select(file_path);
return true;
}
if((position == Position::right || position == Position::split) && !split) if((position == Position::right || position == Position::split) && !split)
toggle_split(); toggle_split();

4
src/window.cpp

@ -1017,8 +1017,8 @@ void Window::set_menu_actions() {
SelectionDialog::get()->on_select = [files = std::move(files)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [files = std::move(files)](unsigned int index, const std::string &text, bool hide_window) {
if(Notebook::get().open(files[index])) { if(Notebook::get().open(files[index])) {
auto view = Notebook::get().get_current_view(); if(auto view = Notebook::get().get_current_view())
view->hide_tooltips(); view->hide_tooltips();
} }
}; };

Loading…
Cancel
Save