コード例 #1
0
ファイル: parser-cxx-assist.c プロジェクト: VujinovM/anjuta
/**
 * parser_cxx_assist_proposal_new:
 * @symbol: IAnjutaSymbol to create the proposal for
 *
 * Creates a new IAnjutaEditorAssistProposal for symbol
 *
 * Returns: a newly allocated IAnjutaEditorAssistProposal
 */
static IAnjutaEditorAssistProposal*
parser_cxx_assist_proposal_new (IAnjutaSymbol* symbol)
{
	IAnjutaEditorAssistProposal* proposal = g_new0 (IAnjutaEditorAssistProposal, 1);
	AnjutaLanguageProposalData* data = 
		anjuta_language_proposal_data_new (g_strdup (ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_NAME, NULL)));
	data->type = ianjuta_symbol_get_sym_type (symbol, NULL);
	switch (data->type)
	{
		case IANJUTA_SYMBOL_TYPE_PROTOTYPE:
		case IANJUTA_SYMBOL_TYPE_FUNCTION:
		case IANJUTA_SYMBOL_TYPE_METHOD:
		case IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG:
			proposal->label = g_strdup_printf ("%s()", data->name);
			data->is_func = TRUE;
			break;
		default:
			proposal->label = g_strdup (data->name);
			data->is_func = FALSE;
	}
	data->has_para = FALSE;
	if (data->is_func)
	{
		const gchar* signature = ianjuta_symbol_get_string (symbol,
		                                                    IANJUTA_SYMBOL_FIELD_SIGNATURE,
		                                                    NULL);
		if (g_strcmp0 (signature, "(void)") || g_strcmp0 (signature, "()"))
			data->has_para = TRUE;
			
	}
	
	proposal->data = data;
	/* Icons are lifetime object of the symbol-db so we can cast here */
	proposal->icon = (GdkPixbuf*) ianjuta_symbol_get_icon (symbol, NULL);
	return proposal;
}
コード例 #2
0
ファイル: class-inherit.c プロジェクト: rosedu/anjuta
gboolean
cls_node_expand (ClsNode *cls_node, ClsNodeExpansionType expansion_type)
{
	Agsym_t *sym;
	GString *label;
	gint max_label_items = 0;
	gint real_items_length = 0;
	gint var_order = -1000;
	gint method_order = 0;
	IAnjutaSymbol *node_sym;
	IAnjutaIterable *iter;
	GError *err = NULL;
	
	if (cls_node->expansion_status == expansion_type ||
	    expansion_type == CLS_NODE_COLLAPSED)
		return FALSE;

	node_sym =
		IANJUTA_SYMBOL (ianjuta_symbol_query_search_id (cls_node->plugin->query_id,
		                                                cls_node->klass_id,
		                                                &err));
	if (err)
	{
		g_warning ("Symbol ID query failed: %s", err->message);
		g_error_free (err);
		err = NULL;
	}
	if (!node_sym)
		return FALSE;
	
	if (!(sym = agfindattr(cls_node->graph->proto->n, "shape")))
		sym = agnodeattr(cls_node->graph, "shape", "");
	agxset (cls_node->agnode, sym->index, "record");
	
	if (!(sym = agfindattr(cls_node->graph->proto->n, "label")))
		sym = agnodeattr(cls_node->graph, "label", "");
	
	label = g_string_new ("");
	g_string_printf (label, "{%s", cls_node->sym_name);
	
	/* get members from the passed symbol node */
	iter = ianjuta_symbol_query_search_members (cls_node->plugin->query_members,
	                                            node_sym, &err);
	if (err)
	{
		g_warning ("Class members query failed: %s", err->message);
		g_error_free (err);
		err = NULL;
	}

	real_items_length = ianjuta_iterable_get_length (iter, NULL);
	
	/* set the max number of items to draw */
	if (real_items_length <= NODE_HALF_DISPLAY_ELEM_NUM || 
	    expansion_type == CLS_NODE_FULL_EXPANDED) 
	{
		max_label_items = real_items_length;
		cls_node->expansion_status = CLS_NODE_FULL_EXPANDED;
	}
	else
	{
		max_label_items = NODE_HALF_DISPLAY_ELEM_NUM;
		cls_node->expansion_status = CLS_NODE_SEMI_EXPANDED;
	}

	g_hash_table_remove_all (cls_node->members);
	if (iter && real_items_length > 0)
	{
		gint i = 0;

		/* First member variables */
		do
		{
			const gchar *name, *args, *type_name;
			IAnjutaSymbol *symbol;
			GdkPixbuf *icon;
			
			symbol = IANJUTA_SYMBOL (iter);
			name = g_strdup (ianjuta_symbol_get_string (symbol,
			                                            IANJUTA_SYMBOL_FIELD_NAME,
			                                            NULL));
			args = ianjuta_symbol_get_string (symbol,
			                                  IANJUTA_SYMBOL_FIELD_SIGNATURE,
			                                  NULL);
			icon = (GdkPixbuf*) ianjuta_symbol_get_icon (symbol, NULL);
			
			if (!args) /* Member variables */
			{
				ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1);

				type_name = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_TYPE_NAME, NULL);
				cls_item->cls_node = cls_node;
				cls_item->label = g_strconcat (name, " : ", type_name, NULL);
				cls_item->order = var_order++;
				if (icon)
					g_object_ref (icon);
				cls_item->icon = icon;
				
				g_hash_table_insert (cls_node->members,
				                     g_strdup (cls_item->label),
				                     cls_item);
				g_string_append_printf (label, "|%s", cls_item->label);

				/* Setup file and line */
				cls_item->type_name = g_strdup (type_name);
				cls_item->line = ianjuta_symbol_get_int (symbol,
				                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
				                                         NULL);
				cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
			}
			else /* Member methods */
			{
				ClsNodeItem *cls_item;
				gchar *method_key = g_strconcat (name, args, NULL);
				cls_item = g_hash_table_lookup (cls_node->members, method_key);

				if (cls_item) /* We found an entry for this method */
				{
					IAnjutaSymbolType sym_type
						= ianjuta_symbol_get_sym_type (symbol, NULL);
					if (!(sym_type & IANJUTA_SYMBOL_TYPE_PROTOTYPE))
					{
						/* This one is method, so take this one instead */
						g_free (cls_item->args);
						cls_item->args = g_strdup (args);

						if (cls_item->file) g_object_unref (cls_item->file);
						cls_item->file = NULL;

						/* Setup file and line */
						cls_item->line = ianjuta_symbol_get_int (symbol,
						                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
						                                         NULL);
						cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
					}
				}
				else /* We did not find a member entry, create a new one */
				{
					ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1);
					type_name = ianjuta_symbol_get_string (symbol,
					                                       IANJUTA_SYMBOL_FIELD_RETURNTYPE,
					                                       NULL);

					cls_item->cls_node = cls_node;
					if (type_name)
					{
						if (strlen (args) > 2)
							cls_item->label = g_strconcat (name, "(...)",
							                               " : ", type_name,
							                               NULL);
						else
							cls_item->label = g_strconcat (name, "()", " : ",
							                               type_name, NULL);
					}
					else
					{
						if (strlen (args) > 2)
							cls_item->label = g_strconcat (name, "(...)", NULL);
						else
							cls_item->label = g_strconcat (name, "()", NULL);
					}
					cls_item->args = g_strdup (args);
					cls_item->type_name = g_strdup (type_name);
					cls_item->order = method_order++;
					if (icon)
						g_object_ref (icon);
					cls_item->icon = icon;
					
					g_string_append_printf (label, "|%s", cls_item->label);
					g_hash_table_insert (cls_node->members, method_key,
					                     cls_item);
					
					/* Setup file and line */
					cls_item->line = ianjuta_symbol_get_int (symbol,
					                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
					                                         NULL);
					cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
				}
			}
			i++;
		}
		while (ianjuta_iterable_next (iter, NULL) && i < max_label_items);
	}
	if (iter)
		g_object_unref (iter);
	
	if (cls_node->expansion_status == CLS_NODE_SEMI_EXPANDED &&
	    real_items_length > NODE_HALF_DISPLAY_ELEM_NUM)
	{
		g_string_append_printf (label, "|%s", NODE_SHOW_ALL_MEMBERS_STR);
	}
	
	g_string_append_printf (label, "}");
	agxset(cls_node->agnode, sym->index, label->str);
	
	/* set the margin for icons */
	if (!(sym = agfindattr(cls_node->graph->proto->n, "margin")))
		sym = agnodeattr(cls_node->graph, "margin", "0.11,0.055");
	agxset(cls_node->agnode, sym->index, "0.3,0.03");

	g_string_free (label, TRUE);

	return TRUE;
}