Browse Source

Remove juci namespace from filesystem

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
70630fc656
  1. 8
      src/cmake.cc
  2. 10
      src/config.cc
  3. 16
      src/filesystem.cc
  4. 35
      src/filesystem.h
  5. 2
      src/notebook.cc
  6. 4
      src/singletons.cc
  7. 4
      src/source.cc
  8. 4
      src/window.cc

8
src/cmake.cc

@ -7,7 +7,7 @@ using namespace std; //TODO: remove
CMake::CMake(const boost::filesystem::path &path) { CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_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 *\\(.*$"); const std::regex project_regex("^ *project *\\(.*$");
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, project_regex)) { 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 #ifdef _WIN32 //Temporary fix to MSYS2's libclang
auto compile_commands_path=path; auto compile_commands_path=path;
compile_commands_path+="/compile_commands.json"; 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; size_t pos=0;
while((pos=compile_commands_file.find("-I/", pos))!=std::string::npos) { while((pos=compile_commands_file.find("-I/", pos))!=std::string::npos) {
if(pos+3<compile_commands_file.size()) { if(pos+3<compile_commands_file.size()) {
@ -60,7 +60,7 @@ bool CMake::create_compile_commands(const boost::filesystem::path &path) {
else else
break; break;
} }
juci::filesystem::write(compile_commands_path, compile_commands_file); filesystem::write(compile_commands_path, compile_commands_file);
#endif #endif
return true; return true;
} }
@ -69,7 +69,7 @@ bool CMake::create_compile_commands(const boost::filesystem::path &path) {
void CMake::read_files() { void CMake::read_files() {
for(auto &path: paths) for(auto &path: paths)
files.emplace_back(juci::filesystem::read(path)); files.emplace_back(filesystem::read(path));
} }
void CMake::remove_tabs() { void CMake::remove_tabs() {

10
src/config.cc

@ -29,8 +29,8 @@ void MainConfig::find_or_create_config_files() {
for (auto &file : files) { for (auto &file : files) {
auto path = boost::filesystem::path(Singleton::config_dir() + file); auto path = boost::filesystem::path(Singleton::config_dir() + file);
if (!boost::filesystem::is_regular_file(path)) { if (!boost::filesystem::is_regular_file(path)) {
if (file == "config.json") juci::filesystem::write(path, configjson); if (file == "config.json") filesystem::write(path, configjson);
if (file == "plugins.py") juci::filesystem::write(path, pluginspy); if (file == "plugins.py") filesystem::write(path, pluginspy);
} }
} }
@ -38,15 +38,15 @@ void MainConfig::find_or_create_config_files() {
boost::filesystem::path juci_style_path=Singleton::style_dir(); boost::filesystem::path juci_style_path=Singleton::style_dir();
juci_style_path+="juci-light.xml"; juci_style_path+="juci-light.xml";
if(!boost::filesystem::exists(juci_style_path)) if(!boost::filesystem::exists(juci_style_path))
juci::filesystem::write(juci_style_path, juci_light_style); filesystem::write(juci_style_path, juci_light_style);
juci_style_path=Singleton::style_dir(); juci_style_path=Singleton::style_dir();
juci_style_path+="juci-dark.xml"; juci_style_path+="juci-dark.xml";
if(!boost::filesystem::exists(juci_style_path)) if(!boost::filesystem::exists(juci_style_path))
juci::filesystem::write(juci_style_path, juci_dark_style); filesystem::write(juci_style_path, juci_dark_style);
juci_style_path=Singleton::style_dir(); juci_style_path=Singleton::style_dir();
juci_style_path+="juci-dark-blue.xml"; juci_style_path+="juci-dark-blue.xml";
if(!boost::filesystem::exists(juci_style_path)) if(!boost::filesystem::exists(juci_style_path))
juci::filesystem::write(juci_style_path, juci_dark_blue_style); filesystem::write(juci_style_path, juci_dark_blue_style);
} }
void MainConfig::retrieve_config() { void MainConfig::retrieve_config() {

16
src/filesystem.cc

@ -8,7 +8,7 @@
const size_t buffer_size=131072; const size_t buffer_size=131072;
//Only use on small files //Only use on small files
std::string juci::filesystem::read(const std::string &path) { std::string filesystem::read(const std::string &path) {
std::stringstream ss; std::stringstream ss;
std::ifstream input(path, std::ofstream::binary); std::ifstream input(path, std::ofstream::binary);
if(input) { if(input) {
@ -26,7 +26,7 @@ std::string safe_get_env(const std::string &env) {
/** /**
* Returns home folder, empty on error * Returns home folder, empty on error
*/ */
std::string juci::filesystem::get_home_folder() { std::string filesystem::get_home_folder() {
auto home=safe_get_env("HOME"); auto home=safe_get_env("HOME");
if(home.empty()) if(home.empty())
home=safe_get_env("AppData"); home=safe_get_env("AppData");
@ -43,7 +43,7 @@ std::string juci::filesystem::get_home_folder() {
/** /**
* Returns tmp folder, empty on error. * Returns tmp folder, empty on error.
*/ */
std::string juci::filesystem::get_tmp_folder() { std::string filesystem::get_tmp_folder() {
boost::system::error_code code; boost::system::error_code code;
auto path = boost::filesystem::temp_directory_path(code); auto path = boost::filesystem::temp_directory_path(code);
if (code.value()!=0) { if (code.value()!=0) {
@ -52,7 +52,7 @@ std::string juci::filesystem::get_tmp_folder() {
return path.string(); return path.string();
} }
int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { int filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
std::ifstream input(path, std::ofstream::binary); std::ifstream input(path, std::ofstream::binary);
if(input) { if(input) {
@ -97,7 +97,7 @@ int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer
return 0; return 0;
} }
int juci::filesystem::read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
std::ifstream input(path, std::ofstream::binary); std::ifstream input(path, std::ofstream::binary);
if(input) { if(input) {
@ -127,7 +127,7 @@ int juci::filesystem::read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::T
} }
//Only use on small files //Only use on small files
std::vector<std::string> juci::filesystem::read_lines(const std::string &path) { std::vector<std::string> filesystem::read_lines(const std::string &path) {
std::vector<std::string> res; std::vector<std::string> res;
std::ifstream input(path, std::ofstream::binary); std::ifstream input(path, std::ofstream::binary);
if (input) { if (input) {
@ -138,7 +138,7 @@ std::vector<std::string> juci::filesystem::read_lines(const std::string &path) {
} }
//Only use on small files //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); std::ofstream output(path, std::ofstream::binary);
if(output) if(output)
output << new_content; output << new_content;
@ -148,7 +148,7 @@ bool juci::filesystem::write(const std::string &path, const std::string &new_con
return true; return true;
} }
bool juci::filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer) { bool filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer) {
std::ofstream output(path, std::ofstream::binary); std::ofstream output(path, std::ofstream::binary);
if(output) { if(output) {
auto start_iter=buffer->begin(); auto start_iter=buffer->begin();

35
src/filesystem.h

@ -13,20 +13,27 @@ namespace juci {
static int read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); static int read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); } static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); }
static int read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); class filesystem {
static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read_non_utf8(path.string(), text_buffer); } 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<Gtk::TextBuffer> text_buffer);
static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); }
static std::vector<std::string> read_lines(const std::string &path); static int read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); }; static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read_non_utf8(path.string(), text_buffer); }
static bool write(const std::string &path, const std::string &new_content); static std::vector<std::string> read_lines(const std::string &path);
static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); };
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, const std::string &new_content);
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); }
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); } static bool write(const std::string &path) { return write(path, ""); };
static std::string get_home_folder(); static bool write(const boost::filesystem::path &path) { return write(path, ""); };
static std::string get_tmp_folder(); static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
}; static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); }
} // namepace juci
static std::string get_home_folder();
static std::string get_tmp_folder();
};
#endif // JUCI_SOURCEFILE_H_ #endif // JUCI_SOURCEFILE_H_

2
src/notebook.cc

@ -159,7 +159,7 @@ bool Notebook::save(int page, bool reparse_needed) {
} }
auto view=get_view(page); auto view=get_view(page);
if (view->file_path != "" && view->get_buffer()->get_modified()) { 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(reparse_needed) {
if(auto clang_view=dynamic_cast<Source::ClangView*>(view)) { if(auto clang_view=dynamic_cast<Source::ClangView*>(view)) {
if(clang_view->language->get_id()=="chdr" || clang_view->language->get_id()=="cpphdr") { if(clang_view->language->get_id()=="chdr" || clang_view->language->get_id()=="cpphdr") {

4
src/singletons.cc

@ -41,10 +41,10 @@ Gtk::Label *Singleton::info() {
std::string Singleton::create_config_path(const std::string &subfolder) { std::string Singleton::create_config_path(const std::string &subfolder) {
boost::filesystem::path home; boost::filesystem::path home;
home = juci::filesystem::get_home_folder(); home = filesystem::get_home_folder();
if(home.empty()) { if(home.empty()) {
Singleton::terminal()->print("Could not find/write to home directory. Using defaults, no settings will be saved."); 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()) { if(home.empty()) {
std::string message("Please fix permissions of your home folder"); std::string message("Please fix permissions of your home folder");
std::cerr << message << std::endl; std::cerr << message << std::endl;

4
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<Gsv::Language> language): file_path(file_path), project_path(project_path), language(language) { Source::View::View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr<Gsv::Language> language): file_path(file_path), project_path(project_path), language(language) {
get_source_buffer()->begin_not_undoable_action(); get_source_buffer()->begin_not_undoable_action();
if(language) { 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"); Singleton::terminal()->print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n");
} }
else { 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"); Singleton::terminal()->print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n");
} }
get_source_buffer()->end_not_undoable_action(); get_source_buffer()->end_not_undoable_action();

4
src/window.cc

@ -177,7 +177,7 @@ void Window::create_menu() {
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); Singleton::terminal()->print("Error: "+path.string()+" already exists.\n");
} }
else { else {
if(juci::filesystem::write(path)) { if(filesystem::write(path)) {
if(Singleton::directories()->current_path!="") if(Singleton::directories()->current_path!="")
Singleton::directories()->update(); Singleton::directories()->update();
notebook.open(path.string()); 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 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 <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; std::string cpp_main="#include <iostream>\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); Singleton::directories()->open(project_path);
notebook.open(cpp_main_path); notebook.open(cpp_main_path);
Singleton::terminal()->print("C++ project "+project_name+" created.\n"); Singleton::terminal()->print("C++ project "+project_name+" created.\n");

Loading…
Cancel
Save