From ffc2193df9e208c2cfbe8242a55f13ea7fc1740a Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 5 Sep 2018 16:55:21 +0300 Subject: [PATCH] Preselect name without extension when renaming files And preselect the whole string for everything else. --- src/gui/addnewtorrentdialog.cpp | 8 ++++---- src/gui/autoexpandabledialog.cpp | 12 +++++++++++- src/gui/autoexpandabledialog.h | 2 +- src/gui/properties/propertieswidget.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index cb6cdf420..bf241545d 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -489,8 +489,9 @@ void AddNewTorrentDialog::renameSelectedFile() // Ask for new name bool ok = false; - QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal, modelIndex.data().toString(), &ok) - .trimmed(); + const bool isFile = (m_contentModel->itemType(modelIndex) == TorrentContentModelItem::FileType); + QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal + , modelIndex.data().toString(), &ok, isFile).trimmed(); if (!ok) return; if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) { @@ -500,8 +501,7 @@ void AddNewTorrentDialog::renameSelectedFile() return; } - if (m_contentModel->itemType(modelIndex) == TorrentContentModelItem::FileType) { - // renaming a file + if (isFile) { const int fileIndex = m_contentModel->getFileIndex(modelIndex); if (newName.endsWith(QB_EXT)) diff --git a/src/gui/autoexpandabledialog.cpp b/src/gui/autoexpandabledialog.cpp index c5e975211..81ae84626 100644 --- a/src/gui/autoexpandabledialog.cpp +++ b/src/gui/autoexpandabledialog.cpp @@ -48,7 +48,7 @@ AutoExpandableDialog::~AutoExpandableDialog() QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, - bool *ok, Qt::InputMethodHints inputMethodHints) + bool *ok, const bool excludeExtension, Qt::InputMethodHints inputMethodHints) { AutoExpandableDialog d(parent); d.setWindowTitle(title); @@ -57,6 +57,16 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con d.m_ui->textEdit->setEchoMode(mode); d.m_ui->textEdit->setInputMethodHints(inputMethodHints); + d.m_ui->textEdit->selectAll(); + if (excludeExtension) { + int lastDotIndex = text.lastIndexOf('.'); + if ((lastDotIndex > 3) && (text.mid(lastDotIndex - 4, 4).toLower() == ".tar")) + lastDotIndex -= 4; + // Select file name without extension, except dot files like .gitignore + if (lastDotIndex > 0) + d.m_ui->textEdit->setSelection(0, lastDotIndex); + } + bool res = d.exec(); if (ok) *ok = res; diff --git a/src/gui/autoexpandabledialog.h b/src/gui/autoexpandabledialog.h index f7f46c88c..2768304be 100644 --- a/src/gui/autoexpandabledialog.h +++ b/src/gui/autoexpandabledialog.h @@ -48,7 +48,7 @@ public: static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString &text = QString(), - bool *ok = nullptr, Qt::InputMethodHints inputMethodHints = Qt::ImhNone); + bool *ok = nullptr, bool excludeExtension = false, Qt::InputMethodHints inputMethodHints = Qt::ImhNone); protected: void showEvent(QShowEvent *e) override; diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index fadcc3675..99dff149d 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -685,8 +685,9 @@ void PropertiesWidget::renameSelectedFile() // Ask for new name bool ok = false; - QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal, modelIndex.data().toString(), &ok) - .trimmed(); + const bool isFile = (m_propListModel->itemType(modelIndex) == TorrentContentModelItem::FileType); + QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal + , modelIndex.data().toString(), &ok, isFile).trimmed(); if (!ok) return; if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) { @@ -696,8 +697,7 @@ void PropertiesWidget::renameSelectedFile() return; } - if (m_propListModel->itemType(modelIndex) == TorrentContentModelItem::FileType) { - // renaming a file + if (isFile) { const int fileIndex = m_propListModel->getFileIndex(modelIndex); if (newName.endsWith(QB_EXT))