diff --git a/CMakeLists.txt b/CMakeLists.txt index 6229322..da710eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,17 +4,10 @@ set(project_name juci) set(module juci_to_python_api) #### TODO WINDOWS SUPPORT #### -set(juci_config_folder "$ENV{HOME}/.juci") set(bin_install_path "/usr/local/bin") set(lib_install_path "/usr/local/lib/python2.7/dist-packages/") ##### project (${project_name}) -add_subdirectory("src") - -install( - DIRECTORY "config" "plugins" - DESTINATION ${juci_config_folder} - USE_SOURCE_PERMISSIONS) -install(CODE "FILE(MAKE_DIRECTORY ${juci_config_filder}/log)") +add_subdirectory("src") \ No newline at end of file diff --git a/config/config.json b/config/config.json deleted file mode 100644 index 0c85f6d..0000000 --- a/config/config.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "source": { - "colors": { - "text_color": "black", - "string": "#CC0000", - "namespace_ref": "#990099", - "type": "#0066FF", - "keyword": "blue", - "comment": "grey", - "own": "pink", - "diagnostic_warning": "orange", - "diagnostic_error": "red" - }, - "syntax": { - "43": "type", - "46": "namespace_ref", - "109": "string", - "702": "keyword", - "703": "own", - "705": "comment" - }, - "extensions": [ - "c", - "cc", - "cpp", - "cxx", - "c++", - "h", - "hh", - "hpp", - "hxx", - "h++" - ], - "visual": { - "background": "white", - "background_selected": "blue", - "background_tooltips": "yellow", - "font": "Monospace", - "show_line_numbers": 1, - "highlight_current_line": 1 - }, - "tab_size": 2, - "tab_char": "" - }, - "keybindings": { - "new_file": "n", - "open_folder": "o", - "open_file": "o", - "save": "s", - "save_as": "s", - "quit": "q", - "split_window": "s", - "close_tab": "w", - "edit_copy": "c", - "edit_cut": "x", - "edit_paste": "v", - "edit_undo": "z", - "edit_redo": "z", - "edit_find": "f", - "source_goto_declaration": "d", - "source_goto_method": "m", - "source_rename": "r", - "compile_and_run": "Return", - "compile": "Return" - }, - "directoryfilter": { - "ignore": [ - "cmake", - "#", - "~", - ".idea", - ".so", - "in-lowercase.pls" - ], - "exceptions": [ - "cmakelists.txt", - "in-lowercase.pls" - ] - }, - "project": { - "run_commands": [ - "./.build/" - ], - "compile_commands": [ - "rm -rf ./.build", - "mkdir ./.build", - "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.", - "cd ./.build/; make", - "cp ./.build/compile_commands.json compile_commands.json" - ] - }, - "example": { - "key": "value", - "key2": [ - "val1", - "val2", - 3 - ], - "key3": "value" - } -} diff --git a/config/menu.xml b/config/menu.xml deleted file mode 100644 index d93305f..0000000 --- a/config/menu.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/plugins.py b/config/plugins.py deleted file mode 100644 index e19fff9..0000000 --- a/config/plugins.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/python -import juci_to_python_api as juci -import glob - -def loadplugins(): - plugin_files = glob.glob("../plugins/*.py") - for current_file in plugin_files: - juci.initPlugin(current_file) -loadplugins() - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79323c8..54c9549 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,6 +119,5 @@ if(${validation}) RUNTIME DESTINATION ${bin_install_path} LIBRARY DESTINATION ${lib_install_path} ) - endif(${validation}) diff --git a/src/config.cc b/src/config.cc index b71cbf5..8671110 100644 --- a/src/config.cc +++ b/src/config.cc @@ -3,24 +3,40 @@ #include "logging.h" #include #include +#include #include - +#include "files.h" MainConfig::MainConfig() { - INFO("Reading config file"); - boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg_); - INFO("Config file read"); + find_or_create_config_files(); + boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg); GenerateSource(); GenerateKeybindings(); GenerateDirectoryFilter(); GenerateTerminalCommands(); } +void MainConfig::find_or_create_config_files() { + std::vector files = {"config.json", "menu.xml", "plugins.py"}; + boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir())); + for (auto &file : files) { + auto path = boost::filesystem::path(Singleton::config_dir() + file); + if (!boost::filesystem::is_regular_file(path)) { + std::ofstream output; + output.open(path.string()); + if (file == "config.json") output << configjson; + if (file == "plugins.py") output << pluginspy; + if (file == "menu.xml") output << menuxml; + output.close(); + } + } +} + void MainConfig::GenerateSource() { auto source_cfg=Singleton::Config::source(); DEBUG("Fetching source cfg"); // boost::property_tree::ptree - auto source_json = cfg_.get_child("source"); + auto source_json = cfg.get_child("source"); auto syntax_json = source_json.get_child("syntax"); auto colors_json = source_json.get_child("colors"); auto extensions_json = source_json.get_child("extensions"); @@ -63,7 +79,7 @@ void MainConfig::GenerateSource() { void MainConfig::GenerateTerminalCommands() { auto terminal_cfg=Singleton::Config::terminal(); - boost::property_tree::ptree source_json = cfg_.get_child("project"); + boost::property_tree::ptree source_json = cfg.get_child("project"); boost::property_tree::ptree compile_commands_json = source_json.get_child("compile_commands"); boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands"); for (auto &i : compile_commands_json) { @@ -87,7 +103,7 @@ void MainConfig::GenerateKeybindings() { while (getline(input, line)) menu->ui += line; } - boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); + boost::property_tree::ptree keys_json = cfg.get_child("keybindings"); for (auto &i : keys_json) { auto key=i.second.get_value(); menu->key_map[i.first] = key; @@ -98,7 +114,7 @@ void MainConfig::GenerateKeybindings() { void MainConfig::GenerateDirectoryFilter() { auto dir_cfg=Singleton::Config::directories(); DEBUG("Fetching directory filter"); - boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter"); + boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); for ( auto &i : except_json ) diff --git a/src/config.h b/src/config.h index 9729467..9f97a90 100644 --- a/src/config.h +++ b/src/config.h @@ -6,13 +6,14 @@ class MainConfig { public: MainConfig(); + void find_or_create_config_files(); void PrintMenu(); void GenerateSource(); void GenerateKeybindings(); void GenerateDirectoryFilter(); void GenerateTerminalCommands(); private: - boost::property_tree::ptree cfg_; - boost::property_tree::ptree key_tree_; + boost::property_tree::ptree cfg; + boost::property_tree::ptree key_tree; }; #endif diff --git a/src/files.h b/src/files.h new file mode 100644 index 0000000..dde0b17 --- /dev/null +++ b/src/files.h @@ -0,0 +1,157 @@ +#include +const std::string configjson = +"{\n" +" \"source\": {\n" +" \"colors\": {\n" +" \"text_color\": \"black\",\n" +" \"string\": \"#CC0000\",\n" +" \"namespace_ref\": \"#990099\",\n" +" \"type\": \"#0066FF\",\n" +" \"keyword\": \"blue\",\n" +" \"comment\": \"grey\",\n" +" \"own\": \"pink\",\n" +" \"diagnostic_warning\": \"orange\",\n" +" \"diagnostic_error\": \"red\"\n" +" },\n" +" \"syntax\": {\n" +" \"43\": \"type\",\n" +" \"46\": \"namespace_ref\",\n" +" \"109\": \"string\",\n" +" \"702\": \"keyword\",\n" +" \"703\": \"own\",\n" +" \"705\": \"comment\"\n" +" },\n" +" \"extensions\": [\n" +" \"c\",\n" +" \"cc\",\n" +" \"cpp\",\n" +" \"cxx\",\n" +" \"c++\",\n" +" \"h\",\n" +" \"hh\",\n" +" \"hpp\",\n" +" \"hxx\",\n" +" \"h++\"\n" +" ],\n" +" \"visual\": {\n" +" \"background\": \"white\",\n" +" \"background_selected\": \"blue\",\n" +" \"background_tooltips\": \"yellow\",\n" +" \"font\": \"Monospace\",\n" +" \"show_line_numbers\": 1,\n" +" \"highlight_current_line\": 1\n" +" },\n" +" \"tab_size\": 2,\n" +" \"tab_char\": \"\"\n" +" },\n" +" \"keybindings\": {\n" +" \"new_file\": \"n\",\n" +" \"open_folder\": \"o\",\n" +" \"open_file\": \"o\",\n" +" \"save\": \"s\",\n" +" \"save_as\": \"s\",\n" +" \"quit\": \"q\",\n" +" \"split_window\": \"s\",\n" +" \"close_tab\": \"w\",\n" +" \"edit_copy\": \"c\",\n" +" \"edit_cut\": \"x\",\n" +" \"edit_paste\": \"v\",\n" +" \"edit_undo\": \"z\",\n" +" \"edit_redo\": \"z\",\n" +" \"edit_find\": \"f\",\n" +" \"source_goto_declaration\": \"d\",\n" +" \"source_goto_method\": \"m\",\n" +" \"source_rename\": \"r\",\n" +" \"compile_and_run\": \"Return\",\n" +" \"compile\": \"Return\"\n" +" },\n" +" \"directoryfilter\": {\n" +" \"ignore\": [\n" +" \"cmake\",\n" +" \"#\",\n" +" \"~\",\n" +" \".idea\",\n" +" \".so\",\n" +" \"in-lowercase.pls\"\n" +" ],\n" +" \"exceptions\": [\n" +" \"cmakelists.txt\",\n" +" \"in-lowercase.pls\"\n" +" ]\n" +" },\n" +" \"project\": {\n" +" \"run_commands\": [\n" +" \"./.build/\"\n" +" ],\n" +" \"compile_commands\": [\n" +" \"rm -rf ./.build\",\n" +" \"mkdir ./.build\",\n" +" \"cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.\",\n" +" \"cd ./.build/; make\",\n" +" \"cp ./.build/compile_commands.json compile_commands.json\"\n" +" ]\n" +" },\n" +" \"example\": {\n" +" \"key\": \"value\",\n" +" \"key2\": [\n" +" \"val1\",\n" +" \"val2\",\n" +" 3\n" +" ],\n" +" \"key3\": \"value\"\n" +" }\n" +"}\n"; + +const std::string menuxml = +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n"; + +const std::string pluginspy = +"#!/usr/bin/python \n" +"import juci_to_python_api as juci \n" +"import glob \n" +"\n" +"def loadplugins(): \n" +" plugin_files = glob.glob(\"../plugins/*.py\") \n" +" for current_file in plugin_files: \n" +" juci.initPlugin(current_file) \n" +"loadplugins() \n"; +