Fwd: closing an IDocument

Milian Wolff mail at milianw.de
Sat Oct 4 13:31:40 UTC 2014


Hey Rene,

please send your messages to the mailing list so others can respond as well. I 
was on vacation and won't have time to review and answer your mail properly 
for a few more days. Please stay tuned.

Cheers

----------  Forwarded Message  ----------

Subject: closing an IDocument
Date: Sunday 28 September 2014, 11:52:16
From: René J.V. Bertin <rjvbertin at gmail.com>
To: Milian Wolff <mail at milianw.de>

Hi Milian,

I don't know if you've seen my latest posts on the "fix another crash when 
closing a patch review" RR? I may have stumbled upon a way to prevent them: 
closing all editor tabs opened by the plugin before stopping the plugin - and 
this seems to apply to the (git) commit toolview as well.
The cleanest way to do that IMHO would be to send a close message that 
resembles the one received from the window manager as closely as possible, and 
then do something like QApplication::flush() to maximise chances the events 
have been handled.

I've been fiddling with that idea:

void PatchReviewPlugin::closeReview()
{
    *if*( m_patch ) {
        *if*( m_highlighters.size() ){
          qDebug() << "## m_highlighters count=" << m_highlighters.size();
          QList<IDocument*> docs;
          docs.clear();
          foreach( PatchHighlighter *entry, m_highlighters ){
            qDebug() << "### m_highlighters entry" << entry << "doc=" << 
entry->doc() << entry->doc()->url();
            // we add the documents to be closed to a cache list to avoid 
reading from m_highlighters
            // while it is being modified (by changing documents).
            docs.append(entry->doc());
          }
          int n = 0;
          foreach( IDocument *i, docs ){
            // give the debugger something to put its teeth in:
            static IDocument *j = i;
            static bool ok = j->close();
            *if*( ok ){
              qDebug() << "### doc->close()=true";
              n += 1;
            }
            *else*{
              qDebug() << i->url() << "failed to close";
            }
          }
          QCoreApplication::flush();
          sleep(1);
          qDebug() << "Closed" << n << "/" << docs.size() << "documents";
        }
        removeHighlighting(); 
But it's like the `close()` function I'm calling takes me back directly into 
`closeReview`. I don't see another way to obtain a reference to the 
view/widget that the IDocument is open in; is there one? Would this require a 
chance to the PatchHighLigher class which seems to be responsible for opening 
the document? And where can I get the reference to the tab showing the patch 
file, it's not a member of m_highlighers?

Despite the impression I have stepping through the code in the debugger, `j-
>close()` does have the effect of closing the document. Because when I arrive 
at the `removeHighlighting()` call, m_highlighters.size() is 0 ... I've only 
tested with a single document though.

Cheers,
René
-----------------------------------------
-- 
Milian Wolff
mail at milianw.de
http://milianw.de


More information about the KDevelop-devel mailing list