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,45 +265,31 @@ void DolphinView::renameSelectedItems()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: check how this can be integrated into KonqUndoManager/KonqOperations
|
// TODO: check how this can be integrated into KonqUndoManager/KonqOperations
|
||||||
|
// as one operation instead of n rename operations like it is done now...
|
||||||
//UndoManager& undoMan = UndoManager::instance();
|
|
||||||
//undoMan.beginMacro();
|
|
||||||
|
|
||||||
Q_ASSERT(newName.contains('#'));
|
Q_ASSERT(newName.contains('#'));
|
||||||
|
|
||||||
const int urlsCount = urls.count();
|
|
||||||
|
|
||||||
// iterate through all selected items and rename them...
|
// iterate through all selected items and rename them...
|
||||||
const int replaceIndex = newName.indexOf('#');
|
const int replaceIndex = newName.indexOf('#');
|
||||||
Q_ASSERT(replaceIndex >= 0);
|
Q_ASSERT(replaceIndex >= 0);
|
||||||
for (int i = 0; i < urlsCount; ++i) {
|
int index = 1;
|
||||||
const KUrl& source = urls[i];
|
|
||||||
|
KUrl::List::const_iterator it = urls.begin();
|
||||||
|
KUrl::List::const_iterator end = urls.end();
|
||||||
|
while (it != end) {
|
||||||
|
const KUrl& oldUrl = *it;
|
||||||
QString number;
|
QString number;
|
||||||
number.setNum(i + 1);
|
number.setNum(index++);
|
||||||
|
|
||||||
QString name(newName);
|
QString name(newName);
|
||||||
name.replace(replaceIndex, 1, number);
|
name.replace(replaceIndex, 1, number);
|
||||||
|
|
||||||
if (source.fileName() != name) {
|
if (oldUrl.fileName() != name) {
|
||||||
KUrl dest(source.upUrl());
|
KUrl newUrl(oldUrl.upUrl());
|
||||||
dest.addPath(name);
|
newUrl.addPath(name);
|
||||||
|
m_mainWindow->rename(oldUrl, newUrl);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
//undoMan.endMacro();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -311,8 +297,9 @@ void DolphinView::renameSelectedItems()
|
||||||
// renaming mechanism from the views.
|
// renaming mechanism from the views.
|
||||||
Q_ASSERT(urls.count() == 1);
|
Q_ASSERT(urls.count() == 1);
|
||||||
|
|
||||||
// TODO: until KFileItemDelegate supports editing, use the the Dolphin
|
// TODO: Think about using KFileItemDelegate as soon as it supports editing.
|
||||||
// rename dialog as temporary workaround:
|
// 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);
|
RenameDialog dialog(urls);
|
||||||
if (dialog.exec() == QDialog::Rejected) {
|
if (dialog.exec() == QDialog::Rejected) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -26,9 +26,17 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
RenameDialog::RenameDialog(const KUrl::List& items) :
|
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);
|
setButtons(Ok|Cancel);
|
||||||
setDefaultButton(Ok);
|
setDefaultButton(Ok);
|
||||||
|
|
||||||
|
@ -40,16 +48,19 @@ RenameDialog::RenameDialog(const KUrl::List& items) :
|
||||||
QVBoxLayout* topLayout = new QVBoxLayout(page);
|
QVBoxLayout* topLayout = new QVBoxLayout(page);
|
||||||
topLayout->setMargin(KDialog::marginHint());
|
topLayout->setMargin(KDialog::marginHint());
|
||||||
|
|
||||||
const int itemCount = items.count();
|
QLabel* editLabel = 0;
|
||||||
QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount),
|
if (m_renameOneItem) {
|
||||||
page);
|
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_lineEdit = new KLineEdit(page);
|
||||||
m_newName = i18n("New name #");
|
m_newName = m_renameOneItem ? i18n("New name") : i18n("New name #");
|
||||||
|
|
||||||
// TODO: reactivate assertion as soon as KFileItemDelegate supports renaming of
|
|
||||||
// single items
|
|
||||||
//Q_ASSERT(itemCount > 1);
|
|
||||||
|
|
||||||
QString postfix(items[0].prettyUrl().section('.',1));
|
QString postfix(items[0].prettyUrl().section('.',1));
|
||||||
if (postfix.length() > 0) {
|
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) {
|
if (postfix.length() > 0) {
|
||||||
m_newName.append(postfix);
|
m_newName.append(postfix);
|
||||||
}
|
}
|
||||||
m_lineEdit->setText(m_newName);
|
m_lineEdit->setText(m_newName);
|
||||||
m_lineEdit->setSelection(0, selectionLength - 1);
|
m_lineEdit->setSelection(0, selectionLength);
|
||||||
m_lineEdit->setFocus();
|
m_lineEdit->setFocus();
|
||||||
|
|
||||||
QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page);
|
|
||||||
|
|
||||||
topLayout->addWidget(editLabel);
|
topLayout->addWidget(editLabel);
|
||||||
topLayout->addWidget(m_lineEdit);
|
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()
|
RenameDialog::~RenameDialog()
|
||||||
|
@ -87,12 +104,12 @@ RenameDialog::~RenameDialog()
|
||||||
|
|
||||||
void RenameDialog::slotButtonClicked(int button)
|
void RenameDialog::slotButtonClicked(int button)
|
||||||
{
|
{
|
||||||
if (button==Ok) {
|
if (button == Ok) {
|
||||||
m_newName = m_lineEdit->text();
|
m_newName = m_lineEdit->text();
|
||||||
if (m_newName.isEmpty()) {
|
if (m_newName.isEmpty()) {
|
||||||
m_errorString = i18n("The new name is empty. A name with at least one character must be entered.");
|
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_newName.truncate(0);
|
||||||
m_errorString = i18n("The name must contain exactly one # character.");
|
m_errorString = i18n("The name must contain exactly one # character.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,10 +54,13 @@ public:
|
||||||
virtual ~RenameDialog();
|
virtual ~RenameDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the new name of the items. If the returned string is not empty,
|
* Returns the new name of the items. If more than one
|
||||||
* then it is assured that the string contains exactly one character #,
|
* item should be renamed, then it is assured that the # character
|
||||||
* which should be replaced by ascending numbers. An empty string indicates
|
* is part of the returned string. If the returned string is empty,
|
||||||
* that the user has removed the # character.
|
* 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; }
|
const QString& newName() const { return m_newName; }
|
||||||
|
|
||||||
|
@ -70,6 +73,7 @@ protected slots:
|
||||||
virtual void slotButtonClicked(int button);
|
virtual void slotButtonClicked(int button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_renameOneItem;
|
||||||
KLineEdit* m_lineEdit;
|
KLineEdit* m_lineEdit;
|
||||||
QString m_newName;
|
QString m_newName;
|
||||||
QString m_errorString;
|
QString m_errorString;
|
||||||
|
|
|
@ -44,7 +44,10 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
|
||||||
m_applyViewPropsJob(0),
|
m_applyViewPropsJob(0),
|
||||||
m_timer(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);
|
setButtons(KDialog::Cancel);
|
||||||
|
|
||||||
m_viewProps = new ViewProperties(dir);
|
m_viewProps = new ViewProperties(dir);
|
||||||
|
|
Loading…
Reference in a new issue