19 #include "tdetoolbarhandler.h"
21 #include <tqpopupmenu.h>
22 #include <tdeapplication.h>
23 #include <tdetoolbar.h>
24 #include <tdemainwindow.h>
26 #include <tdeaction.h>
31 const char *actionListName =
"show_menu_and_toolbar_actionlist";
33 const char *guiDescription =
""
34 "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
36 " <Menu name=\"settings\">"
37 " <ActionList name=\"%1\" />"
42 const char *resourceFileName =
"barhandler.rc";
44 class BarActionBuilder
48 : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
50 TQPtrList<TQDockWindow> dockWindows = m_mainWindow->dockWindows();
51 TQPtrListIterator<TQDockWindow> dockWindowIt( dockWindows );
52 for ( ; dockWindowIt.current(); ++dockWindowIt ) {
58 if ( oldToolBarList.findRef( toolBar ) == -1 )
59 m_needsRebuild =
true;
61 m_toolBars.append( toolBar );
64 if ( !m_needsRebuild )
65 m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
68 bool needsRebuild()
const {
return m_needsRebuild; }
70 TQPtrList<TDEAction>
create()
72 if ( !m_needsRebuild )
73 return TQPtrList<TDEAction>();
75 TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
76 for ( ; toolBarIt.current(); ++toolBarIt )
77 handleToolBar( toolBarIt.current() );
79 TQPtrList<TDEAction> actions;
81 if ( m_toolBarActions.count() == 0 )
84 if ( m_toolBarActions.count() == 1 ) {
86 action->setText( i18n(
"Show Toolbar" ) );
87 action->setCheckedState( i18n(
"Hide Toolbar" ) );
88 return m_toolBarActions;
93 TQPtrListIterator<TDEAction> actionIt( m_toolBarActions );
94 for ( ; actionIt.current(); ++actionIt )
95 menuAction->insert( actionIt.current() );
97 actions.append( menuAction );
101 const TQPtrList<TDEToolBar> &toolBars()
const {
return m_toolBars; }
112 m_toolBarActions.append( action );
118 TQPtrList<TDEToolBar> m_toolBars;
119 TQPtrList<TDEAction> m_toolBarActions;
121 bool m_needsRebuild : 1;
125 using namespace KDEPrivate;
127 ToolBarHandler::ToolBarHandler(
TDEMainWindow *mainWindow,
const char *name )
133 ToolBarHandler::ToolBarHandler(
TDEMainWindow *mainWindow, TQObject *parent,
const char *name )
139 ToolBarHandler::~ToolBarHandler()
141 m_actions.setAutoDelete(
true );
145 TDEAction *ToolBarHandler::toolBarMenuAction()
147 assert( m_actions.count() == 1 );
148 return m_actions.getFirst();
151 void ToolBarHandler::setupActions()
153 if ( !
factory() || !m_mainWindow )
158 if ( !builder.needsRebuild() )
163 m_actions.setAutoDelete(
true );
165 m_actions.setAutoDelete(
false );
167 m_actions = builder.create();
175 m_toolBars = builder.toolBars();
184 if (kapp && kapp->authorizeTDEAction(
"options_show_toolbar"))
187 connectToActionContainers();
192 if ( client ==
this )
199 m_mainWindow = mainWindow;
201 connect( m_mainWindow->guiFactory(), TQ_SIGNAL( clientAdded(
KXMLGUIClient * ) ),
212 TQString completeDescription = TQString::fromLatin1( guiDescription )
213 .arg( actionListName );
215 setXML( completeDescription,
false );
219 void ToolBarHandler::connectToActionContainers()
221 TQPtrListIterator<TDEAction> actionIt( m_actions );
222 for ( ; actionIt.current(); ++actionIt )
223 connectToActionContainer( actionIt.current() );
226 void ToolBarHandler::connectToActionContainer(
TDEAction *action )
228 uint containerCount =
action->containerCount();
229 for ( uint i = 0; i < containerCount; ++i )
230 connectToActionContainer(
action->container( i ) );
233 void ToolBarHandler::connectToActionContainer( TQWidget *container )
235 TQPopupMenu *popupMenu =
dynamic_cast<TQPopupMenu *
>( container );
239 connect( popupMenu, TQ_SIGNAL( aboutToShow() ),
240 this, TQ_SLOT( setupActions() ) );
243 #include "tdetoolbarhandler.moc"
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
void plugActionList(const TQString &name, const TQPtrList< TDEAction > &actionList)
ActionLists are a way for XMLGUI to support dynamic lists of actions.
void unplugActionList(const TQString &name)
The complement of plugActionList() ...
KXMLGUIFactory * factory() const
Retrieves a pointer to the KXMLGUIFactory this client is associated with (will return 0L if the clien...
TDEAction * action(const char *name) const
Retrieves an action of the client by name.
virtual void setXML(const TQString &document, bool merge=false)
Sets the XML for the part.
virtual TDEActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
virtual TQDomDocument domDocument() const
A managed set of TDEAction objects.
Class to encapsulate user-driven action or event.
KDE top level main window
TDEAction * create(StdAction id, const char *name, const TQObject *recvr, const char *slot, TDEActionCollection *parent)
Creates an action corresponding to the KStdAction::StdAction enum.
TQString name(StdAccel id)
TQString action(StdAccel id)