Opened 18 months ago

Closed 17 months ago

Last modified 17 months 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

Description

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

Attachments (3)

activate.patch download (2.6 KB) - added by troelsk 18 months ago.
Trunk
activatedoc.patch download (795 bytes) - added by troelsk 17 months ago.
Doc example
activatedoc.2.patch download (860 bytes) - added by troelsk 17 months ago.
Trunk

Download all attachments as: .zip

Change History (12)

Changed 18 months ago by troelsk

Trunk

comment:1 Changed 18 months ago by troelsk

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

comment:2 Changed 18 months 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 18 months 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 17 months 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 17 months 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();
         it++)
    {
        choices.push_back((*it)->GetUserReadableName());
    }
    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
                doc->Activate();
                return doc;
            }
        }

comment:6 Changed 17 months 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 17 months ago by troelsk

Doc example

comment:7 Changed 17 months 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 17 months ago by troelsk

Trunk

comment:8 Changed 17 months ago by troelsk

Doc patch updated: aligned with #15125

comment:9 Changed 17 months 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.