1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/* This file is part of the KDE libraries
Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "tdetoolbarhandler.h"
#include <tqpopupmenu.h>
#include <tdeapplication.h>
#include <tdetoolbar.h>
#include <tdemainwindow.h>
#include <tdelocale.h>
#include <tdeaction.h>
#include <assert.h>
namespace
{
const char *actionListName = "show_menu_and_toolbar_actionlist";
const char *guiDescription = ""
"<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
"<MenuBar>"
" <Menu name=\"settings\">"
" <ActionList name=\"%1\" />"
" </Menu>"
"</MenuBar>"
"</kpartgui>";
const char *resourceFileName = "barhandler.rc";
class BarActionBuilder
{
public:
BarActionBuilder( TDEActionCollection *actionCollection, TDEMainWindow *mainWindow, TQPtrList<TDEToolBar> &oldToolBarList )
: m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
{
TQPtrList<TQDockWindow> dockWindows = m_mainWindow->dockWindows();
TQPtrListIterator<TQDockWindow> dockWindowIt( dockWindows );
for ( ; dockWindowIt.current(); ++dockWindowIt ) {
TDEToolBar *toolBar = dynamic_cast<TDEToolBar *>( dockWindowIt.current() );
if ( !toolBar )
continue;
if ( oldToolBarList.findRef( toolBar ) == -1 )
m_needsRebuild = true;
m_toolBars.append( toolBar );
}
if ( !m_needsRebuild )
m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
}
bool needsRebuild() const { return m_needsRebuild; }
TQPtrList<TDEAction> create()
{
if ( !m_needsRebuild )
return TQPtrList<TDEAction>();
TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
for ( ; toolBarIt.current(); ++toolBarIt )
handleToolBar( toolBarIt.current() );
TQPtrList<TDEAction> actions;
if ( m_toolBarActions.count() == 0 )
return actions;
if ( m_toolBarActions.count() == 1 ) {
TDEToggleToolBarAction* action = static_cast<TDEToggleToolBarAction *>( m_toolBarActions.getFirst() );
action->setText( i18n( "Show Toolbar" ) );
action->setCheckedState( i18n( "Hide Toolbar" ) );
return m_toolBarActions;
}
TDEActionMenu *menuAction = new TDEActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" );
TQPtrListIterator<TDEAction> actionIt( m_toolBarActions );
for ( ; actionIt.current(); ++actionIt )
menuAction->insert( actionIt.current() );
actions.append( menuAction );
return actions;
}
const TQPtrList<TDEToolBar> &toolBars() const { return m_toolBars; }
private:
void handleToolBar( TDEToolBar *toolBar )
{
TDEToggleToolBarAction *action = new TDEToggleToolBarAction(
toolBar,
toolBar->label(),
m_actionCollection,
toolBar->name() );
// ## tooltips, whatsthis?
m_toolBarActions.append( action );
}
TDEActionCollection *m_actionCollection;
TDEMainWindow *m_mainWindow;
TQPtrList<TDEToolBar> m_toolBars;
TQPtrList<TDEAction> m_toolBarActions;
bool m_needsRebuild : 1;
};
}
using namespace KDEPrivate;
ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, const char *name )
: TQObject( mainWindow, name ), KXMLGUIClient( mainWindow )
{
init( mainWindow );
}
ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, TQObject *parent, const char *name )
: TQObject( parent, name ), KXMLGUIClient( mainWindow )
{
init( mainWindow );
}
ToolBarHandler::~ToolBarHandler()
{
m_actions.setAutoDelete( true );
m_actions.clear();
}
TDEAction *ToolBarHandler::toolBarMenuAction()
{
assert( m_actions.count() == 1 );
return m_actions.getFirst();
}
void ToolBarHandler::setupActions()
{
if ( !factory() || !m_mainWindow )
return;
BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
if ( !builder.needsRebuild() )
return;
unplugActionList( actionListName );
m_actions.setAutoDelete( true );
m_actions.clear();
m_actions.setAutoDelete( false );
m_actions = builder.create();
/*
for ( TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
toolBarIt.current(); ++toolBarIt )
toolBarIt.current()->disconnect( this );
*/
m_toolBars = builder.toolBars();
/*
for ( TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
toolBarIt.current(); ++toolBarIt )
connect( toolBarIt.current(), TQ_SIGNAL( destroyed() ),
this, TQ_SLOT( setupActions() ) );
*/
if (kapp && kapp->authorizeTDEAction("options_show_toolbar"))
plugActionList( actionListName, m_actions );
connectToActionContainers();
}
void ToolBarHandler::clientAdded( KXMLGUIClient *client )
{
if ( client == this )
setupActions();
}
void ToolBarHandler::init( TDEMainWindow *mainWindow )
{
d = 0;
m_mainWindow = mainWindow;
connect( m_mainWindow->guiFactory(), TQ_SIGNAL( clientAdded( KXMLGUIClient * ) ),
this, TQ_SLOT( clientAdded( KXMLGUIClient * ) ) );
/* re-use an existing resource file if it exists. can happen if the user launches the
* toolbar editor */
/*
setXMLFile( resourceFileName );
*/
if ( domDocument().documentElement().isNull() ) {
TQString completeDescription = TQString::fromLatin1( guiDescription )
.arg( actionListName );
setXML( completeDescription, false /*merge*/ );
}
}
void ToolBarHandler::connectToActionContainers()
{
TQPtrListIterator<TDEAction> actionIt( m_actions );
for ( ; actionIt.current(); ++actionIt )
connectToActionContainer( actionIt.current() );
}
void ToolBarHandler::connectToActionContainer( TDEAction *action )
{
uint containerCount = action->containerCount();
for ( uint i = 0; i < containerCount; ++i )
connectToActionContainer( action->container( i ) );
}
void ToolBarHandler::connectToActionContainer( TQWidget *container )
{
TQPopupMenu *popupMenu = dynamic_cast<TQPopupMenu *>( container );
if ( !popupMenu )
return;
connect( popupMenu, TQ_SIGNAL( aboutToShow() ),
this, TQ_SLOT( setupActions() ) );
}
#include "tdetoolbarhandler.moc"
|