예제 #1
0
static void
update_type_list (AnjutaShell *shell, IAnjutaIterable *iter, const gchar *name)
{
	gchar *list = NULL;
	GValue value = {0,};
	
	if (iter)
	{
		ianjuta_iterable_first (iter, NULL);
		if (ianjuta_iterable_get_length (iter, NULL) > 0)
		{
			GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
			do {
				IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
				const gchar *sname = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_NAME, NULL);
				g_string_append(s, sname);
				g_string_append_c(s, ' ');
			} while (ianjuta_iterable_next (iter, NULL));
			list =  g_string_free(s, FALSE);
		}
	}
	
	anjuta_shell_get_value (shell, name, &value, NULL);
	if (G_VALUE_HOLDS_STRING(&value))
	{
		const gchar *value_list = g_value_get_string (&value);
		
		if (list == NULL)
		{
			anjuta_shell_remove_value (shell, name, NULL);
		}
		else if (strcmp (list, value_list) == 0)
		{
			g_free (list);
		}
		else
		{
			g_value_take_string (&value, list);
			anjuta_shell_add_value (shell, name, &value, NULL);
		}
	}
	else
	{
		if (list != NULL)
		{
			g_value_init (&value, G_TYPE_STRING);
			g_value_take_string (&value, list);
			anjuta_shell_add_value (shell, name, &value, NULL);
		}
	}
	if (G_IS_VALUE (&value))
		g_value_unset (&value);
}
예제 #2
0
static void
on_cls_inherit_update (IAnjutaSymbolQuery *query, IAnjutaIterable *iter,
                       AnjutaClassInheritance *plugin)
{
	IAnjutaSymbol *symbol;
	ClsNode *cls_node;
	GError *err = NULL;
	
	/* Mark all nodes for deletion. Selectively, they will be unmarked below */
	g_hash_table_foreach (plugin->nodes,
	                      (GHFunc) on_cls_node_mark_for_deletion,
	                      NULL);
	if (!iter)
	{
		DEBUG_PRINT ("%s", "cls_inherit_update_graph (): search returned no items.");
		goto cleanup;
	}
	
	ianjuta_iterable_first (iter, NULL);
	if (ianjuta_iterable_get_length (iter, NULL) <= 0)
	{
		g_object_unref (iter);
		goto cleanup;
	}
	do 
	{
		gint klass_id;
		IAnjutaIterable *parents;
     
		/* a symbol representing a class */
		symbol = IANJUTA_SYMBOL (iter);

		/* get parents of the current class */
		parents =
			ianjuta_symbol_query_search_class_parents (plugin->query_parents,
			                                           symbol, &err);

		if (err)
		{
			g_warning ("Class parents query failed: %s", err->message);
			g_error_free (err);
			err = NULL;
		}
		/* if no parents are found then continue */
		if (parents == NULL || ianjuta_iterable_get_length (parents, NULL) <= 0)
		{
			/*DEBUG_PRINT ("ClassInheritance: no parents found for class %s",
						 ianjuta_symbol_get_name (symbol, NULL));*/
			continue;
		}

		if ((klass_id = ianjuta_symbol_get_int (symbol,
		                                        IANJUTA_SYMBOL_FIELD_ID,
		                                        NULL)) <= 0)
		{
			/*DEBUG_PRINT ("%s", "ClassInheritance: klass_id cannot be <= 0");*/
			continue;
		}
		
		cls_node = g_hash_table_lookup (plugin->nodes, GINT_TO_POINTER (klass_id));
		if (!cls_node)
		{
			cls_node = cls_inherit_create_node (plugin, symbol);
			g_hash_table_insert (plugin->nodes, GINT_TO_POINTER (klass_id), cls_node);
		}
		cls_node->marked_for_deletion = FALSE;

		/* Get parents */
		do 
		{
			gint parent_id;
			ClsNode *parent_node;
			IAnjutaSymbol *parent_symbol;
			parent_symbol = IANJUTA_SYMBOL (parents);
			parent_id = ianjuta_symbol_get_int (parent_symbol,
			                                    IANJUTA_SYMBOL_FIELD_ID,
			                                    NULL);
			
			parent_node = g_hash_table_lookup (plugin->nodes,
			                                   GINT_TO_POINTER (parent_id));
			if (!parent_node)
			{
				parent_node = cls_inherit_create_node (plugin, parent_symbol);
				g_hash_table_insert (plugin->nodes, GINT_TO_POINTER (parent_id),
				                     parent_node);
			}
			parent_node->marked_for_deletion = FALSE;
			cls_node_add_edge (parent_node, cls_node);
		} while (ianjuta_iterable_next (parents, NULL) == TRUE);
		g_object_unref (parents);

	} while (ianjuta_iterable_next (iter, NULL) == TRUE);

cleanup:
	
	/* Delete all marked nodes that did not get unmarked above. */
	g_hash_table_foreach_remove (plugin->nodes,
	                             (GHRFunc) on_cls_node_delete_marked,
	                             NULL);

	cls_inherit_draw (plugin);
}
예제 #3
0
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;
}