Browse Source

Merge pull request #148 from eidheim/master

Better support for Allman bracket style (break before bracket)
merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
6205b2baa8
  1. 8
      src/selectiondialog.cc
  2. 2
      src/selectiondialog.h
  3. 18
      src/source.cc
  4. 27
      src/source_clang.cc

8
src/selectiondialog.cc

@ -38,8 +38,7 @@ void ListViewText::append(const std::string& value) {
new_row->set_value(column_record.text, value); new_row->set_value(column_record.text, value);
} }
void ListViewText::hide() { void ListViewText::clear() {
Gtk::TreeView::hide();
list_store->clear(); list_store->clear();
} }
@ -101,11 +100,14 @@ void SelectionDialogBase::show() {
} }
void SelectionDialogBase::hide() { void SelectionDialogBase::hide() {
if(!shown)
return;
window->hide(); window->hide();
if(tooltips) if(tooltips)
tooltips->hide(); tooltips->hide();
if(on_hide && shown) if(on_hide)
on_hide(); on_hide();
list_view_text.clear();
shown=false; shown=false;
} }

2
src/selectiondialog.h

@ -18,7 +18,7 @@ public:
bool use_markup; bool use_markup;
ListViewText(bool use_markup); ListViewText(bool use_markup);
void append(const std::string& value); void append(const std::string& value);
void hide(); void clear();
private: private:
Glib::RefPtr<Gtk::ListStore> list_store; Glib::RefPtr<Gtk::ListStore> list_store;
ColumnRecord column_record; ColumnRecord column_record;

18
src/source.cc

@ -217,7 +217,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
return; return;
if(mark->get_name()=="insert") { if(mark->get_name()=="insert") {
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) if(spellcheck_suggestions_dialog)
spellcheck_suggestions_dialog->hide(); spellcheck_suggestions_dialog->hide();
delayed_spellcheck_suggestions_connection.disconnect(); delayed_spellcheck_suggestions_connection.disconnect();
delayed_spellcheck_suggestions_connection=Glib::signal_timeout().connect([this]() { delayed_spellcheck_suggestions_connection=Glib::signal_timeout().connect([this]() {
@ -429,11 +429,11 @@ void Source::View::set_tooltip_and_dialog_events() {
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) if(spellcheck_suggestions_dialog)
spellcheck_suggestions_dialog->hide(); spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown) if(autocomplete_dialog)
autocomplete_dialog->hide(); autocomplete_dialog->hide();
if(selection_dialog && selection_dialog->shown) if(selection_dialog)
selection_dialog->hide(); selection_dialog->hide();
set_info(info); set_info(info);
@ -445,11 +445,11 @@ void Source::View::set_tooltip_and_dialog_events() {
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect(); delayed_spellcheck_suggestions_connection.disconnect();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) if(spellcheck_suggestions_dialog)
spellcheck_suggestions_dialog->hide(); spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown) if(autocomplete_dialog)
autocomplete_dialog->hide(); autocomplete_dialog->hide();
if(selection_dialog && selection_dialog->shown) if(selection_dialog)
selection_dialog->hide(); selection_dialog->hide();
return false; return false;
}); });
@ -459,9 +459,9 @@ void Source::View::set_tooltip_and_dialog_events() {
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect(); delayed_spellcheck_suggestions_connection.disconnect();
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) if(spellcheck_suggestions_dialog)
spellcheck_suggestions_dialog->hide(); spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog && autocomplete_dialog->shown) if(autocomplete_dialog)
autocomplete_dialog->hide(); autocomplete_dialog->hide();
return false; return false;
}); });

27
src/source_clang.cc

@ -99,8 +99,8 @@ void Source::ClangViewParse::configure() {
} }
bracket_regex=boost::regex("^([ \\t]*).*\\{ *$"); bracket_regex=boost::regex("^([ \\t]*).*\\{ *$");
no_bracket_statement_regex=boost::regex("^([ \\t]*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); no_bracket_statement_regex=boost::regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$");
no_bracket_no_para_statement_regex=boost::regex("^([ \\t]*)(else|try|do) *$"); no_bracket_no_para_statement_regex=boost::regex("^([ \\t]*)(else) *$");
} }
void Source::ClangViewParse::parse_initialize() { void Source::ClangViewParse::parse_initialize() {
@ -605,6 +605,29 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return true; return true;
} }
//Indent left when writing { on a new line after for instance if(...)\n...
else if(key->keyval==GDK_KEY_braceleft) {
auto iter=get_buffer()->get_insert()->get_iter();
auto tabs_end_iter=get_tabs_end_iter();
auto tabs=get_line_before(tabs_end_iter);
size_t line_nr=iter.get_line();
if(line_nr>0 && tabs.size()>=tab_size && iter==tabs_end_iter) {
std::string previous_line=get_line(line_nr-1);
boost::smatch sm;
if(!boost::regex_match(previous_line, sm, bracket_regex)) {
auto start_iter=iter;
start_iter.backward_chars(tab_size);
if(boost::regex_match(previous_line, sm, no_bracket_statement_regex) ||
boost::regex_match(previous_line, sm, no_bracket_no_para_statement_regex)) {
get_buffer()->erase(start_iter, iter);
get_buffer()->insert_at_cursor("{");
scroll_to(get_buffer()->get_insert());
get_buffer()->end_user_action();
return true;
}
}
}
}
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return Source::View::on_key_press_event(key); return Source::View::on_key_press_event(key);

Loading…
Cancel
Save