From eccf92803209a7a71b2c0dbc2f8e4cca0ae23e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Sun, 27 Jul 2025 16:28:17 +0200 Subject: [PATCH] Make path in file manager editable --- src/filemanager.cpp | 50 ++++++++++++++++++++++++++++++++++----------- src/filemanager.h | 4 ++-- src/filemanager.ui | 12 ++--------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/filemanager.cpp b/src/filemanager.cpp index a3dd165..b258d9e 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -13,10 +13,10 @@ PathTabBar::PathTabBar(const QStringList &tabs) : setTabsClosable(true); setExpanding(false); - for(auto &t : tabs) + for(auto &t : _tabs) { QDir dir(t); - int i = addTab(dir.dirName()); + int i = addTab(tabName(t)); setTabToolTip(i, t); } @@ -45,9 +45,8 @@ QHBoxLayout *PathTabBar::createLayout() QPushButton *addButton = new QPushButton("+"); connect(addButton, &QPushButton::clicked, [this](){ QString path = _tabs[currentIndex()]; - QDir dir(path); _tabs.append(path); - int i = addTab(dir.dirName()); + int i = addTab(tabName(path)); setTabToolTip(i, path); }); hlayout->addWidget(addButton); @@ -69,11 +68,20 @@ void PathTabBar::pathChanged(const QString &path) { QDir dir(path); int index = currentIndex(); - setTabText(index, dir.dirName()); + setTabText(index, tabName(path)); setTabToolTip(index, path); _tabs[index] = path; } +QString PathTabBar::tabName(const QString &path) +{ + QDir dir(path); + if(dir.dirName().isEmpty()) + return path; + else + return dir.dirName(); +} + FITSSelection::FITSSelection(const QStringList &keywords, QWidget *parent) : QDialog(parent) ,ui(new Ui::FITSKeyword) { @@ -157,6 +165,8 @@ FileManager::FileManager(const QSet &openFilter, QWidget *parent) : QMa connect(ui->actionSelect_columnsLeft, &QAction::triggered, this, &FileManager::selectFITSKeywords); connect(ui->actionSelect_columnsRight, &QAction::triggered, this, &FileManager::selectFITSKeywords); + connect(ui->leftPath, &QLineEdit::returnPressed, this, &FileManager::pathEdited); + connect(ui->rightPath, &QLineEdit::returnPressed, this, &FileManager::pathEdited); QFileInfoList drives = QDir::drives(); for(auto &drive : drives) @@ -203,9 +213,20 @@ void FileManager::selectFITSKeywords() } } -void FileManager::addTab() +void FileManager::pathEdited() { - + if(sender() == ui->leftPath) + { + QDir dir(ui->leftPath->text()); + if(dir.exists()) + ui->leftTab->setDir(dir.absolutePath()); + } + if(sender() == ui->rightPath) + { + QDir dir(ui->rightPath->text()); + if(dir.exists()) + ui->rightTab->setDir(dir.absolutePath()); + } } QCache* DirFileSystemModel::getCacheInstance() @@ -322,11 +343,7 @@ void DirFileSystemModel::loadFitsKeywords(bool enable) DirView::DirView(QWidget *parent) : QTreeView(parent) { _dirFileSystemModel = new DirFileSystemModel(this); -#ifdef Q_OS_WIN64 - _dirFileSystemModel->setRootPath("C:/"); -#else - _dirFileSystemModel->setRootPath("/"); -#endif + _dirFileSystemModel->setRootPath(QDir::drives().first().path()); _dirFileSystemModel->setReadOnly(false); setDragEnabled(true); setAcceptDrops(true); @@ -356,6 +373,15 @@ DirView::DirView(QWidget *parent) : QTreeView(parent) void DirView::setDir(const QString &path) { QString oldPath = _dirFileSystemModel->dir(); +#ifdef Q_OS_WINDOWS + const int ROOT_LEN = 3; +#else + const int ROOT_LEN = 1; +#endif + + if(oldPath.left(ROOT_LEN) != path.left(ROOT_LEN)) + _dirFileSystemModel->setRootPath(path.left(ROOT_LEN)); + _dirFileSystemModel->setDir(path); setRootIndex(_dirFileSystemModel->index(path, 0)); clearSelection(); diff --git a/src/filemanager.h b/src/filemanager.h index 16457c7..3563215 100644 --- a/src/filemanager.h +++ b/src/filemanager.h @@ -29,6 +29,7 @@ signals: void tabChanged(const QString &path); private: QStringList _tabs; + QString tabName(const QString &path); }; class FITSSelection : public QDialog @@ -50,8 +51,7 @@ public: ~FileManager(); public slots: void selectFITSKeywords(); -protected slots: - void addTab(); + void pathEdited(); signals: void openFile(const QString &path); private: diff --git a/src/filemanager.ui b/src/filemanager.ui index d711942..486ef7c 100644 --- a/src/filemanager.ui +++ b/src/filemanager.ui @@ -18,11 +18,7 @@ - - - true - - + @@ -32,11 +28,7 @@ - - - true - - +