provide an option to rename files inline

CCMAIL: fredrik@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=789208
This commit is contained in:
Peter Penz 2008-03-23 15:53:12 +00:00
parent 71afbc513b
commit cfb135f24e
6 changed files with 43 additions and 22 deletions

View file

@ -249,6 +249,11 @@ void DolphinColumnView::showColumn(const KUrl& url)
assureVisibleActiveColumn();
}
void DolphinColumnView::editItem(const KFileItem& item)
{
activeColumn()->editItem(item);
}
void DolphinColumnView::selectAll()
{
activeColumn()->selectAll();
@ -305,13 +310,12 @@ void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::Sel
{
Q_UNUSED(rect);
Q_UNUSED(flags);
//activeColumn()->setSelection(rect, flags);
}
QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const
{
Q_UNUSED(selection);
return QRegion(); //activeColumn()->visualRegionForSelection(selection);
return QRegion();
}
int DolphinColumnView::horizontalOffset() const

View file

@ -91,6 +91,12 @@ public:
*/
void showColumn(const KUrl& url);
/**
* Does an inline editing for the item \a item
* inside the active column.
*/
void editItem(const KFileItem& item);
public slots:
/** @see QAbstractItemView::selectAll() */
virtual void selectAll();

View file

@ -229,6 +229,14 @@ void DolphinColumnWidget::setNameFilter(const QString& nameFilter)
m_proxyModel->setFilterRegExp(nameFilter);
}
void DolphinColumnWidget::editItem(const KFileItem& item)
{
const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
if (proxyIndex.isValid()) {
edit(proxyIndex);
}
}
QStyleOptionViewItem DolphinColumnWidget::viewOptions() const
{
@ -305,15 +313,11 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event)
if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) {
const QRect itemRect = visualRect(proxyIndex);
QPainter painter(viewport());
painter.save();
QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
color.setAlpha(32);
painter.setPen(Qt::NoPen);
painter.setBrush(color);
painter.drawRect(itemRect);
painter.restore();
}
}

View file

@ -98,6 +98,11 @@ public:
*/
void setNameFilter(const QString& nameFilter);
/**
* Does an inline editing for the item \a item.
*/
void editItem(const KFileItem& item);
protected:
virtual QStyleOptionViewItem viewOptions() const;
virtual void startDrag(Qt::DropActions supportedActions);
@ -140,6 +145,8 @@ private:
IconManager* m_iconManager;
QRect m_dropRect;
friend class DolphinColumnView;
};
inline bool DolphinColumnWidget::isActive() const

View file

@ -31,6 +31,7 @@
#include <kactioncollection.h>
#include <kcolorscheme.h>
#include <kdirlister.h>
#include <kfileitemdelegate.h>
#include <kiconeffect.h>
#include <klocale.h>
#include <kio/deletejob.h>
@ -49,7 +50,6 @@
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphindetailsview.h"
#include "dolphiniconsview.h"
@ -866,17 +866,13 @@ void DolphinView::emitContentsMoved()
void DolphinView::showHoverInformation(const KFileItem& item)
{
if (!hasSelection()) {
emit requestItemInfo(item);
}
}
void DolphinView::clearHoverInformation()
{
if (m_active) {
emit requestItemInfo(KFileItem());
}
}
void DolphinView::createView()
{
@ -909,7 +905,7 @@ void DolphinView::createView()
m_controller->setItemView(view);
m_fileItemDelegate = new DolphinFileItemDelegate(view);
m_fileItemDelegate = new KFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);
@ -1021,14 +1017,19 @@ void DolphinView::renameSelectedItems()
}
}
}
} else {
// Only one item has been selected for renaming. Use the custom
// renaming mechanism from the views.
} else if (DolphinSettings::instance().generalSettings()->renameInline()) {
Q_ASSERT(items.count() == 1);
if (isColumnViewActive()) {
m_columnView->editItem(items.first());
} else {
const QModelIndex dirIndex = m_dolphinModel->indexForItem(items.first());
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
itemView()->edit(proxyIndex);
}
} else {
Q_ASSERT(items.count() == 1);
// 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(this, items);
if (dialog.exec() == QDialog::Rejected) {
return;

View file

@ -41,7 +41,6 @@
class DolphinController;
class DolphinColumnView;
class DolphinDetailsView;
class DolphinFileItemDelegate;
class DolphinIconsView;
class DolphinMainWindow;
class DolphinModel;
@ -636,7 +635,7 @@ private:
DolphinIconsView* m_iconsView;
DolphinDetailsView* m_detailsView;
DolphinColumnView* m_columnView;
DolphinFileItemDelegate* m_fileItemDelegate;
KFileItemDelegate* m_fileItemDelegate;
QItemSelectionModel* m_selectionModel;
DolphinModel* m_dolphinModel;