diff --git a/src/cmake.cc b/src/cmake.cc index 37773a7..883b49a 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -7,7 +7,7 @@ using namespace std; //TODO: remove CMake::CMake(const boost::filesystem::path &path) { const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) { - for(auto &line: juci::filesystem::read_lines(cmake_path)) { + for(auto &line: filesystem::read_lines(cmake_path)) { const std::regex project_regex("^ *project *\\(.*$"); std::smatch sm; if(std::regex_match(line, sm, project_regex)) { @@ -49,7 +49,7 @@ bool CMake::create_compile_commands(const boost::filesystem::path &path) { #ifdef _WIN32 //Temporary fix to MSYS2's libclang auto compile_commands_path=path; compile_commands_path+="/compile_commands.json"; - auto compile_commands_file=juci::filesystem::read(compile_commands_path); + auto compile_commands_file=filesystem::read(compile_commands_path); size_t pos=0; while((pos=compile_commands_file.find("-I/", pos))!=std::string::npos) { if(pos+3 text_buffer) { +int filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { std::ifstream input(path, std::ofstream::binary); if(input) { @@ -97,7 +97,7 @@ int juci::filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { +int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr text_buffer) { std::ifstream input(path, std::ofstream::binary); if(input) { @@ -127,7 +127,7 @@ int juci::filesystem::read_non_utf8(const std::string &path, Glib::RefPtr juci::filesystem::read_lines(const std::string &path) { +std::vector filesystem::read_lines(const std::string &path) { std::vector res; std::ifstream input(path, std::ofstream::binary); if (input) { @@ -138,7 +138,7 @@ std::vector juci::filesystem::read_lines(const std::string &path) { } //Only use on small files -bool juci::filesystem::write(const std::string &path, const std::string &new_content) { +bool filesystem::write(const std::string &path, const std::string &new_content) { std::ofstream output(path, std::ofstream::binary); if(output) output << new_content; @@ -148,7 +148,7 @@ bool juci::filesystem::write(const std::string &path, const std::string &new_con return true; } -bool juci::filesystem::write(const std::string &path, Glib::RefPtr buffer) { +bool filesystem::write(const std::string &path, Glib::RefPtr buffer) { std::ofstream output(path, std::ofstream::binary); if(output) { auto start_iter=buffer->begin(); diff --git a/src/filesystem.h b/src/filesystem.h index fd945af..a417825 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -13,20 +13,27 @@ namespace juci { static int read(const std::string &path, Glib::RefPtr text_buffer); static int read(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return read(path.string(), text_buffer); } - static int read_non_utf8(const std::string &path, Glib::RefPtr text_buffer); - static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return read_non_utf8(path.string(), text_buffer); } +class filesystem { +public: + static std::string read(const std::string &path); + static std::string read(const boost::filesystem::path &path) { return read(path.string()); } + static int read(const std::string &path, Glib::RefPtr text_buffer); + static int read(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return read(path.string(), text_buffer); } - static std::vector read_lines(const std::string &path); - static std::vector read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); }; + static int read_non_utf8(const std::string &path, Glib::RefPtr text_buffer); + static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return read_non_utf8(path.string(), text_buffer); } - static bool write(const std::string &path, const std::string &new_content); - static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } - static bool write(const std::string &path) { return write(path, ""); }; - static bool write(const boost::filesystem::path &path) { return write(path, ""); }; - static bool write(const std::string &path, Glib::RefPtr text_buffer); - static bool write(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return write(path.string(), text_buffer); } - static std::string get_home_folder(); - static std::string get_tmp_folder(); - }; -} // namepace juci + static std::vector read_lines(const std::string &path); + static std::vector read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); }; + + static bool write(const std::string &path, const std::string &new_content); + static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } + static bool write(const std::string &path) { return write(path, ""); }; + static bool write(const boost::filesystem::path &path) { return write(path, ""); }; + static bool write(const std::string &path, Glib::RefPtr text_buffer); + static bool write(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return write(path.string(), text_buffer); } + + static std::string get_home_folder(); + static std::string get_tmp_folder(); +}; #endif // JUCI_SOURCEFILE_H_ diff --git a/src/notebook.cc b/src/notebook.cc index 14834c7..895c18f 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -159,7 +159,7 @@ bool Notebook::save(int page, bool reparse_needed) { } auto view=get_view(page); if (view->file_path != "" && view->get_buffer()->get_modified()) { - if(juci::filesystem::write(view->file_path, view->get_buffer())) { + if(filesystem::write(view->file_path, view->get_buffer())) { if(reparse_needed) { if(auto clang_view=dynamic_cast(view)) { if(clang_view->language->get_id()=="chdr" || clang_view->language->get_id()=="cpphdr") { diff --git a/src/singletons.cc b/src/singletons.cc index a24cc82..8ace5c8 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -41,10 +41,10 @@ Gtk::Label *Singleton::info() { std::string Singleton::create_config_path(const std::string &subfolder) { boost::filesystem::path home; - home = juci::filesystem::get_home_folder(); + home = filesystem::get_home_folder(); if(home.empty()) { Singleton::terminal()->print("Could not find/write to home directory. Using defaults, no settings will be saved."); - home = juci::filesystem::get_tmp_folder(); + home = filesystem::get_tmp_folder(); if(home.empty()) { std::string message("Please fix permissions of your home folder"); std::cerr << message << std::endl; diff --git a/src/source.cc b/src/source.cc index c0c1511..d52806c 100644 --- a/src/source.cc +++ b/src/source.cc @@ -85,11 +85,11 @@ AspellConfig* Source::View::spellcheck_config=NULL; Source::View::View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr language): file_path(file_path), project_path(project_path), language(language) { get_source_buffer()->begin_not_undoable_action(); if(language) { - if(juci::filesystem::read_non_utf8(file_path, get_buffer())==-1) + if(filesystem::read_non_utf8(file_path, get_buffer())==-1) Singleton::terminal()->print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n"); } else { - if(juci::filesystem::read(file_path, get_buffer())==-1) + if(filesystem::read(file_path, get_buffer())==-1) Singleton::terminal()->print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n"); } get_source_buffer()->end_not_undoable_action(); diff --git a/src/window.cc b/src/window.cc index d5d3d20..462f5db 100644 --- a/src/window.cc +++ b/src/window.cc @@ -177,7 +177,7 @@ void Window::create_menu() { Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); } else { - if(juci::filesystem::write(path)) { + if(filesystem::write(path)) { if(Singleton::directories()->current_path!="") Singleton::directories()->update(); notebook.open(path.string()); @@ -226,7 +226,7 @@ void Window::create_menu() { } std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n"; std::string cpp_main="#include \n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; - if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) { + if(filesystem::write(cmakelists_path, cmakelists) && filesystem::write(cpp_main_path, cpp_main)) { Singleton::directories()->open(project_path); notebook.open(cpp_main_path); Singleton::terminal()->print("C++ project "+project_name+" created.\n");