[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KApplication::cut()....
From:       Benjamin Meyer <ben () meyerhome ! net>
Date:       2005-09-26 11:50:24
Message-ID: 200509260750.26769.ben () meyerhome ! net
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


On Saturday 24 September 2005 3:34 pm, Benjamin Meyer wrote:
> On Friday 23 September 2005 1:42 pm, David Faure wrote:
> > On Friday 23 September 2005 19:08, Adam Treat wrote:
> > > Speaking as one of the few who actually use these slots... I'd rather
> > > they were in a KStandardSlots class too.  No, not because I would use
> > > them in some app that wouldn't have a mainwindow, but because I like
> > > the slots as is, not some stupid
> > > 'automaticallyCreateSomeKActionsForMePlease' methods
> >
> > Why not KActions? You don't connect copy/cut/paste to some actions?
>
> Good idea, I'll take a look at it and see if it will work.
>
> > > and I don't think we should polute the KMainWindow namespace.
> >
> > Right.

Ok, attached is a new patch.  Rather then going into KMainWindow or making a 
new slotsClass, I have added several new functions to kstdaction such as:

KAction *cut(KActionCollection* parent);

These create a AutomaticAction which is a (kstdaction private) subclass of 
KAction that have the invokeMethod call.

Please RFC

-Benjamin Meyer

-- 
aka icefox
Public Key: http://www.icefox.net/public_key.asc

["editaction.diff" (text/x-diff)]

Index: kdecore/kapplication.h
===================================================================
--- kdecore/kapplication.h	(revision 463257)
+++ kdecore/kapplication.h	(working copy)
@@ -54,7 +54,6 @@
 *
 * Only one object of this class can be instantiated in a single app.
 * This instance is always accessible via the 'kapp' global variable.
-* See cut() for an example.
 *
 * This class provides the following services to all KDE applications.
 *
@@ -394,71 +393,6 @@
    **/
   void setTopWidget( QWidget *topWidget );
 
-public slots:
-
-  /**
-   * If the widget with focus provides a cut() slot, call that slot.  Thus for a
-   * simple application cut can be implemented as:
-   * \code
-   * KStdAction::cut( kapp, SLOT( cut() ), actionCollection() );
-   * \endcode
-   */
-  void cut();
-
-  /**
-   * If the widget with focus provides a copy() slot, call that slot.  Thus for a
-   * simple application copy can be implemented as:
-   * \code
-   * KStdAction::copy( kapp, SLOT( copy() ), actionCollection() );
-   * \endcode
-   */
-  void copy();
-
-  /**
-   * If the widget with focus provides a paste() slot, call that slot.  Thus for a
-   * simple application copy can be implemented as:
-   * \code
-   * KStdAction::paste( kapp, SLOT( paste() ), actionCollection() );
-   * \endcode
-   */
-  void paste();
-
-  /**
-   * If the widget with focus provides a clear() slot, call that slot.  Thus for a
-   * simple application clear() can be implemented as:
-   * \code
-   * new KAction( i18n( "Clear" ), "editclear", 0, kapp, SLOT( clear() ), \
                actionCollection(), "clear" );
-   * \endcode
-   *
-   * Note that for some widgets, this may not provide the intended bahavior.  For
-   * example if you make use of the code above and a KListView has the focus, \
                clear()
-   * will clear all of the items in the list.  If this is not the intened behavior
-   * and you want to make use of this slot, you can subclass KListView and \
                reimplement
-   * this slot.  For example the following code would implement a KListView without \
                this
-   * behavior:
-   *
-   * \code
-   * class MyListView : public KListView {
-   *   Q_OBJECT
-   * public:
-   *   MyListView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : \
                KListView( parent, name, f ) {}
-   *   virtual ~MyListView() {}
-   * public slots:
-   *   virtual void clear() {}
-   * };
-   * \endcode
-   */
-  void clear();
-
-  /**
-   * If the widget with focus provides a selectAll() slot, call that slot.  Thus for \
                a
-   * simple application select all can be implemented as:
-   * \code
-   * KStdAction::selectAll( kapp, SLOT( selectAll() ), actionCollection() );
-   * \endcode
-   */
-  void selectAll();
-
 public:
   /**
    * Returns the DCOP name of the service launcher. This will be something like
@@ -722,39 +656,6 @@
   static KApplication *KApp;
   int pArgc;
 
-  /**
-   * This method is used internally to determine which edit slots are implemented
-   * by the widget that has the focus, and to invoke those slots if available.
-   *
-   * @param slot is the slot as returned using the SLOT() macro, for example SLOT( \
                cut() )
-   *
-   * This method can be used in KApplication subclasses to implement application \
                wide
-   * edit actions not supported by the KApplication class.  For example (in your \
                subclass):
-   *
-   * \code
-   * void MyApplication::deselect()
-   * {
-   *   invokeEditSlot( SLOT( deselect() ) );
-   * }
-   * \endcode
-   *
-   * Now in your application calls to MyApplication::deselect() will call this slot \
                on the
-   * focused widget if it provides this slot.  You can combine this with KAction \
                with:
-   *
-   * \code
-   * KStdAction::deselect( static_cast<MyApplication *>( kapp ), SLOT( cut() ), \
                actionCollection() );
-   * \endcode
-   *
-   * @see cut()
-   * @see copy()
-   * @see paste()
-   * @see clear()
-   * @see selectAll()
-   *
-   * @since 3.2
-   */
-  void invokeEditSlot( const char *slot );
-
 private slots:
   void dcopFailure(const QString &);
   void dcopBlockUserInput( bool );
Index: kdecore/kapplication.cpp
===================================================================
--- kdecore/kapplication.cpp	(revision 463257)
+++ kdecore/kapplication.cpp	(working copy)
@@ -1615,12 +1615,6 @@
 #endif
 }
 
-void KApplication::invokeEditSlot( const char *slot )
-{
-  if ( focusWidget() );
-    QMetaObject::invokeMethod( focusWidget(), slot );
-}
-
 void KApplication::addKipcEventMask(int id)
 {
     if (id >= 32)
@@ -1943,31 +1937,6 @@
 #endif
 }
 
-void KApplication::cut()
-{
-  invokeEditSlot( SLOT( cut() ) );
-}
-
-void KApplication::copy()
-{
-  invokeEditSlot( SLOT( copy() ) );
-}
-
-void KApplication::paste()
-{
-  invokeEditSlot( SLOT( paste() ) );
-}
-
-void KApplication::clear()
-{
-  invokeEditSlot( SLOT( clear() ) );
-}
-
-void KApplication::selectAll()
-{
-  invokeEditSlot( SLOT( selectAll() ) );
-}
-
 QByteArray
 KApplication::launcher()
 {
Index: kdeui/kstdaction.h
===================================================================
--- kdeui/kstdaction.h	(revision 463257)
+++ kdeui/kstdaction.h	(working copy)
@@ -279,6 +279,49 @@
 		KActionCollection* parent, const char *name = 0 );
 
 	/**
+	* Cut selected area and store it in the clipboard.  Calls cut() on the widget with \
the current focus. +	*/
+	KDEUI_EXPORT KAction *cut(KActionCollection* parent);
+	
+	/**
+	* Copy selected area and store it in the clipboard.  Calls copy() on the widget \
with the current focus. +	*/
+	KDEUI_EXPORT KAction *copy(KActionCollection* parent);
+	
+	/**
+	* Paste the contents of clipboard at the current mouse or cursor
+	* Calls paste() on the widget with the current focus.
+	*/
+	KDEUI_EXPORT KAction *paste(KActionCollection* parent);
+ 
+	/**
+	* Clear selected area.  Calls clear() on the widget with the current focus.
+ 	* Note that for some widgets, this may not provide the intended bahavior.  For
+	* example if you make use of the code above and a KListView has the focus, clear()
+	* will clear all of the items in the list.  If this is not the intened behavior
+	* and you want to make use of this slot, you can subclass KListView and reimplement
+	* this slot.  For example the following code would implement a KListView without \
this +	* behavior:
+	*
+	* \code
+	* class MyListView : public KListView {
+	*   Q_OBJECT
+	* public:
+	*   MyListView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : \
KListView( parent, name, f ) {} +	*   virtual ~MyListView() {}
+	* public slots:
+	*   virtual void clear() {}
+	* };
+	* \endcode
+	*/
+	KDEUI_EXPORT KAction *clear(KActionCollection* parent);
+
+	/**
+	* Calls selectAll() on the widget with the current focus.
+	*/
+	KDEUI_EXPORT KAction *selectAll(KActionCollection* parent);
+	      
+	/**
 	* Cut selected area and store it in the clipboard.
 	*/
 	KDEUI_EXPORT KAction *cut(const QObject *recvr, const char *slot,
Index: kdeui/kstdaction_p.h
===================================================================
--- kdeui/kstdaction_p.h	(revision 463257)
+++ kdeui/kstdaction_p.h	(working copy)
@@ -16,11 +16,13 @@
    Boston, MA 02111-1307, USA.
 */
 
-#ifndef _KSTDACTION_PRIVATE_H_
-#define _KSTDACTION_PRIVATE_H_
+#ifndef KSTDACTION_PRIVATE_H
+#define KSTDACTION_PRIVATE_H
 
 #include <klocale.h>
 #include <kstdaccel.h>
+#include <qapplication.h>
+#include <kaction.h>
 
 namespace KStdAction
 {
@@ -132,7 +134,31 @@
             result.append(i18n(g_rgActionInfo[i].psLabel));
     return result;
 }
+class AutomaticAction : public KAction {
 
+Q_OBJECT
+
+public:
+    AutomaticAction(const QString &text, const QString &pix, const KShortcut &cut, \
const char *slot, KActionCollection *parent, const char *name) : KAction (text, pix, \
cut, 0, slot, parent, name){ +      connect(this, SIGNAL( activated() ), this, slot \
); +    }
+    
+public slots:
+    inline void cut(){ invokeEditSlot("cut"); };
+    inline void copy(){ invokeEditSlot("copy"); };
+    inline void paste(){ invokeEditSlot("paste"); };
+    inline void clear(){ invokeEditSlot("clear"); };
+    inline void selectAll(){ invokeEditSlot("selectAll"); };
+
+    void invokeEditSlot( const char *slot )
+    {
+        if ( qApp->focusWidget() );
+            QMetaObject::invokeMethod( qApp->focusWidget(), slot );
+    }
+
+};
+
+
 }
 
 #endif
Index: kdeui/kstdaction.cpp
===================================================================
--- kdeui/kstdaction.cpp	(revision 463257)
+++ kdeui/kstdaction.cpp	(working copy)
@@ -230,6 +230,43 @@
 KAction *spelling( const QObject *recvr, const char *slot, KActionCollection* \
parent, const char *name )  { return KStdAction::create( Spelling, name, recvr, slot, \
parent ); }  
+
+KAction *buildAutomaticAction(KActionCollection* parent, StdAction id, const char* \
slot) +{
+    const KStdActionInfo* p = infoPtr( id );
+    if (!p)
+        return 0;
+    KShortcut cut = KStdAccel::shortcut(p->idAccel);
+    AutomaticAction *action = new AutomaticAction(p->psLabel, p->psIconName, cut, \
slot, parent, p->psName); +    action->setWhatsThis(p->psWhatsThis);
+    return action;
+}
+        
+KAction *cut(KActionCollection* parent)
+{
+    return buildAutomaticAction(parent, Cut, SLOT(cut()));
+}
+
+KAction *copy(KActionCollection* parent)
+{
+    return buildAutomaticAction(parent, Copy, SLOT(copy()));
+}     
+
+KAction *paste(KActionCollection* parent)
+{
+    return buildAutomaticAction(parent, Paste, SLOT(paste()));
+}     
+
+KAction *clear(KActionCollection* parent)
+{
+    return buildAutomaticAction(parent, Clear, SLOT(cleare()));
+}     
+
+KAction *selectAll(KActionCollection* parent)
+{
+    return buildAutomaticAction(parent, SelectAll, SLOT(selectAll()));
+}     
+
 KToggleAction *showMenubar( const QObject *recvr, const char *slot, \
KActionCollection* parent, const char *_name )  {
     KToggleAction *ret;


[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic