diff --git a/src/juci.cc b/src/juci.cc index 5dd0509..6c8a339 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -29,8 +29,18 @@ int Application::on_command_line(const Glib::RefPtr else if(boost::filesystem::is_directory(p)) directories.emplace_back(p); } - else - std::cerr << "Path " << p << " does not exist." << std::endl; + else { //Open new file if parent path exists + auto parent_p=p.parent_path(); + boost::system::error_code ec; + auto new_p=boost::filesystem::canonical(parent_p, ec); + if(!ec && boost::filesystem::is_directory(new_p)) { + new_p+="/"; + new_p+=p.filename(); + files.emplace_back(new_p); + } + else + Singleton::terminal->print("Error: folder path "+parent_p.string()+" does not exist.\n", true); + } } } activate(); diff --git a/src/notebook.cc b/src/notebook.cc index 6119cfe..74d9107 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -65,12 +65,14 @@ void Notebook::open(const boost::filesystem::path &file_path) { } } - std::ifstream can_read(file_path.string()); - if(!can_read) { - Singleton::terminal->print("Error: could not open "+file_path.string()+"\n"); - return; + if(boost::filesystem::exists(file_path)) { + std::ifstream can_read(file_path.string()); + if(!can_read) { + Singleton::terminal->print("Error: could not open "+file_path.string()+"\n", true); + return; + } + can_read.close(); } - can_read.close(); auto language=Source::guess_language(file_path); boost::filesystem::path project_path; @@ -206,7 +208,7 @@ bool Notebook::save(int page, bool reparse_needed) { if(source_clang_view->restart_parse()) Singleton::terminal->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); else - Singleton::terminal->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); + Singleton::terminal->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n", true); } } } @@ -215,7 +217,7 @@ bool Notebook::save(int page, bool reparse_needed) { JDEBUG("end true"); return true; } - Singleton::terminal->print("Error: could not save file " +view->file_path.string()+"\n"); + Singleton::terminal->print("Error: could not save file " +view->file_path.string()+"\n", true); } JDEBUG("end false"); return false; diff --git a/src/source.cc b/src/source.cc index 2f196d8..2688854 100644 --- a/src/source.cc +++ b/src/source.cc @@ -91,7 +91,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy } else { 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", true); } get_source_buffer()->end_not_undoable_action(); @@ -304,7 +304,7 @@ void Source::View::configure() { if(scheme) get_source_buffer()->set_style_scheme(scheme); else - Singleton::terminal->print("Error: Could not find gtksourceview style: "+Singleton::config->source.style+'\n'); + Singleton::terminal->print("Error: Could not find gtksourceview style: "+Singleton::config->source.style+'\n', true); } if(Singleton::config->source.wrap_lines) @@ -1306,7 +1306,7 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const boost::property_tree::xml_parser::read_xml(language_file.string(), pt); } catch(const std::exception &e) { - Singleton::terminal->print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n'); + Singleton::terminal->print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n', true); } bool has_context_class=false; parse_language_file(completion_buffer_keywords, has_context_class, pt); diff --git a/src/source_clang.cc b/src/source_clang.cc index 4fe441d..ebad9e6 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -59,7 +59,7 @@ Source::View(file_path, project_path, language), parse_error(false) { } }); parse_fail_connection=parse_fail.connect([this](){ - Singleton::terminal->print("Error: failed to reparse "+this->file_path.string()+".\n"); + Singleton::terminal->print("Error: failed to reparse "+this->file_path.string()+".\n", true); set_status(""); set_info(""); parsing_in_progress->cancel("failed"); @@ -649,7 +649,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_cancel_s }); autocomplete_fail_connection=autocomplete_fail.connect([this]() { - Singleton::terminal->print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n"); + Singleton::terminal->print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n", true); restart_parse(); autocomplete_starting=false; autocomplete_cancel_starting=false; diff --git a/src/terminal.cc b/src/terminal.cc index 772f8ef..2a1ee90 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -155,7 +155,7 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path pid=popen3(command, path.string(), nullptr, nullptr, nullptr); if (pid<=0) { - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); return -1; } else { @@ -203,7 +203,7 @@ int Terminal::execute(std::istream &stdin_stream, std::ostream &stdout_stream, c auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd); if (pid<=0) { - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); return -1; } else { @@ -269,7 +269,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem async_executes_mutex.unlock(); if (pid<=0) { - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); if(callback) callback(-1); } diff --git a/src/terminal_win.cc b/src/terminal_win.cc index b3c57ec..962a55d 100644 --- a/src/terminal_win.cc +++ b/src/terminal_win.cc @@ -200,7 +200,7 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path else process=popen3(command, path.string(), nullptr, nullptr, nullptr); if(process==NULL) { - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); return -1; } if(use_pipes) { @@ -257,7 +257,7 @@ int Terminal::execute(std::istream &stdin_stream, std::ostream &stdout_stream, c auto process=popen3(command, path.string(), &stdin_h, &stdout_h, &stderr_h); if(process==NULL) { - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); return -1; } std::thread stderr_thread([this, stderr_h](){ @@ -331,7 +331,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem auto process=popen3(command, path.string(), &stdin_h, &stdout_h, &stderr_h); if(process==NULL) { async_executes_mutex.unlock(); - async_print("Error: Failed to run command: " + command + "\n"); + async_print("Error: Failed to run command: " + command + "\n", true); if(callback) callback(-1); return; diff --git a/src/window.cc b/src/window.cc index 388c94d..1ad2711 100644 --- a/src/window.cc +++ b/src/window.cc @@ -154,7 +154,7 @@ void Window::set_menu_actions() { boost::filesystem::path path = Dialog::new_file(); if(path!="") { if(boost::filesystem::exists(path)) { - Singleton::terminal->print("Error: "+path.string()+" already exists.\n"); + Singleton::terminal->print("Error: "+path.string()+" already exists.\n", true); } else { if(filesystem::write(path)) { @@ -164,7 +164,7 @@ void Window::set_menu_actions() { Singleton::terminal->print("New file "+path.string()+" created.\n"); } else - Singleton::terminal->print("Error: could not create new file "+path.string()+".\n"); + Singleton::terminal->print("Error: could not create new file "+path.string()+".\n", true); } } }); @@ -178,7 +178,7 @@ void Window::set_menu_actions() { Singleton::terminal->print("New folder "+path.string()+" created.\n"); } else - Singleton::terminal->print("Error: "+path.string()+" already exists.\n"); + Singleton::terminal->print("Error: "+path.string()+" already exists.\n", true); Singleton::directories->select(path); } }); @@ -195,11 +195,11 @@ void Window::set_menu_actions() { auto cpp_main_path=project_path; cpp_main_path+="/main.cpp"; if(boost::filesystem::exists(cmakelists_path)) { - Singleton::terminal->print("Error: "+cmakelists_path.string()+" already exists.\n"); + Singleton::terminal->print("Error: "+cmakelists_path.string()+" already exists.\n", true); return; } if(boost::filesystem::exists(cpp_main_path)) { - Singleton::terminal->print("Error: "+cpp_main_path.string()+" already exists.\n"); + Singleton::terminal->print("Error: "+cpp_main_path.string()+" already exists.\n", true); return; } 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"; @@ -210,7 +210,7 @@ void Window::set_menu_actions() { Singleton::terminal->print("C++ project "+project_name+" created.\n"); } else - Singleton::terminal->print("Error: Could not create project "+project_path.string()+"\n"); + Singleton::terminal->print("Error: Could not create project "+project_path.string()+"\n", true); } });