┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-03-13 18:33:00 +0000
committerPeter Penz <[email protected]>2007-03-13 18:33:00 +0000
commit507984415a2953000ef1edb77c9dbc3364846b13 (patch)
tree90623c9904c049270c30d5edc5a510f129776b9c /src
parentd9ac44e08f8d2abe7104c20e308d05038e1896da (diff)
improve renaming for n selected items/1 selected item
svn path=/trunk/KDE/kdebase/apps/; revision=642235
Diffstat (limited to 'src')
-rw-r--r--src/dolphinview.cpp45
-rw-r--r--src/renamedialog.cpp51
-rw-r--r--src/renamedialog.h12
-rw-r--r--src/viewpropsprogressinfo.cpp5
4 files changed, 62 insertions, 51 deletions
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index 3602d1563..da8aa3c82 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -265,45 +265,31 @@ 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;
- }
- 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);
- }
+ if (oldUrl.fileName() != name) {
+ KUrl newUrl(oldUrl.upUrl());
+ newUrl.addPath(name);
+ m_mainWindow->rename(oldUrl, newUrl);
}
+ ++it;
}
-
- //undoMan.endMacro();
}
}
else {
@@ -311,8 +297,9 @@ void DolphinView::renameSelectedItems()
// 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;
diff --git a/src/renamedialog.cpp b/src/renamedialog.cpp
index e68feff8d..4055b32a6 100644
--- a/src/renamedialog.cpp
+++ b/src/renamedialog.cpp
@@ -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),
- page);
+ 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,19 +77,25 @@ 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);
- topLayout->addWidget(infoLabel);
+
+ if (!m_renameOneItem) {
+ QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page);
+ topLayout->addWidget(infoLabel);
+ }
}
RenameDialog::~RenameDialog()
@@ -87,12 +104,12 @@ RenameDialog::~RenameDialog()
void RenameDialog::slotButtonClicked(int button)
{
- if (button==Ok) {
+ if (button == Ok) {
m_newName = m_lineEdit->text();
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.");
}
diff --git a/src/renamedialog.h b/src/renamedialog.h
index c08856f8c..220b8b803 100644
--- a/src/renamedialog.h
+++ b/src/renamedialog.h
@@ -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;
diff --git a/src/viewpropsprogressinfo.cpp b/src/viewpropsprogressinfo.cpp
index 36aac51e9..61f6423c4 100644
--- a/src/viewpropsprogressinfo.cpp
+++ b/src/viewpropsprogressinfo.cpp
@@ -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);