@@ -72,12 +72,15 @@ ShellCtrlBase::ShellCtrlBase(wxWindow* parent, int id, const wxString &name, She
7272}
7373
7474
75+ DEFINE_EVENT_TYPE (wxEVT_SHELL_ADD_CLICKED)
76+
7577// //////////////////////////////////// ShellManager /////////////////////////////////////////////
7678
7779BEGIN_EVENT_TABLE(ShellManager, wxPanel)
7880 EVT_CHAR(ShellManager::OnUserInput)
7981 EVT_TIMER(ID_SHELLPOLLTIMER , ShellManager::OnPollandSyncOutput)
8082 EVT_AUINOTEBOOK_PAGE_CLOSE(ID_SHELLMGR , ShellManager::OnPageClosing)
83+ EVT_AUINOTEBOOK_PAGE_CHANGING(ID_SHELLMGR , ShellManager::OnPageChanging)
8184END_EVENT_TABLE()
8285
8386
@@ -87,10 +90,25 @@ void ShellManager::OnPageClosing(wxAuiNotebookEvent& event)
8790 // LOGSTREAM << wxString::Format(_T("OnPageClosing(): ed=%p, title=%s\n"), eb, eb ? eb->GetTitle().c_str() : _T(""));
8891 if (!QueryClose (sh))
8992 event.Veto ();
93+ m_nb->SetSelection (0 );
9094// event.Skip(); // allow others to process it too
9195}
9296
9397
98+ void ShellManager::OnPageChanging (wxAuiNotebookEvent& event)
99+ {
100+ if (event.GetSelection () == int (m_nb->GetPageCount ()-1 ))
101+ {
102+ wxCommandEvent pe (wxEVT_SHELL_ADD_CLICKED,0 );
103+ AddPendingEvent (pe);
104+ event.Veto ();
105+ return ;
106+ }
107+ event.Skip ();
108+ }
109+
110+
111+
94112bool ShellManager::QueryClose (ShellCtrlBase* sh)
95113{
96114 if (!sh)
@@ -134,10 +152,11 @@ long ShellManager::LaunchProcess(const wxString &processcmd, const wxString &nam
134152 delete shell; // TODO: GlobalShellRegistry.FreeControl() ???
135153 return -1 ;
136154 }
137- m_nb->AddPage ( shell,name);
138- m_nb->SetSelection (m_nb->GetPageCount ()-1 );
155+ m_nb->InsertPage (m_nb-> GetPageCount ()- 1 , shell,name);
156+ m_nb->SetSelection (m_nb->GetPageCount ()-2 );
139157// shell->Show();
140158 return procid;
159+
141160}
142161
143162ShellCtrlBase *ShellManager::GetPage (size_t i)
@@ -147,7 +166,7 @@ ShellCtrlBase *ShellManager::GetPage(size_t i)
147166
148167ShellCtrlBase *ShellManager::GetPage (const wxString &name)
149168{
150- for (unsigned int i=0 ;i<m_nb->GetPageCount ();i++)
169+ for (unsigned int i=0 ;i<m_nb->GetPageCount ()- 1 ;i++)
151170 {
152171 ShellCtrlBase *sh=GetPage (i);
153172 if (name==sh->GetName ())
@@ -169,7 +188,7 @@ void ShellManager::KillWindow(int /*id*/)
169188void ShellManager::RemoveDeadPages ()
170189{
171190 unsigned int i=0 ;
172- while (i<m_nb->GetPageCount ())
191+ while (i<m_nb->GetPageCount ()- 1 )
173192 {
174193 ShellCtrlBase *shell=GetPage (i);
175194 if (shell->IsDead ())
@@ -182,7 +201,7 @@ void ShellManager::RemoveDeadPages()
182201
183202size_t ShellManager::GetTermNum (ShellCtrlBase *term)
184203{
185- for (unsigned int i=0 ;i<m_nb->GetPageCount ();i++)
204+ for (unsigned int i=0 ;i<m_nb->GetPageCount ()- 1 ;i++)
186205 {
187206 ShellCtrlBase *shell=GetPage (i);
188207 if (shell==term)
@@ -194,7 +213,7 @@ size_t ShellManager::GetTermNum(ShellCtrlBase *term)
194213int ShellManager::NumAlive ()
195214{
196215 int count=0 ;
197- for (unsigned int i=0 ;i<m_nb->GetPageCount ();i++)
216+ for (unsigned int i=0 ;i<m_nb->GetPageCount ()- 1 ;i++)
198217 count+=!GetPage (i)->IsDead ();
199218 return count;
200219}
@@ -203,15 +222,16 @@ int ShellManager::NumAlive()
203222void ShellManager::OnShellTerminate (ShellCtrlBase *term)
204223{
205224 size_t i=GetTermNum (term);
206- m_nb->SetPageText (i,_ (" [DONE]" )+m_nb->GetPageText (i));
225+ if (i<m_nb->GetPageCount ()-1 )
226+ m_nb->SetPageText (i,_ (" [DONE]" )+m_nb->GetPageText (i));
207227 if (NumAlive ()==0 )
208228 m_synctimer.Stop ();
209229}
210230
211231
212232void ShellManager::OnPollandSyncOutput (wxTimerEvent& /* te*/ )
213233{
214- for (unsigned int i=0 ;i<m_nb->GetPageCount ();i++)
234+ for (unsigned int i=0 ;i<m_nb->GetPageCount ()- 1 ;i++)
215235 {
216236 GetPage (i)->SyncOutput ();
217237 }
@@ -230,6 +250,9 @@ ShellManager::ShellManager(wxWindow* parent)
230250 wxBoxSizer* bs = new wxBoxSizer (wxVERTICAL);
231251 m_nb = new wxAuiNotebook (this , ID_SHELLMGR , wxDefaultPosition, wxDefaultSize, wxAUI_NB_SCROLL_BUTTONS|wxAUI_NB_CLOSE_ON_ACTIVE_TAB);
232252 bs->Add (m_nb, 1 , wxEXPAND | wxALL);
253+ wxBitmap bm = wxArtProvider::GetBitmap (wxART_NEW);
254+ wxButton *wnd = new wxButton (this , wxID_ANY);
255+ m_nb->AddPage (wnd,_ (" " ),false ,bm);
233256 SetAutoLayout (TRUE );
234257 SetSizer (bs);
235258}
0 commit comments