svn path=/trunk/KDE/kdebase/apps/; revision=642219
#include <config-kmetadata.h>\r
#include "dolphinmainwindow.h"\r
\r
#include <config-kmetadata.h>\r
#include "dolphinmainwindow.h"\r
\r
-#include <assert.h>\r
-\r
#include "bookmarkssidebarpage.h"\r
#include "dolphinapplication.h"\r
#include "dolphinnewmenu.h"\r
#include "bookmarkssidebarpage.h"\r
#include "dolphinapplication.h"\r
#include "dolphinnewmenu.h"\r
#include <kmenu.h>\r
#include <kmessagebox.h>\r
#include <konqmimedata.h>\r
#include <kmenu.h>\r
#include <kmessagebox.h>\r
#include <konqmimedata.h>\r
+#include <konq_operations.h>\r
#include <kpropertiesdialog.h>\r
#include <kprotocolinfo.h>\r
#include <ktoggleaction.h>\r
#include <kpropertiesdialog.h>\r
#include <kprotocolinfo.h>\r
#include <ktoggleaction.h>\r
\r
void DolphinMainWindow::setActiveView(DolphinView* view)\r
{\r
\r
void DolphinMainWindow::setActiveView(DolphinView* view)\r
{\r
- assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));\r
+ Q_ASSERT((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));\r
if (m_activeView == view) {\r
return;\r
}\r
if (m_activeView == view) {\r
return;\r
}\r
+void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl)\r
+{\r
+ KonqOperations::rename(this, oldUrl, newUrl);\r
+ m_undoCommandTypes.append(KonqUndoManager::RENAME);\r
+}\r
+\r
void DolphinMainWindow::refreshViews()\r
{\r
const bool split = DolphinSettings::instance().generalSettings()->splitView();\r
void DolphinMainWindow::refreshViews()\r
{\r
const bool split = DolphinSettings::instance().generalSettings()->splitView();\r
}\r
\r
m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];\r
}\r
\r
m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];\r
- assert(m_activeView != 0);\r
+ Q_ASSERT(m_activeView != 0);\r
\r
updateViewActions();\r
emit activeViewChanged();\r
\r
updateViewActions();\r
emit activeViewChanged();\r
{\r
updateEditActions();\r
\r
{\r
updateEditActions();\r
\r
- assert(m_view[PrimaryIdx] != 0);\r
+ Q_ASSERT(m_view[PrimaryIdx] != 0);\r
int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();\r
if (m_view[SecondaryIdx] != 0) {\r
selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();\r
int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();\r
if (m_view[SecondaryIdx] != 0) {\r
selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();\r
clearStatusBar();\r
const KUrl::List selectedUrls = m_activeView->selectedUrls();\r
KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);\r
clearStatusBar();\r
const KUrl::List selectedUrls = m_activeView->selectedUrls();\r
KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);\r
- m_undoOperations.append(KonqOperations::TRASH);\r
+ m_undoCommandTypes.append(KonqUndoManager::TRASH);\r
}\r
\r
void DolphinMainWindow::deleteItems()\r
}\r
\r
void DolphinMainWindow::deleteItems()\r
\r
KUrl::List list = m_activeView->selectedUrls();\r
const uint itemCount = list.count();\r
\r
KUrl::List list = m_activeView->selectedUrls();\r
const uint itemCount = list.count();\r
- assert(itemCount >= 1);\r
+ Q_ASSERT(itemCount >= 1);\r
\r
QString text;\r
if (itemCount > 1) {\r
\r
QString text;\r
if (itemCount > 1) {\r
undoAction->setEnabled(available);\r
}\r
\r
undoAction->setEnabled(available);\r
}\r
\r
- if (available && (m_undoOperations.count() > 0)) {\r
- const KonqOperations::Operation op = m_undoOperations.takeFirst();\r
+ if (available && (m_undoCommandTypes.count() > 0)) {\r
+ const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst();\r
DolphinStatusBar* statusBar = m_activeView->statusBar();\r
DolphinStatusBar* statusBar = m_activeView->statusBar();\r
- switch (op) {\r
- case KonqOperations::COPY:\r
+ switch (command) {\r
+ case KonqUndoManager::COPY:\r
statusBar->setMessage(i18n("Copy operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
statusBar->setMessage(i18n("Copy operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
- case KonqOperations::MOVE:\r
+ case KonqUndoManager::MOVE:\r
statusBar->setMessage(i18n("Move operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
statusBar->setMessage(i18n("Move operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
- case KonqOperations::LINK:\r
+ case KonqUndoManager::LINK:\r
statusBar->setMessage(i18n("Link operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
statusBar->setMessage(i18n("Link operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
- case KonqOperations::TRASH:\r
+ case KonqUndoManager::TRASH:\r
statusBar->setMessage(i18n("Move to trash operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
statusBar->setMessage(i18n("Move to trash operation completed."),\r
DolphinStatusBar::OperationCompleted);\r
break;\r
+ case KonqUndoManager::RENAME:\r
+ statusBar->setMessage(i18n("Renaming operation completed."),\r
+ DolphinStatusBar::OperationCompleted);\r
+ break;\r
+\r
+ case KonqUndoManager::MKDIR:\r
+ statusBar->setMessage(i18n("Created directory."),\r
+ DolphinStatusBar::OperationCompleted);\r
+ break;\r
+\r
// - both in the secondary view\r
// - one in the primary view and the other in the secondary\r
// view\r
// - both in the secondary view\r
// - one in the primary view and the other in the secondary\r
// view\r
- assert(m_view[PrimaryIdx] != 0);\r
+ Q_ASSERT(m_view[PrimaryIdx] != 0);\r
\r
KUrl urlA;\r
KUrl urlB;\r
\r
KUrl urlA;\r
KUrl urlB;\r
\r
switch (urls.count()) {\r
case 0: {\r
\r
switch (urls.count()) {\r
case 0: {\r
- assert(m_view[SecondaryIdx] != 0);\r
+ Q_ASSERT(m_view[SecondaryIdx] != 0);\r
urls = m_view[SecondaryIdx]->selectedUrls();\r
urls = m_view[SecondaryIdx]->selectedUrls();\r
- assert(urls.count() == 2);\r
+ Q_ASSERT(urls.count() == 2);\r
urlA = urls[0];\r
urlB = urls[1];\r
break;\r
urlA = urls[0];\r
urlB = urls[1];\r
break;\r
\r
case 1: {\r
urlA = urls[0];\r
\r
case 1: {\r
urlA = urls[0];\r
- assert(m_view[SecondaryIdx] != 0);\r
+ Q_ASSERT(m_view[SecondaryIdx] != 0);\r
urls = m_view[SecondaryIdx]->selectedUrls();\r
urls = m_view[SecondaryIdx]->selectedUrls();\r
- assert(urls.count() == 1);\r
+ Q_ASSERT(urls.count() == 1);\r
urlB = urls[0];\r
break;\r
}\r
urlB = urls[0];\r
break;\r
}\r
default: {\r
// may not happen: compareFiles may only get invoked if 2\r
// files are selected\r
default: {\r
// may not happen: compareFiles may only get invoked if 2\r
// files are selected\r
DolphinSettings& settings = DolphinSettings::instance();\r
\r
KBookmarkManager* manager = settings.bookmarkManager();\r
DolphinSettings& settings = DolphinSettings::instance();\r
\r
KBookmarkManager* manager = settings.bookmarkManager();\r
- assert(manager != 0);\r
+ Q_ASSERT(manager != 0);\r
KBookmarkGroup root = manager->root();\r
if (root.first().isNull()) {\r
root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home");\r
KBookmarkGroup root = manager->root();\r
if (root.first().isNull()) {\r
root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home");\r
void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::COPY, source, dest);\r
void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::COPY, source, dest);\r
- m_undoOperations.append(KonqOperations::COPY);\r
+ m_undoCommandTypes.append(KonqUndoManager::COPY);\r
}\r
\r
void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::MOVE, source, dest);\r
}\r
\r
void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::MOVE, source, dest);\r
- m_undoOperations.append(KonqOperations::MOVE);\r
+ m_undoCommandTypes.append(KonqUndoManager::MOVE);\r
}\r
\r
void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::LINK, source, dest);\r
}\r
\r
void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)\r
{\r
KonqOperations::copy(this, KonqOperations::LINK, source, dest);\r
- m_undoOperations.append(KonqOperations::LINK);\r
+ m_undoCommandTypes.append(KonqUndoManager::LINK);\r
}\r
\r
void DolphinMainWindow::clearStatusBar()\r
}\r
\r
void DolphinMainWindow::clearStatusBar()\r
KonqUndoManager::UiInterface(mainWin),\r
m_mainWin(mainWin)\r
{\r
KonqUndoManager::UiInterface(mainWin),\r
m_mainWin(mainWin)\r
{\r
- assert(m_mainWin != 0);\r
+ Q_ASSERT(m_mainWin != 0);\r
}\r
\r
DolphinMainWindow::UndoUiInterface::~UndoUiInterface()\r
}\r
\r
DolphinMainWindow::UndoUiInterface::~UndoUiInterface()\r
#include <kmainwindow.h>
#include <ksortablelist.h>
#include <kmainwindow.h>
#include <ksortablelist.h>
-#include <konq_operations.h>
#include <konq_undo.h>
#include <QList>
#include <konq_undo.h>
#include <QList>
DolphinView* activeView() const { return m_activeView; }
/**
DolphinView* activeView() const { return m_activeView; }
/**
- * Handles the dropping of Urls to the given
+ * Handles the dropping of URLs to the given
* destination. A context menu with the options
* 'Move Here', 'Copy Here', 'Link Here' and
* 'Cancel' is offered to the user.
* destination. A context menu with the options
* 'Move Here', 'Copy Here', 'Link Here' and
* 'Cancel' is offered to the user.
- * @param urls List of Urls which have been
+ * @param urls List of URLs which have been
- * @param destination Destination Url, where the
- * list or Urls should be moved,
+ * @param destination Destination URL, where the
+ * list or URLs should be moved,
* copied or linked to.
*/
void dropUrls(const KUrl::List& urls,
const KUrl& destination);
* copied or linked to.
*/
void dropUrls(const KUrl::List& urls,
const KUrl& destination);
+ /** Renames the item represented by \a oldUrl to \a newUrl. */
+ void rename(const KUrl& oldUrl, const KUrl& newUrl);
+
/**
* Refreshs the views of the main window by recreating them dependent from
* the given Dolphin settings.
/**
* Refreshs the views of the main window by recreating them dependent from
* the given Dolphin settings.
/** Updates the 'Create New...' sub menu. */
void updateNewMenu();
/** Updates the 'Create New...' sub menu. */
void updateNewMenu();
- /** Renames the selected item of the active view. */
+ /**
+ * Let the user input a name for the selected item(s) and trigger
+ * a renaming afterwards.
+ */
void rename();
/** Moves the selected items of the active view to the trash. */
void rename();
/** Moves the selected items of the active view to the trash. */
*/
void adjustViewProperties();
*/
void adjustViewProperties();
- /** Goes back on step of the Url history. */
+ /** Goes back on step of the URL history. */
- /** Goes forward one step of the Url history. */
+ /** Goes forward one step of the URL history. */
- /** Goes up one hierarchy of the current Url. */
+ /** Goes up one hierarchy of the current URL. */
- /** Goes to the home Url. */
+ /** Goes to the home URL. */
void goHome();
/** Opens a terminal for the current shown directory. */
void goHome();
/** Opens a terminal for the current shown directory. */
/**
* Updates the caption of the main window and the state
/**
* Updates the caption of the main window and the state
- * of all menu actions which depend from a changed Url.
+ * of all menu actions which depend from a changed URL.
*/
void slotUrlChanged(const KUrl& url);
*/
void slotUrlChanged(const KUrl& url);
DolphinView* m_view[SecondaryIdx + 1];
/// remember pending undo operations until they are finished
DolphinView* m_view[SecondaryIdx + 1];
/// remember pending undo operations until they are finished
- QList<KonqOperations::Operation> m_undoOperations;
+ QList<KonqUndoManager::CommandType> m_undoCommandTypes;
#include <QApplication>
#include <QClipboard>
#include <QDropEvent>
#include <QApplication>
#include <QClipboard>
#include <QDropEvent>
void DolphinView::renameSelectedItems()
{
void DolphinView::renameSelectedItems()
{
+ DolphinView* view = mainWindow()->activeView();
const KUrl::List urls = selectedUrls();
if (urls.count() > 1) {
// More than one item has been selected for renaming. Open
const KUrl::List urls = selectedUrls();
if (urls.count() > 1) {
// More than one item has been selected for renaming. Open
- DolphinView* view = mainWindow()->activeView();
const QString& newName = dialog.newName();
if (newName.isEmpty()) {
const QString& newName = dialog.newName();
if (newName.isEmpty()) {
- view->statusBar()->setMessage(i18n("The new item name is invalid."),
+ view->statusBar()->setMessage(dialog.errorString(),
DolphinStatusBar::Error);
}
else {
DolphinStatusBar::Error);
}
else {
//UndoManager& undoMan = UndoManager::instance();
//undoMan.beginMacro();
//UndoManager& undoMan = UndoManager::instance();
//undoMan.beginMacro();
- assert(newName.contains('#'));
+ Q_ASSERT(newName.contains('#'));
const int urlsCount = urls.count();
// iterate through all selected items and rename them...
const int replaceIndex = newName.indexOf('#');
const int urlsCount = urls.count();
// iterate through all selected items and rename them...
const int replaceIndex = newName.indexOf('#');
- assert(replaceIndex >= 0);
+ Q_ASSERT(replaceIndex >= 0);
for (int i = 0; i < urlsCount; ++i) {
const KUrl& source = urls[i];
QString number;
for (int i = 0; i < urlsCount; ++i) {
const KUrl& source = urls[i];
QString number;
else {
// Only one item has been selected for renaming. Use the custom
// renaming mechanism from the views.
else {
// Only one item has been selected for renaming. Use the custom
// renaming mechanism from the views.
- assert(urls.count() == 1);
- // TODO:
- /*if (m_mode == DetailsView) {
- Q3ListViewItem* item = m_iconsView->firstChild();
- while (item != 0) {
- if (item->isSelected()) {
- m_iconsView->rename(item, DolphinDetailsView::NameColumn);
- break;
- }
- item = item->nextSibling();
- }
+ Q_ASSERT(urls.count() == 1);
+
+ // TODO: until KFileItemDelegate supports editing, use the the Dolphin
+ // rename dialog as temporary workaround:
+ RenameDialog dialog(urls);
+ if (dialog.exec() == QDialog::Rejected) {
+ return;
+ }
+
+ const QString& newName = dialog.newName();
+ if (newName.isEmpty()) {
+ view->statusBar()->setMessage(dialog.errorString(),
+ DolphinStatusBar::Error);
- KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
- while (item != 0) {
- if (item->isSelected()) {
- item->rename();
- break;
- }
- item = static_cast<KFileIconViewItem*>(item->nextItem());
- }
- }*/
+ const KUrl& oldUrl = urls.first();
+ KUrl newUrl = oldUrl.upUrl();
+ newUrl.addPath(newName);
+ m_mainWindow->rename(oldUrl, newUrl);
+ }
void DolphinView::showFilterBar(bool show)
{
void DolphinView::showFilterBar(bool show)
{
- assert(m_filterBar != 0);
+ Q_ASSERT(m_filterBar != 0);
if (show) {
m_filterBar->show();
}
if (show) {
m_filterBar->show();
}
KFileItem* directory = 0;
if (isValidNameIndex(index)) {
KFileItem* item = fileItem(index);
KFileItem* directory = 0;
if (isValidNameIndex(index)) {
KFileItem* item = fileItem(index);
if (item->isDir()) {
// the URLs are dropped above a directory
directory = item;
if (item->isDir()) {
// the URLs are dropped above a directory
directory = item;
m_fileItemDelegate = 0;
}
m_fileItemDelegate = 0;
}
- assert(m_iconsView == 0);
- assert(m_detailsView == 0);
+ Q_ASSERT(m_iconsView == 0);
+ Q_ASSERT(m_detailsView == 0);
// ... and recreate it representing the current mode
switch (m_mode) {
// ... and recreate it representing the current mode
switch (m_mode) {
m_fileItemDelegate = new KFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);
m_fileItemDelegate = new KFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);
/***************************************************************************
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
***************************************************************************/
#include "renamedialog.h"
***************************************************************************/
#include "renamedialog.h"
-#include <klocale.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <q3vbox.h>
-//Added by qt3to4:
-#include <Q3VBoxLayout>
-#include <assert.h>
+#include <klocale.h>
+
+#include <QLabel>
+#include <QVBoxLayout>
RenameDialog::RenameDialog(const KUrl::List& items) :
KDialog()
RenameDialog::RenameDialog(const KUrl::List& items) :
KDialog()
setButtonGuiItem(Ok, KGuiItem(i18n("Rename"), "dialog-apply"));
setButtonGuiItem(Ok, KGuiItem(i18n("Rename"), "dialog-apply"));
- QWidget *page = new QWidget(this);
+ QWidget* page = new QWidget(this);
- Q3VBoxLayout* topLayout = new Q3VBoxLayout(page, 0, spacingHint());
+ QVBoxLayout* topLayout = new QVBoxLayout(page);
topLayout->setMargin(KDialog::marginHint());
const int itemCount = items.count();
topLayout->setMargin(KDialog::marginHint());
const int itemCount = items.count();
- QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:",itemCount),
+ QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount),
page);
m_lineEdit = new KLineEdit(page);
m_newName = i18n("New name #");
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);
+
QString postfix(items[0].prettyUrl().section('.',1));
if (postfix.length() > 0) {
// The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
QString postfix(items[0].prettyUrl().section('.',1));
if (postfix.length() > 0) {
// The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
{
if (button==Ok) {
m_newName = m_lineEdit->text();
{
if (button==Ok) {
m_newName = m_lineEdit->text();
- if (m_newName.contains('#') != 1) {
+ 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) {
+ m_errorString = i18n("The name must contain exactly one # character.");
/***************************************************************************
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
#include <kdialog.h>
#include <kurl.h>
#include <kdialog.h>
#include <kurl.h>
* RenameDialog dialog(...);
* if (dialog.exec() == QDialog::Accepted) {
* const QString& newName = dialog.newName();
* RenameDialog dialog(...);
* if (dialog.exec() == QDialog::Accepted) {
* const QString& newName = dialog.newName();
- * // ... rename items corresponding to the new name
+ * if (newName.isEmpty()) {
+ * // an invalid name has been chosen, use
+ * // dialog.errorString() to tell the user about this
+ * }
+ * else {
+ * // rename items corresponding to the new name
+ * }
*/
class RenameDialog : public KDialog
{
*/
class RenameDialog : public KDialog
{
*/
const QString& newName() const { return m_newName; }
*/
const QString& newName() const { return m_newName; }
+ /**
+ * Returns the error string, if Dialog::newName() returned an empty string.
+ */
+ const QString& errorString() const { return m_errorString; }
+
protected slots:
virtual void slotButtonClicked(int button);
private:
KLineEdit* m_lineEdit;
QString m_newName;
protected slots:
virtual void slotButtonClicked(int button);
private:
KLineEdit* m_lineEdit;
QString m_newName;