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 <kmimetype.h>
34 #include <tdeconfig.h>
37 #include <tqwidgetstack.h>
38 #include <tqpainter.h>
41 #include <tqpopupmenu.h>
43 #include <tqtooltip.h>
62 class KVSSBSep :
public TQWidget {
64 KVSSBSep( KateViewSpace *parent=0) : TQWidget(parent)
69 void paintEvent( TQPaintEvent *e )
72 p.setPen( colorGroup().shadow() );
73 p.drawLine( e->rect().left(), 0, e->rect().right(), 0 );
74 p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() );
75 p.drawLine( e->rect().left(), 1, e->rect().right(), 1 );
81 KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager,
82 TQWidget* parent,
const char* name )
83 : TQVBox(parent, name),
84 m_viewManager( viewManager )
86 mViewList.setAutoDelete(
false);
88 stack =
new TQWidgetStack(
this );
89 setStretchFactor(stack, 1);
92 mStatusBar =
new KateVSStatusBar(
this);
93 mIsActiveSpace =
false;
96 setMinimumWidth (mStatusBar->minimumWidth());
97 m_group = TQString::null;
100 KateViewSpace::~KateViewSpace()
104 void KateViewSpace::polish()
109 void KateViewSpace::addView(Kate::View* v,
bool show)
112 if ( !m_group.isEmpty() )
114 TQString fn = v->getDoc()->url().prettyURL();
117 TQString vgroup = TQString(
"%1 %2").arg(m_group).arg(fn);
120 TDEConfig *asCfg = as->getConfig();
121 if (asCfg && asCfg->hasGroup(vgroup))
123 asCfg->setGroup(vgroup);
124 v->readSessionConfig(asCfg);
129 uint
id = mViewList.count();
130 stack->addWidget(v,
id);
136 Kate::View* c = mViewList.current();
137 mViewList.prepend( v );
142 void KateViewSpace::removeView(Kate::View* v)
144 disconnect( v->getDoc(), TQ_SIGNAL(modifiedChanged()),
145 mStatusBar, TQ_SLOT(modifiedChanged()) );
147 bool active = ( v == currentView() );
149 mViewList.remove (v);
150 stack->removeWidget (v);
155 if (currentView() != 0L)
156 showView(mViewList.current());
157 else if (mViewList.count() > 0)
158 showView(mViewList.last());
161 bool KateViewSpace::showView(Kate::View* v)
163 return showView( v->getDoc()->documentNumber() );
166 bool KateViewSpace::showView(uint documentNumber)
168 TQPtrListIterator<Kate::View> it (mViewList);
170 for( ; it.current(); --it ) {
171 if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
173 disconnect( currentView()->getDoc(), TQ_SIGNAL(modifiedChanged()),
174 mStatusBar, TQ_SLOT(modifiedChanged()) );
176 Kate::View* kv = it.current();
177 connect( kv->getDoc(), TQ_SIGNAL(modifiedChanged()),
178 mStatusBar, TQ_SLOT(modifiedChanged()) );
180 mViewList.removeRef( kv );
181 mViewList.append( kv );
182 stack->raiseWidget( kv );
184 mStatusBar->modifiedChanged();
192 Kate::View* KateViewSpace::currentView()
194 if (mViewList.count() > 0)
195 return (Kate::View*)stack->visibleWidget();
200 bool KateViewSpace::isActiveSpace()
202 return mIsActiveSpace;
205 void KateViewSpace::setActive(
bool active,
bool )
207 mIsActiveSpace = active;
210 TQPalette pal( palette() );
213 pal.setColor( TQColorGroup::Background, pal.active().mid() );
214 pal.setColor( TQColorGroup::Light, pal.active().midlight() );
217 mStatusBar->setPalette( pal );
218 mStatusBar->update();
222 bool KateViewSpace::event( TQEvent *e )
224 if ( e->type() == TQEvent::PaletteChange )
226 setActive( mIsActiveSpace );
229 return TQVBox::event( e );
232 void KateViewSpace::slotStatusChanged (Kate::View *view,
int r,
int c,
int ovr,
bool block,
int mod,
const TQString &msg)
234 if ((TQWidgetStack *)view->parentWidget() != stack)
236 mStatusBar->setStatus( r, c, ovr, block, mod, msg );
239 void KateViewSpace::saveConfig ( TDEConfig* config,
int myIndex ,
const TQString& viewConfGrp)
242 TQString group = TQString(viewConfGrp+
"-ViewSpace %1").arg( myIndex );
244 config->setGroup (group);
245 config->writeEntry (
"Count", mViewList.count());
248 config->writeEntry(
"Active View", currentView()->getDoc()->url().prettyURL() );
251 TQPtrListIterator<Kate::View> it(mViewList);
254 for (; it.current(); ++it)
256 if ( !it.current()->getDoc()->url().isEmpty() )
258 long docListPos = it.current()->getDoc()->documentListPosition();
259 config->setGroup( group );
260 config->writeEntry( TQString(
"View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
263 TQString vgroup = TQString(
"%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
264 config->setGroup( vgroup );
265 it.current()->writeSessionConfig( config );
272 void KateViewSpace::modifiedOnDisc(Kate::Document *,
bool,
unsigned char)
275 mStatusBar->updateMod( currentView()->getDoc()->isModified() );
278 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config,
const TQString &group )
280 config->setGroup (group);
281 TQString fn = config->readEntry(
"Active View" );
285 Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
290 TQString vgroup = TQString(
"%1 %2").arg(group).arg(fn);
291 config->setGroup( vgroup );
293 viewMan->createView (doc);
295 Kate::View *v = viewMan->activeView ();
298 v->readSessionConfig( config );
302 if (mViewList.isEmpty())
303 viewMan->createView (KateDocManager::self()->document(0));
310 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent,
const char *name )
311 : KStatusBar( parent, name ),
312 m_viewSpace( parent )
314 m_lineColLabel =
new TQLabel(
this );
315 addWidget( m_lineColLabel, 0,
false );
316 m_lineColLabel->setAlignment( TQt::AlignCenter );
317 m_lineColLabel->installEventFilter(
this );
319 m_modifiedLabel =
new TQLabel( TQString(
" "),
this );
320 addWidget( m_modifiedLabel, 0,
false );
321 m_modifiedLabel->setAlignment( TQt::AlignCenter );
322 m_modifiedLabel->installEventFilter(
this );
324 m_insertModeLabel =
new TQLabel( i18n(
" INS "),
this );
325 addWidget( m_insertModeLabel, 0,
false );
326 m_insertModeLabel->setAlignment( TQt::AlignCenter );
327 m_insertModeLabel->installEventFilter(
this );
329 m_selectModeLabel =
new TQLabel( i18n(
" NORM "),
this );
330 addWidget( m_selectModeLabel, 0,
false );
331 m_selectModeLabel->setAlignment( TQt::AlignCenter );
332 m_selectModeLabel->installEventFilter(
this );
334 m_fileNameLabel=
new KSqueezedTextLabel(
this );
335 addWidget( m_fileNameLabel, 1,
true );
336 m_fileNameLabel->setMinimumSize( 0, 0 );
337 m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
338 m_fileNameLabel->setAlignment( TQt::AlignLeft );
339 m_fileNameLabel->installEventFilter(
this );
341 installEventFilter(
this );
342 m_modPm = SmallIcon(
"modified");
343 m_modDiscPm = SmallIcon(
"modonhd");
344 m_modmodPm = SmallIcon(
"modmod");
347 KateVSStatusBar::~KateVSStatusBar ()
351 void KateVSStatusBar::setStatus(
int r,
int c,
int ovr,
bool block,
int,
const TQString &msg )
353 m_lineColLabel->setText(
354 i18n(
" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
355 .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
358 m_insertModeLabel->setText( i18n(
" R/O ") );
360 m_insertModeLabel->setText( i18n(
" OVR ") );
362 m_insertModeLabel->setText( i18n(
" INS ") );
366 m_selectModeLabel->setText( block ? i18n(
" BLK ") : i18n(
" NORM ") );
368 m_fileNameLabel->setText( msg );
371 void KateVSStatusBar::updateMod(
bool mod )
373 Kate::View *v = m_viewSpace->currentView();
376 const KateDocumentInfo *info
377 = KateDocManager::self()->documentInfo ( v->getDoc() );
379 bool modOnHD = info && info->modifiedOnDisc;
381 KMimeType::Ptr mime = KMimeType::findByURL(v->getDoc()->url());
383 m_modifiedLabel->setPixmap(
390 mime->pixmap(TDEIcon::Small)
392 TQToolTip::add(
this, mime->comment());
396 void KateVSStatusBar::modifiedChanged()
398 Kate::View *v = m_viewSpace->currentView();
400 updateMod( v->getDoc()->isModified() );
403 void KateVSStatusBar::showMenu()
405 TDEMainWindow* mainWindow =
static_cast<TDEMainWindow*
>( topLevelWidget() );
406 TQPopupMenu* menu =
static_cast<TQPopupMenu*
>( mainWindow->factory()->container(
"viewspace_popup", mainWindow ) );
409 menu->exec(TQCursor::pos());
412 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
414 if (e->type()==TQEvent::MouseButtonPress)
416 if ( m_viewSpace->currentView() )
417 m_viewSpace->currentView()->setFocus();
419 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.