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

List:       koffice-devel
Subject:    Re: [PATCH] save embedded documents
From:       Dag Andersen <danders () get2net ! dk>
Date:       2002-07-18 9:34:28
[Download RAW message or body]

On Wednesday 17 July 2002 16:11, David Faure wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
[snip]
>
> Embedded external docs are not really supported at the moment
> (no GUI for it, only part of the handling is there)
Yes, well, it is possible to embedd docs in kword and as the saving is 
a bit eratic I thought I'd close this hole before release.
>
> > On Wednesday 17 July 2002 14:38, Dag Andersen wrote:
> > > The atttached patch:
> > > - checks if embedded external docs are modified and queries for
> > > save - checks if any embedded doc has been modified so that
> > > they can be saved also if main doc is not modified.
> > >
> > > Commit?
>
> The idea sounds good, but I'm a bit surprised by the duplicate
> message box. Shouldn't this patch simply introduce
> childIsModified() and use it in queryClose() ?
> I don't see the point in queryCloseExternalChildren();, please
> explain ;)
As I see it, there are 2 concerns:
1) To detect that _any_ document has been modified (main or embedded). 
For this childIsModified() is used. 
2) To query when saving modified external embedded documents. For this 
I meant to use queryCloseExternalChildren(). And if _only_ an 
external doc is changed, no need to save main doc. And also, it's 
nice (necessary?) to have individual control of external docs. I 
think it's a bit rude just to overwrite docs wo even a hint of what's 
going on.

New patch:
Does the above. Have moved queryCloseExternalChildren() to KWdocument, 
so 2) only applies to kword.
It was the intention _not_ to change the current behaviour of the save 
button, but with this solution external docs are now _only_ saved if 
changed. (I'm not sure if that's a pro or con, though.:) If it's a 
problem I need some extra state or rethink the whole thing.

>
> - --
> David FAURE, david@mandrakesoft.com, faure@kde.org
> http://people.mandrakesoft.com/~david/
> Contributing to: http://www.konqueror.org/, http://www.koffice.org/
> KOffice-1.2-beta2 is out! http://dot.kde.org/1025176121/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE9NXr772KcVAmwbhARAgQFAKCanousk9vwcjbJzBrcilg9hfJ3WQCfV4sr
> R+oqg48GSk/jOYVn5BQSo6o=
> =g4Cx
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> koffice-devel mailing list
> koffice-devel@mail.kde.org
> http://mail.kde.org/mailman/listinfo/koffice-devel

-- 
Mvh,
Dag Andersen
["save.diff" (text/x-diff)]

Index: kword/kwdoc.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwdoc.cc,v
retrieving revision 1.534
diff -u -p -u -r1.534 kwdoc.cc
--- kword/kwdoc.cc	2002/07/17 14:44:31	1.534
+++ kword/kwdoc.cc	2002/07/18 09:11:07
@@ -2492,10 +2492,12 @@ bool KWDocument::saveChildren( KoStore *
         if (childDoc && !curr->partFrameSet()->isDeleted())
         {
             kdDebug(32001) << "KWDocument::saveChildren url:" << \
                childDoc->url().url()
-                      << " extern:" << childDoc->isStoredExtern() << endl;
-            if ( childDoc->isStoredExtern() ) {
-                if ( !childDoc->save() )
-                    return FALSE;
+                      << " extern:" << childDoc->isStoredExtern() <<" modified:"<< \
childDoc->isModified() << endl; +            if ( childDoc->isStoredExtern() )
+            {
+                if ( childDoc->isModified() || childDoc->childIsModified() )
+                    if ( !childDoc->save() )
+                        return FALSE;
             }
             else
                 if ( !childDoc->saveToStore( _store, QString::number( i++ ) ) )
@@ -4398,6 +4400,44 @@ void KWDocument::configureSpellChecker()
     {
         view->configureSpellChecker();
     }
+}
+
+int KWDocument::queryCloseExternalChildren()
+{
+    int res = KMessageBox::Ok;
+    QPtrListIterator<KoDocumentChild> it( children() );
+    for (; it.current(); ++it )
+    {
+        KWChild* curr = static_cast<KWChild*>(it.current());
+        if ( curr->partFrameSet()->isDeleted() )
+            continue;
+
+        KoDocument *doc = curr->document();
+        kdDebug()<<k_funcinfo<<" doc: "<<doc->url().url()<<endl;
+        if ( doc->queryCloseExternalChildren() == KMessageBox::Cancel )
+            return KMessageBox::Cancel;
+
+        if ( doc->isStoredExtern() && ( doc->isModified() || doc->childIsModified() \
) ) +        {
+            QString name = doc->url().fileName();
+            res = KMessageBox::warningYesNoCancel( 0L,
+                            i18n( "<p>The document <b>'%1'</b> has been \
modified.</p><p>Do you want to save it?</p>" ).arg(name)); +
+            switch(res) {
+                case KMessageBox::Yes :
+                    kdDebug()<<k_funcinfo<<" Saving doc: "<<doc->url().url()<<endl;
+                    doc->save();
+                    break;
+                case KMessageBox::No :
+                    //doc->removeAutoSaveFiles();
+                    doc->setModified( false );
+                    break;
+                default : // case KMessageBox::Cancel :
+                    return res; // cancels the rest of the saving process
+            }
+        }
+    }
+    return res;
 }

 #include "kwdoc.moc"
Index: kword/kwdoc.h
===================================================================
RCS file: /home/kde/koffice/kword/kwdoc.h,v
retrieving revision 1.251
diff -u -p -u -r1.251 kwdoc.h
--- kword/kwdoc.h	2002/07/17 14:44:32	1.251
+++ kword/kwdoc.h	2002/07/18 09:11:11
@@ -718,6 +718,8 @@ public:

     QPtrListIterator<KWBookMark> bookmarkIterator() const { return \
QPtrListIterator<KWBookMark>(m_bookmarkList); }

+    int queryCloseExternalChildren();
+
 signals:
     void sig_insertObject( KWChild *_child, KWPartFrameSet* );

Index: lib/kofficecore/koDocument.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.cc,v
retrieving revision 1.239
diff -u -p -u -r1.239 koDocument.cc
--- lib/kofficecore/koDocument.cc	2002/07/15 12:41:30	1.239
+++ lib/kofficecore/koDocument.cc	2002/07/18 09:11:17
@@ -630,6 +630,24 @@ void KoDocument::paintChild( KoDocumentC
     }
 }

+bool KoDocument::childIsModified()
+{
+    //kdDebug()<<k_funcinfo<<" doc="<<url().url()<<endl;
+    bool res = false;
+    QPtrListIterator<KoDocumentChild> it = children();
+    for (; it.current(); ++it )
+    {
+        KoDocument *doc = it.current()->document();
+        if ( doc )
+        {
+            kdDebug()<<k_funcinfo<<" doc: "<<doc->url().url()<<" \
modified="<<doc->isModified()<<endl; +            if ( doc->isModified() || \
doc->childIsModified() ) +                res = true;//return true;
+        }
+    }
+    return res;
+}
+
 bool KoDocument::saveChildren( KoStore* /*_store*/ )
 {
     // Lets assume that we do not have children
@@ -658,6 +676,7 @@ bool KoDocument::saveNativeFormat( const
     }

     kdDebug(30003) << "KoDocument::saveNativeFormat nativeFormatMimeType=" << \
nativeFormatMimeType() << endl; +    kdDebug(30003) << "KoDocument::saveNativeFormat \
                creating store=" << file << endl;
     KoStore* store = KoStore::createStore( file, KoStore::Write, \
nativeFormatMimeType(), backend );  if ( store->bad() )
     {
@@ -760,6 +779,8 @@ bool KoDocument::saveToStore( KoStore* _
     if ( !completeSaving( _store ) )
         return false;

+    setModified(false);
+
     // Now that we're done leave the directory again
     _store->popDirectory();

@@ -1264,7 +1285,7 @@ void KoDocument::setModified( bool mod )
     if ( mod == isModified() )
         return;

-    kdDebug(30003) << "KoDocument::setModified( " << (mod ? "true" : "false") << ")" \
<< endl; +    kdDebug(30003) << "KoDocument::setModified( " << (mod ? "true" : \
"false") << ")" << " doc: " << url().url() << endl;  \
KParts::ReadWritePart::setModified( mod );

     if ( mod )
@@ -1272,6 +1293,11 @@ void KoDocument::setModified( bool mod )

     // This influences the title
     setTitleModified();
+}
+
+int KoDocument::queryCloseExternalChildren()
+{
+    return KMessageBox::Ok;
 }

 void KoDocument::setTitleModified()
Index: lib/kofficecore/koDocument.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.h,v
retrieving revision 1.119
diff -u -p -u -r1.119 koDocument.h
--- lib/kofficecore/koDocument.h	2002/07/01 15:48:12	1.119
+++ lib/kofficecore/koDocument.h	2002/07/18 09:11:19
@@ -479,9 +479,13 @@ public:
     virtual bool isStoredExtern();

     KoPageLayout pageLayout() const { return m_pageLayout; }
-
+
     void removeAutoSaveFiles();
+
+    virtual bool childIsModified();

+    virtual int queryCloseExternalChildren();
+
 signals:
     /**
      * This signal is emitted, if a direct or indirect child document changes
Index: lib/kofficecore/koMainWindow.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koMainWindow.cc,v
retrieving revision 1.266
diff -u -p -u -r1.266 koMainWindow.cc
--- lib/kofficecore/koMainWindow.cc	2002/06/17 15:54:56	1.266
+++ lib/kofficecore/koMainWindow.cc	2002/07/18 09:11:23
@@ -669,47 +669,54 @@ void KoMainWindow::resizeEvent( QResizeE

 bool KoMainWindow::queryClose()
 {
-  if ( rootDocument() == 0 )
-    return true;
-  //kdDebug(30003) << "KoMainWindow::queryClose() viewcount=" << \
                rootDocument()->viewCount()
-  //               << " shellcount=" << rootDocument()->shellCount() << endl;
-  if ( !d->m_forQuit && rootDocument()->shellCount() > 1 )
-    // there are more open, and we are closing just one, so no problem for closing
-    return true;
+    if ( rootDocument() == 0 )
+        return true;
+    //kdDebug(30003) << "KoMainWindow::queryClose() viewcount=" << \
rootDocument()->viewCount() +    //               << " shellcount=" << \
rootDocument()->shellCount() << endl; +    if ( !d->m_forQuit && \
rootDocument()->shellCount() > 1 ) +        // there are more open, and we are \
closing just one, so no problem for closing +        return true;
+
+    // see DTOR for a descr. of the test
+    if ( d->m_rootDoc->isEmbedded() )
+        return true;
+
+    // external documents first
+    if ( d->m_rootDoc->queryCloseExternalChildren() == KMessageBox::Cancel )
+        return false;

-  // see DTOR for a descr. for the 2nd test
-  if ( d->m_rootDoc->isModified() &&
-       !d->m_rootDoc->isEmbedded())
-  {
-      QString name;
-      if ( rootDocument()->documentInfo() )
-      {
-         name = rootDocument()->documentInfo()->title();
-      }
-      if ( name.isEmpty() )
-          name = rootDocument()->url().fileName();
-
-      if ( name.isEmpty() )
-          name = i18n( "Untitled" );
-
-      int res = KMessageBox::warningYesNoCancel( 0L,
-                    i18n( "<p>The document <b>'%1'</b> has been modified.</p><p>Do \
                you want to save it?</p>" ).arg(name));
-
-      switch(res) {
-          case KMessageBox::Yes : {
-              bool isNative = ( d->m_rootDoc->outputMimeType() == \
                d->m_rootDoc->nativeFormatMimeType() );
-              if (! saveDocument( !isNative ) )
-                  return false;
-          }
-          case KMessageBox::No :
-              rootDocument()->removeAutoSaveFiles();
-              rootDocument()->setModified( false ); // Now when queryClose() is \
                called by closeEvent it won't do anything.
-              break;
-          default : // case KMessageBox::Cancel :
-              return false;
-      }
-  }
-  return true;
+    // main doc + embedded docs in store
+    if ( d->m_rootDoc->isModified() || d->m_rootDoc->childIsModified() )
+    {
+        QString name;
+        if ( rootDocument()->documentInfo() )
+        {
+            name = rootDocument()->documentInfo()->title();
+        }
+        if ( name.isEmpty() )
+            name = rootDocument()->url().fileName();
+
+        if ( name.isEmpty() )
+            name = i18n( "Untitled" );
+
+        int res = KMessageBox::warningYesNoCancel( 0L,
+                        i18n( "<p>The document <b>'%1'</b> has been \
modified.</p><p>Do you want to save it?</p>" ).arg(name)); +
+        switch(res) {
+            case KMessageBox::Yes : {
+                bool isNative = ( d->m_rootDoc->outputMimeType() == \
d->m_rootDoc->nativeFormatMimeType() ); +                if (! saveDocument( \
!isNative ) ) +                    return false;
+            }
+            case KMessageBox::No :
+                rootDocument()->removeAutoSaveFiles();
+                rootDocument()->setModified( false ); // Now when queryClose() is \
called by closeEvent it won't do anything. +                break;
+            default : // case KMessageBox::Cancel :
+                return false;
+        }
+    }
+    return true;
 }

 void KoMainWindow::slotFileNew()


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

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

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