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 (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
00070
for (uint i = 0; i < m_projectManager->projects(); i++)
00071 projectCreated (m_projectManager->project(i));
00072
00073 projectChanged ();
00074
00075
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
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
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 }