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();
115 TQString vgroup = TQString(
"%1 %2").arg(m_group).arg(fn);
118 TDEConfig *asCfg = as->getConfig();
119 if (asCfg && asCfg->hasGroup(vgroup))
121 asCfg->setGroup(vgroup);
122 v->readSessionConfig(asCfg);
127 uint
id = mViewList.count();
128 stack->addWidget(v,
id);
134 Kate::View* c = mViewList.current();
135 mViewList.prepend( v );
140 void KateViewSpace::removeView(Kate::View* v)
142 disconnect( v->getDoc(), TQ_SIGNAL(modifiedChanged()),
143 mStatusBar, TQ_SLOT(modifiedChanged()) );
145 bool active = ( v == currentView() );
147 mViewList.remove (v);
148 stack->removeWidget (v);
153 if (currentView() != 0L)
154 showView(mViewList.current());
155 else if (mViewList.count() > 0)
156 showView(mViewList.last());
159 bool KateViewSpace::showView(Kate::View* v)
161 return showView( v->getDoc()->documentNumber() );
164 bool KateViewSpace::showView(uint documentNumber)
166 TQPtrListIterator<Kate::View> it (mViewList);
168 for( ; it.current(); --it ) {
169 if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
171 disconnect( currentView()->getDoc(), TQ_SIGNAL(modifiedChanged()),
172 mStatusBar, TQ_SLOT(modifiedChanged()) );
174 Kate::View* kv = it.current();
175 connect( kv->getDoc(), TQ_SIGNAL(modifiedChanged()),
176 mStatusBar, TQ_SLOT(modifiedChanged()) );
178 mViewList.removeRef( kv );
179 mViewList.append( kv );
180 stack->raiseWidget( kv );
182 mStatusBar->modifiedChanged();
190 Kate::View* KateViewSpace::currentView()
192 if (mViewList.count() > 0)
193 return (Kate::View*)stack->visibleWidget();
198 bool KateViewSpace::isActiveSpace()
200 return mIsActiveSpace;
203 void KateViewSpace::setActive(
bool active,
bool )
205 mIsActiveSpace = active;
208 TQPalette pal( palette() );
211 pal.setColor( TQColorGroup::Background, pal.active().mid() );
212 pal.setColor( TQColorGroup::Light, pal.active().midlight() );
215 mStatusBar->setPalette( pal );
216 mStatusBar->update();
220 bool KateViewSpace::event( TQEvent *e )
222 if ( e->type() == TQEvent::PaletteChange )
224 setActive( mIsActiveSpace );
227 return TQVBox::event( e );
230 void KateViewSpace::slotStatusChanged (Kate::View *view,
int r,
int c,
int ovr,
bool block,
int mod,
const TQString &msg)
232 if ((TQWidgetStack *)view->parentWidget() != stack)
234 mStatusBar->setStatus( r, c, ovr, block, mod, msg );
237 void KateViewSpace::saveConfig ( TDEConfig* config,
int myIndex ,
const TQString& viewConfGrp)
240 TQString group = TQString(viewConfGrp+
"-ViewSpace %1").arg( myIndex );
242 config->setGroup (group);
243 config->writeEntry (
"Count", mViewList.count());
246 config->writeEntry(
"Active View", currentView()->getDoc()->url().prettyURL() );
249 TQPtrListIterator<Kate::View> it(mViewList);
252 for (; it.current(); ++it)
254 if ( !it.current()->getDoc()->url().isEmpty() )
256 long docListPos = it.current()->getDoc()->documentListPosition();
257 config->setGroup( group );
258 config->writeEntry( TQString(
"View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
261 TQString vgroup = TQString(
"%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
262 config->setGroup( vgroup );
263 it.current()->writeSessionConfig( config );
270 void KateViewSpace::modifiedOnDisc(Kate::Document *,
bool,
unsigned char)
273 mStatusBar->updateMod( currentView()->getDoc()->isModified() );
276 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config,
const TQString &group )
278 config->setGroup (group);
279 TQString fn = config->readEntry(
"Active View" );
283 Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
288 TQString vgroup = TQString(
"%1 %2").arg(group).arg(fn);
289 config->setGroup( vgroup );
291 viewMan->createView (doc);
293 Kate::View *v = viewMan->activeView ();
296 v->readSessionConfig( config );
300 if (mViewList.isEmpty())
301 viewMan->createView (KateDocManager::self()->document(0));
308 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent,
const char *name )
309 : KStatusBar( parent, name ),
310 m_viewSpace( parent )
312 m_lineColLabel =
new TQLabel(
this );
313 addWidget( m_lineColLabel, 0,
false );
314 m_lineColLabel->setAlignment( TQt::AlignCenter );
315 m_lineColLabel->installEventFilter(
this );
317 m_modifiedLabel =
new TQLabel( TQString(
" "),
this );
318 addWidget( m_modifiedLabel, 0,
false );
319 m_modifiedLabel->setAlignment( TQt::AlignCenter );
320 m_modifiedLabel->installEventFilter(
this );
322 m_insertModeLabel =
new TQLabel( i18n(
" INS "),
this );
323 addWidget( m_insertModeLabel, 0,
false );
324 m_insertModeLabel->setAlignment( TQt::AlignCenter );
325 m_insertModeLabel->installEventFilter(
this );
327 m_selectModeLabel =
new TQLabel( i18n(
" NORM "),
this );
328 addWidget( m_selectModeLabel, 0,
false );
329 m_selectModeLabel->setAlignment( TQt::AlignCenter );
330 m_selectModeLabel->installEventFilter(
this );
332 m_fileNameLabel=
new KSqueezedTextLabel(
this );
333 addWidget( m_fileNameLabel, 1,
true );
334 m_fileNameLabel->setMinimumSize( 0, 0 );
335 m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
336 m_fileNameLabel->setAlignment( TQt::AlignLeft );
337 m_fileNameLabel->installEventFilter(
this );
339 installEventFilter(
this );
340 m_modPm = SmallIcon(
"modified");
341 m_modDiscPm = SmallIcon(
"modonhd");
342 m_modmodPm = SmallIcon(
"modmod");
343 m_noPm = SmallIcon(
"null");
346 KateVSStatusBar::~KateVSStatusBar ()
350 void KateVSStatusBar::setStatus(
int r,
int c,
int ovr,
bool block,
int,
const TQString &msg )
352 m_lineColLabel->setText(
353 i18n(
" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
354 .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
357 m_insertModeLabel->setText( i18n(
" R/O ") );
359 m_insertModeLabel->setText( i18n(
" OVR ") );
361 m_insertModeLabel->setText( i18n(
" INS ") );
365 m_selectModeLabel->setText( block ? i18n(
" BLK ") : i18n(
" NORM ") );
367 m_fileNameLabel->setText( msg );
370 void KateVSStatusBar::updateMod(
bool mod )
372 Kate::View *v = m_viewSpace->currentView();
375 const KateDocumentInfo *info
376 = KateDocManager::self()->documentInfo ( v->getDoc() );
378 bool modOnHD = info && info->modifiedOnDisc;
380 m_modifiedLabel->setPixmap(
392 void KateVSStatusBar::modifiedChanged()
394 Kate::View *v = m_viewSpace->currentView();
396 updateMod( v->getDoc()->isModified() );
399 void KateVSStatusBar::showMenu()
401 TDEMainWindow* mainWindow =
static_cast<TDEMainWindow*
>( topLevelWidget() );
402 TQPopupMenu* menu =
static_cast<TQPopupMenu*
>( mainWindow->factory()->container(
"viewspace_popup", mainWindow ) );
405 menu->exec(TQCursor::pos());
408 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
410 if (e->type()==TQEvent::MouseButtonPress)
412 if ( m_viewSpace->currentView() )
413 m_viewSpace->currentView()->setFocus();
415 if ( ((TQMouseEvent*)e)->button()==TQt::RightButton)
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
KateSession * getActiveSession()
An object representing a Kate's session.