static gboolean check_previous (GtkSourceView *view, ModelineOptions *previous, ModelineSet set) { GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); /* Do not restore default when this is the first time */ if (!previous) return FALSE; /* Do not restore default when previous was not set */ if (!(previous->set & set)) return FALSE; /* Only restore default when setting has not changed */ switch (set) { case MODELINE_SET_INSERT_SPACES: return gtk_source_view_get_insert_spaces_instead_of_tabs (view) == previous->insert_spaces; break; case MODELINE_SET_TAB_WIDTH: return gtk_source_view_get_tab_width (view) == previous->tab_width; break; case MODELINE_SET_INDENT_WIDTH: return gtk_source_view_get_indent_width (view) == previous->indent_width; break; case MODELINE_SET_WRAP_MODE: return gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view)) == previous->wrap_mode; break; case MODELINE_SET_RIGHT_MARGIN_POSITION: return gtk_source_view_get_right_margin_position (view) == previous->right_margin_position; break; case MODELINE_SET_SHOW_RIGHT_MARGIN: return gtk_source_view_get_show_right_margin (view) == previous->display_right_margin; break; case MODELINE_SET_LANGUAGE: { GtkSourceLanguage *language = gtk_source_buffer_get_language (buffer); return (language == NULL && previous->language_id == NULL) || (language != NULL && g_strcmp0 (gtk_source_language_get_id (language), previous->language_id) == 0); } break; default: return FALSE; break; } }
static void ide_editor_view_actions_source_view_notify (IdeSourceView *source_view, GParamSpec *pspec, GActionMap *actions) { g_autoptr(GVariant) param = NULL; GtkSourceView *gsv; GAction *action = NULL; g_assert (IDE_IS_SOURCE_VIEW (source_view)); g_assert (pspec != NULL); g_assert (G_IS_ACTION_MAP (actions)); gsv = GTK_SOURCE_VIEW (source_view); if (g_str_equal (pspec->name, "show-line-numbers")) { gboolean show_line_numbers; action = g_action_map_lookup_action (actions, "show-line-numbers"); show_line_numbers = gtk_source_view_get_show_line_numbers (gsv); param = g_variant_new_boolean (show_line_numbers); } else if (g_str_equal (pspec->name, "show-right-margin")) { gboolean show_right_margin; action = g_action_map_lookup_action (actions, "show-right-margin"); show_right_margin = gtk_source_view_get_show_right_margin (gsv); param = g_variant_new_boolean (show_right_margin); } else if (g_str_equal (pspec->name, "highlight-current-line")) { gboolean highlight_current_line; action = g_action_map_lookup_action (actions, "highlight-current-line"); g_object_get (gsv, "highlight-current-line", &highlight_current_line, NULL); param = g_variant_new_boolean (highlight_current_line); } else if (g_str_equal (pspec->name, "auto-indent")) { gboolean auto_indent; action = g_action_map_lookup_action (actions, "auto-indent"); g_object_get (source_view, "auto-indent", &auto_indent, NULL); param = g_variant_new_boolean (auto_indent); } else if (g_str_equal (pspec->name, "tab-width")) { guint tab_width; action = g_action_map_lookup_action (actions, "tab-width"); g_object_get (source_view, "tab-width", &tab_width, NULL); param = g_variant_new_int32 (tab_width); } else if (g_str_equal (pspec->name, "insert-spaces-instead-of-tabs")) { gboolean use_spaces; action = g_action_map_lookup_action (actions, "use-spaces"); g_object_get (source_view, "insert-spaces-instead-of-tabs", &use_spaces, NULL); param = g_variant_new_boolean (use_spaces); } else if (g_str_equal (pspec->name, "smart-backspace")) { gboolean smart_backspace; action = g_action_map_lookup_action (actions, "smart-backspace"); g_object_get (source_view, "smart-backspace", &smart_backspace, NULL); param = g_variant_new_boolean (smart_backspace); } if (action && param) { g_simple_action_set_state (G_SIMPLE_ACTION (action), param); param = NULL; } }