diff --git a/src/files.h b/src/files.h index ee3bc53..8831802 100644 --- a/src/files.h +++ b/src/files.h @@ -79,6 +79,9 @@ const std::string menuxml = " \n" " \n" " \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" diff --git a/src/terminal.cc b/src/terminal.cc index cfcbeb8..280c98b 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -269,11 +269,11 @@ int Terminal::print(const std::string &message, bool bold){ auto iter=get_buffer()->get_insert()->get_iter(); if(iter.backward_char()) { + auto mark=get_buffer()->create_mark(iter); + scroll_to(mark, 0.0, 1.0, 1.0); while(gtk_events_pending()) gtk_main_iteration(); - scroll_to(iter); - while(gtk_events_pending()) - gtk_main_iteration(); + get_buffer()->delete_mark(mark); } return get_buffer()->end().get_line(); } @@ -314,8 +314,6 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { if(unicode>=32 && unicode<=126) { stdin_buffer+=chr; get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1)); - while(gtk_events_pending()) - gtk_main_iteration(); scroll_to(get_buffer()->get_insert()); while(gtk_events_pending()) gtk_main_iteration(); @@ -326,8 +324,6 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { iter--; stdin_buffer.pop_back(); get_buffer()->erase(iter, get_buffer()->end()); - while(gtk_events_pending()) - gtk_main_iteration(); scroll_to(get_buffer()->get_insert()); while(gtk_events_pending()) gtk_main_iteration(); @@ -337,8 +333,6 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { stdin_buffer+='\n'; write(async_executes.back().second, stdin_buffer.c_str(), stdin_buffer.size()); get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1)); - while(gtk_events_pending()) - gtk_main_iteration(); scroll_to(get_buffer()->get_insert()); while(gtk_events_pending()) gtk_main_iteration(); diff --git a/src/window.cc b/src/window.cc index 5c14c1d..d1e4175 100644 --- a/src/window.cc +++ b/src/window.cc @@ -105,6 +105,10 @@ void Window::create_menu() { menu.action_group->add(Gtk::Action::create("FileNewFile", "New file"), Gtk::AccelKey(menu.key_map["new_file"]), [this]() { new_file_entry(); }); + menu.action_group->add(Gtk::Action::create("FileNewProject", "New Project")); + menu.action_group->add(Gtk::Action::create("FileNewProjectCpp", "C++"), [this]() { + new_cpp_project_dialog(); + }); menu.action_group->add(Gtk::Action::create("FileOpenFile", "Open file"), Gtk::AccelKey(menu.key_map["open_file"]), [this]() { open_file_dialog(); }); @@ -363,6 +367,46 @@ void Window::new_file_entry() { entry_box.show(); } +void Window::new_cpp_project_dialog() { + Gtk::FileChooserDialog dialog("Please create and/or choose a folder", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); + if(directories.current_path!="") + gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); + else + gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); + dialog.set_transient_for(*this); + + dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); + dialog.add_button("Select", Gtk::RESPONSE_OK); + + int result = dialog.run(); + + if(result==Gtk::RESPONSE_OK) { + boost::filesystem::path project_path=dialog.get_filename(); + auto project_name=project_path.filename().string(); + auto cmakelists_path=project_path; + cmakelists_path+="/CMakeLists.txt"; + 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"); + return; + } + if(boost::filesystem::exists(cpp_main_path)) { + Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n"); + 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\")\n\nadd_executable("+project_name+" main.cpp)\n"; + std::string cpp_main="#include \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)) { + directories.open_folder(project_path); + notebook.open(cpp_main_path); + Singleton::terminal()->print("C++ project "+project_name+" created.\n"); + } + else + Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n"); + } +} + void Window::open_folder_dialog() { Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); if(directories.current_path!="") diff --git a/src/window.h b/src/window.h index 1307b96..8255aa7 100644 --- a/src/window.h +++ b/src/window.h @@ -32,6 +32,7 @@ private: void create_menu(); void hide(); void new_file_entry(); + void new_cpp_project_dialog(); void open_folder_dialog(); void open_file_dialog(); void save_file_dialog();