@ -78,120 +78,24 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
//TODO: (gtkmm's Gtk::Object has connect_property_changed, so subclassing this might be an idea)
//TODO: (gtkmm's Gtk::Object has connect_property_changed, so subclassing this might be an idea)
g_signal_connect ( search_context , " notify::occurrences-count " , G_CALLBACK ( search_occurrences_updated ) , this ) ;
g_signal_connect ( search_context , " notify::occurrences-count " , G_CALLBACK ( search_occurrences_updated ) , this ) ;
//TODO: Move this to notebook? Might take up too much memory doing this for every tab.
get_buffer ( ) - > create_tag ( " def:warning " ) ;
auto style_scheme_manager = Gsv : : StyleSchemeManager : : get_default ( ) ;
get_buffer ( ) - > create_tag ( " def:warning_underline " ) ;
style_scheme_manager - > prepend_search_path ( Singleton : : style_dir ( ) ) ;
get_buffer ( ) - > create_tag ( " def:error " ) ;
get_buffer ( ) - > create_tag ( " def:error_underline " ) ;
if ( Singleton : : Config : : source ( ) - > style . size ( ) > 0 ) {
get_buffer ( ) - > create_tag ( " def:note_background " ) ;
auto scheme = style_scheme_manager - > get_scheme ( Singleton : : Config : : source ( ) - > style ) ;
get_buffer ( ) - > create_tag ( " def:note " ) ;
if ( spellcheck_config = = NULL )
if ( scheme )
get_source_buffer ( ) - > set_style_scheme ( scheme ) ;
else
Singleton : : terminal ( ) - > print ( " Error: Could not find gtksourceview style: " + Singleton : : Config : : source ( ) - > style + ' \n ' ) ;
}
if ( Singleton : : Config : : source ( ) - > wrap_lines )
set_wrap_mode ( Gtk : : WrapMode : : WRAP_CHAR ) ;
property_highlight_current_line ( ) = Singleton : : Config : : source ( ) - > highlight_current_line ;
property_show_line_numbers ( ) = Singleton : : Config : : source ( ) - > show_line_numbers ;
if ( Singleton : : Config : : source ( ) - > font . size ( ) > 0 )
override_font ( Pango : : FontDescription ( Singleton : : Config : : source ( ) - > font ) ) ;
//Create tags for diagnostic warnings and errors:
auto scheme = get_source_buffer ( ) - > get_style_scheme ( ) ;
auto tag_table = get_buffer ( ) - > get_tag_table ( ) ;
auto style = scheme - > get_style ( " def:warning " ) ;
auto diagnostic_tag = get_source_buffer ( ) - > create_tag ( " def:warning " ) ;
auto diagnostic_tag_underline = get_source_buffer ( ) - > create_tag ( " def:warning_underline " ) ;
if ( style & & ( style - > property_foreground_set ( ) | | style - > property_background_set ( ) ) ) {
Glib : : ustring warning_property ;
if ( style - > property_foreground_set ( ) ) {
warning_property = style - > property_foreground ( ) . get_value ( ) ;
diagnostic_tag - > property_foreground ( ) = warning_property ;
}
else if ( style - > property_background_set ( ) )
warning_property = style - > property_background ( ) . get_value ( ) ;
diagnostic_tag_underline - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
auto tag_class = G_OBJECT_GET_CLASS ( diagnostic_tag_underline - > gobj ( ) ) ; //For older GTK+ 3 versions:
auto param_spec = g_object_class_find_property ( tag_class , " underline-rgba " ) ;
if ( param_spec ! = NULL ) {
diagnostic_tag_underline - > set_property ( " underline-rgba " , Gdk : : RGBA ( warning_property ) ) ;
}
}
style = scheme - > get_style ( " def:error " ) ;
diagnostic_tag = get_source_buffer ( ) - > create_tag ( " def:error " ) ;
diagnostic_tag_underline = get_source_buffer ( ) - > create_tag ( " def:error_underline " ) ;
if ( style & & ( style - > property_foreground_set ( ) | | style - > property_background_set ( ) ) ) {
Glib : : ustring error_property ;
if ( style - > property_foreground_set ( ) ) {
error_property = style - > property_foreground ( ) . get_value ( ) ;
diagnostic_tag - > property_foreground ( ) = error_property ;
}
else if ( style - > property_background_set ( ) )
error_property = style - > property_background ( ) . get_value ( ) ;
diagnostic_tag_underline - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
auto tag_class = G_OBJECT_GET_CLASS ( diagnostic_tag_underline - > gobj ( ) ) ; //For older GTK+ 3 versions:
auto param_spec = g_object_class_find_property ( tag_class , " underline-rgba " ) ;
if ( param_spec ! = NULL ) {
diagnostic_tag_underline - > set_property ( " underline-rgba " , Gdk : : RGBA ( error_property ) ) ;
}
}
//TODO: clear tag_class and param_spec?
//Add tooltip foreground and background
style = scheme - > get_style ( " def:note " ) ;
auto note_tag = get_source_buffer ( ) - > create_tag ( " def:note_background " ) ;
if ( style - > property_background_set ( ) ) {
note_tag - > property_background ( ) = style - > property_background ( ) ;
}
note_tag = get_source_buffer ( ) - > create_tag ( " def:note " ) ;
if ( style - > property_foreground_set ( ) ) {
note_tag - > property_foreground ( ) = style - > property_foreground ( ) ;
}
tab_char = Singleton : : Config : : source ( ) - > default_tab_char ;
tab_size = Singleton : : Config : : source ( ) - > default_tab_size ;
if ( Singleton : : Config : : source ( ) - > auto_tab_char_and_size ) {
auto tab_char_and_size = find_tab_char_and_size ( ) ;
if ( tab_char_and_size . first ! = 0 ) {
if ( tab_char ! = tab_char_and_size . first | | tab_size ! = tab_char_and_size . second ) {
std : : string tab_str ;
if ( tab_char_and_size . first = = ' ' )
tab_str = " <space> " ;
else
tab_str = " <tab> " ;
Singleton : : terminal ( ) - > print ( " Tab char and size for file " + file_path . string ( ) + " set to: " + tab_str + " , " + boost : : lexical_cast < std : : string > ( tab_char_and_size . second ) + " . \n " ) ;
}
tab_char = tab_char_and_size . first ;
tab_size = tab_char_and_size . second ;
}
}
for ( unsigned c = 0 ; c < tab_size ; c + + )
tab + = tab_char ;
tabs_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(.*)$ " ) ;
if ( spellcheck_config = = NULL ) {
spellcheck_config = new_aspell_config ( ) ;
spellcheck_config = new_aspell_config ( ) ;
if ( Singleton : : Config : : source ( ) - > spellcheck_language . size ( ) > 0 )
aspell_config_replace ( spellcheck_config , " lang " , Singleton : : Config : : source ( ) - > spellcheck_language . c_str ( ) ) ;
}
spellcheck_possible_err = new_aspell_speller ( spellcheck_config ) ;
spellcheck_checker = NULL ;
spellcheck_checker = NULL ;
if ( aspell_error_number ( spellcheck_possible_err ) ! = 0 )
std : : cerr < < " Spell check error: " < < aspell_error_message ( spellcheck_possible_err ) < < std : : endl ;
else {
spellcheck_checker = to_aspell_speller ( spellcheck_possible_err ) ;
auto tag = get_buffer ( ) - > create_tag ( " spellcheck_error " ) ;
auto tag = get_buffer ( ) - > create_tag ( " spellcheck_error " ) ;
tag - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
tag - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
configure ( ) ;
get_buffer ( ) - > signal_changed ( ) . connect ( [ this ] ( ) {
get_buffer ( ) - > signal_changed ( ) . connect ( [ this ] ( ) {
if ( spellcheck_checker = = NULL )
return ;
delayed_spellcheck_suggestions_connection . disconnect ( ) ;
delayed_spellcheck_suggestions_connection . disconnect ( ) ;
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
auto iter = get_buffer ( ) - > get_insert ( ) - > get_iter ( ) ;
@ -225,8 +129,25 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
delayed_spellcheck_error_clear . disconnect ( ) ;
delayed_spellcheck_error_clear . disconnect ( ) ;
delayed_spellcheck_error_clear = Glib : : signal_timeout ( ) . connect ( [ this ] ( ) {
delayed_spellcheck_error_clear = Glib : : signal_timeout ( ) . connect ( [ this ] ( ) {
auto iter = get_buffer ( ) - > begin ( ) ;
auto iter = get_buffer ( ) - > begin ( ) ;
bool spell_check = get_source_buffer ( ) - > iter_has_context_class ( iter , " string " ) | | get_source_buffer ( ) - > iter_has_context_class ( iter , " comment " ) ;
Gtk : : TextIter begin_no_spellcheck_iter ;
Gtk : : TextIter begin_no_spellcheck_iter ;
if ( spellcheck_all ) {
bool spell_check = ! get_source_buffer ( ) - > iter_has_context_class ( iter , " no-spell-check " ) ;
if ( ! spell_check )
begin_no_spellcheck_iter = iter ;
while ( iter ! = get_buffer ( ) - > end ( ) ) {
if ( ! get_source_buffer ( ) - > iter_forward_to_context_class_toggle ( iter , " no-spell-check " ) )
iter = get_buffer ( ) - > end ( ) ;
spell_check = ! spell_check ;
if ( ! spell_check )
begin_no_spellcheck_iter = iter ;
else
get_buffer ( ) - > remove_tag_by_name ( " spellcheck_error " , begin_no_spellcheck_iter , iter ) ;
}
return false ;
}
bool spell_check = get_source_buffer ( ) - > iter_has_context_class ( iter , " string " ) | | get_source_buffer ( ) - > iter_has_context_class ( iter , " comment " ) ;
if ( ! spell_check )
if ( ! spell_check )
begin_no_spellcheck_iter = iter ;
begin_no_spellcheck_iter = iter ;
while ( iter ! = get_buffer ( ) - > end ( ) ) {
while ( iter ! = get_buffer ( ) - > end ( ) ) {
@ -252,6 +173,9 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
} ) ;
} ) ;
get_buffer ( ) - > signal_mark_set ( ) . connect ( [ this ] ( const Gtk : : TextBuffer : : iterator & iter , const Glib : : RefPtr < Gtk : : TextBuffer : : Mark > & mark ) {
get_buffer ( ) - > signal_mark_set ( ) . connect ( [ this ] ( const Gtk : : TextBuffer : : iterator & iter , const Glib : : RefPtr < Gtk : : TextBuffer : : Mark > & mark ) {
if ( spellcheck_checker = = NULL )
return ;
if ( mark - > get_name ( ) = = " insert " ) {
if ( mark - > get_name ( ) = = " insert " ) {
if ( spellcheck_suggestions_dialog_shown )
if ( spellcheck_suggestions_dialog_shown )
spellcheck_suggestions_dialog - > hide ( ) ;
spellcheck_suggestions_dialog - > hide ( ) ;
@ -290,7 +214,6 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
} , 500 ) ;
} , 500 ) ;
}
}
} ) ;
} ) ;
}
get_buffer ( ) - > signal_changed ( ) . connect ( [ this ] ( ) {
get_buffer ( ) - > signal_changed ( ) . connect ( [ this ] ( ) {
set_info ( info ) ;
set_info ( info ) ;
@ -299,6 +222,120 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
set_tooltip_events ( ) ;
set_tooltip_events ( ) ;
}
}
void Source : : View : : configure ( ) {
//TODO: Move this to notebook? Might take up too much memory doing this for every tab.
auto style_scheme_manager = Gsv : : StyleSchemeManager : : get_default ( ) ;
style_scheme_manager - > prepend_search_path ( Singleton : : style_dir ( ) ) ;
if ( Singleton : : Config : : source ( ) - > style . size ( ) > 0 ) {
auto scheme = style_scheme_manager - > get_scheme ( Singleton : : Config : : source ( ) - > style ) ;
if ( scheme )
get_source_buffer ( ) - > set_style_scheme ( scheme ) ;
else
Singleton : : terminal ( ) - > print ( " Error: Could not find gtksourceview style: " + Singleton : : Config : : source ( ) - > style + ' \n ' ) ;
}
if ( Singleton : : Config : : source ( ) - > wrap_lines )
set_wrap_mode ( Gtk : : WrapMode : : WRAP_CHAR ) ;
else
set_wrap_mode ( Gtk : : WrapMode : : WRAP_NONE ) ;
property_highlight_current_line ( ) = Singleton : : Config : : source ( ) - > highlight_current_line ;
property_show_line_numbers ( ) = Singleton : : Config : : source ( ) - > show_line_numbers ;
if ( Singleton : : Config : : source ( ) - > font . size ( ) > 0 )
override_font ( Pango : : FontDescription ( Singleton : : Config : : source ( ) - > font ) ) ;
//Create tags for diagnostic warnings and errors:
auto scheme = get_source_buffer ( ) - > get_style_scheme ( ) ;
auto tag_table = get_buffer ( ) - > get_tag_table ( ) ;
auto style = scheme - > get_style ( " def:warning " ) ;
auto diagnostic_tag = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:warning " ) ;
auto diagnostic_tag_underline = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:warning_underline " ) ;
if ( style & & ( style - > property_foreground_set ( ) | | style - > property_background_set ( ) ) ) {
Glib : : ustring warning_property ;
if ( style - > property_foreground_set ( ) ) {
warning_property = style - > property_foreground ( ) . get_value ( ) ;
diagnostic_tag - > property_foreground ( ) = warning_property ;
}
else if ( style - > property_background_set ( ) )
warning_property = style - > property_background ( ) . get_value ( ) ;
diagnostic_tag_underline - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
auto tag_class = G_OBJECT_GET_CLASS ( diagnostic_tag_underline - > gobj ( ) ) ; //For older GTK+ 3 versions:
auto param_spec = g_object_class_find_property ( tag_class , " underline-rgba " ) ;
if ( param_spec ! = NULL ) {
diagnostic_tag_underline - > set_property ( " underline-rgba " , Gdk : : RGBA ( warning_property ) ) ;
}
}
style = scheme - > get_style ( " def:error " ) ;
diagnostic_tag = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:error " ) ;
diagnostic_tag_underline = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:error_underline " ) ;
if ( style & & ( style - > property_foreground_set ( ) | | style - > property_background_set ( ) ) ) {
Glib : : ustring error_property ;
if ( style - > property_foreground_set ( ) ) {
error_property = style - > property_foreground ( ) . get_value ( ) ;
diagnostic_tag - > property_foreground ( ) = error_property ;
}
else if ( style - > property_background_set ( ) )
error_property = style - > property_background ( ) . get_value ( ) ;
diagnostic_tag_underline - > property_underline ( ) = Pango : : Underline : : UNDERLINE_ERROR ;
auto tag_class = G_OBJECT_GET_CLASS ( diagnostic_tag_underline - > gobj ( ) ) ; //For older GTK+ 3 versions:
auto param_spec = g_object_class_find_property ( tag_class , " underline-rgba " ) ;
if ( param_spec ! = NULL ) {
diagnostic_tag_underline - > set_property ( " underline-rgba " , Gdk : : RGBA ( error_property ) ) ;
}
}
//TODO: clear tag_class and param_spec?
//Add tooltip foreground and background
style = scheme - > get_style ( " def:note " ) ;
auto note_tag = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:note_background " ) ;
if ( style - > property_background_set ( ) ) {
note_tag - > property_background ( ) = style - > property_background ( ) ;
}
note_tag = get_buffer ( ) - > get_tag_table ( ) - > lookup ( " def:note " ) ;
if ( style - > property_foreground_set ( ) ) {
note_tag - > property_foreground ( ) = style - > property_foreground ( ) ;
}
if ( Singleton : : Config : : source ( ) - > spellcheck_language . size ( ) > 0 )
aspell_config_replace ( spellcheck_config , " lang " , Singleton : : Config : : source ( ) - > spellcheck_language . c_str ( ) ) ;
spellcheck_possible_err = new_aspell_speller ( spellcheck_config ) ;
if ( spellcheck_checker ! = NULL )
delete_aspell_speller ( spellcheck_checker ) ;
spellcheck_checker = NULL ;
if ( aspell_error_number ( spellcheck_possible_err ) ! = 0 )
std : : cerr < < " Spell check error: " < < aspell_error_message ( spellcheck_possible_err ) < < std : : endl ;
else
spellcheck_checker = to_aspell_speller ( spellcheck_possible_err ) ;
get_buffer ( ) - > remove_tag_by_name ( " spellcheck_error " , get_buffer ( ) - > begin ( ) , get_buffer ( ) - > end ( ) ) ;
tab_char = Singleton : : Config : : source ( ) - > default_tab_char ;
tab_size = Singleton : : Config : : source ( ) - > default_tab_size ;
if ( Singleton : : Config : : source ( ) - > auto_tab_char_and_size ) {
auto tab_char_and_size = find_tab_char_and_size ( ) ;
if ( tab_char_and_size . first ! = 0 ) {
if ( tab_char ! = tab_char_and_size . first | | tab_size ! = tab_char_and_size . second ) {
std : : string tab_str ;
if ( tab_char_and_size . first = = ' ' )
tab_str = " <space> " ;
else
tab_str = " <tab> " ;
Singleton : : terminal ( ) - > print ( " Tab char and size for file " + file_path . string ( ) + " set to: " + tab_str + " , " + boost : : lexical_cast < std : : string > ( tab_char_and_size . second ) + " . \n " ) ;
}
tab_char = tab_char_and_size . first ;
tab_size = tab_char_and_size . second ;
}
}
tab . clear ( ) ;
for ( unsigned c = 0 ; c < tab_size ; c + + )
tab + = tab_char ;
tabs_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(.*)$ " ) ;
}
void Source : : View : : set_tooltip_events ( ) {
void Source : : View : : set_tooltip_events ( ) {
signal_motion_notify_event ( ) . connect ( [ this ] ( GdkEventMotion * event ) {
signal_motion_notify_event ( ) . connect ( [ this ] ( GdkEventMotion * event ) {
if ( on_motion_last_x ! = event - > x | | on_motion_last_y ! = event - > y ) {
if ( on_motion_last_x ! = event - > x | | on_motion_last_y ! = event - > y ) {
@ -981,27 +1018,14 @@ clang::Index Source::ClangViewParse::clang_index(0, 0);
Source : : ClangViewParse : : ClangViewParse ( const boost : : filesystem : : path & file_path , const boost : : filesystem : : path & project_path , Glib : : RefPtr < Gsv : : Language > language ) :
Source : : ClangViewParse : : ClangViewParse ( const boost : : filesystem : : path & file_path , const boost : : filesystem : : path & project_path , Glib : : RefPtr < Gsv : : Language > language ) :
Source : : View ( file_path , language ) , project_path ( project_path ) , parse_error ( false ) {
Source : : View ( file_path , language ) , project_path ( project_path ) , parse_error ( false ) {
DEBUG ( " start " ) ;
DEBUG ( " start " ) ;
auto scheme = get_source_buffer ( ) - > get_style_scheme ( ) ;
auto tag_table = get_buffer ( ) - > get_tag_table ( ) ;
auto tag_table = get_buffer ( ) - > get_tag_table ( ) ;
for ( auto & item : Singleton : : Config : : source ( ) - > clang_types ) {
for ( auto & item : Singleton : : Config : : source ( ) - > clang_types ) {
if ( ! tag_table - > lookup ( item . second ) ) {
if ( ! tag_table - > lookup ( item . second ) ) {
auto style = scheme - > get_style ( item . second ) ;
get_buffer ( ) - > create_tag ( item . second ) ;
auto tag = get_source_buffer ( ) - > create_tag ( item . second ) ;
if ( style ) {
if ( style - > property_foreground_set ( ) )
tag - > property_foreground ( ) = style - > property_foreground ( ) ;
if ( style - > property_background_set ( ) )
tag - > property_background ( ) = style - > property_background ( ) ;
if ( style - > property_strikethrough_set ( ) )
tag - > property_strikethrough ( ) = style - > property_strikethrough ( ) ;
// // if (style->property_bold_set()) tag->property_weight() = style->property_bold();
// // if (style->property_italic_set()) tag->property_italic() = style->property_italic();
// // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background();
// // if (style->property_underline_set()) tag->property_underline() = style->property_underline();
} else
INFO ( " Style " + item . second + " not found in " + scheme - > get_name ( ) ) ;
}
}
}
}
configure ( ) ;
parsing_in_progress = Singleton : : terminal ( ) - > print_in_progress ( " Parsing " + file_path . string ( ) ) ;
parsing_in_progress = Singleton : : terminal ( ) - > print_in_progress ( " Parsing " + file_path . string ( ) ) ;
//GTK-calls must happen in main thread, so the parse_thread
//GTK-calls must happen in main thread, so the parse_thread
@ -1043,10 +1067,37 @@ Source::View(file_path, language), project_path(project_path), parse_error(false
diagnostic_tooltips . hide ( ) ;
diagnostic_tooltips . hide ( ) ;
} ) ;
} ) ;
DEBUG ( " end " ) ;
}
void Source : : ClangViewParse : : configure ( ) {
Source : : View : : configure ( ) ;
auto scheme = get_source_buffer ( ) - > get_style_scheme ( ) ;
auto tag_table = get_buffer ( ) - > get_tag_table ( ) ;
for ( auto & item : Singleton : : Config : : source ( ) - > clang_types ) {
auto tag = get_buffer ( ) - > get_tag_table ( ) - > lookup ( item . second ) ;
if ( tag ) {
auto style = scheme - > get_style ( item . second ) ;
if ( style ) {
if ( style - > property_foreground_set ( ) )
tag - > property_foreground ( ) = style - > property_foreground ( ) ;
if ( style - > property_background_set ( ) )
tag - > property_background ( ) = style - > property_background ( ) ;
if ( style - > property_strikethrough_set ( ) )
tag - > property_strikethrough ( ) = style - > property_strikethrough ( ) ;
// // if (style->property_bold_set()) tag->property_weight() = style->property_bold();
// // if (style->property_italic_set()) tag->property_italic() = style->property_italic();
// // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background();
// // if (style->property_underline_set()) tag->property_underline() = style->property_underline();
} else
INFO ( " Style " + item . second + " not found in " + scheme - > get_name ( ) ) ;
}
}
bracket_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *).* \\ { *$ " ) ;
bracket_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *).* \\ { *$ " ) ;
no_bracket_statement_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(if|for|else if|catch|while) * \\ (.*[^;}] *$ " ) ;
no_bracket_statement_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(if|for|else if|catch|while) * \\ (.*[^;}] *$ " ) ;
no_bracket_no_para_statement_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(else|try|do) *$ " ) ;
no_bracket_no_para_statement_regex = std : : regex ( std : : string ( " ^( " ) + tab_char + " *)(else|try|do) *$ " ) ;
DEBUG ( " end " ) ;
}
}
Source : : ClangViewParse : : ~ ClangViewParse ( ) {
Source : : ClangViewParse : : ~ ClangViewParse ( ) {