[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-23 14:50:41
Message-ID: 200509231050.43441.ben () meyerhome ! net
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


On Friday 23 September 2005 9:22 am, Joseph Wenninger wrote:
> Hi !
>
> 1) Why do I have to retrieve the action object, if I just want to cut or
> copy from the currently focused widget ? The focus widget doesn't have to
> be the mainwindow, but could be a child widget, right ? Ok, the advantage
> would be that you don't have to call the slots cut/copy/paste, ...

yah having functions named cut() was a bad idea and a bad polution of the name 
space, I have moved it into the private class

> 2) If there are methods like createAutomaticCutActions, they should check
> if the action collection already has a cut action and only create a new one
> , if it doesn't , otherwise return the already existing

If we want that funcionality KStdAction::create should really do that, not 
createAutomaticCutActions.

Ok attached is a new diff.  Let me know what you think.

-Benjamin Meyer

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

["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
@@ -477,7 +411,6 @@
    */
   QString caption() const;
 
-
   /**
    * Builds a caption that contains the application name along with the
    * userCaption using a standard layout.
@@ -722,39 +655,8 @@
   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/kmainwindow.h
===================================================================
--- kdeui/kmainwindow.h	(revision 463257)
+++ kdeui/kmainwindow.h	(working copy)
@@ -641,6 +641,70 @@
     // KDE4 remove
     virtual void setIcon( const QPixmap & );
 
+    /**
+     * If the widget with focus provides a cut() slot, call that slot.  Thus for a
+     * simple application cut can be implemented as:
+     * \code
+     * createAutomaticCutAction(actionCollection());
+     * \endcode
+     */
+    KAction *createAutomaticCutAction(KActionCollection *collection) const;
+
+    /**
+     * If the widget with focus provides a copy() slot, call that slot.  Thus for a
+     * simple application copy can be implemented as:
+     * \code
+     * createAutomaticCopyAction(actionCollection());
+     * \endcode
+     */
+    KAction *createAutomaticCopyAction(KActionCollection *collection) const;
+
+    /**
+     * If the widget with focus provides a paste() slot, call that slot.  Thus for a
+     * simple application copy can be implemented as:
+     * \code
+     * createAutomaticPasteAction(actionCollection());
+     * \endcode
+     */
+    KAction *createAutomaticPasteAction(KActionCollection *collection) const;
+
+    /**
+     * 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, this, 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
+     */
+    KAction *createAutomaticClearAction(KActionCollection *collection) const;
+
+    /**
+     * 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( this, SLOT( selectAll() ), actionCollection() );
+     * \endcode
+     */
+    KAction *createAutomaticSelectAllAction(KActionCollection *collection) const;
+
+
 public slots:
     /**
      * Show a standard configure toolbar dialog.
Index: kdeui/kmainwindow.cpp
===================================================================
--- kdeui/kmainwindow.cpp	(revision 463257)
+++ kdeui/kmainwindow.cpp	(working copy)
@@ -62,26 +62,8 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <assert.h>
+#include "kmainwindow_p.h"
 
-class KMainWindowPrivate {
-public:
-    bool showHelpMenu:1;
-
-    bool autoSaveSettings:1;
-    bool settingsDirty:1;
-    bool autoSaveWindowSize:1;
-    bool care_about_geometry:1;
-    bool shuttingDown:1;
-    QString autoSaveGroup;
-    KAccel * kaccel;
-    KMainWindowInterface *m_interface;
-    KDEPrivate::ToolBarHandler *toolBarHandler;
-    QTimer* settingsTimer;
-    KToggleAction *showStatusBarAction;
-    QRect defaultWindowSize;
-    Q3PtrList<Q3DockWindow> hiddenDockWindows;
-};
-
 Q3PtrList<KMainWindow>* KMainWindow::mMemberList = 0L;
 static bool no_query_exit = false;
 static KMWSessionManaged* ksm = 0;
@@ -1180,6 +1162,61 @@
   KXMLGUIClient::virtual_hook( id, data ); }
 
 
+KAction *KMainWindow::createAutomaticCutAction(KActionCollection *actionCollection) \
const +{
+    return KStdAction::cut( d, SLOT(cut()), actionCollection );
+}
 
+KAction *KMainWindow::createAutomaticCopyAction(KActionCollection *actionCollection) \
const +{
+    return KStdAction::copy( d, SLOT(copy()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticPasteAction(KActionCollection \
*actionCollection) const +{
+    return KStdAction::paste( d, SLOT(paste()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticClearAction(KActionCollection \
*actionCollection) const +{
+    return KStdAction::clear( d, SLOT(clear()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticSelectAllAction(KActionCollection \
*actionCollection) const +{
+    return KStdAction::selectAll( d, SLOT(selectAll()), actionCollection );
+}
+
+void KMainWindowPrivate::cut()
+{
+  invokeEditSlot( SLOT( copy() ) );
+}
+
+void KMainWindowPrivate::copy()
+{
+  invokeEditSlot( SLOT( copy() ) );
+}
+
+void KMainWindowPrivate::paste()
+{
+  invokeEditSlot( SLOT( paste() ) );
+}
+
+void KMainWindowPrivate::clear()
+{
+  invokeEditSlot( SLOT( clear() ) );
+}
+
+void KMainWindowPrivate::selectAll()
+{
+  invokeEditSlot( SLOT( selectAll() ) );
+}
+
+void KMainWindowPrivate::invokeEditSlot( const char *slot )
+{
+  if ( qApp->focusWidget() );
+    QMetaObject::invokeMethod( qApp->focusWidget(), slot );
+}
+
 #include "kmainwindow.moc"
 
Index: kdeui/kmainwindow_p.h
===================================================================
--- kdeui/kmainwindow_p.h	(revision 0)
+++ kdeui/kmainwindow_p.h	(revision 0)
@@ -0,0 +1,104 @@
+ /* This file is part of the KDE libraries
+     Copyright
+     (C) 2000 Reginald Stadlbauer (reggie@kde.org)
+     (C) 1997 Stephan Kulow (coolo@kde.org)
+     (C) 1997-2000 Sven Radej (radej@kde.org)
+     (C) 1997-2000 Matthias Ettrich (ettrich@kde.org)
+     (C) 1999 Chris Schlaeger (cs@kde.org)
+     (C) 2002 Joseph Wenninger (jowenn@kde.org)
+
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+     License version 2 as published by the Free Software Foundation.
+
+     This library is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     Library General Public License for more details.
+
+     You should have received a copy of the GNU Library General Public License
+     along with this library; see the file COPYING.LIB.  If not, write to
+     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+ */
+
+#ifndef KMAINWINDOW_P_H
+#define KMAINWINDOW_P_H
+
+#include <qobject.h>
+#include <Q3PtrList>
+#include <Q3DockWindow>
+#include "ktoolbarhandler.h"
+class KAccel;
+class KMainWindowInterface;
+class QTimer;
+class KToggleAction;
+
+class KMainWindowPrivate : public QObject {
+
+Q_OBJECT
+    
+public:
+    KMainWindowPrivate(QObject* parent = 0):QObject(parent){};
+    ~KMainWindowPrivate(){};
+    
+    /**
+     * 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( this, SLOT( cut() ), actionCollection() );
+     * \endcode
+     *
+     * @see cut()
+     * @see copy()
+     * @see paste()
+     * @see clear()
+     * @see selectAll()
+     *
+     * @since 3.2
+     */
+    void invokeEditSlot( const char *slot );
+
+    bool showHelpMenu:1;
+
+    bool autoSaveSettings:1;
+    bool settingsDirty:1;
+    bool autoSaveWindowSize:1;
+    bool care_about_geometry:1;
+    bool shuttingDown:1;
+    QString autoSaveGroup;
+    KAccel * kaccel;
+    KMainWindowInterface *m_interface;
+    KDEPrivate::ToolBarHandler *toolBarHandler;
+    QTimer* settingsTimer;
+    KToggleAction *showStatusBarAction;
+    QRect defaultWindowSize;
+    Q3PtrList<Q3DockWindow> hiddenDockWindows;
+
+public slots:
+    void cut();
+    void copy();
+    void paste();
+    void clear();
+    void selectAll();
+
+};
+
+#endif
+
Index: kdeui/Makefile.am
===================================================================
--- kdeui/Makefile.am	(revision 463257)
+++ kdeui/Makefile.am	(working copy)
@@ -39,7 +39,7 @@
 
 include_HEADERS = kprogress.h kcolordlg.h kcolordialog.h kselect.h kdatepik.h \
 	kdatepicker.h kdatetbl.h kdatetable.h kfontdialog.h kmenu.h kfontrequester.h \
                ktabctl.h \
-	kstatusbar.h kmainwindow.h kmainwindowiface.h ktoolbar.h kmenubar.h knuminput.h \
+	kstatusbar.h kmainwindow.h kmainwindow_p.h kmainwindowiface.h ktoolbar.h kmenubar.h \
knuminput.h \  kseparator.h klineedit.h krestrictedline.h kcolorbutton.h kcolorbtn.h \
ksystemtray.h \  kbuttonbox.h keditcl.h kled.h keditlistbox.h kwizard.h kkeydialog.h \
kkeybutton.h \  kurllabel.h kruler.h kcursor.h kinputdialog.h kactivelabel.h \
kcharselect.h \


[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