*/
#include "gui.h"
-#include "version.h"
#include "Engine/iFileFinder"
#include <Common/iApp>
#include <SdiWindow/iSdiWindow>
-#include <QtGui>
+#include <QtWidgets>
VER_EXPORT_VERSION_INFO()
-Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::FileFinder::GUI::Module)
using namespace eVaf;
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return: {
- QList<QPushButton *> buttons = qFindChildren<QPushButton *>(this);
+ QList<QPushButton *> buttons = findChildren<QPushButton *>();
foreach (QPushButton * btn, buttons) {
if (btn->isDefault() && btn->isVisible()) {
if (btn->isEnabled())
//-------------------------------------------------------------------
+int const FileFinder::GUI::Module::MaxHistoryItems = 20;
+
FileFinder::GUI::Module::Module()
: Plugins::iPlugin()
, mReady(false)
, mFinder(0)
, mOpenFileAction(0)
, mOpenDirectoryAction(0)
+ , mCopyNameAction(0)
+ , mCopyAllNamesAction(0)
, wMain(0)
, wDirectory(0)
, wRecursive(0)
// Create the main widget for this window
wMain = new Internal::MainWidget;
connect(wMain, SIGNAL(quit()), qApp, SLOT(quit()));
- win->addWidget(wMain);
+ win->addPanel("FileFinder", wMain);
// Create actions for the window and widgets on it
createActions();
{
mReady = false;
+ mFinder = 0;
+
/*
* Widgets are deleted by the SdiWindow module. We use wMain to track calls to done() without
* proper init().
QSettings settings(VER_COMPANY_NAME_STR, Common::iApp::instance()->name());
QStringList t;
- for (int i = 0; i < wDirectory->count(); ++i)
+ for (int i = 0; i < wDirectory->count() && i < MaxHistoryItems; ++i)
t.append(wDirectory->itemText(i));
settings.setValue("FileFinder/Directories", t);
t.clear();
- for (int i = 0; i < wIncludeNames->count(); ++i)
+ for (int i = 0; i < wIncludeNames->count() && i < MaxHistoryItems; ++i)
t.append(wIncludeNames->itemText(i));
settings.setValue("FileFinder/IncludeNames", t);
t.clear();
- for (int i = 0; i < wExcludeNames->count(); ++i)
+ for (int i = 0; i < wExcludeNames->count() && i < MaxHistoryItems; ++i)
t.append(wExcludeNames->itemText(i));
settings.setValue("FileFinder/ExcludeNames", t);
t.clear();
- for (int i = 0; i < wIncludeContent->count(); ++i)
+ for (int i = 0; i < wIncludeContent->count() && i < MaxHistoryItems; ++i)
t.append(wIncludeContent->itemText(i));
settings.setValue("FileFinder/IncludeContent", t);
t.clear();
- for (int i = 0; i < wExcludeContent->count(); ++i)
+ for (int i = 0; i < wExcludeContent->count() && i < MaxHistoryItems; ++i)
t.append(wExcludeContent->itemText(i));
settings.setValue("FileFinder/ExcludeContent", t);
wDirectory->addItems(settings.value("FileFinder/Directories").toStringList());
wDirectory->setEditText(QDir::currentPath());
+ mDirModel->setRootPath(QDir::currentPath());
wIncludeNames->addItems(settings.value("FileFinder/IncludeNames").toStringList());
wIncludeNames->setEditText("");
wDirectory->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
wDirectory->setEditable(true);
wDirectory->setInsertPolicy(QComboBox::InsertAtTop);
+ QCompleter * completer = new QCompleter(wMain);
+ mDirModel = new QFileSystemModel(wMain);
+ mDirModel->setFilter(QDir::AllDirs | QDir::Dirs | QDir::NoDotAndDotDot);
+ completer->setModel(mDirModel);
+ wDirectory->setCompleter(completer);
l->setBuddy(wDirectory);
hbox->addWidget(wDirectory);
- QPushButton * btn = new QPushButton(tr("&Browse"));
- connect(btn, SIGNAL(clicked()), this, SLOT(browseDirectory()));
- hbox->addWidget(btn);
+ wBrowse = new QPushButton(tr("&Browse"));
+ connect(wBrowse, SIGNAL(clicked()), this, SLOT(browseDirectory()));
+ hbox->addWidget(wBrowse);
wRecursive = new QCheckBox(tr("&Recursive"));
wRecursive->setChecked(true);
wResults = new QListWidget;
wResults->setContextMenuPolicy(Qt::ActionsContextMenu);
- wResults->addAction(mOpenFileAction);
- wResults->addAction(mOpenDirectoryAction);
+ wResults->addActions(QList<QAction *>() << mOpenFileAction << mOpenDirectoryAction << mCopyNameAction << mCopyAllNamesAction);
connect(wResults, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChanged(int)));
connect(wResults, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openFile(QModelIndex)));
vbox->addWidget(wResults);
connect(wFind, SIGNAL(clicked()), this, SLOT(find()));
hbox->addWidget(wFind);
- btn = new QPushButton(tr("&Close"));
+ QPushButton * btn = new QPushButton(tr("&Close"));
connect(btn, SIGNAL(clicked()), qApp, SLOT(quit()));
hbox->addWidget(btn);
}
mOpenDirectoryAction = new QAction(tr("Open &location"), wMain);
mOpenDirectoryAction->setEnabled(false);
connect(mOpenDirectoryAction, SIGNAL(triggered()), this, SLOT(openDirectory()));
+
+ mCopyNameAction = new QAction(tr("&Copy name"), wMain);
+ mCopyNameAction->setEnabled(false);
+ connect(mCopyNameAction, SIGNAL(triggered()), this, SLOT(copyName()));
+
+ mCopyAllNamesAction = new QAction(tr("Copy &all names"), wMain);
+ connect(mCopyAllNamesAction, SIGNAL(triggered()), this, SLOT(copyAllNames()));
+
}
void FileFinder::GUI::Module::browseDirectory()
}
else {
wResults->clear();
-
+
+ if (wDirectory->findText(wDirectory->currentText()) == -1)
+ wDirectory->insertItem(0, wDirectory->currentText());
+ if (wIncludeNames->findText(wIncludeNames->currentText()) == -1)
+ wIncludeNames->insertItem(0, wIncludeNames->currentText());
+ if (wExcludeNames->findText(wExcludeNames->currentText()) == -1)
+ wExcludeNames->insertItem(0, wExcludeNames->currentText());
+ if (wIncludeContent->findText(wIncludeContent->currentText()) == -1)
+ wIncludeContent->insertItem(0, wIncludeContent->currentText());
+ if (wExcludeContent->findText(wExcludeContent->currentText()) == -1)
+ wExcludeContent->insertItem(0, wExcludeContent->currentText());
+
+ // Disable input fields
+ wDirectory->setEnabled(false);
+ wBrowse->setEnabled(false);
+ wRecursive->setEnabled(false);
+ wIncludeNames->setEnabled(false);
+ wExcludeNames->setEnabled(false);
+ wIncludeContent->setEnabled(false);
+ wExcludeContent->setEnabled(false);
+
mFinder->search(wDirectory->currentText(),
wRecursive->isChecked(),
FileFinder::Filter(
{
Q_UNUSED(canceled)
+ // Enable input fields
+ wDirectory->setEnabled(true);
+ wBrowse->setEnabled(true);
+ wRecursive->setEnabled(true);
+ wIncludeNames->setEnabled(true);
+ wExcludeNames->setEnabled(true);
+ wIncludeContent->setEnabled(true);
+ wExcludeContent->setEnabled(true);
+
wFind->setText(tr("&Search"));
}
{
mOpenFileAction->setEnabled(currentRow >= 0);
mOpenDirectoryAction->setEnabled(currentRow >= 0);
+ mCopyNameAction->setEnabled(currentRow >= 0);
}
void FileFinder::GUI::Module::openFile(QModelIndex const & index)
{
Q_UNUSED(index)
- if (wResults->currentItem())
- QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(wResults->currentItem()->text())));
+ if (wResults->currentItem()) {
+ QString t = wResults->currentItem()->text();
+ t.replace("?", "\0453f");
+ QDesktopServices::openUrl(QUrl::fromEncoded(QString("file:///%1").arg(t).toUtf8()));
+ }
}
void FileFinder::GUI::Module::openDirectory()
{
if (wResults->currentItem()) {
- QFileInfo fi(wResults->currentItem()->text());
- QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(fi.path())));
+ QString t = wResults->currentItem()->text();
+ t.replace("?", "\0453f");
+ QFileInfo fi(t);
+ QDesktopServices::openUrl(QUrl::fromEncoded(QString("file:///%1").arg(fi.path()).toUtf8()));
+ }
+}
+
+void FileFinder::GUI::Module::copyName()
+{
+ if (wResults->currentItem()) {
+ QClipboard * cb = QApplication::clipboard();
+ if (cb)
+ cb->setText(wResults->currentItem()->text());
+ }
+}
+
+void FileFinder::GUI::Module::copyAllNames()
+{
+#ifdef Q_OS_WIN32
+ static char const * const EOLN = "\r\n";
+#else
+ static char const * const EOLN = "\n";
+#endif
+
+ QString t;
+ for (int i = 0; i < wResults->count(); ++i)
+ t.append(wResults->item(i)->text() + EOLN);
+ if (!t.isEmpty()) {
+ QClipboard * cb = QApplication::clipboard();
+ if (cb)
+ cb->setText(t);
}
}