Browse Source

Can now create files from command line arguments (juci . new_file.py), and error messages in terminal are set to bold.

merge-requests/365/head
eidheim 10 years ago
parent
commit
8617e5894d
  1. 14
      src/juci.cc
  2. 16
      src/notebook.cc
  3. 6
      src/source.cc
  4. 4
      src/source_clang.cc
  5. 6
      src/terminal.cc
  6. 6
      src/terminal_win.cc
  7. 12
      src/window.cc

14
src/juci.cc

@ -29,8 +29,18 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
else if(boost::filesystem::is_directory(p)) else if(boost::filesystem::is_directory(p))
directories.emplace_back(p); directories.emplace_back(p);
} }
else else { //Open new file if parent path exists
std::cerr << "Path " << p << " does not exist." << std::endl; 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(); activate();

16
src/notebook.cc

@ -65,12 +65,14 @@ void Notebook::open(const boost::filesystem::path &file_path) {
} }
} }
std::ifstream can_read(file_path.string()); if(boost::filesystem::exists(file_path)) {
if(!can_read) { std::ifstream can_read(file_path.string());
Singleton::terminal->print("Error: could not open "+file_path.string()+"\n"); if(!can_read) {
return; 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); auto language=Source::guess_language(file_path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
@ -206,7 +208,7 @@ bool Notebook::save(int page, bool reparse_needed) {
if(source_clang_view->restart_parse()) if(source_clang_view->restart_parse())
Singleton::terminal->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); Singleton::terminal->async_print("Reparsing "+source_clang_view->file_path.string()+"\n");
else 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"); JDEBUG("end true");
return 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"); JDEBUG("end false");
return false; return false;

6
src/source.cc

@ -91,7 +91,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
} }
else { else {
if(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", true);
} }
get_source_buffer()->end_not_undoable_action(); get_source_buffer()->end_not_undoable_action();
@ -304,7 +304,7 @@ void Source::View::configure() {
if(scheme) if(scheme)
get_source_buffer()->set_style_scheme(scheme); get_source_buffer()->set_style_scheme(scheme);
else 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) 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); boost::property_tree::xml_parser::read_xml(language_file.string(), pt);
} }
catch(const std::exception &e) { 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; bool has_context_class=false;
parse_language_file(completion_buffer_keywords, has_context_class, pt); parse_language_file(completion_buffer_keywords, has_context_class, pt);

4
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](){ 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_status("");
set_info(""); set_info("");
parsing_in_progress->cancel("failed"); 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]() { 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(); restart_parse();
autocomplete_starting=false; autocomplete_starting=false;
autocomplete_cancel_starting=false; autocomplete_cancel_starting=false;

6
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); pid=popen3(command, path.string(), nullptr, nullptr, nullptr);
if (pid<=0) { if (pid<=0) {
async_print("Error: Failed to run command: " + command + "\n"); async_print("Error: Failed to run command: " + command + "\n", true);
return -1; return -1;
} }
else { 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); auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd);
if (pid<=0) { if (pid<=0) {
async_print("Error: Failed to run command: " + command + "\n"); async_print("Error: Failed to run command: " + command + "\n", true);
return -1; return -1;
} }
else { else {
@ -269,7 +269,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem
async_executes_mutex.unlock(); async_executes_mutex.unlock();
if (pid<=0) { if (pid<=0) {
async_print("Error: Failed to run command: " + command + "\n"); async_print("Error: Failed to run command: " + command + "\n", true);
if(callback) if(callback)
callback(-1); callback(-1);
} }

6
src/terminal_win.cc

@ -200,7 +200,7 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path
else else
process=popen3(command, path.string(), nullptr, nullptr, nullptr); process=popen3(command, path.string(), nullptr, nullptr, nullptr);
if(process==NULL) { if(process==NULL) {
async_print("Error: Failed to run command: " + command + "\n"); async_print("Error: Failed to run command: " + command + "\n", true);
return -1; return -1;
} }
if(use_pipes) { 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); auto process=popen3(command, path.string(), &stdin_h, &stdout_h, &stderr_h);
if(process==NULL) { if(process==NULL) {
async_print("Error: Failed to run command: " + command + "\n"); async_print("Error: Failed to run command: " + command + "\n", true);
return -1; return -1;
} }
std::thread stderr_thread([this, stderr_h](){ 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); auto process=popen3(command, path.string(), &stdin_h, &stdout_h, &stderr_h);
if(process==NULL) { if(process==NULL) {
async_executes_mutex.unlock(); 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) if(callback)
callback(-1); callback(-1);
return; return;

12
src/window.cc

@ -154,7 +154,7 @@ void Window::set_menu_actions() {
boost::filesystem::path path = Dialog::new_file(); boost::filesystem::path path = Dialog::new_file();
if(path!="") { if(path!="") {
if(boost::filesystem::exists(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 { else {
if(filesystem::write(path)) { if(filesystem::write(path)) {
@ -164,7 +164,7 @@ void Window::set_menu_actions() {
Singleton::terminal->print("New file "+path.string()+" created.\n"); Singleton::terminal->print("New file "+path.string()+" created.\n");
} }
else 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"); Singleton::terminal->print("New folder "+path.string()+" created.\n");
} }
else else
Singleton::terminal->print("Error: "+path.string()+" already exists.\n"); Singleton::terminal->print("Error: "+path.string()+" already exists.\n", true);
Singleton::directories->select(path); Singleton::directories->select(path);
} }
}); });
@ -195,11 +195,11 @@ void Window::set_menu_actions() {
auto cpp_main_path=project_path; auto cpp_main_path=project_path;
cpp_main_path+="/main.cpp"; cpp_main_path+="/main.cpp";
if(boost::filesystem::exists(cmakelists_path)) { 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; return;
} }
if(boost::filesystem::exists(cpp_main_path)) { 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; 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"; 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"); Singleton::terminal->print("C++ project "+project_name+" created.\n");
} }
else 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);
} }
}); });

Loading…
Cancel
Save