Author Topic: Speeding up "Close all"  (Read 4773 times)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Speeding up "Close all"
« on: August 25, 2008, 07:49:57 pm »
I just noticed that regarding editor windows (tabs), "Close others" command works much faster than "close all", because "close all" changes the active tab and the screen is refreshed, carrying along a lot of UI overhead with it.

I was wondering if it was possible to implement "close all" by first "closing others" and then closing the current window.

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Speeding up "Close all"
« Reply #1 on: August 25, 2008, 08:19:49 pm »
That's an interesting observation.  I've observed this same UI overhead.

It certainly sounds like you would get the desired result in all cases.

Furthermore, Code::Blocks already has the code to implement this, although it looks like it was implemented as a workaround to handling popup menus potentially existing for the open file.


Here's the current sdk/editorbase.cpp, starting at line 339

Code
    else if (id == idCloseAll)
    {
    if (m_pData->m_DisplayingPopupMenu)
    {
            Manager::Get()->GetEditorManager()->CloseAllExcept(this);
            m_pData->m_CloseMe = true; // defer delete 'this' until after PopupMenu() call returns
    }
        else
            Manager::Get()->GetEditorManager()->CloseAll();
    }

I imagine that the change you describe would change the code to this:

Code
    else if (id == idCloseAll)
    {
        Manager::Get()->GetEditorManager()->CloseAllExcept(this);
        if (m_pData->m_DisplayingPopupMenu)
            m_pData->m_CloseMe = true; // defer delete 'this' until after PopupMenu() call returns
        else
            Manager::Get()->GetEditorManager()->Close(this);
    }

As best I can tell, that change alone would give us the speedup you describe.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Speeding up "Close all"
« Reply #2 on: August 25, 2008, 08:44:04 pm »
That looks interesting, but what about changing EditorManager::CloseAll directly, too? Would it be possible?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Speeding up "Close all"
« Reply #3 on: August 25, 2008, 09:03:51 pm »
I don't perceive the overhead very noticeable or even a problem, but sure... why not.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Speeding up "Close all"
« Reply #4 on: August 25, 2008, 09:31:11 pm »
I don't perceive the overhead very noticeable or even a problem, but sure... why not.

In one of my environments -- a 3GHz machine -- C::B can close about 4 to 6 windows each second.  That's a guess.  And you can see that the time is spent drawing.

It's not a huge problem, but when you have 100 files open, it looks a little silly to see C::B labor for many seconds to show you each and every file that you just said you're no longer interested in seeing.  :)

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Speeding up "Close all"
« Reply #5 on: August 25, 2008, 09:50:59 pm »
That looks interesting, but what about changing EditorManager::CloseAll directly, too? Would it be possible?

Hmm...I just took a look there.  My change would work or changing EditorManager::CloseAll would work.  You wouldn't need both.

However -- (Thomas, are you there?) -- looking at EditorManager, I see now that Close All is not functionally identical to Close Others plus Close

Specifically, Close All will leave Code::Block's "Start Page" open.  Close Others will not.  This specific "start page" exception is hard-coded in.  It should also be noted Close All will spare the Start Page if it happens to be open, but it will not open the Start Page if it has been closed.

To recap, the behavior of Close All is to leave you looking at either an "empty" editor or the Start Page, depending on whether you have closed the Start page.


Perhaps it should be discussed what the desired behavior is.  I'll happily whip up a patch for any scenario, but let's make sure we're all picturing the same scenario.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Speeding up "Close all"
« Reply #6 on: August 27, 2008, 05:32:50 am »
I think that closing all windows (including the active one) should put the default workspace, as given in the settings: The last used workspace, an empty workspace, or the start page (can't remember well, i just know it's in some settings).