26 #include "tdeactioncollection.h" 27 #include "tdeactionshortcutlist.h" 28 #include "tdetoolbar.h" 29 #include "kxmlguifactory.h" 30 #include "kxmlguiclient.h" 33 #include <tdeaccelbase.h> 34 #include <tdeapplication.h> 37 #include <tqpopupmenu.h> 38 #include <tqptrdict.h> 39 #include <tqvariant.h> 41 class TDEActionCollection::TDEActionCollectionPrivate
44 TDEActionCollectionPrivate()
49 m_bAutoConnectShortcuts =
true;
51 m_tdeaccel = m_builderTDEAccel = 0;
52 m_dctHighlightContainers.setAutoDelete(
true );
54 m_currentHighlightAction = 0;
55 m_statusCleared =
true;
56 m_parentGUIClient = 0L;
61 bool m_bAutoConnectShortcuts;
66 TQValueList<TDEActionCollection*> m_docList;
71 TQAsciiDict<TDEAction> m_actionDict;
72 TQPtrDict< TQPtrList<TDEAction> > m_dctHighlightContainers;
79 TDEActionCollection::TDEActionCollection( TQWidget *parent,
const char *name,
81 : TQObject( parent, name )
83 kdDebug(129) <<
"TDEActionCollection::TDEActionCollection( " << parent <<
", " << name <<
" ): this = " <<
this <<
endl;
84 d =
new TDEActionCollectionPrivate;
88 setInstance( instance );
92 TDEActionCollection::TDEActionCollection( TQWidget *watch, TQObject* parent,
const char *name,
94 : TQObject( parent, name )
96 kdDebug(129) <<
"TDEActionCollection::TDEActionCollection( " << watch <<
", " << parent <<
", " << name <<
" ): this = " <<
this <<
endl;
97 d =
new TDEActionCollectionPrivate;
101 setInstance( instance );
104 #ifndef KDE_NO_COMPAT 106 TDEActionCollection::TDEActionCollection( TQObject *parent,
const char *name,
108 : TQObject( parent, name )
110 kdWarning(129) <<
"TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, TDEInstance *instance )" <<
endl;
112 d =
new TDEActionCollectionPrivate;
113 TQWidget* w = tqt_dynamic_cast<TQWidget*>( parent );
117 setInstance( instance );
123 kdWarning(129) <<
"TDEActionCollection::TDEActionCollection( const TDEActionCollection & ): function is severely deprecated." <<
endl;
124 d =
new TDEActionCollectionPrivate;
127 #endif // KDE 4: remove end 129 TDEActionCollection::TDEActionCollection(
const char *name,
const KXMLGUIClient *parent )
130 : TQObject( 0L, name )
132 d =
new TDEActionCollectionPrivate;
133 d->m_parentGUIClient=parent;
138 TDEActionCollection::~TDEActionCollection()
140 kdDebug(129) <<
"TDEActionCollection::~TDEActionCollection(): this = " <<
this <<
endl;
141 for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) {
143 if ( pAction->m_parentCollection ==
this )
144 pAction->m_parentCollection = 0L;
147 delete d->m_tdeaccel;
148 delete d->m_builderTDEAccel;
159 if ( !d->m_widget ) {
161 d->m_tdeaccel =
new TDEAccel( w,
this,
"TDEActionCollection-TDEAccel" );
163 else if ( d->m_widget != w )
164 kdWarning(129) <<
"TDEActionCollection::setWidget(): tried to change widget from " << d->m_widget <<
" to " << w <<
endl;
169 d->m_bAutoConnectShortcuts = b;
174 return d->m_bAutoConnectShortcuts;
179 d->m_docList.append( pDoc );
183 void TDEActionCollection::beginXMLPlug( TQWidget *widget )
185 kdDebug(129) <<
"TDEActionCollection::beginXMLPlug( buildWidget = " << widget <<
" ): this = " <<
this <<
" d->m_builderTDEAccel = " << d->m_builderTDEAccel <<
endl;
187 if( widget && !d->m_builderTDEAccel ) {
188 d->m_builderTDEAccel =
new TDEAccel( widget,
this,
"TDEActionCollection-BuilderTDEAccel" );
192 void TDEActionCollection::endXMLPlug()
194 kdDebug(129) <<
"TDEActionCollection::endXMLPlug(): this = " <<
this <<
endl;
198 void TDEActionCollection::prepareXMLUnplug()
200 kdDebug(129) <<
"TDEActionCollection::prepareXMLUnplug(): this = " <<
this <<
endl;
201 unplugShortcuts( d->m_tdeaccel );
203 if( d->m_builderTDEAccel ) {
204 unplugShortcuts( d->m_builderTDEAccel );
205 delete d->m_builderTDEAccel;
206 d->m_builderTDEAccel = 0;
212 for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) {
214 pAction->removeTDEAccel( tdeaccel );
217 for( uint i = 0; i < d->m_docList.count(); i++ )
218 d->m_docList[i]->unplugShortcuts( tdeaccel );
288 return d->m_tdeaccel;
297 return d->m_tdeaccel;
304 const char* name = action->name();
305 if( !qstrcmp( name,
"unnamed" ) )
307 sprintf(buffer,
"unnamed-%p", (
void *)action);
313 void TDEActionCollection::_insert(
TDEAction* action )
315 char unnamed_name[100];
316 const char *name = actionDictKey( action, unnamed_name );
321 d->m_actionDict.insert( name, action );
323 emit inserted( action );
326 void TDEActionCollection::_remove(
TDEAction* action )
328 char unnamed_name[100];
329 const char *name = actionDictKey( action, unnamed_name );
331 TDEAction *a = d->m_actionDict.take( name );
332 if ( !a || a != action )
335 emit removed( action );
343 char unnamed_name[100];
344 const char *name = actionDictKey( action, unnamed_name );
346 TDEAction *a = d->m_actionDict.take( name );
347 if ( !a || a != action )
350 if ( a->m_parentCollection ==
this )
351 a->m_parentCollection = 0;
353 emit removed( action );
358 void TDEActionCollection::_clear()
360 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
361 while ( it.current() )
362 _remove( it.current() );
377 if ( !classname && name )
378 pAction = d->m_actionDict[ name ];
381 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
382 for( ; it.current(); ++it )
384 if ( ( !name || !strcmp( it.current()->name(), name ) ) &&
385 ( !classname || !strcmp( it.current()->className(), classname ) ) ) {
386 pAction = it.current();
393 for( uint i = 0; i < d->m_docList.count() && !pAction; i++ )
394 pAction = d->m_docList[i]->action( name, classname );
402 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
410 return TDEActionShortcutList(
this).readSettings( sConfigGroup, pConfig );
415 return TDEActionShortcutList((
TDEActionCollection*)
this).writeSettings( sConfigGroup, pConfig );
420 return d->m_actionDict.count();
427 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
428 for( ; it.current(); ++it )
429 if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) )
430 lst.append( it.current()->group() );
437 TDEActionPtrList lst;
439 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
440 for( ; it.current(); ++it )
441 if ( it.current()->group() == group )
442 lst.append( it.current() );
443 else if ( it.current()->group().isEmpty() && group.isEmpty() )
444 lst.append( it.current() );
451 TDEActionPtrList lst;
453 TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
454 for( ; it.current(); ++it )
455 lst.append( it.current() );
460 void TDEActionCollection::setInstance(
TDEInstance *instance )
470 return d->m_instance;
475 d->m_sXMLFile = sXMLFile;
480 return d->m_sXMLFile;
485 d->m_highlight = enable;
490 return d->m_highlight;
495 if ( !d->m_highlight )
498 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ];
502 actionList =
new TQPtrList<TDEAction>;
504 if ( ::tqqt_cast<TQPopupMenu *>( container ) )
506 connect( container, TQT_SIGNAL( highlighted(
int ) ),
507 this, TQT_SLOT( slotMenuItemHighlighted(
int ) ) );
508 connect( container, TQT_SIGNAL( aboutToHide() ),
509 this, TQT_SLOT( slotMenuAboutToHide() ) );
511 else if ( ::tqqt_cast<TDEToolBar *>( container ) )
513 connect( container, TQT_SIGNAL( highlighted(
int,
bool ) ),
514 this, TQT_SLOT( slotToolBarButtonHighlighted(
int,
bool ) ) );
517 connect( container, TQT_SIGNAL( destroyed() ),
518 this, TQT_SLOT( slotDestroyed() ) );
520 d->m_dctHighlightContainers.insert( container, actionList );
523 actionList->append( action );
528 if ( !d->m_highlight )
531 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ];
536 actionList->removeRef( action );
538 if ( actionList->isEmpty() )
539 d->m_dctHighlightContainers.remove( container );
542 void TDEActionCollection::slotMenuItemHighlighted(
int id )
544 if ( !d->m_highlight )
547 if ( d->m_currentHighlightAction )
550 TQWidget *container =
static_cast<TQWidget *
>(
const_cast<TQObject *
>( sender() ));
552 d->m_currentHighlightAction = findAction( container,
id );
554 if ( !d->m_currentHighlightAction )
556 if ( !d->m_statusCleared )
558 d->m_statusCleared =
true;
562 d->m_statusCleared =
false;
568 void TDEActionCollection::slotMenuAboutToHide()
570 if ( d->m_currentHighlightAction )
572 d->m_currentHighlightAction = 0;
574 if ( !d->m_statusCleared )
576 d->m_statusCleared =
true;
579 void TDEActionCollection::slotToolBarButtonHighlighted(
int id,
bool highlight )
581 if ( !d->m_highlight )
584 TQWidget *container =
static_cast<TQWidget *
>(
const_cast<TQObject *
>( sender() ));
586 TDEAction *action = findAction( container,
id );
590 d->m_currentHighlightAction = 0;
599 d->m_currentHighlightAction =
action;
602 d->m_currentHighlightAction = 0;
607 void TDEActionCollection::slotDestroyed()
609 d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<TQObject*>(sender()) ) );
612 TDEAction *TDEActionCollection::findAction( TQWidget *container,
int id )
614 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[
reinterpret_cast<void *
>( container ) ];
619 TQPtrListIterator<TDEAction> it( *actionList );
620 for (; it.current(); ++it )
621 if ( it.current()->isPlugged( container,
id ) )
629 return d->m_parentGUIClient;
632 #ifndef KDE_NO_COMPAT 636 kdWarning(129) <<
"TDEActionCollection::operator+(): function is severely deprecated." <<
endl;
640 TQValueList<TDEAction *>::ConstIterator it = actions.begin();
641 TQValueList<TDEAction *>::ConstIterator end = actions.end();
642 for (; it != end; ++it )
650 kdWarning(129) <<
"TDEActionCollection::operator=(): function is severely deprecated." <<
endl;
655 d->m_widget = copy.d->m_widget;
656 d->m_tdeaccel = copy.d->m_tdeaccel;
657 d->m_actionDict = copy.d->m_actionDict;
664 kdWarning(129) <<
"TDEActionCollection::operator+=(): function is severely deprecated." <<
endl;
665 TQAsciiDictIterator<TDEAction> it(c.d->m_actionDict);
666 for ( ; it.current(); ++it )
671 #endif // KDE 4: remove end 678 : m_actions( *pColl )
680 TDEActionShortcutList::~TDEActionShortcutList()
682 uint TDEActionShortcutList::count()
const 683 {
return m_actions.count(); }
684 TQString TDEActionShortcutList::name( uint i )
const 685 {
return m_actions.action(i)->name(); }
686 TQString TDEActionShortcutList::label( uint i )
const 687 {
return m_actions.action(i)->text(); }
688 TQString TDEActionShortcutList::whatsThis( uint i )
const 689 {
return m_actions.action(i)->whatsThis(); }
690 const TDEShortcut& TDEActionShortcutList::shortcut( uint i )
const 691 {
return m_actions.action(i)->shortcut(); }
692 const TDEShortcut& TDEActionShortcutList::shortcutDefault( uint i )
const 693 {
return m_actions.action(i)->shortcutDefault(); }
694 bool TDEActionShortcutList::isConfigurable( uint i )
const 695 {
return m_actions.action(i)->isShortcutConfigurable(); }
696 bool TDEActionShortcutList::setShortcut( uint i,
const TDEShortcut& cut )
697 {
return m_actions.action(i)->setShortcut( cut ); }
698 const TDEInstance* TDEActionShortcutList::instance()
const 699 {
return m_actions.instance(); }
700 TQVariant TDEActionShortcutList::getOther( Other, uint )
const 701 {
return TQVariant(); }
702 bool TDEActionShortcutList::setOther( Other, uint, TQVariant )
704 const TDEAction *TDEActionShortcutList::action( uint i)
const 705 {
return m_actions.action(i); }
707 bool TDEActionShortcutList::save()
const 710 const TQString
xmlFile=guiClient ? guiClient->
xmlFile() : m_actions.xmlFile();
711 kdDebug(129) <<
"TDEActionShortcutList::save(): xmlFile = " << xmlFile <<
endl;
713 if( m_actions.xmlFile().isEmpty() )
714 return writeSettings();
716 TQString attrShortcut = TQString::fromLatin1(
"shortcut");
717 TQString attrAccel = TQString::fromLatin1(
"accel");
720 TQString sXml( KXMLGUIFactory::readConfigFile( xmlFile,
false,
instance() ) );
722 doc.setContent( sXml );
730 uint nSize =
count();
731 for( uint i = 0; i < nSize; i++ ) {
732 const TQString& sName = name(i);
734 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
740 if ( act_elem.isNull() )
743 act_elem.removeAttribute( attrAccel );
744 if( bSameAsDefault ) {
745 act_elem.removeAttribute( attrShortcut );
747 if( act_elem.attributes().count() == 1 )
748 elem.removeChild( act_elem );
750 act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() );
755 return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(),
instance() );
762 TDEActionPtrShortcutList::TDEActionPtrShortcutList( TDEActionPtrList& list )
765 TDEActionPtrShortcutList::~TDEActionPtrShortcutList()
767 uint TDEActionPtrShortcutList::count()
const 768 {
return m_actions.count(); }
769 TQString TDEActionPtrShortcutList::name( uint i )
const 770 {
return m_actions[i]->name(); }
771 TQString TDEActionPtrShortcutList::label( uint i )
const 772 {
return m_actions[i]->text(); }
773 TQString TDEActionPtrShortcutList::whatsThis( uint i )
const 774 {
return m_actions[i]->whatsThis(); }
775 const TDEShortcut& TDEActionPtrShortcutList::shortcut( uint i )
const 776 {
return m_actions[i]->shortcut(); }
777 const TDEShortcut& TDEActionPtrShortcutList::shortcutDefault( uint i )
const 778 {
return m_actions[i]->shortcutDefault(); }
779 bool TDEActionPtrShortcutList::isConfigurable( uint i )
const 780 {
return m_actions[i]->isShortcutConfigurable(); }
781 bool TDEActionPtrShortcutList::setShortcut( uint i,
const TDEShortcut& cut )
782 {
return m_actions[i]->setShortcut( cut ); }
783 TQVariant TDEActionPtrShortcutList::getOther( Other, uint )
const 784 {
return TQVariant(); }
785 bool TDEActionPtrShortcutList::setOther( Other, uint, TQVariant )
787 bool TDEActionPtrShortcutList::save()
const 790 void TDEActionShortcutList::virtual_hook(
int id,
void* data )
793 void TDEActionPtrShortcutList::virtual_hook(
int id,
void* data )
796 void TDEActionCollection::virtual_hook(
int,
void* )
799 #include "tdeactioncollection.moc" TQString kdBacktrace(int levels=-1)
void insert(TDEAction *action)
Add an action to the collection.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
void setHighlightingEnabled(bool enable)
Enable highlighting notification for specific TDEActions.
virtual TDEActionPtrList actions(const TQString &group) const
Returns the list of actions in a particular group managed by this action collection.
kdbgstream kdDebug(int area=0)
virtual void setWidget(TQWidget *widget)
This sets the widget to which the keyboard shortcuts should be attached.
void connectHighlight(TQWidget *container, TDEAction *action)
Call this function if you want to receive a signal whenever a TDEAction is highlighted in a menu or a...
A managed set of TDEAction objects.
Class to encapsulate user-driven action or event.
void setAutoConnectShortcuts(bool)
This indicates whether new actions which are created in this collection should have their keyboard sh...
bool addDocCollection(TDEActionCollection *pDoc)
This sets the default shortcut scope for new actions created in this collection.
void actionHighlighted(TDEAction *action)
Emitted when action is highlighted.
virtual TQStringList groups() const
Returns a list of all the groups of all the TDEActions in this action collection. ...
static TQDomElement findActionByName(TQDomElement &elem, const TQString &sName, bool create)
bool writeShortcutSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0) const
Used for writing shortcut configuration to a non-XML rc file.
TDEAccel * builderTDEAccel() const
static TDEInstance * instance()
TDEAction * take(TDEAction *action)
Removes an action from the collection.
kdbgstream kdWarning(int area=0)
TDEInstance * instance() const
The instance with which this class is associated.
virtual void virtual_hook(int id, void *data)
virtual TDEAction * action(int index) const
Return the TDEAction* at position "index" in the action collection.
void setXMLFile(const TQString &)
static TQDomElement actionPropertiesElement(TQDomDocument &doc)
virtual TDEInstance * instance() const
const TQString & xmlFile() const
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, return 0L if not available.
void clearStatusText()
Emitted when an action loses highlighting.
virtual TQString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
void actionStatusText(const TQString &text)
Emitted when an action is highlighted, with text being the tooltip for the action.
virtual TDEAccel * accel() KDE_DEPRECATED
Returns the number of widgets which this collection is associated with.
virtual TDEActionPtrList actions() const
Returns the list of actions managed by this action collection.
virtual uint count() const
Returns the TDEAccel object associated with widget #.
TDEAccel * tdeaccel()
Returns the TDEAccel object of the most recently set widget.
void clear()
Clears the entire actionCollection, deleting all actions.
void disconnectHighlight(TQWidget *container, TDEAction *action)
Disconnect highlight notifications for a particular pair of contianer and action. ...
bool isAutoConnectShortcuts()
This indicates whether new actions which are created in this collection have their keyboard shortcuts...
kndbgstream & endl(kndbgstream &s)
bool highlightingEnabled() const
Return whether highlighting notifications are enabled.
void remove(TDEAction *action)
Removes an action from the collection and deletes it.
bool readShortcutSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0)
Used for reading shortcut configuration from a non-XML rc file.