void FillBSPMenu (void)
{
	HMENU	hmenu;
	epair_t	*ep;
	int		i;
	static int count;

	hmenu = GetSubMenu (GetMenu(g_qeglobals.d_hwndMain), MENU_BSP);

	for (i=0 ; i<count ; i++)
		DeleteMenu (hmenu, CMD_BSPCOMMAND+i, MF_BYCOMMAND);
	count = 0;

	if ( g_qeglobals.bBSPFrontendPlugin )
	{
		CString str = g_BSPFrontendTable.m_pfnGetBSPMenu();
		char cTemp[1024];
		strcpy(cTemp, str);
		char* token = strtok(cTemp, ",;");
		if (token && *token == ' ')
		{
			while (*token == ' ')
				token++;
		}
		i = 0;
		// first token is menu name
		ModifyMenu( GetMenu(g_qeglobals.d_hwndMain), MENU_BSP, MF_BYPOSITION, MENU_BSP, (LPCTSTR)token );
		// redraw the menu bar
		DrawMenuBar( g_qeglobals.d_hwndMain );
		token = strtok(NULL, ",;");
		while (token != NULL)
		{
			g_BSPFrontendCommands.Add(token);
			AppendMenu (hmenu, MF_ENABLED|MF_STRING, CMD_BSPCOMMAND+i, (LPCTSTR)token );
			token = strtok(NULL, ",;");
			i++;
		}
		count = i;
	}
	else
	{
		i = 0;
		for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
		{
			if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
			{
				bsp_commands[i] = ep->key;
				AppendMenu (hmenu, MF_ENABLED|MF_STRING,
					CMD_BSPCOMMAND+i, (LPCTSTR)ep->key);
				i++;
			}
		}
		count = i;
	}
}
Exemple #2
0
void FillBSPMenu(){
	GtkWidget *item, *menu; // menu points to a GtkMenu (not an item)
	epair_t *ep;
	GList *lst;
	int i;

	menu = GTK_WIDGET( g_object_get_data( G_OBJECT( g_qeglobals_gui.d_main_window ), "menu_bsp" ) );

	while ( ( lst = gtk_container_children( GTK_CONTAINER( menu ) ) ) != NULL )
		gtk_container_remove( GTK_CONTAINER( menu ), GTK_WIDGET( lst->data ) );

	if ( g_PrefsDlg.m_bDetachableMenus ) {
		item = gtk_tearoff_menu_item_new();
		gtk_menu_append( GTK_MENU( menu ), item );
		gtk_widget_set_sensitive( item, TRUE );
		gtk_widget_show( item );
	}

	if ( g_qeglobals.bBSPFrontendPlugin ) {
		CString str = g_BSPFrontendTable.m_pfnGetBSPMenu();
		char cTemp[1024];
		strcpy( cTemp, str );
		char* token = strtok( cTemp, ",;" );
		if ( token && *token == ' ' ) {
			while ( *token == ' ' )
				token++;
		}
		i = 0;

		// first token is menu name
		item = gtk_menu_get_attach_widget( GTK_MENU( menu ) );
		gtk_label_set_text( GTK_LABEL( GTK_BIN( item )->child ), token );

		token = strtok( NULL, ",;" );
		while ( token != NULL )
		{
			g_BSPFrontendCommands = g_slist_append( g_BSPFrontendCommands, g_strdup( token ) );
			item = gtk_menu_item_new_with_label( token );
			gtk_widget_show( item );
			gtk_container_add( GTK_CONTAINER( menu ), item );
			gtk_signal_connect( GTK_OBJECT( item ), "activate",
								GTK_SIGNAL_FUNC( HandleCommand ), GINT_TO_POINTER( CMD_BSPCOMMAND + i ) );
			token = strtok( NULL, ",;" );
			i++;
		}
	}
	else
	{
		i = 0;
		for ( ep = g_qeglobals.d_project_entity->epairs; ep; ep = ep->next )
		{
			if ( strncmp( ep->key, "bsp_", 4 ) == 0 ) {
				bsp_commands[i] = ep->key;
				item = gtk_menu_item_new_with_label( ep->key + 4 );
				gtk_widget_show( item );
				gtk_container_add( GTK_CONTAINER( menu ), item );
				gtk_signal_connect( GTK_OBJECT( item ), "activate",
									GTK_SIGNAL_FUNC( HandleCommand ), GINT_TO_POINTER( CMD_BSPCOMMAND + i ) );
				i++;
			}
		}
	}
}