extension to queryClose, which allows bc virtual

Joseph Wenninger jowenn at kde.org
Fri Sep 26 18:47:13 BST 2003


Hi

With the kate part there is the problem that, if the part's queryClose
method detects that the document has been modified it shows a the
standard file dialog. ==> no encoding selection. With the attached patch
it is somehow possible to oveerride the standard behaviour so that the
kate part can display the save dialgo with the encoding chooser. I know
it is a hack, but it seems to work.
May I commit that till we can break binary compatibility in 4.0 again ?
Any better solutions ? 
Suggestions ? flames? ....

Kind regards
Joseph Wenninger
-------------- next part --------------
? part_queryclose_extension.diff
Index: part.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/part.cpp,v
retrieving revision 1.127
diff -u -3 -p -r1.127 part.cpp
--- part.cpp	31 Aug 2003 06:36:33 -0000	1.127
+++ part.cpp	26 Sep 2003 17:22:44 -0000
@@ -487,20 +487,27 @@ bool ReadWritePart::queryClose()
                 "Do you want to save it?" ).arg( docName ),
           i18n( "Save Document?" ), KStdGuiItem::save(), KStdGuiItem::discard() );
 
+  bool abortClose=false;
+  bool handled=false;
+
   switch(res) {
   case KMessageBox::Yes :
-    if (m_url.isEmpty())
+    queryClose_save(&handled,&abortClose);
+    if (!handled)
     {
-        KURL url = KFileDialog::getSaveURL();
-        if (url.isEmpty())
-          return false;
+      if (m_url.isEmpty())
+      {
+          KURL url = KFileDialog::getSaveURL();
+          if (url.isEmpty())
+            return false;
 
-        saveAs( url );
-    }
-    else
-    {
-        save();
-    }
+          saveAs( url );
+      }
+      else
+      {
+          save();
+      }
+    } else if (abortClose) return false;
     return waitSaveComplete();
   case KMessageBox::No :
     return true;
Index: part.h
===================================================================
RCS file: /home/kde/kdelibs/kparts/part.h,v
retrieving revision 1.106
diff -u -3 -p -r1.106 part.h
--- part.h	6 Sep 2003 19:06:37 -0000	1.106
+++ part.h	26 Sep 2003 17:22:45 -0000
@@ -618,6 +618,15 @@ public:
    */
   virtual void setModified( bool modified );
 
+signals:
+   /**
+    * @since 3.2, remove int KDE 4, when queryClose is made virtual
+    * set handled to true, if you don't want the default handling
+    * set abortClosing to true, if you handled the request, but for any reason don't
+    * want to allow closing the document
+    */
+   void queryClose_save(bool *handled, bool* abortClosing);
+
 public slots:
   /**
    * Call setModified() whenever the contents get modified.


More information about the kde-core-devel mailing list