From a9d421fff7836108e44143656b2c490c4fada0a7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 11 Dec 2019 10:59:33 +0100 Subject: [PATCH] Added markdown_command to project preferences --- CMakeLists.txt | 2 +- src/config.cc | 1 + src/config.h | 1 + src/files.h | 3 ++- src/project.cc | 25 +++++-------------------- src/project.h | 2 -- 6 files changed, 10 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7c20af..0924938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.5.0.4") +set(JUCI_VERSION "1.5.0.5") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/config.cc b/src/config.cc index 0441a19..317e2f1 100644 --- a/src/config.cc +++ b/src/config.cc @@ -203,6 +203,7 @@ void Config::read(const boost::property_tree::ptree &cfg) { project.clear_terminal_on_compile = cfg.get("project.clear_terminal_on_compile"); project.ctags_command = cfg.get("project.ctags_command"); project.python_command = cfg.get("project.python_command"); + project.markdown_command = cfg.get("project.markdown_command"); terminal.history_size = cfg.get("terminal.history_size"); terminal.font = cfg.get("terminal.font"); diff --git a/src/config.h b/src/config.h index 1eb8765..cff6dc1 100644 --- a/src/config.h +++ b/src/config.h @@ -49,6 +49,7 @@ public: bool clear_terminal_on_compile; std::string ctags_command; std::string python_command; + std::string markdown_command; }; class Source { diff --git a/src/files.h b/src/files.h index 141fa06..995182b 100644 --- a/src/files.h +++ b/src/files.h @@ -192,7 +192,8 @@ const std::string default_config_file = R"RAW({ "save_on_compile_or_run": true, "clear_terminal_on_compile": true, "ctags_command": "ctags", - "python_command": "PYTHONUNBUFFERED=1 python" + "python_command": "PYTHONUNBUFFERED=1 python", + "markdown_command": "grip -b" }, "documentation_searches": { "clang": { diff --git a/src/project.cc b/src/project.cc index 4d439ab..aa44bde 100644 --- a/src/project.cc +++ b/src/project.cc @@ -928,28 +928,13 @@ void Project::Clang::recreate_build() { } } -Project::Markdown::~Markdown() { - if(!last_temp_path.empty()) { - boost::filesystem::remove(last_temp_path); - last_temp_path = boost::filesystem::path(); - } -} void Project::Markdown::compile_and_run() { - if(!last_temp_path.empty()) { - boost::filesystem::remove(last_temp_path); - last_temp_path = boost::filesystem::path(); - } - - std::stringstream stdin_stream, stdout_stream; - auto exit_status = Terminal::get().process(stdin_stream, stdout_stream, "command -v grip"); - if(exit_status == 0) { - auto command = "grip -b " + filesystem::escape_argument(filesystem::get_short_path(Notebook::get().get_current_view()->file_path).string()); - Terminal::get().print("Running: " + command + " in a quiet background process\n"); - Terminal::get().async_process(command, "", nullptr, true); - } - else - Terminal::get().print("Warning: install grip to preview Markdown files\n"); + auto command = Config::get().project.markdown_command + ' ' + filesystem::escape_argument(filesystem::get_short_path(Notebook::get().get_current_view()->file_path).string()); + Terminal::get().async_process(command, "", [command](int exit_status) { + if(exit_status == 127) + Terminal::get().async_print("Error: executable not found: " + command + "\n", true); + }, true); } void Project::Python::compile_and_run() { diff --git a/src/project.h b/src/project.h index 0d5c3d0..efa9911 100644 --- a/src/project.h +++ b/src/project.h @@ -119,9 +119,7 @@ namespace Project { class Markdown : public Base { public: Markdown(std::unique_ptr &&build) : Base(std::move(build)) {} - ~Markdown() override; - boost::filesystem::path last_temp_path; void compile_and_run() override; };