static gboolean highlight_in_background (SearchBox *search_box) { gboolean found = FALSE; GTimer *timer = g_timer_new(); if (search_box->priv->start_highlight != NULL) { const gchar* search_text = gtk_entry_get_text (GTK_ENTRY (search_box->priv->search_entry)); do { IAnjutaEditorCell* result_start; IAnjutaEditorCell* result_end; found = editor_search (search_box->priv->current_editor, search_text, search_box->priv->case_sensitive, TRUE, search_box->priv->regex_mode, search_box->priv->start_highlight, search_box->priv->end_highlight, &result_start, &result_end); if (found) { ianjuta_indicable_set(IANJUTA_INDICABLE(search_box->priv->current_editor), IANJUTA_ITERABLE (result_start), IANJUTA_ITERABLE (result_end), IANJUTA_INDICABLE_IMPORTANT, NULL); g_object_unref (result_start); g_object_unref (search_box->priv->start_highlight); search_box->priv->start_highlight = result_end; } } while (found && g_timer_elapsed(timer, NULL) < CONTINUOUS_SEARCH_TIMEOUT); g_timer_destroy (timer); } if (!found) { search_box->priv->idle_id = 0; g_clear_object (&search_box->priv->start_highlight); g_clear_object (&search_box->priv->end_highlight); } return found; }
IAnjutaIterable* isymbol_manager_get_members (IAnjutaSymbolManager *sm, const IAnjutaSymbol *symbol, IAnjutaSymbolField info_fields, GError **err) { SymbolDBEngineIteratorNode *node; SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; gint sym_id; SymbolDBEngineIterator *iterator; sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); node = SYMBOL_DB_ENGINE_ITERATOR_NODE (symbol); sym_id = symbol_db_engine_iterator_node_get_symbol_id (node); iterator = symbol_db_engine_get_scope_members_by_symbol_id (dbe, sym_id, -1, -1, info_fields); return IANJUTA_ITERABLE (iterator); }
IAnjutaIterable* isymbol_manager_search_symbol_in_scope (IAnjutaSymbolManager *sm, const gchar *pattern, const IAnjutaSymbol *container_symbol, IAnjutaSymbolType match_types, gboolean include_types, gint results_limit, gint results_offset, IAnjutaSymbolField info_fields, GError **err) { SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; SymbolDBEngineIterator *iterator; SymbolDBEngineIteratorNode *node; gint container_sym_id; sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); node = SYMBOL_DB_ENGINE_ITERATOR_NODE (container_symbol); container_sym_id = symbol_db_engine_iterator_node_get_symbol_id (node); iterator = symbol_db_engine_find_symbol_in_scope (dbe, pattern, container_sym_id , match_types, include_types, results_limit, results_offset, info_fields); return IANJUTA_ITERABLE (iterator); }
IAnjutaIterable* isymbol_manager_get_parent_scope (IAnjutaSymbolManager *sm, const IAnjutaSymbol *symbol, const gchar *filename, IAnjutaSymbolField info_fields, GError **err) { SymbolDBEngineIteratorNode *node; gint child_node_id, parent_node_id; SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; SymbolDBEngineIterator *iterator; sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); node = SYMBOL_DB_ENGINE_ITERATOR_NODE (symbol); child_node_id = symbol_db_engine_iterator_node_get_symbol_id (node); if (child_node_id <= 0) return NULL; parent_node_id = symbol_db_engine_get_parent_scope_id_by_symbol_id (dbe, child_node_id, filename); iterator = symbol_db_engine_get_symbol_info_by_id (dbe, parent_node_id, info_fields); return IANJUTA_ITERABLE (iterator); }
static gboolean sourceview_provider_activate_proposal (GtkSourceCompletionProvider* provider, GtkSourceCompletionProposal* proposal, GtkTextIter* iter) { SourceviewProvider* prov = SOURCEVIEW_PROVIDER (provider); SourceviewCell* cell = sourceview_cell_new (iter, GTK_TEXT_VIEW(prov->sv->priv->view)); gpointer data = g_object_get_data (G_OBJECT(proposal), "__data"); ianjuta_provider_activate(prov->iprov, IANJUTA_ITERABLE(cell), data, NULL); g_object_unref (cell); return TRUE; }
static void sourceview_provider_populate (GtkSourceCompletionProvider* provider, GtkSourceCompletionContext* context) { SourceviewProvider* prov = SOURCEVIEW_PROVIDER(provider); GtkTextIter iter; SourceviewCell* cell; gtk_source_completion_context_get_iter(context, &iter); cell = sourceview_cell_new (&iter, GTK_TEXT_VIEW(prov->sv->priv->view)); prov->context = context; prov->cancelled = FALSE; g_signal_connect (context, "cancelled", G_CALLBACK(on_context_cancelled), prov); ianjuta_provider_populate(prov->iprov, IANJUTA_ITERABLE(cell), NULL); g_object_unref (cell); }
IAnjutaIterable* isymbol_manager_search (IAnjutaSymbolManager *sm, IAnjutaSymbolType match_types, gboolean include_types, IAnjutaSymbolField info_fields, const gchar *match_name, gboolean partial_name_match, IAnjutaSymbolManagerSearchFileScope filescope_search, gboolean global_tags_search, gint results_limit, gint results_offset, GError **err) { SymbolDBEngineIterator *iterator = NULL; SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe_project; SymbolDBEngine *dbe_globals; gchar *pattern; gboolean exact_match = !partial_name_match; sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe_project = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); dbe_globals = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_globals); if (exact_match == FALSE) pattern = g_strdup_printf ("%s%%", match_name == NULL ? "" : match_name); else { pattern = g_strdup_printf ("%s", match_name == NULL ? "%" : match_name); } /* should we lookup for project of system tags? */ iterator = symbol_db_engine_find_symbol_by_name_pattern_filtered ( global_tags_search == FALSE ? dbe_project : dbe_globals, pattern, match_types, include_types, filescope_search, global_tags_search == FALSE ? NULL : sdb_plugin->session_packages, results_limit, results_offset, info_fields); g_free (pattern); return IANJUTA_ITERABLE (iterator); }
static void on_sdb_search_command_data_arrived (AnjutaCommand *command, IAnjutaSymbolManagerSearchCallback callback) { SymbolDBSearchCommand *sdbsc; SymbolDBEngineIterator *iterator; gpointer callback_user_data = NULL; guint cmd_id; sdbsc = SYMBOL_DB_SEARCH_COMMAND (command); iterator = symbol_db_search_command_get_iterator_result (sdbsc); /* get the previously saved cmd_id and callback data */ cmd_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (command), "cmd_id")); callback_user_data = g_object_get_data (G_OBJECT (command), "callback_user_data"); callback (cmd_id, IANJUTA_ITERABLE (iterator), callback_user_data); }
IAnjutaIterable* isymbol_manager_get_scope (IAnjutaSymbolManager *sm, const gchar* filename, gulong line, IAnjutaSymbolField info_fields, GError **err) { SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; SymbolDBEngineIterator *iterator; sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); iterator = symbol_db_engine_get_current_scope (dbe, filename, line, info_fields); return IANJUTA_ITERABLE (iterator); }
static IAnjutaIterable* language_support_get_mark_position (IAnjutaEditor* editor, gchar* mark) { IAnjutaEditorCell *search_start = IANJUTA_EDITOR_CELL ( ianjuta_editor_get_start_position (editor, NULL)); IAnjutaEditorCell *search_end = IANJUTA_EDITOR_CELL ( ianjuta_editor_get_end_position (editor, NULL)); IAnjutaEditorCell *result_start = NULL; IAnjutaEditorCell *result_end = NULL; ianjuta_editor_search_forward (IANJUTA_EDITOR_SEARCH (editor), mark, FALSE, search_start, search_end, &result_start, &result_end, NULL); if (result_start) g_object_unref (result_start); return result_end ? IANJUTA_ITERABLE (result_end) : NULL; }
IAnjutaIterable* isymbol_manager_search_project (IAnjutaSymbolManager *sm, IAnjutaSymbolType match_types, gboolean include_types, IAnjutaSymbolField info_fields, const gchar *pattern, IAnjutaSymbolManagerSearchFileScope filescope_search, gint results_limit, gint results_offset, GError **err) { SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; SymbolDBEngineIterator *iterator; g_return_val_if_fail (pattern != NULL, NULL); sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); /* take the project's engine */ dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); iterator = do_search_prj_glb (dbe, match_types, include_types, info_fields, pattern, filescope_search, results_limit, results_offset, NULL); return IANJUTA_ITERABLE (iterator); }
IAnjutaIterable* isymbol_manager_search_file (IAnjutaSymbolManager *sm, IAnjutaSymbolType match_types, gboolean include_types, IAnjutaSymbolField info_fields, const gchar *pattern, const GFile *file, gint results_limit, gint results_offset, GError **err) { SymbolDBPlugin *sdb_plugin; SymbolDBEngine *dbe; SymbolDBEngineIterator *iterator; gchar *abs_file_path; g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (pattern != NULL, NULL); sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (sm); dbe = SYMBOL_DB_ENGINE (sdb_plugin->sdbe_project); abs_file_path = g_file_get_path ((GFile *)file); if (abs_file_path == NULL) { g_warning ("isymbol_manager_search_file (): GFile has no absolute path"); return NULL; } iterator = symbol_db_engine_find_symbol_by_name_pattern_on_file (dbe, pattern, abs_file_path, match_types, include_types, results_limit, results_offset, info_fields); g_free (abs_file_path); return IANJUTA_ITERABLE (iterator); }
gboolean search_box_incremental_search (SearchBox* search_box, gboolean search_forward, gboolean search_next, gboolean wrap) { IAnjutaIterable* real_start; IAnjutaEditorCell* search_start; IAnjutaEditorCell* search_end; IAnjutaEditorCell* result_start; IAnjutaEditorCell* result_end; IAnjutaEditorSelection* selection; const gchar* search_text = gtk_entry_get_text (GTK_ENTRY (search_box->priv->search_entry)); gboolean found = FALSE; if (!search_box->priv->current_editor || !search_text || !strlen (search_text)) return FALSE; selection = IANJUTA_EDITOR_SELECTION (search_box->priv->current_editor); if (ianjuta_editor_selection_has_selection (selection, NULL)) { search_start = IANJUTA_EDITOR_CELL (ianjuta_editor_selection_get_start (selection, NULL)); } else { search_start = IANJUTA_EDITOR_CELL (ianjuta_editor_get_position (search_box->priv->current_editor, NULL)); } real_start = ianjuta_iterable_clone (IANJUTA_ITERABLE (search_start), NULL); /* If forward, set search start and end to current position of * cursor and editor end, respectively, or if backward to editor * start and current position of cursor, respectively. Current * position of cursor is selection start if have selection. */ if (search_forward) { search_end = IANJUTA_EDITOR_CELL (ianjuta_editor_get_position (search_box->priv->current_editor, NULL)); ianjuta_iterable_last (IANJUTA_ITERABLE (search_end), NULL); } else { search_end = search_start; search_start = IANJUTA_EDITOR_CELL (ianjuta_editor_get_position (search_box->priv->current_editor, NULL)); ianjuta_iterable_first (IANJUTA_ITERABLE (search_start), NULL); } /* When there's a selection, if forward, set search start and end * to match end and editor end, respectively, or if backward to * editor start and match start, respectively. If forward and * selection starts with a match, look for next match. */ if (ianjuta_editor_selection_has_selection (selection, NULL) && search_next) { gchar* selected_text = ianjuta_editor_selection_get (selection, NULL); gint start_pos, end_pos; gboolean selected_have_search_text = FALSE; selected_have_search_text = search_box->priv->regex_mode ? search_regex_in_text (search_text, selected_text, TRUE, &start_pos, &end_pos) : search_str_in_text (search_text, selected_text, search_box->priv->case_sensitive, &start_pos, &end_pos); if (selected_have_search_text) { IAnjutaIterable* selection_start = ianjuta_editor_selection_get_start (selection, NULL); if (search_forward && start_pos == 0) { end_pos += ianjuta_iterable_get_position(IANJUTA_ITERABLE (selection_start), NULL); ianjuta_iterable_set_position (IANJUTA_ITERABLE(search_start), end_pos, NULL); ianjuta_iterable_last (IANJUTA_ITERABLE (search_end), NULL); } else if (!search_forward) { start_pos += ianjuta_iterable_get_position(IANJUTA_ITERABLE (selection_start), NULL); ianjuta_iterable_set_position (IANJUTA_ITERABLE(search_end), start_pos, NULL); ianjuta_iterable_first (IANJUTA_ITERABLE (search_start), NULL); } g_object_unref (selection_start); } g_free (selected_text); } /* Try searching in current position */ found = editor_search (search_box->priv->current_editor, search_text, search_box->priv->case_sensitive, search_forward, search_box->priv->regex_mode, search_start, search_end, &result_start, &result_end); if (found) { anjuta_status_pop (ANJUTA_STATUS (search_box->priv->status)); } else if (wrap) { /* Try to wrap if not found */ ianjuta_iterable_first (IANJUTA_ITERABLE (search_start), NULL); ianjuta_iterable_last (IANJUTA_ITERABLE (search_end), NULL); /* Try to search again */ found = editor_search (search_box->priv->current_editor, search_text, search_box->priv->case_sensitive, search_forward, search_box->priv->regex_mode, search_start, search_end, &result_start, &result_end); /* Check if successful */ if (found) { if (ianjuta_iterable_compare (IANJUTA_ITERABLE (result_start), real_start, NULL) != 0) { anjuta_status_pop (search_box->priv->status); if (search_forward) { anjuta_status_push (search_box->priv->status, _("Search for \"%s\" reached the end and was continued at the top."), search_text); } else { anjuta_status_push (search_box->priv->status, _("Search for \"%s\" reached top and was continued at the bottom."), search_text); } } else if (ianjuta_editor_selection_has_selection (selection, NULL)) { found = FALSE; anjuta_status_pop (search_box->priv->status); if (search_forward) { anjuta_status_push (search_box->priv->status, _("Search for \"%s\" reached the end and was continued at the top but no new match was found."), search_text); } else { anjuta_status_push (search_box->priv->status, _("Search for \"%s\" reached top and was continued at the bottom but no new match was found."), search_text); } } else { found = FALSE; } } } if (found) { ianjuta_editor_selection_set (selection, IANJUTA_ITERABLE (result_start), IANJUTA_ITERABLE (result_end), TRUE, NULL); g_object_unref (result_start); g_object_unref (result_end); } search_box_set_entry_color (search_box, found); g_object_unref (real_start); g_object_unref (search_start); g_object_unref (search_end); return found; }
/* Search string in editor, return TRUE and matching part as start and * end editor cell */ static gboolean editor_search (IAnjutaEditor *editor, const gchar *search_text, gboolean case_sensitive, gboolean search_forward, gboolean regex_mode, IAnjutaEditorCell* search_start, IAnjutaEditorCell* search_end, IAnjutaEditorCell** result_start, IAnjutaEditorCell** result_end) { gboolean found; if (regex_mode) { gint start_pos; gint end_pos; gchar *text_to_search; text_to_search = ianjuta_editor_get_text (editor, IANJUTA_ITERABLE (search_start), IANJUTA_ITERABLE (search_end), NULL); found = search_regex_in_text (search_text, text_to_search, search_forward, &start_pos, &end_pos); start_pos += ianjuta_iterable_get_position(IANJUTA_ITERABLE (search_start), NULL); end_pos += ianjuta_iterable_get_position(IANJUTA_ITERABLE (search_start), NULL); if (found && start_pos >= 0) { *result_start = IANJUTA_EDITOR_CELL (ianjuta_editor_get_start_position (editor, NULL)); *result_end = IANJUTA_EDITOR_CELL (ianjuta_editor_get_start_position (editor, NULL)); if (!ianjuta_iterable_set_position(IANJUTA_ITERABLE(*result_start), start_pos, NULL) || !ianjuta_iterable_set_position(IANJUTA_ITERABLE(*result_end), end_pos, NULL)) { g_object_unref(*result_start); g_object_unref(*result_end); found = FALSE; } } g_free(text_to_search); } else { if (search_forward) { found = ianjuta_editor_search_forward (IANJUTA_EDITOR_SEARCH (editor), search_text, case_sensitive, search_start, search_end, result_start, result_end, NULL); } else { found = ianjuta_editor_search_backward (IANJUTA_EDITOR_SEARCH (editor), search_text, case_sensitive, search_end, search_start, result_start, result_end, NULL); } } return found; }