Skip to content

Commit

Permalink
add status/feedback to Files
Browse files Browse the repository at this point in the history
The toolbar now shows an item count updates periodically on very full
directories to show some progress and activity.

The Locations combo now shows the current path, which is nice to have
when the folders tree is closed. Plus, it can be copied, and pasted into
to change to a directory.
  • Loading branch information
ddennedy committed Jan 8, 2025
1 parent bd7a18b commit d3277d1
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 400 deletions.
42 changes: 38 additions & 4 deletions src/docks/filesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ FilesDock::FilesDock(QWidget *parent)
toggleViewAction()->setIcon(windowIcon());

const auto ls = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
ui->locationsCombo->addItem(QString());
ui->locationsCombo->addItem(tr("Home", "The user's home folder in the file system"), ls.first());
ui->locationsCombo->addItem(tr("Current Project"), "");
ui->locationsCombo->addItem(tr("Documents"),
Expand Down Expand Up @@ -543,6 +542,8 @@ FilesDock::FilesDock(QWidget *parent)
auto path = Settings.filesLocationPath(name);
ui->locationsCombo->addItem(name, path);
}
ui->locationsCombo->setEditText(QDir::toNativeSeparators(Settings.filesCurrentDir()));
connect(ui->locationsCombo->lineEdit(), &QLineEdit::editingFinished, this, &FilesDock::onLocationsEditingFinished);

m_filesModel = new FilesModel(this);
m_filesModel->setOption(QFileSystemModel::DontUseCustomDirectoryIcons);
Expand Down Expand Up @@ -624,6 +625,11 @@ FilesDock::FilesDock(QWidget *parent)
toolbar->addAction(Actions["filesViewIconsAction"]);
toolbar->addSeparator();
toolbar->addAction(Actions["filesGoUp"]);
toolbar->addSeparator();
m_label = new QLabel(toolbar);
toolbar->addWidget(m_label);
connect(m_filesModel, &QAbstractItemModel::rowsInserted, this, &FilesDock::updateStatus);
connect(m_filesModel, &QFileSystemModel::directoryLoaded, this, &FilesDock::updateStatus);
ui->verticalLayout->addWidget(toolbar);
ui->verticalLayout->addSpacing(2);

Expand Down Expand Up @@ -1114,8 +1120,10 @@ void FilesDock::changeFilesDirectory(const QModelIndex &index)
{
m_view->setRootIndex(index);
m_iconsView->updateSizes();
ui->locationsCombo->setCurrentIndex(0);
auto path = QDir::toNativeSeparators(m_filesModel->rootPath());
ui->locationsCombo->setCurrentText(path);
m_view->scrollToTop();
clearStatus();
}

void FilesDock::viewCustomContextMenuRequested(const QPoint &pos)
Expand Down Expand Up @@ -1282,15 +1290,41 @@ void FilesDock::onOpenOtherRemove()
}
}

void FilesDock::on_locationsCombo_activated(int index)
void FilesDock::clearStatus()
{
m_label->setText("...");
}

void FilesDock::updateStatus()
{
if (0 == index)
auto n = m_filesModel->rowCount(m_filesModel->index(m_filesModel->rootPath()));
m_label->setText(tr("%n item(s)", nullptr, n));
QCoreApplication::processEvents();
}

void FilesDock::onLocationsEditingFinished()
{
auto path = ui->locationsCombo->currentText();
LOG_DEBUG() << path;
if (!QFile::exists(path))
return;
#if defined(Q_OS_WIN)
if (QLatin1String("/") == path)
path = QStringLiteral("C:/");
#endif
changeDirectory(path, false);
}

void FilesDock::on_locationsCombo_activated(int index)
{
auto path = ui->locationsCombo->currentData().toString();
if (path.isEmpty() && !MAIN.fileName().isEmpty())
path = QFileInfo(MAIN.fileName()).absolutePath();
if (path.isEmpty())
return;
ui->locationsCombo->clearFocus();
if (!QFile::exists(path))
return;
#if defined(Q_OS_WIN)
if (QLatin1String("/") == path)
path = QStringLiteral("C:/");
Expand Down
5 changes: 5 additions & 0 deletions src/docks/filesdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FilesModel;
class FilesProxyModel;
class QSortFilterProxyModel;
class LineEditClear;
class QLabel;

class FilesDock : public QDockWidget
{
Expand Down Expand Up @@ -66,6 +67,9 @@ private slots:
void onMediaTypeClicked();
void onOpenOtherAdd();
void onOpenOtherRemove();
void clearStatus();
void updateStatus();
void onLocationsEditingFinished();

void on_locationsCombo_activated(int index);

Expand Down Expand Up @@ -100,6 +104,7 @@ private slots:
QHash<QString, CacheItem> m_cache;
QMutex m_cacheMutex;
LineEditClear *m_searchField;
QLabel *m_label;
};

#endif // FILESDOCK_H
6 changes: 6 additions & 0 deletions src/docks/filesdock.ui
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item>
Expand Down
Loading

0 comments on commit d3277d1

Please sign in to comment.