mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
improve renaming for n selected items/1 selected item
svn path=/trunk/KDE/kdebase/apps/; revision=642235
This commit is contained in:
parent
d9ac44e08f
commit
507984415a
|
@ -265,54 +265,41 @@ void DolphinView::renameSelectedItems()
|
|||
}
|
||||
else {
|
||||
// TODO: check how this can be integrated into KonqUndoManager/KonqOperations
|
||||
|
||||
//UndoManager& undoMan = UndoManager::instance();
|
||||
//undoMan.beginMacro();
|
||||
|
||||
// as one operation instead of n rename operations like it is done now...
|
||||
Q_ASSERT(newName.contains('#'));
|
||||
|
||||
const int urlsCount = urls.count();
|
||||
|
||||
// iterate through all selected items and rename them...
|
||||
const int replaceIndex = newName.indexOf('#');
|
||||
Q_ASSERT(replaceIndex >= 0);
|
||||
for (int i = 0; i < urlsCount; ++i) {
|
||||
const KUrl& source = urls[i];
|
||||
int index = 1;
|
||||
|
||||
KUrl::List::const_iterator it = urls.begin();
|
||||
KUrl::List::const_iterator end = urls.end();
|
||||
while (it != end) {
|
||||
const KUrl& oldUrl = *it;
|
||||
QString number;
|
||||
number.setNum(i + 1);
|
||||
number.setNum(index++);
|
||||
|
||||
QString name(newName);
|
||||
name.replace(replaceIndex, 1, number);
|
||||
|
||||
if (source.fileName() != name) {
|
||||
KUrl dest(source.upUrl());
|
||||
dest.addPath(name);
|
||||
|
||||
const bool destExists = KIO::NetAccess::exists(dest, false, view);
|
||||
if (destExists) {
|
||||
view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name),
|
||||
DolphinStatusBar::Error);
|
||||
break;
|
||||
if (oldUrl.fileName() != name) {
|
||||
KUrl newUrl(oldUrl.upUrl());
|
||||
newUrl.addPath(name);
|
||||
m_mainWindow->rename(oldUrl, newUrl);
|
||||
}
|
||||
else if (KIO::NetAccess::file_move(source, dest)) {
|
||||
// TODO: From the users point of view he executed one 'rename n files' operation,
|
||||
// but internally we store it as n 'rename 1 file' operations for the undo mechanism.
|
||||
//DolphinCommand command(DolphinCommand::Rename, source, dest);
|
||||
//undoMan.addCommand(command);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//undoMan.endMacro();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Only one item has been selected for renaming. Use the custom
|
||||
// renaming mechanism from the views.
|
||||
Q_ASSERT(urls.count() == 1);
|
||||
|
||||
// TODO: until KFileItemDelegate supports editing, use the the Dolphin
|
||||
// rename dialog as temporary workaround:
|
||||
// TODO: Think about using KFileItemDelegate as soon as it supports editing.
|
||||
// Currently the RenameDialog is used, but I'm not sure whether inline renaming
|
||||
// is a benefit for the user at all -> let's wait for some input first...
|
||||
RenameDialog dialog(urls);
|
||||
if (dialog.exec() == QDialog::Rejected) {
|
||||
return;
|
||||
|
|
|
@ -26,9 +26,17 @@
|
|||
#include <QVBoxLayout>
|
||||
|
||||
RenameDialog::RenameDialog(const KUrl::List& items) :
|
||||
KDialog()
|
||||
KDialog(),
|
||||
m_renameOneItem(false)
|
||||
{
|
||||
setCaption(i18n("Rename Items"));
|
||||
const QSize minSize = minimumSize();
|
||||
setMinimumSize(QSize(320, minSize.height()));
|
||||
|
||||
const int itemCount = items.count();
|
||||
Q_ASSERT(itemCount >= 1);
|
||||
m_renameOneItem = (itemCount == 1);
|
||||
|
||||
setCaption(m_renameOneItem ? i18n("Rename Item") : i18n("Rename Items"));
|
||||
setButtons(Ok|Cancel);
|
||||
setDefaultButton(Ok);
|
||||
|
||||
|
@ -40,16 +48,19 @@ RenameDialog::RenameDialog(const KUrl::List& items) :
|
|||
QVBoxLayout* topLayout = new QVBoxLayout(page);
|
||||
topLayout->setMargin(KDialog::marginHint());
|
||||
|
||||
const int itemCount = items.count();
|
||||
QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount),
|
||||
QLabel* editLabel = 0;
|
||||
if (m_renameOneItem) {
|
||||
const KUrl& url = items.first();
|
||||
editLabel = new QLabel(i18n("Rename the item '%1' to:", url.fileName()),
|
||||
page);
|
||||
}
|
||||
else {
|
||||
editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount),
|
||||
page);
|
||||
}
|
||||
|
||||
m_lineEdit = new KLineEdit(page);
|
||||
m_newName = i18n("New name #");
|
||||
|
||||
// TODO: reactivate assertion as soon as KFileItemDelegate supports renaming of
|
||||
// single items
|
||||
//Q_ASSERT(itemCount > 1);
|
||||
m_newName = m_renameOneItem ? i18n("New name") : i18n("New name #");
|
||||
|
||||
QString postfix(items[0].prettyUrl().section('.',1));
|
||||
if (postfix.length() > 0) {
|
||||
|
@ -66,20 +77,26 @@ RenameDialog::RenameDialog(const KUrl::List& items) :
|
|||
}
|
||||
}
|
||||
|
||||
const int selectionLength = m_newName.length();
|
||||
int selectionLength = m_newName.length();
|
||||
if (!m_renameOneItem) {
|
||||
--selectionLength; // don't select the # character
|
||||
}
|
||||
|
||||
if (postfix.length() > 0) {
|
||||
m_newName.append(postfix);
|
||||
}
|
||||
m_lineEdit->setText(m_newName);
|
||||
m_lineEdit->setSelection(0, selectionLength - 1);
|
||||
m_lineEdit->setSelection(0, selectionLength);
|
||||
m_lineEdit->setFocus();
|
||||
|
||||
QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page);
|
||||
|
||||
topLayout->addWidget(editLabel);
|
||||
topLayout->addWidget(m_lineEdit);
|
||||
|
||||
if (!m_renameOneItem) {
|
||||
QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page);
|
||||
topLayout->addWidget(infoLabel);
|
||||
}
|
||||
}
|
||||
|
||||
RenameDialog::~RenameDialog()
|
||||
{
|
||||
|
@ -92,7 +109,7 @@ void RenameDialog::slotButtonClicked(int button)
|
|||
if (m_newName.isEmpty()) {
|
||||
m_errorString = i18n("The new name is empty. A name with at least one character must be entered.");
|
||||
}
|
||||
else if (m_newName.contains('#') != 1) {
|
||||
else if (!m_renameOneItem && m_newName.contains('#') != 1) {
|
||||
m_newName.truncate(0);
|
||||
m_errorString = i18n("The name must contain exactly one # character.");
|
||||
}
|
||||
|
|
|
@ -54,10 +54,13 @@ public:
|
|||
virtual ~RenameDialog();
|
||||
|
||||
/**
|
||||
* Returns the new name of the items. If the returned string is not empty,
|
||||
* then it is assured that the string contains exactly one character #,
|
||||
* which should be replaced by ascending numbers. An empty string indicates
|
||||
* that the user has removed the # character.
|
||||
* Returns the new name of the items. If more than one
|
||||
* item should be renamed, then it is assured that the # character
|
||||
* is part of the returned string. If the returned string is empty,
|
||||
* then RenameDialog::errorString() should be used to show the reason
|
||||
* of having an empty string (e. g. if the # character has
|
||||
* been deleted by the user, although more then one item should be
|
||||
* renamed).
|
||||
*/
|
||||
const QString& newName() const { return m_newName; }
|
||||
|
||||
|
@ -70,6 +73,7 @@ protected slots:
|
|||
virtual void slotButtonClicked(int button);
|
||||
|
||||
private:
|
||||
bool m_renameOneItem;
|
||||
KLineEdit* m_lineEdit;
|
||||
QString m_newName;
|
||||
QString m_errorString;
|
||||
|
|
|
@ -44,7 +44,10 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
|
|||
m_applyViewPropsJob(0),
|
||||
m_timer(0)
|
||||
{
|
||||
setCaption(i18n("Applying view properties"));
|
||||
const QSize minSize = minimumSize();
|
||||
setMinimumSize(QSize(320, minSize.height()));
|
||||
|
||||
setCaption(i18n("Applying View Properties"));
|
||||
setButtons(KDialog::Cancel);
|
||||
|
||||
m_viewProps = new ViewProperties(dir);
|
||||
|
|
Loading…
Reference in a new issue