21 #include "kateviewspace.h"
22 #include "kateviewspace.moc"
24 #include "katemainwindow.h"
25 #include "kateviewspacecontainer.h"
26 #include "katedocmanager.h"
28 #include "katesession.h"
30 #include <kiconloader.h>
31 #include <tdelocale.h>
32 #include <ksqueezedtextlabel.h>
33 #include <tdeconfig.h>
36 #include <tqwidgetstack.h>
37 #include <tqpainter.h>
40 #include <tqpopupmenu.h>
60 class KVSSBSep :
public TQWidget {
62 KVSSBSep( KateViewSpace *parent=0) : TQWidget(parent)
67 void paintEvent( TQPaintEvent *e )
70 p.setPen( colorGroup().shadow() );
71 p.drawLine( e->rect().left(), 0, e->rect().right(), 0 );
72 p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() );
73 p.drawLine( e->rect().left(), 1, e->rect().right(), 1 );
79 KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager,
80 TQWidget* parent,
const char* name )
81 : TQVBox(parent, name),
82 m_viewManager( viewManager )
84 mViewList.setAutoDelete(
false);
86 stack =
new TQWidgetStack(
this );
87 setStretchFactor(stack, 1);
90 mStatusBar =
new KateVSStatusBar(
this);
91 mIsActiveSpace =
false;
94 setMinimumWidth (mStatusBar->minimumWidth());
95 m_group = TQString::null;
98 KateViewSpace::~KateViewSpace()
102 void KateViewSpace::polish()
107 void KateViewSpace::addView(Kate::View* v,
bool show)
110 if ( !m_group.isEmpty() )
112 TQString fn = v->getDoc()->url().prettyURL();
113 if ( ! fn.isEmpty() )
115 TQString vgroup = TQString(
"%1 %2").arg(m_group).arg(fn);
117 KateSession::Ptr as = KateSessionManager::self()->activeSession ();
118 if ( as->configRead() && as->configRead()->hasGroup( vgroup ) )
120 as->configRead()->setGroup( vgroup );
121 v->readSessionConfig ( as->configRead() );
126 uint
id = mViewList.count();
127 stack->addWidget(v,
id);
133 Kate::View* c = mViewList.current();
134 mViewList.prepend( v );
139 void KateViewSpace::removeView(Kate::View* v)
141 disconnect( v->getDoc(), TQT_SIGNAL(modifiedChanged()),
142 mStatusBar, TQT_SLOT(modifiedChanged()) );
144 bool active = ( v == currentView() );
146 mViewList.remove (v);
147 stack->removeWidget (v);
152 if (currentView() != 0L)
153 showView(mViewList.current());
154 else if (mViewList.count() > 0)
155 showView(mViewList.last());
158 bool KateViewSpace::showView(Kate::View* v)
160 return showView( v->getDoc()->documentNumber() );
163 bool KateViewSpace::showView(uint documentNumber)
165 TQPtrListIterator<Kate::View> it (mViewList);
167 for( ; it.current(); --it ) {
168 if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
170 disconnect( currentView()->getDoc(), TQT_SIGNAL(modifiedChanged()),
171 mStatusBar, TQT_SLOT(modifiedChanged()) );
173 Kate::View* kv = it.current();
174 connect( kv->getDoc(), TQT_SIGNAL(modifiedChanged()),
175 mStatusBar, TQT_SLOT(modifiedChanged()) );
177 mViewList.removeRef( kv );
178 mViewList.append( kv );
179 stack->raiseWidget( kv );
181 mStatusBar->modifiedChanged();
189 Kate::View* KateViewSpace::currentView()
191 if (mViewList.count() > 0)
192 return (Kate::View*)stack->visibleWidget();
197 bool KateViewSpace::isActiveSpace()
199 return mIsActiveSpace;
202 void KateViewSpace::setActive(
bool active,
bool )
204 mIsActiveSpace = active;
207 TQPalette pal( palette() );
210 pal.setColor( TQColorGroup::Background, pal.active().mid() );
211 pal.setColor( TQColorGroup::Light, pal.active().midlight() );
214 mStatusBar->setPalette( pal );
215 mStatusBar->update();
219 bool KateViewSpace::event( TQEvent *e )
221 if ( e->type() == TQEvent::PaletteChange )
223 setActive( mIsActiveSpace );
226 return TQVBox::event( e );
229 void KateViewSpace::slotStatusChanged (Kate::View *view,
int r,
int c,
int ovr,
bool block,
int mod,
const TQString &msg)
231 if ((TQWidgetStack *)view->parentWidget() != stack)
233 mStatusBar->setStatus( r, c, ovr, block, mod, msg );
236 void KateViewSpace::saveConfig ( TDEConfig* config,
int myIndex ,
const TQString& viewConfGrp)
239 TQString group = TQString(viewConfGrp+
"-ViewSpace %1").arg( myIndex );
241 config->setGroup (group);
242 config->writeEntry (
"Count", mViewList.count());
245 config->writeEntry(
"Active View", currentView()->getDoc()->url().prettyURL() );
248 TQPtrListIterator<Kate::View> it(mViewList);
251 for (; it.current(); ++it)
253 if ( !it.current()->getDoc()->url().isEmpty() )
255 long docListPos = it.current()->getDoc()->documentListPosition();
256 config->setGroup( group );
257 config->writeEntry( TQString(
"View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
260 TQString vgroup = TQString(
"%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
261 config->setGroup( vgroup );
262 it.current()->writeSessionConfig( config );
269 void KateViewSpace::modifiedOnDisc(Kate::Document *,
bool,
unsigned char)
272 mStatusBar->updateMod( currentView()->getDoc()->isModified() );
275 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config,
const TQString &group )
277 config->setGroup (group);
278 TQString fn = config->readEntry(
"Active View" );
282 Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
287 TQString vgroup = TQString(
"%1 %2").arg(group).arg(fn);
288 config->setGroup( vgroup );
290 viewMan->createView (doc);
292 Kate::View *v = viewMan->activeView ();
295 v->readSessionConfig( config );
299 if (mViewList.isEmpty())
300 viewMan->createView (KateDocManager::self()->document(0));
307 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent,
const char *name )
308 : KStatusBar( parent, name ),
309 m_viewSpace( parent )
311 m_lineColLabel =
new TQLabel(
this );
312 addWidget( m_lineColLabel, 0,
false );
313 m_lineColLabel->setAlignment( Qt::AlignCenter );
314 m_lineColLabel->installEventFilter(
this );
316 m_modifiedLabel =
new TQLabel( TQString(
" "),
this );
317 addWidget( m_modifiedLabel, 0,
false );
318 m_modifiedLabel->setAlignment( Qt::AlignCenter );
319 m_modifiedLabel->installEventFilter(
this );
321 m_insertModeLabel =
new TQLabel( i18n(
" INS "),
this );
322 addWidget( m_insertModeLabel, 0,
false );
323 m_insertModeLabel->setAlignment( Qt::AlignCenter );
324 m_insertModeLabel->installEventFilter(
this );
326 m_selectModeLabel =
new TQLabel( i18n(
" NORM "),
this );
327 addWidget( m_selectModeLabel, 0,
false );
328 m_selectModeLabel->setAlignment( Qt::AlignCenter );
329 m_selectModeLabel->installEventFilter(
this );
331 m_fileNameLabel=
new KSqueezedTextLabel(
this );
332 addWidget( m_fileNameLabel, 1,
true );
333 m_fileNameLabel->setMinimumSize( 0, 0 );
334 m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
335 m_fileNameLabel->setAlignment( Qt::AlignLeft );
336 m_fileNameLabel->installEventFilter(
this );
338 installEventFilter(
this );
339 m_modPm = SmallIcon(
"modified");
340 m_modDiscPm = SmallIcon(
"modonhd");
341 m_modmodPm = SmallIcon(
"modmod");
342 m_noPm = SmallIcon(
"null");
345 KateVSStatusBar::~KateVSStatusBar ()
349 void KateVSStatusBar::setStatus(
int r,
int c,
int ovr,
bool block,
int,
const TQString &msg )
351 m_lineColLabel->setText(
352 i18n(
" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
353 .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
356 m_insertModeLabel->setText( i18n(
" R/O ") );
358 m_insertModeLabel->setText( i18n(
" OVR ") );
360 m_insertModeLabel->setText( i18n(
" INS ") );
364 m_selectModeLabel->setText( block ? i18n(
" BLK ") : i18n(
" NORM ") );
366 m_fileNameLabel->setText( msg );
369 void KateVSStatusBar::updateMod(
bool mod )
371 Kate::View *v = m_viewSpace->currentView();
374 const KateDocumentInfo *info
375 = KateDocManager::self()->documentInfo ( v->getDoc() );
377 bool modOnHD = info && info->modifiedOnDisc;
379 m_modifiedLabel->setPixmap(
391 void KateVSStatusBar::modifiedChanged()
393 Kate::View *v = m_viewSpace->currentView();
395 updateMod( v->getDoc()->isModified() );
398 void KateVSStatusBar::showMenu()
400 TDEMainWindow* mainWindow =
static_cast<TDEMainWindow*
>( topLevelWidget() );
401 TQPopupMenu* menu =
static_cast<TQPopupMenu*
>( mainWindow->factory()->container(
"viewspace_popup", mainWindow ) );
404 menu->exec(TQCursor::pos());
407 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
409 if (e->type()==TQEvent::MouseButtonPress)
411 if ( m_viewSpace->currentView() )
412 m_viewSpace->currentView()->setFocus();
414 if ( ((TQMouseEvent*)e)->button()==Qt::RightButton)