Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15120 closed enhancement (fixed)

Move convenience method ActivateDocument() from wxDocManager to wxDocument and document it.

Reported by: troelsk Owned by:
Priority: normal Milestone: 2.9.5
Component: GUI-all Version: stable-latest
Keywords: wxDocument wxDocManager Cc:
Blocked By: Blocking:
Patch: yes


Maybe a better method name would be Activate(), or ActivateFirstView().

Attachments (3)

activate.patch download (2.6 KB) - added by troelsk 5 years ago.
activatedoc.patch download (795 bytes) - added by troelsk 5 years ago.
Doc example
activatedoc.2.patch download (860 bytes) - added by troelsk 5 years ago.

Download all attachments as: .zip

Change History (12)

Changed 5 years ago by troelsk


comment:1 Changed 5 years ago by troelsk

This method can be made const. No sure that it'll make sense.

comment:2 Changed 5 years ago by vadz

  • Milestone set to 2.9.5
  • Status changed from new to confirmed

Making it const doesn't make much sense but I'm unsure about the name. wxDocument::ActivateDocument() definitely seems redundant so I agree that it should be either Activate() or ActivateFirstView(). The first one is shorter but possibly unclear, the second one is consistent with the existing GetFirstView() and perfectly clear but less flexible exactly because of it, e.g. what if we allow specifying the "main document" view in the future which would be activated by this function instead? Of course, all this is hardly important knowing that multiple views support in wxDocument is pretty broken anyhow :-(

So finally I think I'd like to make it just Activate() (already did the changes locally, in fact), any objections?

comment:3 Changed 5 years ago by troelsk

The name Activate() is fine. Thanks!

(it could also be made to return bool - but the other similar methods returns void, namely wxView::Activate() and wxDocManager::ActivateView())

comment:4 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [73720]) Add wxDocument::Activate() method.

Make activating the first (and, in the vast majority of cases, the only) view
of the document easier.

Closes #15120.

comment:5 Changed 5 years ago by troelsk

Great! Now docview users can implement a "Windows" dialog as simple as this,

void WindowsDialog(wxWindow* parent, const wxDocVector& docs)
    wxArrayString choices;
    for (wxDocVector::const_iterator it = docs.begin();
         it != docs.end();
    int index = wxGetSingleChoiceIndex(_("Activate window:"), _("Windows"), choices, parent);
    if (index != wxNOT_FOUND)
        docs[index]->Activate(); // new method from this ticket (r73720)
::WindowsDialog(frame, docManager->GetDocumentsVector());

BTW, I was thinking about maybe moving this code to a separate method too, FindOpenDocument(), but admittedly I need it only in a single project, and it is needed only once inside wx, so maybe a bad idea?

        const wxFileName fn(path);
        for ( wxList::const_iterator i = m_docs.begin(); i != m_docs.end(); ++i )
            wxDocument * const doc = (wxDocument*)*i;

            if ( fn == doc->GetFilename() )
                // file already open, just activate it and return
                return doc;

comment:6 Changed 5 years ago by vadz

FWIW I'm fine with adding a method for finding the document from file name, it does seem like something potentially useful and it wouldn't add much to the existing code considering that it already exists inside wx and just needs to be extracted into a separate function.

Changed 5 years ago by troelsk

Doc example

comment:7 Changed 5 years ago by troelsk

Created ticket #15126 "wxDocManager::FindDocumentByFileName() convenience method".

Also, I have added a patch to this ticket, activatedoc.patch, adding an example to the doc.
To be valid the example requires yet another ticket #15125 to be applied.

Changed 5 years ago by troelsk


comment:8 Changed 5 years ago by troelsk

Doc patch updated: aligned with #15125

comment:9 Changed 5 years ago by VZ

(In [73736]) Mention the relationship of wxDocument::Activate() with Raise().

Also provide an example of a custom overridden Raise().

See #15120.

Note: See TracTickets for help on using tickets.