diff options
author | Christian Hergert <chergert@redhat.com> | 2022-05-13 17:57:33 -0700 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2022-06-12 10:19:07 -0700 |
commit | f7d14875175c66af6e67bab1588759007c723467 (patch) | |
tree | 084ea461c92a9b2cdd4f70988d78c0d85eadc9dc | |
parent | 256e6cc53c34b586213b07a5a86d8f70021794ff (diff) | |
download | gtksourceview-f7d14875175c66af6e67bab1588759007c723467.tar.gz |
snippets: avoid creating informative until necessary
This fixes GtkSourceStyleSchemePreview so that it doesn't create a new
informative for every widget. GtkSourceMap as well.
-rw-r--r-- | gtksourceview/gtksourceview-snippets.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/gtksourceview/gtksourceview-snippets.c b/gtksourceview/gtksourceview-snippets.c index 64d41ec9..b0662093 100644 --- a/gtksourceview/gtksourceview-snippets.c +++ b/gtksourceview/gtksourceview-snippets.c @@ -312,6 +312,17 @@ gtk_source_view_snippets_update_informative (GtkSourceViewSnippets *snippets) goto hide_informative; } + if (snippets->informative == NULL) + { + snippets->informative = g_object_new (GTK_SOURCE_TYPE_INFORMATIVE, + "position", GTK_POS_TOP, + "message-type", GTK_MESSAGE_INFO, + "icon-name", "completion-snippet-symbolic", + NULL); + _gtk_source_view_add_assistant (snippets->view, + GTK_SOURCE_ASSISTANT (snippets->informative)); + } + _gtk_source_assistant_set_mark (GTK_SOURCE_ASSISTANT (snippets->informative), chunk->begin_mark); gtk_source_informative_set_message (snippets->informative, tooltip_text); @@ -327,7 +338,10 @@ gtk_source_view_snippets_update_informative (GtkSourceViewSnippets *snippets) return; hide_informative: - gtk_widget_hide (GTK_WIDGET (snippets->informative)); + if (snippets->informative != NULL) + { + gtk_widget_hide (GTK_WIDGET (snippets->informative)); + } } static void @@ -386,14 +400,6 @@ _gtk_source_view_snippets_init (GtkSourceViewSnippets *snippets, _gtk_source_view_snippets_set_buffer (snippets, GTK_SOURCE_BUFFER (buffer)); } - - snippets->informative = g_object_new (GTK_SOURCE_TYPE_INFORMATIVE, - "position", GTK_POS_TOP, - "message-type", GTK_MESSAGE_INFO, - "icon-name", "completion-snippet-symbolic", - NULL); - _gtk_source_view_add_assistant (snippets->view, - GTK_SOURCE_ASSISTANT (snippets->informative)); } void @@ -415,8 +421,11 @@ _gtk_source_view_snippets_shutdown (GtkSourceViewSnippets *snippets) g_clear_signal_handler (&snippets->buffer_cursor_moved_handler, snippets->buffer); - _gtk_source_view_remove_assistant (snippets->view, - GTK_SOURCE_ASSISTANT (snippets->informative)); + if (snippets->informative != NULL) + { + _gtk_source_view_remove_assistant (snippets->view, + GTK_SOURCE_ASSISTANT (snippets->informative)); + } if (snippets->snippet_signals != NULL) { @@ -661,7 +670,10 @@ _gtk_source_view_snippets_pop (GtkSourceViewSnippets *snippets) g_object_unref (snippet); - gtk_widget_hide (GTK_WIDGET (snippets->informative)); + if (snippets->informative != NULL) + { + gtk_widget_hide (GTK_WIDGET (snippets->informative)); + } } snippet = g_queue_peek_head (&snippets->queue); |