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 (KateProjectManager *_projectManager, 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_projectManager = _projectManager; 00050 m_mainWindow = _mainWindow; 00051 00052 QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar2 ); 00053 00054 KateProjectListToolBarParent *tbp=new KateProjectListToolBarParent(this); 00055 toolbar = new KateProjectListToolBar(tbp); 00056 tbp->setToolBar(toolbar); 00057 lo->addWidget(tbp); 00058 toolbar->setMovingEnabled(false); 00059 toolbar->setFlat(true); 00060 qInstallMsgHandler( oldHandler ); 00061 toolbar->setIconText( KToolBar::IconOnly ); 00062 toolbar->setIconSize( 16 ); 00063 toolbar->setEnableContextMenu( false ); 00064 00065 m_projectList = new KComboBox (this); 00066 lo->addWidget(m_projectList); 00067 lo->setStretchFactor(m_projectList, 2); 00068 00069 // init of the combo box 00070 for (uint i = 0; i < m_projectManager->projects(); i++) 00071 projectCreated (m_projectManager->project(i)); 00072 00073 projectChanged (); 00074 00075 // connecting 00076 connect(m_projectManager->projectManager(),SIGNAL(projectCreated(Kate::Project *)),this,SLOT(projectCreated(Kate::Project *))); 00077 connect(m_projectManager->projectManager(),SIGNAL(projectDeleted(uint)),this,SLOT(projectDeleted(uint))); 00078 connect(m_mainWindow->mainWindow(),SIGNAL(projectChanged()),this,SLOT(projectChanged())); 00079 connect(m_projectList,SIGNAL(activated(int)),this,SLOT(slotActivated(int))); 00080 } 00081 00082 KateProjectList::~KateProjectList () 00083 { 00084 } 00085 00086 void KateProjectList::setupActions () 00087 { 00088 toolbar->clear(); 00089 00090 QStringList tbactions; 00091 tbactions << "project_new" << "project_open" << "project_save" << "project_close"; 00092 00093 KAction *ac; 00094 for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it ) { 00095 ac = mActionCollection->action( (*it).latin1() ); 00096 if ( ac ) 00097 ac->plug( toolbar ); 00098 } 00099 } 00100 00101 void KateProjectList::slotActivated ( int index ) 00102 { 00103 if ((uint)index >= m_projects.size()) 00104 return; 00105 00106 for (uint i = 0; i < m_projectManager->projects(); i++) 00107 if (m_projectManager->project(i)->projectNumber() == m_projects[index]) 00108 { 00109 m_mainWindow->activateProject (m_projectManager->project(i)); 00110 return; 00111 } 00112 } 00113 00114 void KateProjectList::projectChanged () 00115 { 00116 Kate::Project *p = 0; 00117 00118 if (!(p = m_mainWindow->mainWindow()->activeProject())) 00119 return; 00120 00121 for (uint i = 0; i < m_projects.size(); i++) 00122 { 00123 if (m_projects[i] == p->projectNumber()) 00124 { 00125 m_projectList->setCurrentItem (i); 00126 return; 00127 } 00128 } 00129 } 00130 00131 void KateProjectList::projectCreated (Kate::Project *project) 00132 { 00133 if (!project) 00134 return; 00135 00136 m_projects.append (project->projectNumber()); 00137 m_projectList->insertItem (project->name()); 00138 } 00139 00140 void KateProjectList::projectDeleted (uint projectNumber) 00141 { 00142 for (uint i = 0; i < m_projects.size(); i++) 00143 { 00144 if (m_projects[i] == projectNumber) 00145 { 00146 m_projectList->removeItem (i); 00147 m_projects.remove (projectNumber); 00148 return; 00149 } 00150 } 00151 } 00152 00153 // 00154 // STUFF FOR THE TOOLBAR 00155 // 00156 00157 KateProjectListToolBar::KateProjectListToolBar(QWidget *parent):KToolBar( parent, "Kate ProjectList Toolbar", true ) 00158 { 00159 setMinimumWidth(10); 00160 } 00161 00162 KateProjectListToolBar::~KateProjectListToolBar(){} 00163 00164 void KateProjectListToolBar::setMovingEnabled( bool) 00165 { 00166 //kdDebug(13001)<<"JoWenn's setMovingEnabled called ******************************"<<endl; 00167 KToolBar::setMovingEnabled(false); 00168 } 00169 00170 00171 KateProjectListToolBarParent::KateProjectListToolBarParent(QWidget *parent) 00172 :QFrame(parent),m_tb(0){} 00173 KateProjectListToolBarParent::~KateProjectListToolBarParent(){} 00174 void KateProjectListToolBarParent::setToolBar(KateProjectListToolBar *tb) 00175 { 00176 m_tb=tb; 00177 } 00178 00179 void KateProjectListToolBarParent::resizeEvent ( QResizeEvent * ) 00180 { 00181 if (m_tb) 00182 { 00183 setMinimumHeight(m_tb->sizeHint().height()); 00184 m_tb->resize(width(),height()); 00185 } 00186 }
KDE Logo
This file is part of the documentation for kate Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 13 21:47:01 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003