Browse Source

More robust directory/file code, fixed at least one infinite loop.

merge-requests/365/head
eidheim 10 years ago
parent
commit
4321febd41
  1. 2
      src/directories.cc
  2. 19
      src/juci.cc
  3. 5
      src/juci.h
  4. 4
      src/notebook.cc

2
src/directories.cc

@ -160,7 +160,7 @@ void Directories::select(const boost::filesystem::path &path) {
if(current_path=="") if(current_path=="")
return; return;
if(path.string().substr(0, current_path.string().size())!=current_path.string()) if(path.generic_string().substr(0, current_path.generic_string().size()+1)!=current_path.generic_string()+'/')
return; return;
std::list<boost::filesystem::path> paths; std::list<boost::filesystem::path> paths;

19
src/juci.cc

@ -25,9 +25,9 @@ int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
if(boost::filesystem::exists(p)) { if(boost::filesystem::exists(p)) {
p=boost::filesystem::canonical(p); p=boost::filesystem::canonical(p);
if(boost::filesystem::is_regular_file(p)) if(boost::filesystem::is_regular_file(p))
files.emplace_back(p.string()); files.emplace_back(p);
else if(boost::filesystem::is_directory(p)) else if(boost::filesystem::is_directory(p))
directories.emplace_back(p.string()); directories.emplace_back(p);
} }
else else
std::cerr << "Path " << p << " does not exist." << std::endl; std::cerr << "Path " << p << " does not exist." << std::endl;
@ -49,16 +49,17 @@ void app::on_activate() {
} }
else { else {
std::string files_in_directory; std::string files_in_directory;
for(size_t c=0;c<files.size();c++) { for(auto it=files.begin();it!=files.end();) {
if(files[c].substr(0, directory.size())==directory) { if(it->generic_string().substr(0, directory.generic_string().size()+1)==directory.generic_string()+'/') {
files_in_directory+=" "+files[c]; files_in_directory+=" "+it->string();
files.erase(files.begin()+c); it=files.erase(it);
c--;
} }
else
it++;
} }
std::thread another_juci_app([this, directory, files_in_directory](){ std::thread another_juci_app([this, directory, files_in_directory](){
Singleton::terminal()->async_print("Executing: juci "+directory+files_in_directory); Singleton::terminal()->async_print("Executing: juci "+directory.string()+files_in_directory);
Singleton::terminal()->execute("juci "+directory+files_in_directory, ""); //TODO: do not open pipes here, doing this after Juci compiles on Windows Singleton::terminal()->execute("juci "+directory.string()+files_in_directory, ""); //TODO: do not open pipes here, doing this after Juci compiles on Windows
}); });
another_juci_app.detach(); another_juci_app.detach();
} }

5
src/juci.h

@ -3,6 +3,7 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
class app : public Gtk::Application { class app : public Gtk::Application {
public: public:
app(); app();
@ -11,8 +12,8 @@ class app : public Gtk::Application {
private: private:
std::unique_ptr<Window> window; std::unique_ptr<Window> window;
std::vector<std::string> directories; std::vector<boost::filesystem::path> directories;
std::vector<std::string> files; std::vector<boost::filesystem::path> files;
}; };
#endif // JUCI_JUCI_H_ #endif // JUCI_JUCI_H_

4
src/notebook.cc

@ -67,7 +67,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
auto language=Source::guess_language(file_path); auto language=Source::guess_language(file_path);
if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
boost::filesystem::path project_path; boost::filesystem::path project_path;
if(directories.cmake && directories.cmake->project_path!="" && file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string()) if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/')
project_path=directories.cmake->project_path; project_path=directories.cmake->project_path;
else { else {
project_path=file_path.parent_path(); project_path=file_path.parent_path();
@ -153,7 +153,7 @@ bool Notebook::save(int page, bool reparse_needed) {
//If CMakeLists.txt have been modified: //If CMakeLists.txt have been modified:
//TODO: recreate cmake even without directories open? //TODO: recreate cmake even without directories open?
if(view->file_path.filename()=="CMakeLists.txt") { if(view->file_path.filename()=="CMakeLists.txt") {
if(directories.cmake && directories.cmake->project_path!="" && view->file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string() && CMake::create_compile_commands(directories.cmake->project_path)) { if(directories.cmake && directories.cmake->project_path!="" && view->file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories.cmake->project_path)) {
for(auto source_view: source_views) { for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) { if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(directories.cmake->project_path.string()==source_clang_view->project_path) { if(directories.cmake->project_path.string()==source_clang_view->project_path) {

Loading…
Cancel
Save