Commit 387ff206 authored by Christoph Cullmann's avatar Christoph Cullmann

start to let project plugin talk with search plugin ;)

parent cb907fb8
......@@ -62,6 +62,7 @@ KateProjectPluginView::KateProjectPluginView( KateProjectPlugin *plugin, Kate::M
* connect to important signals, e.g. for auto project view creation
*/
connect (m_plugin, SIGNAL(projectCreated (KateProject *)), this, SLOT(viewForProject (KateProject *)));
connect (m_toolBox, SIGNAL(currentChanged (int)), this, SLOT(slotCurrentChanged (int)));
}
KateProjectPluginView::~KateProjectPluginView()
......@@ -125,7 +126,7 @@ void KateProjectPluginView::writeSessionConfig( KConfigBase* config, const QStri
Q_UNUSED( groupPrefix );
}
QString KateProjectPluginView::currentProjectFileName ()
QString KateProjectPluginView::projectFileName ()
{
QWidget *active = m_toolBox->currentWidget ();
if (!active)
......@@ -134,7 +135,7 @@ QString KateProjectPluginView::currentProjectFileName ()
return static_cast<KateProjectView *> (active)->project()->fileName ();
}
QStringList KateProjectPluginView::currentProjectFiles ()
QStringList KateProjectPluginView::projectFiles ()
{
QWidget *active = m_toolBox->currentWidget ();
if (!active)
......@@ -143,5 +144,10 @@ QStringList KateProjectPluginView::currentProjectFiles ()
return static_cast<KateProjectView *> (active)->project()->files ();
}
void KateProjectPluginView::slotCurrentChanged (int)
{
emit projectFileNameChanged ();
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -31,8 +31,8 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
{
Q_OBJECT
Q_PROPERTY(QString currentProjectFileName READ currentProjectFileName)
Q_PROPERTY(QStringList currentProjectFiles READ currentProjectFiles)
Q_PROPERTY(QString projectFileName READ projectFileName NOTIFY projectFileNameChanged)
Q_PROPERTY(QStringList projectFiles READ projectFiles)
public:
KateProjectPluginView( KateProjectPlugin *plugin, Kate::MainWindow *mainWindow );
......@@ -45,13 +45,13 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
* which project file is currently active?
* @return empty string if none, else project file name
*/
QString currentProjectFileName ();
QString projectFileName ();
/**
* files for the current active project?
* @return empty list if none, else project files as stringlist
*/
QStringList currentProjectFiles ();
QStringList projectFiles ();
public slots:
/**
......@@ -62,6 +62,19 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
*/
KateProjectView *viewForProject (KateProject *project);
Q_SIGNALS:
/**
* Emitted if currentProjectFileName changed.
*/
void projectFileNameChanged ();
private slots:
/**
* Current project changed.
* @param index index in toolbox
*/
void slotCurrentChanged (int index);
private:
/**
* our plugin
......
/* Kate search plugin
*
*
* Copyright (C) 2011 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
......@@ -69,7 +69,7 @@ static QAction *menuEntry(QMenu *menu,
Results::Results(QWidget *parent): QWidget(parent), matches(0)
{
setupUi(this);
tree->setItemDelegate(new SPHtmlDelegate(tree));
selectAllCB->setText(i18n("Select all 9999 matches"));
selectAllCB->setFixedWidth(selectAllCB->sizeHint().width());
......@@ -150,7 +150,8 @@ KatePluginSearchView::KatePluginSearchView(Kate::MainWindow *mainWin, Kate::Appl
: Kate::PluginView(mainWin),
Kate::XMLGUIClient(KatePluginSearchFactory::componentData()),
m_kateApp(application),
m_curResults(0)
m_curResults(0),
m_projectPluginView(0)
{
KAction *a = actionCollection()->addAction("search_in_files");
a->setText(i18n("Search in Files"));
......@@ -251,6 +252,17 @@ m_curResults(0)
connect(mainWindow(), SIGNAL(unhandledShortcutOverride(QEvent*)),
this, SLOT(handleEsc(QEvent*)));
// watch for project plugin view creation/deletion
connect(mainWindow(), SIGNAL(pluginViewCreated (const QString &, Kate::PluginView *))
, this, SLOT(slotPluginViewCreated (const QString &, Kate::PluginView *)));
connect(mainWindow(), SIGNAL(pluginViewDeleted (const QString &, Kate::PluginView *))
, this, SLOT(slotPluginViewDeleted (const QString &, Kate::PluginView *)));
// update once project plugin state manually
m_projectPluginView = mainWindow()->pluginView ("kateprojectplugin");
slotProjectFileNameChanged ();
m_replacer.setDocumentManager(m_kateApp->documentManager());
searchPlaceChanged();
......@@ -340,7 +352,7 @@ void KatePluginSearchView::setSearchString(const QString &pattern)
void KatePluginSearchView::startSearch()
{
mainWindow()->showToolView(m_toolView); // in case we are invoked from the command interface
if (m_ui.searchCombo->currentText().isEmpty()) {
// return pressed in the folder combo or filter combo
return;
......@@ -404,11 +416,12 @@ void KatePluginSearchView::setSearchPlace(int place)
void KatePluginSearchView::searchPlaceChanged()
{
bool disable = (m_ui.searchPlaceCombo->currentIndex() == 0);
if (!disable) {
bool needFolderOptions = (m_ui.searchPlaceCombo->currentIndex() == 1);
if (needFolderOptions)
m_ui.displayOptions->setChecked(true);
}
m_ui.folderOptions->setDisabled(disable);
m_ui.folderOptions->setDisabled(!needFolderOptions);
}
void KatePluginSearchView::searchPatternChanged()
......@@ -425,7 +438,7 @@ QTreeWidgetItem * KatePluginSearchView::rootFileItem(const QString &url)
KUrl kurl(url);
QString path = kurl.isLocalFile() ? kurl.upUrl().path() : kurl.upUrl().url();
QString name = kurl.fileName();
for (int i=0; i<m_curResults->tree->topLevelItemCount(); i++) {
if (m_curResults->tree->topLevelItem(i)->data(0, Qt::UserRole).toString() == url) {
int matches = m_curResults->tree->topLevelItem(i)->data(1, Qt::UserRole).toInt() + 1;
......@@ -667,7 +680,7 @@ void KatePluginSearchView::goToNextMatch()
curr = res->tree->itemBelow(curr);
}
if (!curr) return;
res->tree->setCurrentItem(curr);
itemSelected(curr);
}
......@@ -946,6 +959,56 @@ void KatePluginSearchView::replaceDone()
}
}
void KatePluginSearchView::slotPluginViewCreated (const QString &name, Kate::PluginView *pluginView)
{
// add view
if (name == "kateprojectplugin") {
m_projectPluginView = pluginView;
slotProjectFileNameChanged ();
connect (pluginView, SIGNAL(projectFileNameChanged()), this, SLOT(slotProjectFileNameChanged()));
}
}
void KatePluginSearchView::slotPluginViewDeleted (const QString &name, Kate::PluginView *)
{
// remove view
if (name == "kateprojectplugin") {
m_projectPluginView = 0;
slotProjectFileNameChanged ();
}
}
void KatePluginSearchView::slotProjectFileNameChanged ()
{
// query new project file name
QString projectFileName;
if (m_projectPluginView)
projectFileName = m_projectPluginView->property("projectFileName").toString();
// have project, enable gui for it
if (!projectFileName.isEmpty()) {
if (m_ui.searchPlaceCombo->count() < 3) {
// add "in Project"
m_ui.searchPlaceCombo->addItem (SmallIcon("project-open"), i18n("in Project"));
// switch to search "in Project"
setSearchPlace (2);
}
}
// else: disable gui for it
else {
if (m_ui.searchPlaceCombo->count() > 2) {
// switch to search "in Open files", if "in Project" is active
if (m_ui.searchPlaceCombo->currentIndex () == 2)
setSearchPlace (0);
// remove "in Project"
m_ui.searchPlaceCombo->removeItem (2);
}
}
}
KateSearchCommand::KateSearchCommand(QObject *parent)
: QObject(parent), KTextEditor::Command()
{
......@@ -982,7 +1045,7 @@ bool KateSearchCommand::exec (KTextEditor::View* /*view*/, const QString& cmd, Q
}
emit setSearchString(searchText);
emit startSearch();
return true;
}
......
/* Kate search plugin
*
*
* Copyright (C) 2011 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
......@@ -119,6 +119,13 @@ private Q_SLOTS:
void resultTabChanged(int index);
/**
* keep track if the project plugin is alive and if the project file did change
*/
void slotPluginViewCreated (const QString &name, Kate::PluginView *pluginView);
void slotPluginViewDeleted (const QString &name, Kate::PluginView *pluginView);
void slotProjectFileNameChanged ();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
......@@ -136,6 +143,11 @@ private:
KAction *m_useRegExp;
Results *m_curResults;
QList<KTextEditor::MovingRange*> m_matchRanges;
/**
* current project plugin view, if any
*/
Kate::PluginView *m_projectPluginView;
};
class KateSearchCommand : public QObject, public KTextEditor::Command
......@@ -150,7 +162,7 @@ Q_SIGNALS:
void setSearchString(const QString &pattern);
void startSearch();
void newTab();
//
// KTextEditor::Command
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment