static gboolean gb_beautifier_config_check_duplicates (GbBeautifierWorkbenchAddin *self, GArray *entries, const gchar *lang_id, const gchar *display_name) { g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self)); g_assert (entries != NULL); g_assert (!ide_str_empty0 (lang_id)); g_assert (!ide_str_empty0 (display_name)); for (gint i = 0; i < entries->len; ++i) { GbBeautifierConfigEntry *entry = &g_array_index (entries, GbBeautifierConfigEntry, i); /* Check for a NULL element at the array end */ if (entry->config_file == NULL) break; if (0 == g_strcmp0 (entry->lang_id, lang_id) && 0 == g_strcmp0 (entry->name, display_name)) return TRUE; } return FALSE; }
gboolean gb_str_simple_match (const gchar *haystack, const gchar *needle_down) { if (ide_str_empty0 (haystack)) return FALSE; else if (ide_str_empty0 (needle_down)) return TRUE; for (; *needle_down; needle_down = g_utf8_next_char (needle_down)) { gunichar ch = g_utf8_get_char (needle_down); const gchar *tmp; tmp = strchr (haystack, ch); if (!tmp) tmp = strchr (haystack, g_unichar_toupper (ch)); if (!tmp) return FALSE; haystack = tmp; } return TRUE; }
static gchar * match_and_replace (const gchar *str, const gchar *pattern, const gchar *replacement) { g_autofree gchar *head = NULL; g_autofree gchar *tail = NULL; gchar *needle; gsize head_len; g_assert (!ide_str_empty0 (str)); g_assert (!ide_str_empty0 (pattern)); if (NULL != (needle = g_strstr_len (str, -1, pattern))) { head_len = needle - str; if (head_len > 0) head = g_strndup (str, head_len); else head = g_strdup (""); tail = needle + strlen (pattern); if (*tail != '\0') tail = g_strdup (tail); else tail = g_strdup (""); return g_strconcat (head, replacement, tail, NULL); } else return NULL; }
static void update_replace_actions_sensitivity (IdeEditorFrame *self) { GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; GtkTextBuffer *buffer; GtkTextIter start; GtkTextIter end; const gchar *search_text; const gchar *replace_text; gint pos; gint count; gboolean enable_replace; gboolean enable_replace_all; gboolean replace_regex_valid; g_autoptr(GError) regex_error = NULL; g_autoptr(GError) replace_regex_error = NULL; GActionGroup *group; GAction *replace_action; GAction *replace_all_action; g_assert (IDE_IS_EDITOR_FRAME (self)); search_context = ide_source_view_get_search_context (self->source_view); search_settings = gtk_source_search_context_get_settings (search_context); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view)); gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start, &end); replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry)); /* Gather enough info to determine if Replace or Replace All would make sense */ search_text = gtk_entry_get_text (GTK_ENTRY (self->search_entry)); pos = gtk_source_search_context_get_occurrence_position (search_context, &start, &end); count = gtk_source_search_context_get_occurrences_count (search_context); regex_error = gtk_source_search_context_get_regex_error (search_context); replace_regex_valid = gtk_source_search_settings_get_regex_enabled (search_settings) ? g_regex_check_replacement (replace_text, NULL, &replace_regex_error) : TRUE; enable_replace = (!ide_str_empty0 (search_text) && regex_error == NULL && replace_regex_valid && pos > 0); enable_replace_all = (!ide_str_empty0 (search_text) && regex_error == NULL && replace_regex_valid && count > 0); group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry"); replace_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace"); replace_all_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace-all"); g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_action), enable_replace); g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_all_action), enable_replace_all); }
static void gb_rename_file_popover__button_clicked (GbRenameFilePopover *self, GtkButton *button) { g_autoptr(GFile) file = NULL; g_autoptr(GFile) parent = NULL; const gchar *path; g_assert (GB_IS_RENAME_FILE_POPOVER (self)); g_assert (GTK_IS_BUTTON (button)); g_assert (self->file != NULL); g_assert (G_IS_FILE (self->file)); path = gtk_entry_get_text (self->entry); if (ide_str_empty0 (path)) return; parent = g_file_get_parent (self->file); file = g_file_get_child (parent, path); /* only activate once */ gtk_widget_set_sensitive (GTK_WIDGET (self->button), FALSE); g_signal_emit (self, signals [RENAME_FILE], 0, self->file, file); }
static void ide_editor_spell_widget__add_button_clicked_cb (IdeEditorSpellWidget *self, GtkButton *button) { const gchar *word; GtkWidget *item; GtkWidget *toplevel; GtkWidget *focused_widget; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (GTK_IS_BUTTON (button)); word = gtk_entry_get_text (GTK_ENTRY (self->dict_word_entry)); /* TODO: check if word already in dict */ if (check_dict_available (self) && !ide_str_empty0 (word)) { if (!ide_editor_spell_dict_add_word_to_personal (self->dict, word)) return; item = dict_create_word_row (self, word); gtk_list_box_insert (GTK_LIST_BOX (self->dict_words_list), item, 0); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); if (GTK_IS_WINDOW (toplevel) && NULL != (focused_widget = gtk_window_get_focus (GTK_WINDOW (toplevel)))) { if (focused_widget != GTK_WIDGET (self->word_entry) && focused_widget != self->dict_word_entry) gtk_widget_grab_focus (self->dict_word_entry); } gtk_entry_set_text (GTK_ENTRY (self->dict_word_entry), ""); } }
static void present_greeter_with_surface (GSimpleAction *action, GVariant *param, gpointer user_data) { GbpGreeterApplicationAddin *self = user_data; g_autoptr(IdeWorkbench) workbench = NULL; IdeGreeterWorkspace *workspace; const gchar *name; g_assert (!action || G_IS_SIMPLE_ACTION (action)); g_assert (!param || g_variant_is_of_type (param, G_VARIANT_TYPE_STRING)); g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (self)); g_assert (IDE_IS_APPLICATION (self->application)); workbench = ide_workbench_new (); ide_application_add_workbench (self->application, workbench); workspace = ide_greeter_workspace_new (self->application); ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace)); if (param != NULL && (name = g_variant_get_string (param, NULL)) && !ide_str_empty0 (name)) ide_workspace_set_visible_surface_name (IDE_WORKSPACE (workspace), name); ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace)); }
static void ide_git_clone_widget_init (IdeGitCloneWidget *self) { g_autoptr(GSettings) settings = NULL; g_autofree gchar *path = NULL; g_autofree gchar *projects_dir = NULL; gtk_widget_init_template (GTK_WIDGET (self)); settings = g_settings_new ("org.gnome.builder"); path = g_settings_get_string (settings, "projects-directory"); if (!ide_str_empty0 (path)) { projects_dir = g_build_filename (g_get_home_dir (), path, NULL); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->clone_location_button), projects_dir); } g_signal_connect_object (self->clone_uri_entry, "changed", G_CALLBACK (ide_git_clone_widget_uri_changed), self, G_CONNECT_SWAPPED); }
static void ide_editor_view_goto_line_activate (IdeEditorView *self, const gchar *text, EggSimplePopover *popover) { gint64 value; g_assert (IDE_IS_EDITOR_VIEW (self)); g_assert (EGG_IS_SIMPLE_POPOVER (popover)); if (!ide_str_empty0 (text)) { value = g_ascii_strtoll (text, NULL, 10); if ((value > 0) && (value < G_MAXINT)) { GtkTextIter iter; GtkTextBuffer *buffer = GTK_TEXT_BUFFER (self->document); gtk_widget_grab_focus (GTK_WIDGET (self->frame1->source_view)); gtk_text_buffer_get_iter_at_line (buffer, &iter, value - 1); gtk_text_buffer_select_range (buffer, &iter, &iter); ide_source_view_scroll_to_iter (self->frame1->source_view, &iter, 0.25, TRUE, 1.0, 0.5, TRUE); } } }
static gboolean gb_vim_command_vsplit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; gchar *file_path; SplitCallbackData *split_callback_data; GVariant *variant; g_assert (GTK_IS_WIDGET (active_widget)); if (!IDE_IS_LAYOUT_VIEW (active_widget)) return gb_vim_set_no_view_error (error); if (ide_str_empty0 (options)) { variant = g_variant_new_string (""); ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "split-left", variant); } else { if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } file_path = g_strdup (options); if (!g_path_is_absolute (file_path)) file_path = g_build_filename (g_file_get_path (workdir), file_path, NULL); file = g_file_new_for_path (file_path); split_callback_data = g_slice_new (SplitCallbackData); split_callback_data->active_widget = g_object_ref (active_widget); split_callback_data->file_path = file_path; ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_BACKGROUND, NULL, gb_vim_command_vsplit_cb, split_callback_data); g_clear_object (&file); } return TRUE; }
static void ide_editor_frame_actions_replace (GSimpleAction *action, GVariant *state, gpointer user_data) { IdeEditorFrame *self = user_data; GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; const gchar *replace_text; gchar *unescaped_replace_text; const gchar *search_text; GError *error = NULL; GtkTextIter start; GtkTextIter end; GtkTextBuffer *buffer; gint occurrence_position; g_assert (IDE_IS_EDITOR_FRAME (self)); search_context = ide_source_view_get_search_context (self->source_view); g_assert (search_context != NULL); search_settings = gtk_source_search_context_get_settings (search_context); search_text = gtk_source_search_settings_get_search_text (search_settings); replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry)); if (ide_str_empty0 (search_text) || replace_text == NULL) return; unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view)); gtk_text_buffer_get_selection_bounds (buffer, &start, &end); occurrence_position = gtk_source_search_context_get_occurrence_position (search_context, &start, &end); if (occurrence_position > 0) { /* Temporarily disable updating the search position label to prevent flickering */ g_signal_handler_block (buffer, self->cursor_moved_handler); gtk_source_search_context_replace2 (search_context, &start, &end, unescaped_replace_text, -1, &error); /* Re-enable updating the search position label. The next-search-result action * below will cause it to update. */ g_signal_handler_unblock (buffer, self->cursor_moved_handler); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } ide_widget_action (GTK_WIDGET (self), "frame", "next-search-result", NULL); } g_free (unescaped_replace_text); }
static GArray * gb_beautifier_config_get_map (GbBeautifierWorkbenchAddin *self, const gchar *path) { GArray *map; g_autofree gchar *file_name = NULL; g_autoptr(GKeyFile) key_file = NULL; g_auto(GStrv) lang_ids = NULL; gsize nb_lang_ids; GError *error = NULL; g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self)); g_assert (!ide_str_empty0 (path)); map = g_array_new (TRUE, TRUE, sizeof (GbBeautifierMapEntry)); g_array_set_clear_func (map, map_entry_clear_func); file_name = g_build_filename (path, "global.ini", NULL); key_file = g_key_file_new (); if (!g_file_test (file_name, G_FILE_TEST_EXISTS)) { g_debug ("%s doesn't exist", file_name); return map; } if (g_key_file_load_from_file (key_file, file_name, G_KEY_FILE_NONE, &error) && NULL != (lang_ids = g_key_file_get_groups (key_file, &nb_lang_ids))) { for (gint i = 0; i < nb_lang_ids; ++i) { g_autofree gchar *mapped_lang_id = NULL; g_autofree gchar *default_profile = NULL; GbBeautifierMapEntry entry; gchar *lang_id = lang_ids [i]; if (!is_a_lang_id (self, lang_id) || NULL == (mapped_lang_id = g_key_file_get_string (key_file, lang_id, "map", NULL))) continue; if (gb_beautifier_map_check_duplicates (self, map, lang_id)) continue; default_profile = g_key_file_get_string (key_file, lang_id, "default", NULL); entry.lang_id = g_strdup (lang_id); entry.mapped_lang_id = g_steal_pointer (&mapped_lang_id); entry.default_profile = g_steal_pointer (&default_profile); g_array_append_val (map, entry); } } return map; }
static gboolean dict_check_word_timeout_cb (IdeEditorSpellWidget *self) { const gchar *word; g_autofree gchar *tooltip = NULL; gchar *icon_name; gboolean valid = FALSE; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); self->dict_check_word_state = CHECK_WORD_CHECKING; word = gtk_entry_get_text (GTK_ENTRY (self->dict_word_entry)); if (!ide_str_empty0 (word)) { if (ide_editor_spell_dict_personal_contains (self->dict, word)) gtk_widget_set_tooltip_text (self->dict_word_entry, _("This word is already in the personal dictionary")); else if (gspell_checker_check_word (self->checker, word, -1, NULL)) { tooltip = g_strdup_printf (_("This word is already in the %s dictionary"), gspell_language_get_name (self->spellchecker_language)); gtk_widget_set_tooltip_text (self->dict_word_entry, tooltip); } else { valid = TRUE; gtk_widget_set_tooltip_text (self->dict_word_entry, NULL); } icon_name = valid ? "" : "dialog-warning-symbolic"; } else icon_name = ""; gtk_widget_set_sensitive (GTK_WIDGET (self->dict_add_button), valid); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->dict_word_entry), GTK_ENTRY_ICON_SECONDARY, icon_name); self->dict_check_word_state = CHECK_WORD_NONE; self->dict_check_word_timeout_id = 0; if (self->is_dict_check_word_invalid == TRUE) { self->dict_check_word_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, DICT_CHECK_WORD_INTERVAL_MIN, (GSourceFunc)dict_check_word_timeout_cb, self, NULL); self->dict_check_word_state = CHECK_WORD_IDLE; self->is_dict_check_word_invalid = FALSE; } return G_SOURCE_REMOVE; }
static gboolean gb_vim_command_tabe (GtkSourceView *source_view, const gchar *command, const gchar *options, GError **error) { if (!ide_str_empty0 (options)) return gb_vim_command_edit (source_view, command, options, error); gb_widget_activate_action (GTK_WIDGET (source_view), "workbench", "new-document", NULL); return TRUE; }
static gboolean check_word_timeout_cb (IdeEditorSpellWidget *self) { const gchar *word; g_autoptr(GError) error = NULL; gchar *icon_name; gboolean ret = TRUE; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); self->check_word_state = CHECK_WORD_CHECKING; word = gtk_entry_get_text (self->word_entry); if (!ide_str_empty0 (word)) { /* FIXME: suggestions can give a multiple-words suggestion * that failed to the checkword test, ex: auto tools */ ret = gspell_checker_check_word (self->checker, word, -1, &error); if (error != NULL) { g_message ("check error:%s\n", error->message); } icon_name = ret ? "" : "dialog-warning-symbolic"; } else icon_name = ""; gtk_entry_set_icon_from_icon_name (self->word_entry, GTK_ENTRY_ICON_SECONDARY, icon_name); self->check_word_state = CHECK_WORD_NONE; self->is_word_entry_valid = ret; self->check_word_timeout_id = 0; if (self->is_check_word_invalid == TRUE) { self->check_word_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, CHECK_WORD_INTERVAL_MIN, (GSourceFunc)check_word_timeout_cb, self, NULL); self->check_word_state = CHECK_WORD_IDLE; self->is_check_word_invalid = FALSE; } return G_SOURCE_REMOVE; }
gboolean gbp_flatpak_split_id (const gchar *str, gchar **id, gchar **arch, gchar **branch) { g_auto(GStrv) parts = g_strsplit (str, "/", 0); guint i = 0; if (id) *id = NULL; if (arch) *arch = NULL; if (branch) *branch = NULL; if (parts[i] != NULL) { if (id != NULL) *id = g_strdup (parts[i]); } else { /* we require at least a runtime/app ID */ return FALSE; } i++; if (parts[i] != NULL) { if (arch != NULL) *arch = g_strdup (parts[i]); } else return TRUE; i++; if (parts[i] != NULL) { if (branch != NULL && !ide_str_empty0 (parts[i])) *branch = g_strdup (parts[i]); } return TRUE; }
static void change_misspelled_word (IdeEditorSpellWidget *self, gboolean change_all) { const gchar *word; g_autofree gchar *change_to = NULL; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); word = gtk_label_get_text (self->word_label); g_assert (!ide_str_empty0 (word)); change_to = g_strdup (gtk_entry_get_text (self->word_entry)); g_assert (!ide_str_empty0 (change_to)); gspell_checker_set_correction (self->checker, word, -1, change_to, -1); if (change_all) gspell_navigator_change_all (self->navigator, word, change_to); else gspell_navigator_change (self->navigator, word, change_to); jump_to_next_misspelled_word (self); }
static void ide_editor_spell_widget__ignore_all_button_clicked_cb (IdeEditorSpellWidget *self, GtkButton *button) { const gchar *word; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (GTK_IS_BUTTON (button)); word = gtk_label_get_text (self->word_label); g_assert (!ide_str_empty0 (word)); gspell_checker_add_word_to_session (self->checker, word, -1); jump_to_next_misspelled_word (self); }
static gboolean gb_vim_command_tabe (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { g_assert (GTK_IS_WIDGET (active_widget)); if (!ide_str_empty0 (options)) return gb_vim_command_edit (active_widget, command, options, error); ide_widget_action (GTK_WIDGET (active_widget), "perspective", "new-file", NULL); return TRUE; }
static GSubprocess * gb_beautifier_process_create_generic (GbBeautifierWorkbenchAddin *self, ProcessState *state, GError *error) { GSubprocess *subprocess = NULL; gchar *src_path; g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self)); g_assert (state != NULL); src_path = g_file_get_path (state->src_file); g_assert (!ide_str_empty0 (src_path)); g_assert (!ide_str_empty0 (state->lang_id)); command_args_expand (self, state->command_args, state); subprocess = g_subprocess_newv ((const gchar * const *)state->command_args->pdata, G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &error); return subprocess; }
static void ide_editor_frame_update_search_position_label (IdeEditorFrame *self) { GtkSourceSearchContext *search_context; GtkStyleContext *context; GtkTextBuffer *buffer; GtkTextIter begin; GtkTextIter end; const gchar *search_text; gchar *text; gint count; gint pos; g_return_if_fail (IDE_IS_EDITOR_FRAME (self)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view)); search_context = ide_source_view_get_search_context (self->source_view); gtk_text_buffer_get_selection_bounds (buffer, &begin, &end); pos = gtk_source_search_context_get_occurrence_position (search_context, &begin, &end); count = gtk_source_search_context_get_occurrences_count (search_context); if ((pos == -1) || (count == -1)) { /* * We are not yet done scanning the buffer. * We will be updated when we know more, so just hide it for now. */ ide_editor_frame_set_position_label (self, NULL); return; } context = gtk_widget_get_style_context (GTK_WIDGET (self->search_entry)); search_text = gtk_entry_get_text (GTK_ENTRY (self->search_entry)); /* We use our own error class because we don't want to colide with styling * from GTK+ themes. */ if ((count == 0) && !ide_str_empty0 (search_text)) gtk_style_context_add_class (context, "search-missing"); else gtk_style_context_remove_class (context, "search-missing"); text = g_strdup_printf (_("%u of %u"), pos, count); ide_editor_frame_set_position_label (self, text); g_free (text); }
static void ide_editor_spell_widget__populate_popup_cb (IdeEditorSpellWidget *self, GtkWidget *popup, GtkEntry *entry) { GSList *suggestions = NULL; const gchar *text; GtkWidget *item; gint count = 0; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (GTK_IS_WIDGET (popup)); g_assert (GTK_IS_ENTRY (entry)); text = gtk_entry_get_text (entry); if (self->is_word_entry_valid || ide_str_empty0 (text) || NULL == (suggestions = gspell_checker_get_suggestions (self->checker, text, -1))) return; item = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM, "visible", TRUE, NULL); gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item); suggestions = g_slist_reverse (suggestions); for (GSList *l = (GSList *)suggestions; l != NULL; l = l->next) { item = g_object_new (GTK_TYPE_MENU_ITEM, "label", l->data, "visible", TRUE, NULL); g_object_set_data (G_OBJECT (item), "word", g_strdup (l->data)); gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item); g_signal_connect_object (item, "activate", G_CALLBACK (ide_editor_spell_widget__word_entry_suggestion_activate), self, G_CONNECT_SWAPPED); if (++count >= WORD_ENTRY_MAX_SUGGESTIONS) break; } g_slist_free_full (suggestions, g_free); }
static void gb_rename_file_popover__entry_changed (GbRenameFilePopover *self, GtkEntry *entry) { g_autoptr(GFile) parent = NULL; g_autoptr(GFile) file = NULL; const gchar *text; g_assert (GB_IS_RENAME_FILE_POPOVER (self)); g_assert (GTK_IS_ENTRY (entry)); g_assert (self->file != NULL); g_assert (G_IS_FILE (self->file)); gtk_widget_set_sensitive (GTK_WIDGET (self->button), FALSE); gtk_label_set_label (self->message, NULL); text = gtk_entry_get_text (entry); if (ide_str_empty0 (text)) return; if (strchr (text, G_DIR_SEPARATOR) != NULL) { gtk_label_set_label (self->message, _("File name must not contain subdirectories.")); return; } if (self->cancellable) { g_cancellable_cancel (self->cancellable); g_clear_object (&self->cancellable); } self->cancellable = g_cancellable_new (); parent = g_file_get_parent (self->file); file = g_file_get_child (parent, text); g_file_query_info_async (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, self->cancellable, gb_rename_file_popover__file_query_info, g_object_ref (self)); }
static GtkWidget * create_suggestion_row (IdeEditorSpellWidget *self, const gchar *word) { GtkWidget *row; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (!ide_str_empty0 (word)); row = g_object_new (GTK_TYPE_LABEL, "label", word, "visible", TRUE, "halign", GTK_ALIGN_START, NULL); return row; }
static void ide_editor_frame_actions_replace_all (GSimpleAction *action, GVariant *state, gpointer user_data) { IdeEditorFrame *self = user_data; GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; const gchar *replace_text; gchar *unescaped_replace_text; const gchar *search_text; GError *error = NULL; GtkSourceCompletion *completion; g_assert (IDE_IS_EDITOR_FRAME (self)); search_context = ide_source_view_get_search_context (self->source_view); g_assert (search_context != NULL); search_settings = gtk_source_search_context_get_settings (search_context); search_text = gtk_source_search_settings_get_search_text (search_settings); replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry)); if (ide_str_empty0 (search_text) || replace_text == NULL) return; /* Temporarily disabling auto completion makes replace more efficient. */ completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (self->source_view)); gtk_source_completion_block_interactive (completion); unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text); gtk_source_search_context_replace_all (search_context, unescaped_replace_text, -1, &error); gtk_source_completion_unblock_interactive (completion); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } g_free (unescaped_replace_text); }
static void ide_editor_spell_widget__language_notify_cb (IdeEditorSpellWidget *self, GParamSpec *pspec, GtkButton *language_chooser_button) { const GspellLanguage *current_language; const GspellLanguage *spell_language; g_autofree gchar *word = NULL; g_autofree gchar *first_result = NULL; GtkListBoxRow *row; g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self)); g_assert (GTK_IS_BUTTON (language_chooser_button)); current_language = gspell_checker_get_language (self->checker); spell_language = gspell_language_chooser_get_language (GSPELL_LANGUAGE_CHOOSER (language_chooser_button)); if (gspell_language_compare (current_language, spell_language) != 0) { gspell_checker_set_language (self->checker, spell_language); fill_suggestions_box (self, word, &first_result); if (!ide_str_empty0 (first_result)) { row = gtk_list_box_get_row_at_index (self->suggestions_box, 0); gtk_list_box_select_row (self->suggestions_box, row); } g_clear_pointer (&self->words_array, g_ptr_array_unref); if (current_language == NULL) { dict_clean_listbox (self); gtk_widget_set_sensitive (GTK_WIDGET (self->dict_add_button), FALSE); gtk_widget_set_sensitive (GTK_WIDGET (self->dict_words_list), FALSE); return; } ide_editor_spell_widget__dict_word_entry_changed_cb (self, GTK_ENTRY (self->dict_word_entry)); gtk_widget_set_sensitive (GTK_WIDGET (self->dict_words_list), TRUE); ide_editor_spell_navigator_goto_word_start (IDE_EDITOR_SPELL_NAVIGATOR (self->navigator)); jump_to_next_misspelled_word (self); } }
static gboolean gb_vim_command_edit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; g_assert (GTK_IS_WIDGET (active_widget)); if (ide_str_empty0 (options)) { ide_widget_action (GTK_WIDGET (active_widget), "win", "open-with-dialog", NULL); return TRUE; } if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } if (g_path_is_absolute (options)) file = g_file_new_for_path (options); else file = g_file_get_child (workdir, options); ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, NULL); g_clear_object (&file); return TRUE; }
static void ide_editor_view_goto_line_changed (IdeEditorView *self, EggSimplePopover *popover) { gchar *message; const gchar *text; GtkTextIter begin; GtkTextIter end; g_assert (IDE_IS_EDITOR_VIEW (self)); g_assert (EGG_IS_SIMPLE_POPOVER (popover)); text = egg_simple_popover_get_text (popover); gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (self->document), &begin, &end); if (!ide_str_empty0 (text)) { gint64 value; value = g_ascii_strtoll (text, NULL, 10); if (value > 0) { if (value <= gtk_text_iter_get_line (&end) + 1) { egg_simple_popover_set_message (popover, NULL); egg_simple_popover_set_ready (popover, TRUE); return; } } } /* translators: the user selected a number outside the value range for the document. */ message = g_strdup_printf (_("Provide a number between 1 and %u"), gtk_text_iter_get_line (&end) + 1); egg_simple_popover_set_message (popover, message); egg_simple_popover_set_ready (popover, FALSE); g_free (message); }
static gboolean ide_doap_parse_maintainer (IdeDoap *self, XmlReader *reader) { g_assert (IDE_IS_DOAP (self)); g_assert (XML_IS_READER (reader)); if (!xml_reader_read (reader)) return FALSE; do { if (xml_reader_is_a_local (reader, "Person") && xml_reader_read (reader)) { g_autoptr(IdeDoapPerson) person = ide_doap_person_new (); do { if (xml_reader_is_a_local (reader, "name")) { ide_doap_person_set_name (person, xml_reader_read_string (reader)); } else if (xml_reader_is_a_local (reader, "mbox")) { gchar *str; str = xml_reader_get_attribute (reader, "rdf:resource"); if (!ide_str_empty0 (str) && g_str_has_prefix (str, "mailto:")) ide_doap_person_set_email (person, str + strlen ("mailto:")); g_free (str); } } while (xml_reader_read_to_next (reader)); if (ide_doap_person_get_name (person) || ide_doap_person_get_email (person)) self->maintainers = g_list_append (self->maintainers, g_object_ref (person)); } } while (xml_reader_read_to_next (reader)); return TRUE; }
static gboolean gb_vim_command_edit (GtkSourceView *source_view, const gchar *command, const gchar *options, GError **error) { GbWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; if (ide_str_empty0 (options)) { gb_widget_activate_action (GTK_WIDGET (source_view), "workbench", "open", NULL); return TRUE; } if (!(workbench = gb_widget_get_workbench (GTK_WIDGET (source_view))) || !(context = gb_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } if (g_path_is_absolute (options)) file = g_file_new_for_path (options); else file = g_file_get_child (workdir, options); gb_workbench_open (workbench, file); g_clear_object (&file); return TRUE; }