Commit 41882f19 authored by Christoph Cullmann's avatar Christoph Cullmann

highlight active file in project view ;)

parent 4ad3e5ee
......@@ -161,7 +161,6 @@ namespace Kate
* This signal is emitted whenever a new view is created
* @since 4.2
*/
void viewCreated(KTextEditor::View * view);
/**
......
......@@ -97,7 +97,7 @@ bool KateProject::reload ()
* now, clear model once and load other stuff that is possible in all groups
*/
m_model->clear ();
m_files.clear ();
m_file2Item.clear ();
loadGroup (m_model->invisibleRootItem(), globalGroup);
/**
......@@ -251,11 +251,6 @@ void KateProject::loadDirectory (QStandardItem *parent, const QVariantMap &direc
*/
files.sort ();
/**
* append to FULL files list
*/
m_files += files;
/**
* construct paths first in tree and items in a map
*/
......@@ -264,6 +259,12 @@ void KateProject::loadDirectory (QStandardItem *parent, const QVariantMap &direc
QIcon dirIcon (KIconLoader::global ()->loadIcon ("folder", KIconLoader::Small));
QList<QPair<QStandardItem *, QStandardItem *> > item2ParentPath;
foreach (QString filePath, files) {
/**
* skip dupes
*/
if (m_file2Item.contains(filePath))
continue;
/**
* get the right icon for the file
*/
......@@ -278,6 +279,7 @@ void KateProject::loadDirectory (QStandardItem *parent, const QVariantMap &direc
QStandardItem *fileItem = new QStandardItem (icon, fileInfo.fileName());
item2ParentPath.append (QPair<QStandardItem *, QStandardItem *>(fileItem, directoryParent(dir2Item, dirIcon, dir.relativeFilePath (fileInfo.absolutePath()))));
fileItem->setData (filePath, Qt::UserRole);
m_file2Item[filePath] = fileItem;
}
/**
......
......@@ -23,6 +23,7 @@
#include <QObject>
#include <QStandardItemModel>
#include <QMap>
/**
* Class representing a project.
......@@ -90,7 +91,17 @@ class KateProject : public QObject
*/
QStringList files ()
{
return m_files;
return m_file2Item.keys ();
}
/**
* get item for file
* @param file file to get item for
* @return item for given file or 0
*/
QStandardItem *itemForFile (const QString &file)
{
return m_file2Item.value (file);
}
private:
......@@ -124,11 +135,11 @@ class KateProject : public QObject
* standard item model with content of this project
*/
QStandardItemModel *m_model;
/**
* all project files
* mapping files => items
*/
QStringList m_files;
QMap<QString, QStandardItem *> m_file2Item;
};
#endif
......
......@@ -23,6 +23,7 @@
#include <kate/application.h>
#include <ktexteditor/view.h>
#include <ktexteditor/document.h>
#include <kaction.h>
#include <kactioncollection.h>
......@@ -62,6 +63,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 (mainWindow(), SIGNAL(viewChanged ()), this, SLOT(slotViewChanged ()));
connect (m_toolBox, SIGNAL(currentChanged (int)), this, SLOT(slotCurrentChanged (int)));
}
......@@ -137,11 +139,39 @@ QString KateProjectPluginView::projectFileName ()
QStringList KateProjectPluginView::projectFiles ()
{
QWidget *active = m_toolBox->currentWidget ();
KateProjectView *active = static_cast<KateProjectView *> (m_toolBox->currentWidget ());
if (!active)
return QStringList ();
return static_cast<KateProjectView *> (active)->project()->files ();
return active->project()->files ();
}
void KateProjectPluginView::slotViewChanged ()
{
/**
* get active project view
*/
KateProjectView *active = static_cast<KateProjectView *> (m_toolBox->currentWidget ());
if (!active)
return;
/**
* get active view
*/
KTextEditor::View *activeView = mainWindow()->activeView ();
if (!activeView)
return;
/**
* abort if empty url or no local path
*/
if (activeView->document()->url().isEmpty() || !activeView->document()->url().isLocalFile())
return;
/**
* else get local filename and then select it
*/
active->selectFile (activeView->document()->url().toLocalFile ());
}
void KateProjectPluginView::slotCurrentChanged (int)
......
......@@ -69,6 +69,11 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
void projectFileNameChanged ();
private slots:
/**
* This slot is called whenever the active view changes in our main window.
*/
void slotViewChanged ();
/**
* Current project changed.
* @param index index in toolbox
......
......@@ -47,6 +47,23 @@ KateProjectView::~KateProjectView ()
{
}
void KateProjectView::selectFile (const QString &file)
{
/**
* get item if any
*/
QStandardItem *item = m_project->itemForFile (file);
if (!item)
return;
/**
* select it
*/
QModelIndex index = m_project->model()->indexFromItem (item);
scrollTo (index, QAbstractItemView::EnsureVisible);
selectionModel()->setCurrentIndex (index, QItemSelectionModel::Clear | QItemSelectionModel::Select);
}
void KateProjectView::slotActivated (const QModelIndex &index)
{
/**
......
......@@ -56,6 +56,12 @@ class KateProjectView : public QTreeView
{
return m_project;
}
/**
* Select given file in the view.
* @param file select this file in the view, will be shown if invisible
*/
void selectFile (const QString &file);
private Q_SLOTS:
/**
......
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