Had to move more code to DolphinView, to use it from the part.
svn path=/trunk/KDE/kdebase/apps/; revision=737203
m_viewContainer[SecondaryView] = container;
}
-void DolphinMainWindow::slotRenaming()
+void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType)
{
clearStatusBar();
- m_undoCommandTypes.append(KonqFileUndoManager::RENAME);
+ m_undoCommandTypes.append(commandType);
}
void DolphinMainWindow::refreshViews()
void DolphinMainWindow::cut()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
- QApplication::clipboard()->setMimeData(mimeData);
+ m_activeViewContainer->view()->cutSelectedItems();
}
void DolphinMainWindow::copy()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
-
- QApplication::clipboard()->setMimeData(mimeData);
+ m_activeViewContainer->view()->copySelectedItems();
}
void DolphinMainWindow::paste()
{
- QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
-
- clearStatusBar();
-
- const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-
- // per default the pasting is done into the current Url of the view
- KUrl destUrl(m_activeViewContainer->url());
-
- // check whether the pasting should be done into a selected directory
- KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls();
- if (selectedUrls.count() == 1) {
- const KFileItem fileItem(S_IFDIR,
- KFileItem::Unknown,
- selectedUrls.first(),
- true);
- if (fileItem.isDir()) {
- // only one item is selected which is a directory, hence paste
- // into this directory
- destUrl = selectedUrls.first();
- }
- }
-
- if (KonqMimeData::decodeIsCutSelection(mimeData)) {
- moveUrls(sourceUrls, destUrl);
- clipboard->clear();
- } else {
- copyUrls(sourceUrls, destUrl);
- }
+ m_activeViewContainer->view()->paste();
}
void DolphinMainWindow::updatePasteAction()
return;
}
- QString text(i18nc("@action:inmenu", "Paste"));
- QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
-
- KUrl::List urls = KUrl::List::fromMimeData(mimeData);
- if (!urls.isEmpty()) {
- pasteAction->setEnabled(true);
-
- pasteAction->setText(i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls.count()));
- } else {
- pasteAction->setEnabled(false);
- pasteAction->setText(i18nc("@action:inmenu", "Paste"));
- }
-
- if (pasteAction->isEnabled()) {
- KUrl::List urls = m_activeViewContainer->view()->selectedUrls();
- const uint count = urls.count();
- if (count > 1) {
- // pasting should not be allowed when more than one file
- // is selected
- pasteAction->setEnabled(false);
- } else if (count == 1) {
- // Only one file is selected. Pasting is only allowed if this
- // file is a directory.
- // TODO: this doesn't work with remote protocols; instead we need a
- // m_activeViewContainer->selectedFileItems() to get the real KFileItems
- const KFileItem fileItem(S_IFDIR,
- KFileItem::Unknown,
- urls.first(),
- true);
- pasteAction->setEnabled(fileItem.isDir());
- }
- }
+ QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
+ pasteAction->setEnabled(pasteInfo.first);
+ pasteAction->setText(pasteInfo.second);
}
void DolphinMainWindow::selectAll()
this, SLOT(slotRequestItemInfo(KFileItem)));
connect(view, SIGNAL(activated()),
this, SLOT(toggleActiveView()));
- connect(view, SIGNAL(renaming()),
- this, SLOT(slotRenaming()));
+ connect(view, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
+ this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
const KUrlNavigator* navigator = container->urlNavigator();
connect(navigator, SIGNAL(urlChanged(const KUrl&)),
/** Toggles the active view if two views are shown within the main window. */
void toggleActiveView();
- /** Called when the view is renaming a file. */
- void slotRenaming();
+ /** Called when the view is doing a file operation, like renaming, copying, moving etc. */
+ void slotDoingOperation(KonqFileUndoManager::CommandType type);
private:
DolphinMainWindow(int id);
*/
#include "dolphinpart.h"
-#include <kactioncollection.h>
-#include <ktoggleaction.h>
-#include <QActionGroup>
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "dolphinmodel.h"
+#include <kactioncollection.h>
#include <kdirlister.h>
#include <kmessagebox.h>
-#include <kparts/browserextension.h>
#include <kparts/genericfactory.h>
+#include <ktoggleaction.h>
+
+#include <QActionGroup>
#include <QApplication>
+#include <QClipboard>
typedef KParts::GenericFactory<DolphinPart> DolphinPartFactory;
K_EXPORT_COMPONENT_FACTORY(dolphinpart, DolphinPartFactory)
-class DolphinPartBrowserExtension : public KParts::BrowserExtension
-{
-public:
- DolphinPartBrowserExtension( KParts::ReadOnlyPart* part )
- : KParts::BrowserExtension( part ) {}
-};
-
DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringList& args)
: KParts::ReadOnlyPart(parent)
{
connect(m_view, SIGNAL(modeChanged()),
this, SLOT(updateViewActions()));
+ QClipboard* clipboard = QApplication::clipboard();
+ connect(clipboard, SIGNAL(dataChanged()),
+ this, SLOT(updatePasteAction()));
+
createActions();
updateViewActions();
// TODO MMB-click should do something like KonqDirPart::mmbClicked
- // TODO updating the paste action
- // if (paste) emit m_extension->setActionText( "paste", actionText );
- // emit m_extension->enableAction( "paste", paste );
-
// TODO updating the trash and del actions too - or removing special handling of those from konq?
}
void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
{
// Yes, DolphinMainWindow has very similar code :/
- if (selection.isEmpty()) {
+ const bool hasSelection = !selection.isEmpty();
+ if (!hasSelection) {
stateChanged("has_no_selection");
} else {
stateChanged("has_selection");
renameAction->setEnabled(true);
}
}
+ emit m_extension->enableAction("cut", hasSelection);
+ emit m_extension->enableAction("copy", hasSelection);
+}
+
+void DolphinPart::updatePasteAction()
+{
+ QPair<bool, QString> pasteInfo = m_view->pasteInfo();
+ emit m_extension->enableAction( "paste", pasteInfo.first );
+ emit m_extension->setActionText( "paste", pasteInfo.second );
}
void DolphinPart::updateViewActions()
}
}
+////
+
+void DolphinPartBrowserExtension::cut()
+{
+ m_part->view()->cutSelectedItems();
+}
+
+void DolphinPartBrowserExtension::copy()
+{
+ m_part->view()->copySelectedItems();
+}
+
+void DolphinPartBrowserExtension::paste()
+{
+ m_part->view()->paste();
+}
+
#include "dolphinpart.moc"
#define DOLPHINPART_H
#include <kparts/part.h>
+#include <kparts/browserextension.h>
class KFileItemList;
class KFileItem;
class DolphinPartBrowserExtension;
/// see the supportsUndo property
bool supportsUndo() const { return true; }
+ DolphinView* view() { return m_view; }
+
protected:
/**
* We reimplement openUrl so no need to implement openFile.
*/
void updateViewActions();
+ /**
+ * Updates the text of the paste action dependent from
+ * the number of items which are in the clipboard.
+ */
+ void updatePasteAction();
+
private:
void createActions();
Q_DISABLE_COPY(DolphinPart)
};
+class DolphinPartBrowserExtension : public KParts::BrowserExtension
+{
+ Q_OBJECT
+public:
+ DolphinPartBrowserExtension( DolphinPart* part )
+ : KParts::BrowserExtension( part ), m_part(part) {}
+
+public Q_SLOTS:
+ void cut();
+ void copy();
+ void paste();
+
+private:
+ DolphinPart* m_part;
+};
+
#endif /* DOLPHINPART_H */
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="dolphinpart" version="4" >
<MenuBar>
- <Menu name="edit">
- <!-- TODO cut, copy, paste -->
+ <Menu name="edit">
<Action name="rename"/>
<!-- TODO trash, del -->
<Action name="select_all" />
</ToolBar>
<State name="has_selection" >
<enable>
- <Action name="edit_cut" />
- <Action name="edit_copy" />
<Action name="move_to_trash" />
<Action name="delete" />
<Action name="properties" />
</State>
<State name="has_no_selection" >
<disable>
- <Action name="edit_cut" />
- <Action name="edit_copy" />
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="delete" />
#include <QBoxLayout>
#include <QTimer>
#include <QScrollBar>
+#include <QClipboard>
#include <kcolorscheme.h>
#include <kdirlister.h>
KUrl newUrl = oldUrl;
newUrl.setFileName(name);
KonqOperations::rename(this, oldUrl, newUrl);
- emit renaming();
+ emit doingOperation(KonqFileUndoManager::RENAME);
}
++it;
}
KUrl newUrl = oldUrl;
newUrl.setFileName(newName);
KonqOperations::rename(this, oldUrl, newUrl);
- emit renaming();
+ emit doingOperation(KonqFileUndoManager::RENAME);
+ }
+ }
+}
+
+void DolphinView::cutSelectedItems()
+{
+ QMimeData* mimeData = new QMimeData();
+ const KUrl::List kdeUrls = selectedUrls();
+ const KUrl::List mostLocalUrls;
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::copySelectedItems()
+{
+ QMimeData* mimeData = new QMimeData();
+ const KUrl::List kdeUrls = selectedUrls();
+ const KUrl::List mostLocalUrls;
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::paste()
+{
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+
+ const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
+
+ // per default the pasting is done into the current Url of the view
+ KUrl destUrl(url());
+
+ // check whether the pasting should be done into a selected directory
+ const KUrl::List selectedUrls = this->selectedUrls();
+ if (selectedUrls.count() == 1) {
+ const KFileItem fileItem(S_IFDIR,
+ KFileItem::Unknown,
+ selectedUrls.first(),
+ true);
+ if (fileItem.isDir()) {
+ // only one item is selected which is a directory, hence paste
+ // into this directory
+ destUrl = selectedUrls.first();
+ }
+ }
+
+ if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+ KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, destUrl);
+ emit doingOperation(KonqFileUndoManager::MOVE);
+ clipboard->clear();
+ } else {
+ KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, destUrl);
+ emit doingOperation(KonqFileUndoManager::COPY);
+ }
+}
+
+QPair<bool, QString> DolphinView::pasteInfo() const
+{
+ QPair<bool, QString> ret;
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+
+ KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+ if (!urls.isEmpty()) {
+ ret.first = true;
+ ret.second = i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls.count());
+ } else {
+ ret.first = false;
+ ret.second = i18nc("@action:inmenu", "Paste");
+ }
+
+ if (ret.first) {
+ const KUrl::List urls = selectedUrls();
+ const uint count = urls.count();
+ if (count > 1) {
+ // pasting should not be allowed when more than one file
+ // is selected
+ ret.first = false;
+ } else if (count == 1) {
+ // Only one file is selected. Pasting is only allowed if this
+ // file is a directory.
+ // TODO: this doesn't work with remote protocols; instead we need a
+ // m_activeViewContainer->selectedFileItems() to get the real KFileItems
+ const KFileItem fileItem(S_IFDIR,
+ KFileItem::Unknown,
+ urls.first(),
+ true);
+ ret.first = fileItem.isDir();
}
}
+ return ret;
}
#include "dolphinview.moc"
#include <kparts/part.h>
#include <kfileitem.h>
#include <kfileitemdelegate.h>
+#include <konq_fileundomanager.h>
#include <kio/job.h>
#include <QBoxLayout>
*/
QString currentViewModeActionName() const;
+ /**
+ * Returns the state of the paste action:
+ * first is whether the action should be enabled
+ * second is the text for the action
+ */
+ QPair<bool, QString> pasteInfo() const;
+
public slots:
/**
* Changes the directory to \a url. If the current directory is equal to
*/
void renameSelectedItems();
+ /**
+ * Copies all selected items to the clipboard and marks
+ * the items as cutted.
+ */
+ void cutSelectedItems();
+
+ /** Copies all selected items to the clipboard. */
+ void copySelectedItems();
+
+ /** Pastes the clipboard data to this view. */
+ void paste();
+
signals:
/**
* Is emitted if the view has been activated by e. g. a mouse click.
void startedPathLoading(const KUrl& url);
/**
- * Is emitted when renaming one or more items.
+ * Is emitted when renaming, copying, moving, linking etc.
* Used for feedback in the mainwindow.
*/
- void renaming();
+ void doingOperation(KonqFileUndoManager::CommandType type);
protected:
/** @see QWidget::mouseReleaseEvent */