kateprojectlist.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00069 for (uint i = 0; i < KateProjectManager::self()->projects(); i++)
00070 projectCreated (KateProjectManager::self()->project(i));
00071
00072 projectChanged ();
00073
00074
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
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
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 }
This file is part of the documentation for kate Library Version 3.4.0.