kate Library API Documentation

kateprojectlist.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "kateprojectlist.h"
00022 #include "kateprojectlist.moc"
00023 
00024 #include "kateprojectmanager.h"
00025 #include "katemainwindow.h"
00026 #include "kactionselector.h"
00027 
00028 #include <qapplication.h>
00029 #include <qlayout.h>
00030 #include <qstringlist.h>
00031 #include <qpainter.h>
00032 
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <ktoolbarbutton.h>
00036 #include <qtoolbar.h>
00037 
00038 // from kfiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors)
00039 static void silenceQToolBar2 (QtMsgType, const char *) {}
00040 
00041 KateProjectList::KateProjectList (KateMainWindow *_mainWindow, QWidget * parent, const char * name ):  QWidget (parent, name)
00042 {
00043   setFocusPolicy ((QWidget::FocusPolicy)0);
00044 
00045   QVBoxLayout* lo = new QVBoxLayout(this);
00046 
00047   mActionCollection = _mainWindow->actionCollection();
00048 
00049   m_mainWindow = _mainWindow;
00050 
00051   QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar2 );
00052 
00053   KateProjectListToolBarParent *tbp=new KateProjectListToolBarParent(this);
00054   toolbar = new KateProjectListToolBar(tbp);
00055   tbp->setToolBar(toolbar);
00056   lo->addWidget(tbp);
00057   toolbar->setMovingEnabled(false);
00058   toolbar->setFlat(true);
00059   qInstallMsgHandler( oldHandler );
00060   toolbar->setIconText( KToolBar::IconOnly );
00061   toolbar->setIconSize( 16 );
00062   toolbar->setEnableContextMenu( false );
00063 
00064   m_projectList = new KComboBox (this);
00065   lo->addWidget(m_projectList);
00066   lo->setStretchFactor(m_projectList, 2);
00067 
00068   // init of the combo box
00069   for (uint i = 0; i < KateProjectManager::self()->projects(); i++)
00070     projectCreated (KateProjectManager::self()->project(i));
00071 
00072   projectChanged ();
00073 
00074   // connecting
00075   connect(KateProjectManager::self()->projectManager(),SIGNAL(projectCreated(Kate::Project *)),this,SLOT(projectCreated(Kate::Project *)));
00076   connect(KateProjectManager::self()->projectManager(),SIGNAL(projectDeleted(uint)),this,SLOT(projectDeleted(uint)));
00077   connect(m_mainWindow->mainWindow(),SIGNAL(projectChanged()),this,SLOT(projectChanged()));
00078   connect(m_projectList,SIGNAL(activated(int)),this,SLOT(slotActivated(int)));
00079 }
00080 
00081 KateProjectList::~KateProjectList ()
00082 {
00083 }
00084 
00085 void KateProjectList::setupActions ()
00086 {
00087   toolbar->clear();
00088 
00089   QStringList tbactions;
00090    tbactions << "project_new" << "project_open" << "project_save" << "project_close";
00091 
00092   KAction *ac;
00093   for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) {
00094     ac = mActionCollection->action( (*it).latin1() );
00095     if ( ac )
00096       ac->plug( toolbar );
00097   }
00098 }
00099 
00100 void KateProjectList::slotActivated ( int index )
00101 {
00102   if ((uint)index >= m_projects.size())
00103     return;
00104 
00105   for (uint i = 0; i < KateProjectManager::self()->projects(); i++)
00106     if (KateProjectManager::self()->project(i)->projectNumber() == m_projects[index])
00107     {
00108       m_mainWindow->activateProject (KateProjectManager::self()->project(i));
00109       return;
00110     }
00111 }
00112 
00113 void KateProjectList::projectChanged ()
00114 {
00115   Kate::Project *p = 0;
00116 
00117   if (!(p = m_mainWindow->mainWindow()->activeProject()))
00118     return;
00119 
00120   for (uint i = 0; i < m_projects.size(); i++)
00121   {
00122     if (m_projects[i] == p->projectNumber())
00123     {
00124       m_projectList->setCurrentItem (i);
00125       return;
00126     }
00127   }
00128 }
00129 
00130 void KateProjectList::projectCreated (Kate::Project *project)
00131 {
00132   if (!project)
00133     return;
00134 
00135   m_projects.append (project->projectNumber());
00136   m_projectList->insertItem (project->name());
00137 }
00138 
00139 void KateProjectList::projectDeleted (uint projectNumber)
00140 {
00141   for (uint i = 0; i < m_projects.size(); i++)
00142   {
00143     if (m_projects[i] == projectNumber)
00144     {
00145       m_projectList->removeItem (i);
00146       m_projects.remove (projectNumber);
00147       return;
00148     }
00149   }
00150 }
00151 
00152 //
00153 // STUFF FOR THE TOOLBAR
00154 //
00155 
00156 KateProjectListToolBar::KateProjectListToolBar(QWidget *parent):KToolBar( parent, "Kate ProjectList Toolbar", true )
00157 {
00158     setMinimumWidth(10);
00159 }
00160 
00161 KateProjectListToolBar::~KateProjectListToolBar(){}
00162 
00163 void KateProjectListToolBar::setMovingEnabled( bool)
00164 {
00165     //kdDebug(13001)<<"JoWenn's setMovingEnabled called ******************************"<<endl;
00166     KToolBar::setMovingEnabled(false);
00167 }
00168 
00169 
00170 KateProjectListToolBarParent::KateProjectListToolBarParent(QWidget *parent)
00171     :QFrame(parent),m_tb(0){}
00172 KateProjectListToolBarParent::~KateProjectListToolBarParent(){}
00173 void KateProjectListToolBarParent::setToolBar(KateProjectListToolBar *tb)
00174 {
00175     m_tb=tb;
00176 }
00177 
00178 void KateProjectListToolBarParent::resizeEvent ( QResizeEvent * )
00179 {
00180     if (m_tb)
00181     {
00182         setMinimumHeight(m_tb->sizeHint().height());
00183         m_tb->resize(width(),height());
00184     }
00185 }
KDE Logo
This file is part of the documentation for kate Library Version 3.4.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Nov 4 00:48:31 2005 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003