[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    problem with ActionList (long)
From:       Jason Harris <kstars () 30doradus ! org>
Date:       2002-02-25 16:16:49
[Download RAW message or body]

Hello,

I'm trying to add dynamic menu items to my app (KStars) using XMLGUI, but I 
can't get it to work.  I was hoping someone here might be able to see what I 
am doing wrong.  I've followed the example at: 
http://developer.kde.org/documentation/kde2arch/xmlgui.html
and I've also looked at the konqueror source code.

I have the following in my kstarsui.rc:
    <Menu name="settings" noMerge="1"><text>&amp;Settings</text>
        <ActionList name="colorschemes" />
        ...
    </Menu>

and the following in my source code:

//in class definition (header file):
    QPtrList<KAction> colorActions;  

//in source code file:
//these actions don't take actionCollection() as a parent 
//(use (QObject*)0 instead)
    KAction *actCSDefault = new KAction( i18n( "&Default" ),
         0, this, SLOT( ks->mDefaultScheme(int) ), (QObject*)0, "cs_def" );
    KAction *actCSChart = new KAction( i18n( "&Star Chart" ),
         0, this, SLOT( ks->mChartScheme(int) ), (QObject*)0, "cs_chart" );
    KAction *actCSNight = new KAction( i18n( "&Night Vision" ),
        0, this, SLOT( ks->mNightScheme(int) ), (QObject*)0, "cs_night" );

    colorActions.setAutoDelete( true );
    colorActions.clear();
    colorActions.append( actCSDefault );
    colorActions.append( actCSChart );
    colorActions.append( actCSNight );

    plugActionList( "colorschemes", colorActions );

When I run the program, the menu items don't appear in the menu.  
I tried moving the above code to both before and after 
createGUI("kstarsui.rc") is called, but it doesn't seem to make a difference 
(which location is correct?)

I also dug around in kdelibs, trying to track down the problem.  I found that 
in KXMLGUIFactory::plugActionList(), in the following statement:

    d->clientName = client->domDocument().documentElement().attribute(
        d->attrName );

"d->clientName" is assigned an empty string.
and so, in ContainerNode::plugActionList(), it returns prematurely when it 
gets to the statement:

    if ( mergingIdx.clientName != state.clientName )
        return;

because mergingIdx.clientName is "colorschemes" but state.clientName is empty.
If I comment these two lines out, then my menu items appear in the menu.

I'm afraid I don't know enough about KDE's XMLGUI functions to really 
understand what's happening here.  Can anyone see something obvious that I've 
done wrong?  Or perhaps point me to some more documentation/examples on using 
XMLGUI to create dynamic menu items? 

Thanks in advance, and please cc me on any replies.

sincerely,
Jason Harris

-- 
KStars: A K Desktop Planetarium
http://kstars.sourceforge.net
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic