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" ) );
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;
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 )
156 BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
158 if ( !builder.needsRebuild() )
161 unplugActionList( actionListName );
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"))
185 plugActionList( actionListName, m_actions );
187 connectToActionContainers();
192 if ( client ==
this )
199 m_mainWindow = mainWindow;
201 connect( m_mainWindow->guiFactory(), TQ_SIGNAL( clientAdded(
KXMLGUIClient * ) ),
210 if ( domDocument().documentElement().isNull() ) {
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...
A managed set of TDEAction objects.
Class to encapsulate user-driven action or event.
KDE top level main window
virtual void setText(const TQString &text)
Sets the text associated with this action.
void setCheckedState(const KGuiItem &checkedItem)
Defines the text (and icon, tooltip, whatsthis) that should be displayed instead of the normal text...
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 action(StdAccel id) KDE_DEPRECATED