mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
Preselect name without extension when renaming files
And preselect the whole string for everything else.
This commit is contained in:
parent
9fa78c7b50
commit
ffc2193df9
@ -489,8 +489,9 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||||||
|
|
||||||
// Ask for new name
|
// Ask for new name
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal, modelIndex.data().toString(), &ok)
|
const bool isFile = (m_contentModel->itemType(modelIndex) == TorrentContentModelItem::FileType);
|
||||||
.trimmed();
|
QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal
|
||||||
|
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
||||||
@ -500,8 +501,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_contentModel->itemType(modelIndex) == TorrentContentModelItem::FileType) {
|
if (isFile) {
|
||||||
// renaming a file
|
|
||||||
const int fileIndex = m_contentModel->getFileIndex(modelIndex);
|
const int fileIndex = m_contentModel->getFileIndex(modelIndex);
|
||||||
|
|
||||||
if (newName.endsWith(QB_EXT))
|
if (newName.endsWith(QB_EXT))
|
||||||
|
@ -48,7 +48,7 @@ AutoExpandableDialog::~AutoExpandableDialog()
|
|||||||
|
|
||||||
QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, const QString &label,
|
QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, const QString &label,
|
||||||
QLineEdit::EchoMode mode, const QString &text,
|
QLineEdit::EchoMode mode, const QString &text,
|
||||||
bool *ok, Qt::InputMethodHints inputMethodHints)
|
bool *ok, const bool excludeExtension, Qt::InputMethodHints inputMethodHints)
|
||||||
{
|
{
|
||||||
AutoExpandableDialog d(parent);
|
AutoExpandableDialog d(parent);
|
||||||
d.setWindowTitle(title);
|
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->setEchoMode(mode);
|
||||||
d.m_ui->textEdit->setInputMethodHints(inputMethodHints);
|
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();
|
bool res = d.exec();
|
||||||
if (ok)
|
if (ok)
|
||||||
*ok = res;
|
*ok = res;
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
static QString getText(QWidget *parent, const QString &title, const QString &label,
|
static QString getText(QWidget *parent, const QString &title, const QString &label,
|
||||||
QLineEdit::EchoMode mode = QLineEdit::Normal, const QString &text = QString(),
|
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:
|
protected:
|
||||||
void showEvent(QShowEvent *e) override;
|
void showEvent(QShowEvent *e) override;
|
||||||
|
@ -685,8 +685,9 @@ void PropertiesWidget::renameSelectedFile()
|
|||||||
|
|
||||||
// Ask for new name
|
// Ask for new name
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal, modelIndex.data().toString(), &ok)
|
const bool isFile = (m_propListModel->itemType(modelIndex) == TorrentContentModelItem::FileType);
|
||||||
.trimmed();
|
QString newName = AutoExpandableDialog::getText(this, tr("Renaming"), tr("New name:"), QLineEdit::Normal
|
||||||
|
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
||||||
@ -696,8 +697,7 @@ void PropertiesWidget::renameSelectedFile()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_propListModel->itemType(modelIndex) == TorrentContentModelItem::FileType) {
|
if (isFile) {
|
||||||
// renaming a file
|
|
||||||
const int fileIndex = m_propListModel->getFileIndex(modelIndex);
|
const int fileIndex = m_propListModel->getFileIndex(modelIndex);
|
||||||
|
|
||||||
if (newName.endsWith(QB_EXT))
|
if (newName.endsWith(QB_EXT))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user