Browse Source

More appropriate function names in sourcefile.*.

merge-requests/365/head
eidheim 11 years ago
parent
commit
1443ba89b2
  1. 8
      src/config.cc
  2. 4
      src/directories.cc
  3. 2
      src/notebook.cc
  4. 2
      src/source.cc
  5. 10
      src/sourcefile.cc
  6. 20
      src/sourcefile.h
  7. 2
      src/window.cc

8
src/config.cc

@ -20,9 +20,9 @@ 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::save(path, configjson); if (file == "config.json") juci::filesystem::write(path, configjson);
if (file == "plugins.py") juci::filesystem::save(path, pluginspy); if (file == "plugins.py") juci::filesystem::write(path, pluginspy);
if (file == "menu.xml") juci::filesystem::save(path, menuxml); if (file == "menu.xml") juci::filesystem::write(path, menuxml);
} }
} }
} }
@ -76,7 +76,7 @@ void MainConfig::GenerateKeybindings() {
std::cerr << "menu.xml not found" << std::endl; std::cerr << "menu.xml not found" << std::endl;
throw; throw;
} }
menu.ui = juci::filesystem::open(path); menu.ui = juci::filesystem::read(path);
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) { for (auto &i : keys_json) {
auto key=i.second.get_value<std::string>(); auto key=i.second.get_value<std::string>();

4
src/directories.cc

@ -103,7 +103,7 @@ std::string Directories::get_cmakelists_variable(const boost::filesystem::path&
boost::filesystem::directory_iterator end_itr; boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path );itr != end_itr;++itr ) { for (boost::filesystem::directory_iterator itr( dir_path );itr != end_itr;++itr ) {
if (itr->path().filename().string() == "CMakeLists.txt") { if (itr->path().filename().string() == "CMakeLists.txt") {
for (auto &line : juci::filesystem::lines(itr->path())) { for (auto &line : juci::filesystem::read_lines(itr->path())) {
if (line.find(command_name+"(", 0) != std::string::npos if (line.find(command_name+"(", 0) != std::string::npos
|| line.find(command_name+" (", 0) != std::string::npos ) { || line.find(command_name+" (", 0) != std::string::npos ) {
size_t variable_start = line.find("{", 0); size_t variable_start = line.find("{", 0);
@ -138,7 +138,7 @@ std::string Directories::get_cmakelists_variable(const boost::filesystem::path&
} }
} }
} }
for (auto &line : juci::filesystem::lines(itr->path())) { for (auto &line : juci::filesystem::read_lines(itr->path())) {
if (line.find("set(", 0) != std::string::npos if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) { || line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) { if( line.find(project_name_var, 0) != std::string::npos) {

2
src/notebook.cc

@ -92,7 +92,7 @@ bool Notebook::save(int page) {
return false; return false;
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::save(view->file_path, view->get_buffer())) { if(juci::filesystem::write(view->file_path, view->get_buffer())) {
view->get_buffer()->set_modified(false); view->get_buffer()->set_modified(false);
Singleton::terminal()->print("File saved to: " +view->file_path+"\n"); Singleton::terminal()->print("File saved to: " +view->file_path+"\n");
return true; return true;

2
src/source.cc

@ -43,7 +43,7 @@ file_path(file_path), project_path(project_path) {
set_highlight_current_line(Singleton::Config::source()->highlight_current_line); set_highlight_current_line(Singleton::Config::source()->highlight_current_line);
get_source_buffer()->get_undo_manager()->begin_not_undoable_action(); get_source_buffer()->get_undo_manager()->begin_not_undoable_action();
juci::filesystem::open(file_path, get_buffer()); juci::filesystem::read(file_path, get_buffer());
get_source_buffer()->get_undo_manager()->end_not_undoable_action(); get_source_buffer()->get_undo_manager()->end_not_undoable_action();
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));

10
src/sourcefile.cc

@ -5,7 +5,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::open(const std::string &path) { std::string juci::filesystem::read(const std::string &path) {
std::stringstream ss; std::stringstream ss;
std::ifstream input(path); std::ifstream input(path);
if(input) { if(input) {
@ -15,7 +15,7 @@ std::string juci::filesystem::open(const std::string &path) {
return ss.str(); return ss.str();
} }
bool juci::filesystem::open(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { bool juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
std::ifstream input(path); std::ifstream input(path);
if(input) { if(input) {
std::vector<char> buffer(buffer_size); std::vector<char> buffer(buffer_size);
@ -29,7 +29,7 @@ bool juci::filesystem::open(const std::string &path, Glib::RefPtr<Gtk::TextBuffe
} }
//Only use on small files //Only use on small files
std::vector<std::string> juci::filesystem::lines(const std::string &path) { std::vector<std::string> juci::filesystem::read_lines(const std::string &path) {
std::vector<std::string> res; std::vector<std::string> res;
std::ifstream input(path); std::ifstream input(path);
if (input) { if (input) {
@ -40,7 +40,7 @@ std::vector<std::string> juci::filesystem::lines(const std::string &path) {
} }
//Only use on small files //Only use on small files
bool juci::filesystem::save(const std::string &path, const std::string &new_content) { bool juci::filesystem::write(const std::string &path, const std::string &new_content) {
std::ofstream output(path); std::ofstream output(path);
if(output) if(output)
output << new_content; output << new_content;
@ -50,7 +50,7 @@ bool juci::filesystem::save(const std::string &path, const std::string &new_cont
return true; return true;
} }
bool juci::filesystem::save(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer) { bool juci::filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer) {
std::ofstream output(path); std::ofstream output(path);
if(output) { if(output) {
auto start_iter=buffer->begin(); auto start_iter=buffer->begin();

20
src/sourcefile.h

@ -8,18 +8,18 @@
namespace juci { namespace juci {
class filesystem { class filesystem {
public: public:
static std::string open(const std::string &path); static std::string read(const std::string &path);
static std::string open(const boost::filesystem::path &path) { return open(path.string()); } static std::string read(const boost::filesystem::path &path) { return read(path.string()); }
static bool open(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); static bool read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static std::vector<std::string> lines(const std::string &path); static std::vector<std::string> read_lines(const std::string &path);
static std::vector<std::string> lines(const boost::filesystem::path &path) { return lines(path.string()); }; static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); };
static bool save(const std::string &path, const std::string &new_content); static bool write(const std::string &path, const std::string &new_content);
static bool save(const boost::filesystem::path &path, const std::string &new_content) { return save(path.string(), new_content); } static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); }
static bool save(const std::string &path) { return save(path, ""); }; static bool write(const std::string &path) { return write(path, ""); };
static bool save(const boost::filesystem::path &path) { return save(path, ""); }; static bool write(const boost::filesystem::path &path) { return write(path, ""); };
static bool save(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
}; };
} // namepace juci } // namepace juci
#endif // JUCI_SOURCEFILE_H_ #endif // JUCI_SOURCEFILE_H_

2
src/window.cc

@ -279,7 +279,7 @@ void Window::new_file_entry() {
Singleton::terminal()->print("Error: "+p.string()+" already exists.\n"); Singleton::terminal()->print("Error: "+p.string()+" already exists.\n");
} }
else { else {
if(juci::filesystem::save(p)) { if(juci::filesystem::write(p)) {
notebook.open(boost::filesystem::canonical(p).string()); notebook.open(boost::filesystem::canonical(p).string());
Singleton::terminal()->print("New file "+p.string()+" created.\n"); Singleton::terminal()->print("New file "+p.string()+" created.\n");
if(notebook.project_path!="") if(notebook.project_path!="")

Loading…
Cancel
Save