Make path in file manager editable
This commit is contained in:
+38
-12
@@ -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<QString> &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<QString, ImageInfoData>* 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();
|
||||
|
||||
+2
-2
@@ -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:
|
||||
|
||||
+2
-10
@@ -18,11 +18,7 @@
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="leftLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leftPath">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="leftPath"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DirView" name="leftTab"/>
|
||||
@@ -32,11 +28,7 @@
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="rightLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="rightPath">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="rightPath"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="DirView" name="rightTab"/>
|
||||
|
||||
Reference in New Issue
Block a user