|
|
|
@ -30,7 +30,6 @@ Range(const Source::Range &org) : |
|
|
|
//////////////
|
|
|
|
//////////////
|
|
|
|
Source::View::View() { |
|
|
|
Source::View::View() { |
|
|
|
Gsv::init(); |
|
|
|
Gsv::init(); |
|
|
|
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string Source::View::GetLine(size_t line_number) { |
|
|
|
string Source::View::GetLine(size_t line_number) { |
|
|
|
@ -49,18 +48,6 @@ string Source::View::GetLineBeforeInsert() { |
|
|
|
return line; |
|
|
|
return line; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Source::View::ApplyConfig
|
|
|
|
|
|
|
|
// Applies theme in textview
|
|
|
|
|
|
|
|
void Source::View::ApplyConfig(const Source::Config &config) { |
|
|
|
|
|
|
|
override_font(Pango::FontDescription(config.font)); |
|
|
|
|
|
|
|
set_show_line_numbers(config.show_line_numbers); |
|
|
|
|
|
|
|
set_highlight_current_line(config.highlight_current_line); |
|
|
|
|
|
|
|
this->override_background_color(Gdk::RGBA(config.background)); |
|
|
|
|
|
|
|
for (auto &item : config.tagtable()) { |
|
|
|
|
|
|
|
get_buffer()->create_tag(item.first)->property_foreground() = item.second; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Source::View::Config::tagtable()
|
|
|
|
// Source::View::Config::tagtable()
|
|
|
|
// returns a const refrence to the tagtable
|
|
|
|
// returns a const refrence to the tagtable
|
|
|
|
const std::unordered_map<string, string>& Source::Config::tagtable() const { |
|
|
|
const std::unordered_map<string, string>& Source::Config::tagtable() const { |
|
|
|
@ -105,11 +92,7 @@ SetTagTable(const std::unordered_map<string, string> &tagtable) { |
|
|
|
///////////////
|
|
|
|
///////////////
|
|
|
|
//// Model ////
|
|
|
|
//// Model ////
|
|
|
|
///////////////
|
|
|
|
///////////////
|
|
|
|
Source::Model::Model(const Source::Config &config) : |
|
|
|
void Source::Parser:: |
|
|
|
config_(config) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Source::Model:: |
|
|
|
|
|
|
|
InitSyntaxHighlighting(const std::string &filepath, |
|
|
|
InitSyntaxHighlighting(const std::string &filepath, |
|
|
|
const std::string &project_path, |
|
|
|
const std::string &project_path, |
|
|
|
const std::map<std::string, std::string> |
|
|
|
const std::map<std::string, std::string> |
|
|
|
@ -117,7 +100,7 @@ InitSyntaxHighlighting(const std::string &filepath, |
|
|
|
int start_offset, |
|
|
|
int start_offset, |
|
|
|
int end_offset, |
|
|
|
int end_offset, |
|
|
|
clang::Index *index) { |
|
|
|
clang::Index *index) { |
|
|
|
set_project_path(project_path); |
|
|
|
this->project_path=project_path; |
|
|
|
std::vector<string> arguments = get_compilation_commands(); |
|
|
|
std::vector<string> arguments = get_compilation_commands(); |
|
|
|
tu_ = std::unique_ptr<clang::TranslationUnit>(new clang::TranslationUnit(index, |
|
|
|
tu_ = std::unique_ptr<clang::TranslationUnit>(new clang::TranslationUnit(index, |
|
|
|
filepath, |
|
|
|
filepath, |
|
|
|
@ -133,9 +116,9 @@ OnLineEdit(const std::vector<Source::Range> &locations, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Source::Model::UpdateLine
|
|
|
|
// Source::Model::UpdateLine
|
|
|
|
int Source::Model:: |
|
|
|
int Source::Parser:: |
|
|
|
ReParse(const std::map<std::string, std::string> &buffer) { |
|
|
|
ReParse(const std::map<std::string, std::string> &buffer) { |
|
|
|
return tu_->ReparseTranslationUnit(file_path(), buffer); |
|
|
|
return tu_->ReparseTranslationUnit(file_path, buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -151,8 +134,8 @@ GetAutoCompleteSuggestions(int line_number, |
|
|
|
INFO("Getting auto complete suggestions"); |
|
|
|
INFO("Getting auto complete suggestions"); |
|
|
|
parsing.lock(); |
|
|
|
parsing.lock(); |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
notebook.MapBuffers(&buffers); |
|
|
|
model().GetAutoCompleteSuggestions(buffers, |
|
|
|
parser.GetAutoCompleteSuggestions(buffers, |
|
|
|
line_number, |
|
|
|
line_number, |
|
|
|
column, |
|
|
|
column, |
|
|
|
suggestions); |
|
|
|
suggestions); |
|
|
|
@ -161,14 +144,14 @@ GetAutoCompleteSuggestions(int line_number, |
|
|
|
parsing.unlock(); |
|
|
|
parsing.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Source::Model:: |
|
|
|
void Source::Parser:: |
|
|
|
GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers, |
|
|
|
GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers, |
|
|
|
int line_number, |
|
|
|
int line_number, |
|
|
|
int column, |
|
|
|
int column, |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
*suggestions) { |
|
|
|
*suggestions) { |
|
|
|
clang::CodeCompleteResults results(tu_.get(), |
|
|
|
clang::CodeCompleteResults results(tu_.get(), |
|
|
|
file_path(), |
|
|
|
file_path, |
|
|
|
buffers, |
|
|
|
buffers, |
|
|
|
line_number, |
|
|
|
line_number, |
|
|
|
column); |
|
|
|
column); |
|
|
|
@ -182,33 +165,10 @@ GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// sets the filepath for this mvc
|
|
|
|
std::vector<std::string> Source::Parser:: |
|
|
|
void Source::Model:: |
|
|
|
|
|
|
|
set_file_path(const std::string &file_path) { |
|
|
|
|
|
|
|
file_path_ = file_path; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// sets the project path for this mvc
|
|
|
|
|
|
|
|
void Source::Model:: |
|
|
|
|
|
|
|
set_project_path(const std::string &project_path) { |
|
|
|
|
|
|
|
project_path_ = project_path; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// gets the file_path member
|
|
|
|
|
|
|
|
const std::string& Source::Model::file_path() const { |
|
|
|
|
|
|
|
return file_path_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// gets the project_path member
|
|
|
|
|
|
|
|
const std::string& Source::Model::project_path() const { |
|
|
|
|
|
|
|
return project_path_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// gets the config member
|
|
|
|
|
|
|
|
const Source::Config& Source::Model::config() const { |
|
|
|
|
|
|
|
return config_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> Source::Model:: |
|
|
|
|
|
|
|
get_compilation_commands() { |
|
|
|
get_compilation_commands() { |
|
|
|
clang::CompilationDatabase db(project_path()+"/"); |
|
|
|
clang::CompilationDatabase db(project_path+"/"); |
|
|
|
clang::CompileCommands commands(file_path(), &db); |
|
|
|
clang::CompileCommands commands(file_path, &db); |
|
|
|
std::vector<clang::CompileCommand> cmds = commands.get_commands(); |
|
|
|
std::vector<clang::CompileCommand> cmds = commands.get_commands(); |
|
|
|
std::vector<std::string> arguments; |
|
|
|
std::vector<std::string> arguments; |
|
|
|
for (auto &i : cmds) { |
|
|
|
for (auto &i : cmds) { |
|
|
|
@ -220,11 +180,11 @@ get_compilation_commands() { |
|
|
|
return arguments; |
|
|
|
return arguments; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Source::Range> Source::Model:: |
|
|
|
std::vector<Source::Range> Source::Parser:: |
|
|
|
ExtractTokens(int start_offset, int end_offset) { |
|
|
|
ExtractTokens(int start_offset, int end_offset) { |
|
|
|
std::vector<Source::Range> ranges; |
|
|
|
std::vector<Source::Range> ranges; |
|
|
|
clang::SourceLocation start(tu_.get(), file_path(), start_offset); |
|
|
|
clang::SourceLocation start(tu_.get(), file_path, start_offset); |
|
|
|
clang::SourceLocation end(tu_.get(), file_path(), end_offset); |
|
|
|
clang::SourceLocation end(tu_.get(), file_path, end_offset); |
|
|
|
clang::SourceRange range(&start, &end); |
|
|
|
clang::SourceRange range(&start, &end); |
|
|
|
clang::Tokens tokens(tu_.get(), &range); |
|
|
|
clang::Tokens tokens(tu_.get(), &range); |
|
|
|
std::vector<clang::Token> tks = tokens.tokens(); |
|
|
|
std::vector<clang::Token> tks = tokens.tokens(); |
|
|
|
@ -240,7 +200,7 @@ ExtractTokens(int start_offset, int end_offset) { |
|
|
|
return ranges; |
|
|
|
return ranges; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Source::Model:: |
|
|
|
void Source::Parser:: |
|
|
|
HighlightCursor(clang::Token *token, |
|
|
|
HighlightCursor(clang::Token *token, |
|
|
|
std::vector<Source::Range> *source_ranges) { |
|
|
|
std::vector<Source::Range> *source_ranges) { |
|
|
|
clang::SourceLocation location = token->get_source_location(tu_.get()); |
|
|
|
clang::SourceLocation location = token->get_source_location(tu_.get()); |
|
|
|
@ -256,7 +216,7 @@ HighlightCursor(clang::Token *token, |
|
|
|
Source::Location(end_line_num, |
|
|
|
Source::Location(end_line_num, |
|
|
|
end_offset), (int) cursor.kind()); |
|
|
|
end_offset), (int) cursor.kind()); |
|
|
|
} |
|
|
|
} |
|
|
|
void Source::Model:: |
|
|
|
void Source::Parser:: |
|
|
|
HighlightToken(clang::Token *token, |
|
|
|
HighlightToken(clang::Token *token, |
|
|
|
std::vector<Source::Range> *source_ranges, |
|
|
|
std::vector<Source::Range> *source_ranges, |
|
|
|
int token_kind) { |
|
|
|
int token_kind) { |
|
|
|
@ -279,10 +239,18 @@ HighlightToken(clang::Token *token, |
|
|
|
// Source::Controller::Controller()
|
|
|
|
// Source::Controller::Controller()
|
|
|
|
// Constructor for Controller
|
|
|
|
// Constructor for Controller
|
|
|
|
Source::Controller::Controller(const Source::Config &config, |
|
|
|
Source::Controller::Controller(const Source::Config &config, |
|
|
|
Notebook::Controller *notebook) : |
|
|
|
Notebook::Controller ¬ebook) : |
|
|
|
model_(config), notebook_(notebook) { |
|
|
|
config(config), notebook(notebook) { |
|
|
|
INFO("Source Controller with childs constructed"); |
|
|
|
INFO("Source Controller with childs constructed"); |
|
|
|
view().signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::OnKeyPress), false); |
|
|
|
view.signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::OnKeyPress), false); |
|
|
|
|
|
|
|
view.set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); |
|
|
|
|
|
|
|
view.override_font(Pango::FontDescription(config.font)); |
|
|
|
|
|
|
|
view.set_show_line_numbers(config.show_line_numbers); |
|
|
|
|
|
|
|
view.set_highlight_current_line(config.highlight_current_line); |
|
|
|
|
|
|
|
view.override_background_color(Gdk::RGBA(config.background)); |
|
|
|
|
|
|
|
for (auto &item : config.tagtable()) { |
|
|
|
|
|
|
|
buffer()->create_tag(item.first)->property_foreground() = item.second; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Source::Controller::~Controller() { |
|
|
|
Source::Controller::~Controller() { |
|
|
|
@ -290,29 +258,14 @@ Source::Controller::~Controller() { |
|
|
|
parsing.unlock(); |
|
|
|
parsing.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Source::Controller::view()
|
|
|
|
|
|
|
|
// return shared_ptr to the view
|
|
|
|
|
|
|
|
Source::View& Source::Controller::view() { |
|
|
|
|
|
|
|
return view_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Source::Controller::model()
|
|
|
|
|
|
|
|
// return shared_ptr to the model()
|
|
|
|
|
|
|
|
Source::Model& Source::Controller::model() { |
|
|
|
|
|
|
|
return model_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Source::Controller::OnNewEmptyFile() { |
|
|
|
void Source::Controller::OnNewEmptyFile() { |
|
|
|
string filename("/tmp/juci_t"); |
|
|
|
string filename("/tmp/juci_t"); |
|
|
|
sourcefile s(filename); |
|
|
|
sourcefile s(filename); |
|
|
|
model().set_file_path(filename); |
|
|
|
parser.file_path=filename; |
|
|
|
model().set_project_path(filename); |
|
|
|
parser.project_path=filename; |
|
|
|
s.save(""); |
|
|
|
s.save(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string extract_file_path(const std::string &file_path) { |
|
|
|
|
|
|
|
return file_path.substr(0, file_path.find_last_of('/')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges, |
|
|
|
void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges, |
|
|
|
const Source::Config &config) { |
|
|
|
const Source::Config &config) { |
|
|
|
if (ranges.empty() || ranges.size() == 0) { |
|
|
|
if (ranges.empty() || ranges.size() == 0) { |
|
|
|
@ -344,34 +297,31 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
set_file_path(filepath); |
|
|
|
parser.file_path=filepath; |
|
|
|
sourcefile s(filepath); |
|
|
|
sourcefile s(filepath); |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
notebook.MapBuffers(&buffers); |
|
|
|
buffers[filepath] = s.get_content(); |
|
|
|
buffers[filepath] = s.get_content(); |
|
|
|
buffer()->get_undo_manager()->begin_not_undoable_action(); |
|
|
|
buffer()->get_undo_manager()->begin_not_undoable_action(); |
|
|
|
buffer()->set_text(s.get_content()); |
|
|
|
buffer()->set_text(s.get_content()); |
|
|
|
buffer()->get_undo_manager()->end_not_undoable_action(); |
|
|
|
buffer()->get_undo_manager()->end_not_undoable_action(); |
|
|
|
int start_offset = buffer()->begin().get_offset(); |
|
|
|
int start_offset = buffer()->begin().get_offset(); |
|
|
|
int end_offset = buffer()->end().get_offset(); |
|
|
|
int end_offset = buffer()->end().get_offset(); |
|
|
|
view().ApplyConfig(model().config()); |
|
|
|
if (notebook.LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) { |
|
|
|
if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) { |
|
|
|
parser.InitSyntaxHighlighting(filepath, |
|
|
|
model().InitSyntaxHighlighting(filepath, |
|
|
|
parser.file_path.substr(0, parser.file_path.find_last_of('/')), |
|
|
|
extract_file_path(filepath), |
|
|
|
|
|
|
|
buffers, |
|
|
|
buffers, |
|
|
|
start_offset, |
|
|
|
start_offset, |
|
|
|
end_offset, |
|
|
|
end_offset, |
|
|
|
notebook_->index()); |
|
|
|
notebook.index()); |
|
|
|
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), |
|
|
|
view.OnUpdateSyntax(parser.ExtractTokens(start_offset, end_offset), config); |
|
|
|
model().config()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//OnUpdateSyntax must happen in main thread, so the parse-thread
|
|
|
|
//OnUpdateSyntax must happen in main thread, so the parse-thread
|
|
|
|
//sends a signal to the main thread that it is to call the following function:
|
|
|
|
//sends a signal to the main thread that it is to call the following function:
|
|
|
|
parsing_done.connect([this](){ |
|
|
|
parsing_done.connect([this](){ |
|
|
|
INFO("Updating syntax"); |
|
|
|
INFO("Updating syntax"); |
|
|
|
view(). |
|
|
|
view. |
|
|
|
OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), |
|
|
|
OnUpdateSyntax(parser.ExtractTokens(0, buffer()->get_text().size()), config); |
|
|
|
model().config()); |
|
|
|
|
|
|
|
INFO("Syntax updated"); |
|
|
|
INFO("Syntax updated"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -382,9 +332,9 @@ void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
const std::string raw = buffer()->get_text().raw(); |
|
|
|
const std::string raw = buffer()->get_text().raw(); |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
notebook.MapBuffers(&buffers); |
|
|
|
buffers[model().file_path()] = raw; |
|
|
|
buffers[parser.file_path] = raw; |
|
|
|
if (model().ReParse(buffers) == 0 && |
|
|
|
if (parser.ReParse(buffers) == 0 && |
|
|
|
raw == buffer()->get_text().raw()) { |
|
|
|
raw == buffer()->get_text().raw()) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -400,7 +350,7 @@ void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Glib::RefPtr<Gsv::Buffer> Source::Controller::buffer() { |
|
|
|
Glib::RefPtr<Gsv::Buffer> Source::Controller::buffer() { |
|
|
|
return view().get_source_buffer(); |
|
|
|
return view.get_source_buffer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
@ -411,44 +361,44 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
|
|
|
|
|
|
|
|
//Indent as in previous line, and indent right after if/else/etc
|
|
|
|
//Indent as in previous line, and indent right after if/else/etc
|
|
|
|
if(key->keyval==GDK_KEY_Return && key->state==0) { |
|
|
|
if(key->keyval==GDK_KEY_Return && key->state==0) { |
|
|
|
string line(view().GetLineBeforeInsert()); |
|
|
|
string line(view.GetLineBeforeInsert()); |
|
|
|
std::smatch sm; |
|
|
|
std::smatch sm; |
|
|
|
if(std::regex_match(line, sm, bracket_regex)) { |
|
|
|
if(std::regex_match(line, sm, bracket_regex)) { |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+model().config().tab+"\n"+sm[1].str()+"}"); |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab+"\n"+sm[1].str()+"}"); |
|
|
|
auto insert_it = buffer()->get_insert()->get_iter(); |
|
|
|
auto insert_it = buffer()->get_insert()->get_iter(); |
|
|
|
for(size_t c=0;c<model().config().tab_size+sm[1].str().size();c++) |
|
|
|
for(size_t c=0;c<config.tab_size+sm[1].str().size();c++) |
|
|
|
insert_it--; |
|
|
|
insert_it--; |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
buffer()->place_cursor(insert_it); |
|
|
|
buffer()->place_cursor(insert_it); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(std::regex_match(line, sm, no_bracket_statement_regex)) { |
|
|
|
else if(std::regex_match(line, sm, no_bracket_statement_regex)) { |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+model().config().tab); |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab); |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) { |
|
|
|
else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) { |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+model().config().tab); |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab); |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(std::regex_match(line, sm, spaces_regex)) { |
|
|
|
else if(std::regex_match(line, sm, spaces_regex)) { |
|
|
|
std::smatch sm2; |
|
|
|
std::smatch sm2; |
|
|
|
size_t line_nr=buffer()->get_insert()->get_iter().get_line(); |
|
|
|
size_t line_nr=buffer()->get_insert()->get_iter().get_line(); |
|
|
|
if(line_nr>0 && sm[1].str().size()>=model().config().tab_size) { |
|
|
|
if(line_nr>0 && sm[1].str().size()>=config.tab_size) { |
|
|
|
string previous_line=view().GetLine(line_nr-1); |
|
|
|
string previous_line=view.GetLine(line_nr-1); |
|
|
|
if(!std::regex_match(previous_line, sm2, bracket_regex)) { |
|
|
|
if(!std::regex_match(previous_line, sm2, bracket_regex)) { |
|
|
|
if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) { |
|
|
|
if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) { |
|
|
|
buffer()->insert_at_cursor("\n"+sm2[1].str()); |
|
|
|
buffer()->insert_at_cursor("\n"+sm2[1].str()); |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if(std::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) { |
|
|
|
else if(std::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) { |
|
|
|
buffer()->insert_at_cursor("\n"+sm2[1].str()); |
|
|
|
buffer()->insert_at_cursor("\n"+sm2[1].str()); |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()); |
|
|
|
buffer()->insert_at_cursor("\n"+sm[1].str()); |
|
|
|
view().scroll_to(buffer()->get_insert()); |
|
|
|
view.scroll_to(buffer()->get_insert()); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -460,7 +410,7 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
int line_end=selection_end.get_line(); |
|
|
|
int line_end=selection_end.get_line(); |
|
|
|
for(int line=line_start;line<=line_end;line++) { |
|
|
|
for(int line=line_start;line<=line_end;line++) { |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(line); |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(line); |
|
|
|
buffer()->insert(line_it, model().config().tab); |
|
|
|
buffer()->insert(line_it, config.tab); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -472,8 +422,8 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
int line_end=selection_end.get_line(); |
|
|
|
int line_end=selection_end.get_line(); |
|
|
|
|
|
|
|
|
|
|
|
for(int line_nr=line_start;line_nr<=line_end;line_nr++) { |
|
|
|
for(int line_nr=line_start;line_nr<=line_end;line_nr++) { |
|
|
|
string line=view().GetLine(line_nr); |
|
|
|
string line=view.GetLine(line_nr); |
|
|
|
if(!(line.size()>=model().config().tab_size && line.substr(0, model().config().tab_size)==model().config().tab)) |
|
|
|
if(!(line.size()>=config.tab_size && line.substr(0, config.tab_size)==config.tab)) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -481,7 +431,7 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(line_nr); |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(line_nr); |
|
|
|
Gtk::TextIter line_plus_it=line_it; |
|
|
|
Gtk::TextIter line_plus_it=line_it; |
|
|
|
|
|
|
|
|
|
|
|
for(unsigned c=0;c<model().config().tab_size;c++) |
|
|
|
for(unsigned c=0;c<config.tab_size;c++) |
|
|
|
line_plus_it++; |
|
|
|
line_plus_it++; |
|
|
|
buffer()->erase(line_it, line_plus_it); |
|
|
|
buffer()->erase(line_it, line_plus_it); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -489,8 +439,8 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
} |
|
|
|
} |
|
|
|
//Indent left when writing } on a new line
|
|
|
|
//Indent left when writing } on a new line
|
|
|
|
else if(key->keyval==GDK_KEY_braceright) { |
|
|
|
else if(key->keyval==GDK_KEY_braceright) { |
|
|
|
string line=view().GetLineBeforeInsert(); |
|
|
|
string line=view.GetLineBeforeInsert(); |
|
|
|
if(line.size()>=model().config().tab_size) { |
|
|
|
if(line.size()>=config.tab_size) { |
|
|
|
for(auto c: line) { |
|
|
|
for(auto c: line) { |
|
|
|
if(c!=' ') |
|
|
|
if(c!=' ') |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
@ -498,7 +448,7 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
Gtk::TextIter insert_it = buffer()->get_insert()->get_iter(); |
|
|
|
Gtk::TextIter insert_it = buffer()->get_insert()->get_iter(); |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(insert_it.get_line()); |
|
|
|
Gtk::TextIter line_it = buffer()->get_iter_at_line(insert_it.get_line()); |
|
|
|
Gtk::TextIter line_plus_it=line_it; |
|
|
|
Gtk::TextIter line_plus_it=line_it; |
|
|
|
for(unsigned c=0;c<model().config().tab_size;c++) |
|
|
|
for(unsigned c=0;c<config.tab_size;c++) |
|
|
|
line_plus_it++; |
|
|
|
line_plus_it++; |
|
|
|
|
|
|
|
|
|
|
|
buffer()->erase(line_it, line_plus_it); |
|
|
|
buffer()->erase(line_it, line_plus_it); |
|
|
|
@ -510,8 +460,8 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { |
|
|
|
Gtk::TextIter insert_it=buffer()->get_insert()->get_iter(); |
|
|
|
Gtk::TextIter insert_it=buffer()->get_insert()->get_iter(); |
|
|
|
int line_nr=insert_it.get_line(); |
|
|
|
int line_nr=insert_it.get_line(); |
|
|
|
if(line_nr>0) { |
|
|
|
if(line_nr>0) { |
|
|
|
string line=view().GetLine(line_nr); |
|
|
|
string line=view.GetLine(line_nr); |
|
|
|
string previous_line=view().GetLine(line_nr-1); |
|
|
|
string previous_line=view.GetLine(line_nr-1); |
|
|
|
smatch sm; |
|
|
|
smatch sm; |
|
|
|
if(std::regex_match(previous_line, sm, spaces_regex)) { |
|
|
|
if(std::regex_match(previous_line, sm, spaces_regex)) { |
|
|
|
if(line==sm[1]) { |
|
|
|
if(line==sm[1]) { |
|
|
|
|