enhance KRecentFilesAction with a ui action to remove entries
Christoph Pfister
christophpfister at gmail.com
Sat Mar 7 17:24:51 GMT 2009
Patch and screenshot attached - comments welcome (don't know how the
k-c-d development model works, but I don't mind you / me commiting it
if it's ok).
Christoph
-------------- next part --------------
diff -dNpru kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction.cpp kdelibs-4.1.0/kdeui/actions/krecentfilesaction.cpp
--- kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction.cpp 2008-06-25 09:57:24.000000000 +0200
+++ kdelibs-4.1.0/kdeui/actions/krecentfilesaction.cpp 2009-03-07 17:10:04.000000000 +0100
@@ -199,6 +199,31 @@ KUrl::List KRecentFilesAction::urls() co
return d->m_urls.values ();
}
+bool KRecentFilesAction::clearActionEnabled() const
+{
+ Q_D(const KRecentFilesAction);
+ return d->clearActionEnabled;
+}
+
+void KRecentFilesAction::setClearActionEnabled(bool enabled)
+{
+ Q_D(KRecentFilesAction);
+ if (d->clearActionEnabled == enabled)
+ return;
+ if (enabled) {
+ d->clearSeparator = menu()->addSeparator();
+ d->clearAction = new QAction(i18n("Remove all entries"), selectableActionGroup());
+ menu()->addAction(d->clearAction);
+ connect(d->clearAction, SIGNAL(triggered(bool)), this, SLOT(clear()));
+ } else {
+ delete d->clearSeparator;
+ delete d->clearAction;
+ d->clearSeparator = 0;
+ d->clearAction = 0;
+ }
+ d->clearActionEnabled = enabled;
+}
+
void KRecentFilesAction::clear()
{
Q_D(KRecentFilesAction);
@@ -209,6 +234,12 @@ void KRecentFilesAction::clear()
d->m_noEntriesAction=new QAction(i18n("No entries"),selectableActionGroup());
d->m_noEntriesAction->setEnabled(false);
KSelectAction::addAction(d->m_noEntriesAction);
+ if (d->clearActionEnabled) {
+ d->clearSeparator = menu()->addSeparator();
+ d->clearAction = new QAction(i18n("Remove all entries"), selectableActionGroup());
+ menu()->addAction(d->clearAction);
+ connect(d->clearAction, SIGNAL(triggered(bool)), this, SLOT(clear()));
+ }
}
void KRecentFilesAction::loadEntries( const KConfigGroup& _config)
diff -dNpru kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction.h kdelibs-4.1.0/kdeui/actions/krecentfilesaction.h
--- kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction.h 2008-05-21 13:08:25.000000000 +0200
+++ kdelibs-4.1.0/kdeui/actions/krecentfilesaction.h 2009-03-07 15:24:46.000000000 +0100
@@ -47,6 +47,7 @@ class KDEUI_EXPORT KRecentFilesAction :
{
Q_OBJECT
Q_PROPERTY( int maxItems READ maxItems WRITE setMaxItems )
+ Q_PROPERTY( bool clearActionEnabled READ clearActionEnabled WRITE setClearActionEnabled )
Q_DECLARE_PRIVATE(KRecentFilesAction)
public:
@@ -103,11 +104,6 @@ public:
virtual QAction* removeAction(QAction* action);
/**
- * Reimplemented for internal reasons.
- */
- virtual void clear();
-
- /**
* Returns the maximum of items in the recent files list.
*/
int maxItems() const;
@@ -158,6 +154,18 @@ public:
*/
KUrl::List urls() const;
+ /**
+ * Returns whether an entry for clearing the recent files list is enabled.
+ */
+ bool clearActionEnabled() const;
+
+ /**
+ * Enables or disables an entry for clearing the recent files list (disabled by default).
+ *
+ * @param enabled True to enable and false to disable.
+ */
+ void setClearActionEnabled(bool enabled);
+
Q_SIGNALS:
/**
* This signal gets emitted when the user selects an URL.
@@ -166,6 +174,12 @@ Q_SIGNALS:
*/
void urlSelected( const KUrl& url );
+public Q_SLOTS:
+ /**
+ * Reimplemented for internal reasons.
+ */
+ virtual void clear();
+
private:
// Don't warn about the virtual overload. As the comment of the other
diff -dNpru kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction_p.h kdelibs-4.1.0/kdeui/actions/krecentfilesaction_p.h
--- kdelibs-4.1.0-orig/kdeui/actions/krecentfilesaction_p.h 2008-05-21 13:08:25.000000000 +0200
+++ kdelibs-4.1.0/kdeui/actions/krecentfilesaction_p.h 2009-03-07 17:07:15.000000000 +0100
@@ -39,6 +39,9 @@ public:
{
m_maxItems = 10;
m_noEntriesAction=0;
+ clearActionEnabled = false;
+ clearSeparator = 0;
+ clearAction = 0;
}
virtual ~KRecentFilesActionPrivate()
@@ -53,6 +56,9 @@ public:
QMap<QAction*, QString> m_shortNames;
QMap<QAction*, KUrl> m_urls;
QPointer<QAction> m_noEntriesAction;
+ bool clearActionEnabled;
+ QAction *clearSeparator;
+ QAction *clearAction;
};
/* vim: et sw=2 ts=2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: appearance.png
Type: image/png
Size: 9873 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090307/661eff8e/attachment.png>
More information about the kde-core-devel
mailing list