• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Generic Shell
 

KDevelop Generic Shell

  • src
multibuffer.cpp
1/*
2 * KDevelop Multiple Buffer Support
3 *
4 * Copyright (c) 2005 Adam Treat <treat@kde.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22// Ewww... need this to access KParts::Part::setWidget(), so that tdevelop
23// doesn't need to be rearchitected for multiple views before the lazy view
24// creation can go in
25#define protected public
26#include <tdeparts/part.h>
27#undef protected
28
29#include "multibuffer.h"
30
31#include "api.h"
32#include "toplevel.h"
33#include "editorproxy.h"
34#include "partcontroller.h"
35#include "kdevlanguagesupport.h"
36
37#include <kdebug.h>
38#include <kmimetype.h>
39#include <tdemainwindow.h>
40#include <tdeapplication.h>
41
42#include <tdeparts/factory.h>
43
44#include <tdetexteditor/view.h>
45#include <tdetexteditor/document.h>
46#include <tdetexteditor/viewcursorinterface.h>
47
48MultiBuffer::MultiBuffer( TQWidget *parent )
49 : TQSplitter( parent, "MultiBuffer" ),
50 m_editorFactory( 0 ),
51 m_delayActivate( false ),
52 m_activated( false ),
53 m_activeBuffer( 0 )
54{
55 EditorProxy::getInstance() ->registerEditor( this );
56 if ( KDevLanguageSupport *lang =
57 API::getInstance() ->languageSupport() )
58 {
59 setOrientation( lang->splitOrientation() );
60 connect( lang, TQ_SIGNAL( splitOrientationChanged( TQt::Orientation ) ),
61 this, TQ_SLOT( setOrientation( TQt::Orientation ) ) );
62 }
63 else
64 {
65 setOrientation( TQt::Vertical );
66 }
67}
68
69MultiBuffer::~MultiBuffer()
70{
71 EditorProxy::getInstance() ->deregisterEditor( this );
72}
73
74KParts::Part *MultiBuffer::activeBuffer( ) const
75{
76 if ( m_activeBuffer )
77 return m_activeBuffer;
78 // The active buffer might just been deleted...
79 else if ( m_buffers.begin().data() )
80 return ( m_buffers.begin().data() );
81 else
82 return 0;
83}
84
85bool MultiBuffer::hasURL( const KURL &url ) const
86{
87 return m_buffers.contains( url );
88}
89
90int MultiBuffer::numberOfBuffers() const
91{
92 return m_buffers.count();
93}
94
95bool MultiBuffer::isActivated() const
96{
97 if ( m_delayActivate )
98 return m_activated;
99 else
100 return true;
101}
102
103void MultiBuffer::setDelayedActivation( bool delayed )
104{
105 m_delayActivate = delayed;
106 if ( delayed )
107 m_activated = false;
108}
109
110KParts::Part* MultiBuffer::openURL( const KURL &url )
111{
112 KParts::ReadOnlyPart * part =
113 dynamic_cast<KParts::ReadOnlyPart*>( createPart( url ) );
114
115 if ( !part )
116 return 0;
117
118 if ( !part->openURL( url ) )
119 return 0;
120
121 m_buffers.insert( url, part );
122 return part;
123}
124
125bool MultiBuffer::closeURL( const KURL &url )
126{
127 if ( !m_buffers.contains( url ) )
128 return false;
129
130 bool result = false;
131 KParts::ReadOnlyPart * part =
132 dynamic_cast<KParts::ReadOnlyPart *>( m_buffers[ url ] );
133 if ( part )
134 if (part->closeURL())
135 {
136 m_buffers.remove( url );
137 return true;
138 }
139 return false;
140}
141
142void MultiBuffer::registerURL( const KURL &url, KParts::Part *part )
143{
144 m_buffers.insert( url, part );
145}
146
147void MultiBuffer::registerDelayedActivation( KParts::Part *part,
148 int line, int col )
149{
150 m_delayedActivation[ part ] = qMakePair( line, col );
151}
152
153KParts::Part* MultiBuffer::createPart( const TQString &mimeType,
154 const TQString &partType,
155 const TQString &className,
156 const TQString &preferredName )
157{
158 m_editorFactory = PartController::getInstance() ->findPartFactory(
159 mimeType, partType, preferredName );
160
161 if ( !className.isEmpty() && m_editorFactory )
162 {
163 return m_editorFactory->createPart(
164 this, 0, 0, 0, className.latin1() );
165 }
166
167 return 0;
168}
169
170KParts::Part* MultiBuffer::createPart( const KURL &url )
171{
172 if ( !url.isValid() )
173 return 0;
174
175 KMimeType::Ptr mimeType = KMimeType::findByURL( url );
176
177 TQString className;
178 TQString services[] = { "KParts/ReadWritePart", "KParts/ReadOnlyPart" };
179 TQString classnames[] = { "KParts::ReadWritePart", "KParts::ReadOnlyPart" };
180 for ( uint i = 0; i < 2; ++i )
181 {
182 m_editorFactory = PartController::getInstance() ->findPartFactory(
183 mimeType->name(), services[ i ] );
184 if ( m_editorFactory )
185 {
186 className = classnames[ i ];
187 break;
188 }
189 }
190
191 if ( !className.isEmpty() && m_editorFactory )
192 {
193 return m_editorFactory->createPart(
194 this, 0, 0, 0, className.latin1() );
195 }
196
197 return 0;
198}
199
200void MultiBuffer::show()
201{
202 if ( !m_delayedActivation.count() || m_activated )
203 {
204 TQSplitter::show();
205 return ;
206 }
207
208 ActivationMap::Iterator it = m_delayedActivation.begin();
209 for ( ; it != m_delayedActivation.end(); ++it )
210 {
211 KTextEditor::Document *document =
212 dynamic_cast<KTextEditor::Document*>( it.key() );
213
214 if ( !document )
215 continue;
216
217 int line = it.data().first;
218 int column = it.data().second;
219 KTextEditor::View *view = document->createView( this );
220 document->setWidget( view );
221
222 // We're managing the view deletion by being its parent,
223 // don't let the part self-destruct
224 disconnect( view, TQ_SIGNAL( destroyed() ),
225 document, TQ_SLOT( slotWidgetDestroyed() ) );
226
227 document->insertChildClient( view );
228 PartController::getInstance() ->integrateTextEditorPart( document );
229
230 KTextEditor::ViewCursorInterface *iface =
231 dynamic_cast<KTextEditor::ViewCursorInterface*>(
232 static_cast<KTextEditor::View*>( view ) );
233 if ( iface )
234 {
235 iface->setCursorPositionReal( line,
236 column == -1 ? 0 : column );
237 }
238 else
239 {
240 // Shouldn't get here
241 Q_ASSERT( false );
242 }
243 view->show();
244 kdDebug( 9000 ) << "Delayed activation of "
245 << document->url().fileName() << " is now complete." << endl;
246 }
247
248 m_activated = true;
249 TQSplitter::show();
250}
251
252void MultiBuffer::setOrientation( TQt::Orientation orientation )
253{
254 TQSplitter::setOrientation( orientation );
255}
256
257void MultiBuffer::activePartChanged( const KURL &url )
258{
259 if ( !m_buffers.contains( url ) )
260 return ;
261
262 m_activeBuffer = m_buffers[ url ];
263 TopLevel::getInstance() ->setCurrentDocumentCaption( url.fileName() );
264}
265
266void MultiBuffer::focusInEvent( TQFocusEvent *ev )
267{
268 KParts::Part *active = activeBuffer();
269 if (active && active->widget())
270 active->widget()->setFocus();
271 TQSplitter::focusInEvent(ev);
272}
273
274bool MultiBuffer::hasPart( KParts::Part *part )
275{
276 for (BufferMap::iterator it = m_buffers.begin(); it != m_buffers.end(); ++it)
277 {
278 if (it.data() == part)
279 return true;
280 }
281 return false;
282}
283
284void MultiBuffer::updateUrlForPart(KParts::Part *part, KURL url)
285{
286 if (!url.isValid())
287 return;
288 KURL formerURL;
289 for (BufferMap::iterator it = m_buffers.begin(); it != m_buffers.end(); ++it)
290 {
291 if (it.data() == part)
292 {
293 formerURL = it.key();
294 break;
295 }
296 }
297 m_buffers.remove(formerURL);
298 m_buffers.insert(url, part);
299}
300
301#include "multibuffer.moc"
TopLevel::getInstance
static KDevMainWindow * getInstance()
Get a pointer to the single KDevTopLevel object.
Definition toplevel.cpp:18

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Generic Shell by doxygen 1.9.8
This website is maintained by Timothy Pearson.