Make path in file manager editable

This commit is contained in:
2025-07-27 16:28:17 +02:00
parent 897306d1c3
commit eccf928032
3 changed files with 42 additions and 24 deletions
+38 -12
View File
@@ -13,10 +13,10 @@ PathTabBar::PathTabBar(const QStringList &tabs) :
setTabsClosable(true); setTabsClosable(true);
setExpanding(false); setExpanding(false);
for(auto &t : tabs) for(auto &t : _tabs)
{ {
QDir dir(t); QDir dir(t);
int i = addTab(dir.dirName()); int i = addTab(tabName(t));
setTabToolTip(i, t); setTabToolTip(i, t);
} }
@@ -45,9 +45,8 @@ QHBoxLayout *PathTabBar::createLayout()
QPushButton *addButton = new QPushButton("+"); QPushButton *addButton = new QPushButton("+");
connect(addButton, &QPushButton::clicked, [this](){ connect(addButton, &QPushButton::clicked, [this](){
QString path = _tabs[currentIndex()]; QString path = _tabs[currentIndex()];
QDir dir(path);
_tabs.append(path); _tabs.append(path);
int i = addTab(dir.dirName()); int i = addTab(tabName(path));
setTabToolTip(i, path); setTabToolTip(i, path);
}); });
hlayout->addWidget(addButton); hlayout->addWidget(addButton);
@@ -69,11 +68,20 @@ void PathTabBar::pathChanged(const QString &path)
{ {
QDir dir(path); QDir dir(path);
int index = currentIndex(); int index = currentIndex();
setTabText(index, dir.dirName()); setTabText(index, tabName(path));
setTabToolTip(index, path); setTabToolTip(index, path);
_tabs[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) FITSSelection::FITSSelection(const QStringList &keywords, QWidget *parent) : QDialog(parent)
,ui(new Ui::FITSKeyword) ,ui(new Ui::FITSKeyword)
{ {
@@ -157,6 +165,8 @@ FileManager::FileManager(const QSet<QString> &openFilter, QWidget *parent) : QMa
connect(ui->actionSelect_columnsLeft, &QAction::triggered, this, &FileManager::selectFITSKeywords); connect(ui->actionSelect_columnsLeft, &QAction::triggered, this, &FileManager::selectFITSKeywords);
connect(ui->actionSelect_columnsRight, &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(); QFileInfoList drives = QDir::drives();
for(auto &drive : 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<QString, ImageInfoData>* DirFileSystemModel::getCacheInstance() QCache<QString, ImageInfoData>* DirFileSystemModel::getCacheInstance()
@@ -322,11 +343,7 @@ void DirFileSystemModel::loadFitsKeywords(bool enable)
DirView::DirView(QWidget *parent) : QTreeView(parent) DirView::DirView(QWidget *parent) : QTreeView(parent)
{ {
_dirFileSystemModel = new DirFileSystemModel(this); _dirFileSystemModel = new DirFileSystemModel(this);
#ifdef Q_OS_WIN64 _dirFileSystemModel->setRootPath(QDir::drives().first().path());
_dirFileSystemModel->setRootPath("C:/");
#else
_dirFileSystemModel->setRootPath("/");
#endif
_dirFileSystemModel->setReadOnly(false); _dirFileSystemModel->setReadOnly(false);
setDragEnabled(true); setDragEnabled(true);
setAcceptDrops(true); setAcceptDrops(true);
@@ -356,6 +373,15 @@ DirView::DirView(QWidget *parent) : QTreeView(parent)
void DirView::setDir(const QString &path) void DirView::setDir(const QString &path)
{ {
QString oldPath = _dirFileSystemModel->dir(); 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); _dirFileSystemModel->setDir(path);
setRootIndex(_dirFileSystemModel->index(path, 0)); setRootIndex(_dirFileSystemModel->index(path, 0));
clearSelection(); clearSelection();
+2 -2
View File
@@ -29,6 +29,7 @@ signals:
void tabChanged(const QString &path); void tabChanged(const QString &path);
private: private:
QStringList _tabs; QStringList _tabs;
QString tabName(const QString &path);
}; };
class FITSSelection : public QDialog class FITSSelection : public QDialog
@@ -50,8 +51,7 @@ public:
~FileManager(); ~FileManager();
public slots: public slots:
void selectFITSKeywords(); void selectFITSKeywords();
protected slots: void pathEdited();
void addTab();
signals: signals:
void openFile(const QString &path); void openFile(const QString &path);
private: private:
+2 -10
View File
@@ -18,11 +18,7 @@
<item> <item>
<layout class="QVBoxLayout" name="leftLayout"> <layout class="QVBoxLayout" name="leftLayout">
<item> <item>
<widget class="QLineEdit" name="leftPath"> <widget class="QLineEdit" name="leftPath"/>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="DirView" name="leftTab"/> <widget class="DirView" name="leftTab"/>
@@ -32,11 +28,7 @@
<item> <item>
<layout class="QVBoxLayout" name="rightLayout"> <layout class="QVBoxLayout" name="rightLayout">
<item> <item>
<widget class="QLineEdit" name="rightPath"> <widget class="QLineEdit" name="rightPath"/>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="DirView" name="rightTab"/> <widget class="DirView" name="rightTab"/>