Browse Source

Now uses tab char and size from config.json when creating new C++ project. Also fixed a minor issue when using tab as tab_char.

merge-requests/365/head
eidheim 10 years ago
parent
commit
a8301256a7
  1. 8
      src/source.cc
  2. 7
      src/window.cc

8
src/source.cc

@ -1472,11 +1472,13 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
iter=get_buffer()->get_insert()->get_iter(); iter=get_buffer()->get_insert()->get_iter();
auto found_iter=iter; auto found_iter=iter;
if(find_open_expression_symbol(iter, start_of_sentence_iter, found_iter)) { if(find_open_expression_symbol(iter, start_of_sentence_iter, found_iter)) {
auto offset=found_iter.get_line_offset(); auto line=get_line_before(found_iter);
tabs.clear(); if(std::regex_match(line, sm, tabs_regex)) {
for(int c=0;c<offset+1;c++) tabs=sm[1].str();
for(int c=0;c<sm[2].str().size()+1;c++)
tabs+=' '; tabs+=' ';
} }
}
else if(std::regex_match(line, sm, no_bracket_statement_regex)) { else if(std::regex_match(line, sm, no_bracket_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+tabs+tab); get_source_buffer()->insert_at_cursor("\n"+tabs+tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());

7
src/window.cc

@ -513,8 +513,13 @@ void Window::new_cpp_project_dialog() {
Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n"); Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n");
return; return;
} }
auto tab_char=Singleton::Config::source()->default_tab_char;
auto tab_size=Singleton::Config::source()->default_tab_size;
std::string tab;
for(unsigned c=0;c<tab_size;c++)
tab+=tab_char;
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";
std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n"+tab+"cout << \"Hello World!\" << endl;\n\n"+tab+"return 0;\n}\n";
if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) { if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) {
directories.open(project_path); directories.open(project_path);
notebook.open(cpp_main_path); notebook.open(cpp_main_path);

Loading…
Cancel
Save