Ticket #8021: context_control.cpp

File context_control.cpp, 19.7 KB (added by harsh, 9 years ago)
Line 
1#include <filezilla.h>
2#include "inputdialog.h"
3
4#include "commandqueue.h"
5#include "context_control.h"
6#include "filelist_statusbar.h"
7#include "LocalListView.h"
8#include "LocalTreeView.h"
9#include "Mainfrm.h"
10#include "Options.h"
11#include "queue.h"
12#include "recursive_operation.h"
13#include "RemoteListView.h"
14#include "RemoteTreeView.h"
15#include "sitemanager.h"
16#include "splitter.h"
17#include "view.h"
18#include "viewheader.h"
19#include <unistd.h>
20#include <stdlib.h>
21//#include "./resources/menus.xrc"
22
23DECLARE_EVENT_TYPE(fzEVT_TAB_CLOSING_DEFERRED, -1);
24DEFINE_EVENT_TYPE(fzEVT_TAB_CLOSING_DEFERRED);
25
26BEGIN_EVENT_TABLE(CContextControl, wxSplitterWindow)
27EVT_MENU(XRCID("ID_TABCONTEXT_REFRESH"), CContextControl::OnTabRefresh)
28EVT_COMMAND(wxID_ANY, fzEVT_TAB_CLOSING_DEFERRED, CContextControl::OnTabClosing_Deferred)
29EVT_MENU(XRCID("ID_TABCONTEXT_CLOSE"), CContextControl::OnTabContextClose)
30EVT_MENU(XRCID("ID_TABCONTEXT_CLOSEOTHERS"), CContextControl::OnTabContextCloseOthers)
31EVT_MENU(XRCID("ID_TABCONTEXT_NEW"), CContextControl::OnTabContextNew)
32//
33EVT_MENU(XRCID("ID_TABCONTEXT_RENAME"), CContextControl::OnTabContextRename)
34END_EVENT_TABLE()
35
36CContextControl::CContextControl(CMainFrame* pMainFrame)
37 : CStateEventHandler(0),
38 m_tabs(0), m_right_clicked_tab(-1), m_pMainFrame(pMainFrame)
39{
40 m_current_context_controls = -1;
41 m_tabs = 0;
42
43 wxASSERT(!CContextManager::Get()->HandlerCount(STATECHANGE_CHANGEDCONTEXT));
44 CContextManager::Get()->RegisterHandler(this, STATECHANGE_CHANGEDCONTEXT, false, false);
45 CContextManager::Get()->RegisterHandler(this, STATECHANGE_SERVER, false, false);
46}
47
48CContextControl::~CContextControl()
49{
50}
51
52void CContextControl::Create(wxWindow *parent)
53{
54 wxSplitterWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER);
55}
56
57void CContextControl::CreateTab()
58{
59 Freeze();
60
61 CState* pState = 0;
62 // See if we can reuse an existing context
63
64 /*for (size_t i = 0; i < m_context_controls.size(); i++)
65 {
66 if (m_context_controls[i].tab_index != -1)
67 continue;
68
69 if (m_context_controls[i].pState->IsRemoteConnected() ||
70 !m_context_controls[i].pState->IsRemoteIdle())
71 continue;
72
73 pState = m_context_controls[i].pState;
74 m_context_controls.erase(m_context_controls.begin() + i);
75 if (m_current_context_controls > (int)i)
76 m_current_context_controls--;
77
78 std::cout << pState->GetTitle() << std::endl;
79 break;
80 }*/
81 if (!pState)
82 {
83
84 pState = CContextManager::Get()->CreateState(m_pMainFrame);
85 if (!pState->CreateEngine())
86 {
87 wxMessageBox(_("Failed to initialize FTP engine"));
88 }
89 }
90
91 // Restore last server and path
92 CServer last_server;
93 CServerPath last_path;
94 if (COptions::Get()->GetLastServer(last_server) && last_path.SetSafePath(COptions::Get()->GetOption(OPTION_LASTSERVERPATH)))
95 pState->SetLastServer(last_server, last_path);
96
97 CreateContextControls(pState);
98
99 pState->GetRecursiveOperationHandler()->SetQueue(m_pMainFrame->GetQueue());
100
101 wxString localDir = COptions::Get()->GetOption(OPTION_LASTLOCALDIR);
102 if (!pState->SetLocalDir(localDir))
103 pState->SetLocalDir(_T("/"));
104
105 CContextManager::Get()->SetCurrentContext(pState);
106
107 if (!m_pMainFrame->RestoreSplitterPositions())
108 m_pMainFrame->SetDefaultSplitterPositions();
109
110 if (m_tabs)
111 m_tabs->SetSelection(m_tabs->GetPageCount() - 1);
112
113
114 Thaw();
115}
116
117void CContextControl::CreateContextControls(CState* pState)
118{
119 wxWindow* parent = this;
120
121#ifdef __WXGTK__
122 // This prevents some ugly flickering on tab creation.
123 const wxPoint initial_position(1000000, 1000000);
124#else
125 const wxPoint initial_position(wxDefaultPosition);
126#endif
127
128 if (!m_context_controls.empty())
129 {
130 if (!m_tabs )
131 {
132 m_tabs = new wxAuiNotebookEx();
133
134 wxSize splitter_size = m_context_controls[m_current_context_controls].pViewSplitter->GetSize();
135 m_tabs->Create(this, wxID_ANY, initial_position, splitter_size, wxNO_BORDER | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_CLOSE_ON_ALL_TABS);
136 m_tabs->SetExArtProvider();
137 m_tabs->SetSelectedFont(*wxNORMAL_FONT);
138 m_tabs->SetMeasuringFont(*wxNORMAL_FONT);
139
140 m_context_controls[m_current_context_controls].pViewSplitter->Reparent(m_tabs);
141
142 m_tabs->AddPage(m_context_controls[m_current_context_controls].pViewSplitter, m_context_controls[m_current_context_controls].pState->GetTitle());
143 ReplaceWindow(m_context_controls[m_current_context_controls].pViewSplitter, m_tabs);
144
145 m_tabs->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(CContextControl::OnTabChanged), 0, this);
146 m_tabs->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(CContextControl::OnTabClosing), 0, this);
147 m_tabs->Connect(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEventHandler(CContextControl::OnTabBgDoubleclick), 0, this);
148 m_tabs->Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, wxAuiNotebookEventHandler(CContextControl::OnTabClosing), 0, this);
149 m_tabs->Connect(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEventHandler(CContextControl::OnTabRightclick), 0, this);
150 }
151
152 m_pMainFrame->RememberSplitterPositions();
153 m_context_controls[m_current_context_controls].pLocalListView->SaveColumnSettings(OPTION_LOCALFILELIST_COLUMN_WIDTHS, OPTION_LOCALFILELIST_COLUMN_SHOWN, OPTION_LOCALFILELIST_COLUMN_ORDER);
154 m_context_controls[m_current_context_controls].pRemoteListView->SaveColumnSettings(OPTION_REMOTEFILELIST_COLUMN_WIDTHS, OPTION_REMOTEFILELIST_COLUMN_SHOWN, OPTION_REMOTEFILELIST_COLUMN_ORDER);
155
156 parent = m_tabs;
157 }
158
159 struct CContextControl::_context_controls context_controls;
160
161 context_controls.pState = pState;
162 context_controls.pViewSplitter = new CSplitterWindowEx(parent, -1, initial_position, wxDefaultSize, wxSP_NOBORDER | wxSP_LIVE_UPDATE);
163 context_controls.pViewSplitter->SetMinimumPaneSize(50, 100);
164 context_controls.pViewSplitter->SetSashGravity(0.5);
165
166 context_controls.pLocalSplitter = new CSplitterWindowEx(context_controls.pViewSplitter, -1, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_LIVE_UPDATE);
167 context_controls.pLocalSplitter->SetMinimumPaneSize(50, 100);
168
169 context_controls.pRemoteSplitter = new CSplitterWindowEx(context_controls.pViewSplitter, -1, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_LIVE_UPDATE);
170 context_controls.pRemoteSplitter->SetMinimumPaneSize(50, 100);
171
172 context_controls.pLocalTreeViewPanel = new CView(context_controls.pLocalSplitter);
173 context_controls.pLocalListViewPanel = new CView(context_controls.pLocalSplitter);
174 context_controls.pLocalTreeView = new CLocalTreeView(context_controls.pLocalTreeViewPanel, -1, pState, m_pMainFrame->GetQueue());
175 context_controls.pLocalListView = new CLocalListView(context_controls.pLocalListViewPanel, pState, m_pMainFrame->GetQueue());
176 context_controls.pLocalTreeViewPanel->SetWindow(context_controls.pLocalTreeView);
177 context_controls.pLocalListViewPanel->SetWindow(context_controls.pLocalListView);
178
179 context_controls.pRemoteTreeViewPanel = new CView(context_controls.pRemoteSplitter);
180 context_controls.pRemoteListViewPanel = new CView(context_controls.pRemoteSplitter);
181 context_controls.pRemoteTreeView = new CRemoteTreeView(context_controls.pRemoteTreeViewPanel, -1, pState, m_pMainFrame->GetQueue());
182 context_controls.pRemoteListView = new CRemoteListView(context_controls.pRemoteListViewPanel, pState, m_pMainFrame->GetQueue());
183 context_controls.pRemoteTreeViewPanel->SetWindow(context_controls.pRemoteTreeView);
184 context_controls.pRemoteListViewPanel->SetWindow(context_controls.pRemoteListView);
185
186 bool show_filelist_statusbars = COptions::Get()->GetOptionVal(OPTION_FILELIST_STATUSBAR) != 0;
187
188 CFilelistStatusBar* pLocalFilelistStatusBar = new CFilelistStatusBar(context_controls.pLocalListViewPanel);
189 if (!show_filelist_statusbars)
190 pLocalFilelistStatusBar->Hide();
191 context_controls.pLocalListViewPanel->SetStatusBar(pLocalFilelistStatusBar);
192 context_controls.pLocalListView->SetFilelistStatusBar(pLocalFilelistStatusBar);
193
194 CFilelistStatusBar* pRemoteFilelistStatusBar = new CFilelistStatusBar(context_controls.pRemoteListViewPanel);
195 if (!show_filelist_statusbars)
196 pRemoteFilelistStatusBar->Hide();
197 context_controls.pRemoteListViewPanel->SetStatusBar(pRemoteFilelistStatusBar);
198 context_controls.pRemoteListView->SetFilelistStatusBar(pRemoteFilelistStatusBar);
199 pRemoteFilelistStatusBar->SetConnected(false);
200
201
202 const int layout = COptions::Get()->GetOptionVal(OPTION_FILEPANE_LAYOUT);
203 const int swap = COptions::Get()->GetOptionVal(OPTION_FILEPANE_SWAP);
204
205 if (layout == 1)
206 {
207 if (swap)
208 context_controls.pViewSplitter->SplitHorizontally(context_controls.pRemoteSplitter, context_controls.pLocalSplitter);
209 else
210 context_controls.pViewSplitter->SplitHorizontally(context_controls.pLocalSplitter, context_controls.pRemoteSplitter);
211 }
212 else
213 {
214 if (swap)
215 context_controls.pViewSplitter->SplitVertically(context_controls.pRemoteSplitter, context_controls.pLocalSplitter);
216 else
217 context_controls.pViewSplitter->SplitVertically(context_controls.pLocalSplitter, context_controls.pRemoteSplitter);
218 }
219
220 context_controls.pLocalViewHeader = new CLocalViewHeader(context_controls.pLocalSplitter, pState);
221 if (COptions::Get()->GetOptionVal(OPTION_SHOW_TREE_LOCAL))
222 {
223 context_controls.pLocalTreeViewPanel->SetHeader(context_controls.pLocalViewHeader);
224 if (layout == 3 && swap)
225 context_controls.pLocalSplitter->SplitVertically(context_controls.pLocalListViewPanel, context_controls.pLocalTreeViewPanel);
226 else if (layout)
227 context_controls.pLocalSplitter->SplitVertically(context_controls.pLocalTreeViewPanel, context_controls.pLocalListViewPanel);
228 else
229 context_controls.pLocalSplitter->SplitHorizontally(context_controls.pLocalTreeViewPanel, context_controls.pLocalListViewPanel);
230 }
231 else
232 {
233 context_controls.pLocalTreeViewPanel->Hide();
234 context_controls.pLocalListViewPanel->SetHeader(context_controls.pLocalViewHeader);
235 context_controls.pLocalSplitter->Initialize(context_controls.pLocalListViewPanel);
236 }
237
238 context_controls.pRemoteViewHeader = new CRemoteViewHeader(context_controls.pRemoteSplitter, pState);
239 if (COptions::Get()->GetOptionVal(OPTION_SHOW_TREE_REMOTE))
240 {
241 context_controls.pRemoteTreeViewPanel->SetHeader(context_controls.pRemoteViewHeader);
242 if (layout == 3 && !swap)
243 context_controls.pRemoteSplitter->SplitVertically(context_controls.pRemoteListViewPanel, context_controls.pRemoteTreeViewPanel);
244 else if (layout)
245 context_controls.pRemoteSplitter->SplitVertically(context_controls.pRemoteTreeViewPanel, context_controls.pRemoteListViewPanel);
246 else
247 context_controls.pRemoteSplitter->SplitHorizontally(context_controls.pRemoteTreeViewPanel, context_controls.pRemoteListViewPanel);
248 }
249 else
250 {
251 context_controls.pRemoteTreeViewPanel->Hide();
252 context_controls.pRemoteListViewPanel->SetHeader(context_controls.pRemoteViewHeader);
253 context_controls.pRemoteSplitter->Initialize(context_controls.pRemoteListViewPanel);
254 }
255
256 if (layout == 3)
257 {
258 if (!swap)
259 context_controls.pRemoteSplitter->SetSashGravity(1.0);
260 else
261 context_controls.pLocalSplitter->SetSashGravity(1.0);
262 }
263
264 m_pMainFrame->ConnectNavigationHandler(context_controls.pLocalListView);
265 m_pMainFrame->ConnectNavigationHandler(context_controls.pRemoteListView);
266 m_pMainFrame->ConnectNavigationHandler(context_controls.pLocalTreeView);
267 m_pMainFrame->ConnectNavigationHandler(context_controls.pRemoteTreeView);
268 m_pMainFrame->ConnectNavigationHandler(context_controls.pLocalViewHeader);
269 m_pMainFrame->ConnectNavigationHandler(context_controls.pRemoteViewHeader);
270
271 pState->GetComparisonManager()->SetListings(context_controls.pLocalListView, context_controls.pRemoteListView);
272
273 if (m_tabs)
274 {
275 context_controls.tab_index = m_tabs->GetPageCount();
276 m_tabs->AddPage(context_controls.pViewSplitter, pState->GetTitle());
277
278 // Copy reconnect and bookmark information
279 pState->SetLastServer(
280 m_context_controls[m_current_context_controls].pState->GetLastServer(),
281 m_context_controls[m_current_context_controls].pState->GetLastServerPath());
282
283 context_controls.site_bookmarks = m_context_controls[m_current_context_controls].site_bookmarks;
284 }
285 else
286 {
287 context_controls.tab_index = 0;
288 context_controls.site_bookmarks = new CContextControl::_context_controls::_site_bookmarks;
289
290 context_controls.site_bookmarks->path = COptions::Get()->GetOption(OPTION_LAST_CONNECTED_SITE);
291 CSiteManager::GetBookmarks(context_controls.site_bookmarks->path,
292 context_controls.site_bookmarks->bookmarks);
293
294 Initialize(context_controls.pViewSplitter);
295 }
296
297 m_context_controls.push_back(context_controls);
298}
299
300void CContextControl::OnTabRefresh(wxCommandEvent& event)
301{
302 if (m_right_clicked_tab == -1)
303 return;
304
305 for (size_t j = 0; j < m_context_controls.size(); j++)
306 {
307 if (m_context_controls[j].tab_index != m_right_clicked_tab)
308 continue;
309
310 m_context_controls[j].pState->RefreshLocal();
311 m_context_controls[j].pState->RefreshRemote();
312
313 break;
314 }
315}
316
317struct CContextControl::_context_controls* CContextControl::GetCurrentControls()
318{
319 if (m_current_context_controls == -1)
320 return 0;
321
322 return &m_context_controls[m_current_context_controls];
323}
324
325struct CContextControl::_context_controls* CContextControl::GetControlsFromState(CState* pState)
326{
327 size_t i = 0;
328 for (i = 0; i < m_context_controls.size(); i++)
329 {
330 if (m_context_controls[i].pState == pState)
331 return &m_context_controls[i];
332 }
333 return 0;
334}
335
336bool CContextControl::CloseTab(int tab)
337{
338 if (!m_tabs)
339 return false;
340 if (tab < 0)
341 return false;
342
343 size_t i = 0;
344 for (i = 0; i < m_context_controls.size(); i++)
345 {
346 if (m_context_controls[i].tab_index == tab)
347 break;
348 }
349 if (i == m_context_controls.size())
350 return false;
351
352 CState* pState = m_context_controls[i].pState;
353
354 if (!pState->m_pCommandQueue->Idle())
355 {
356 if (wxMessageBox(_("Cannot close tab while busy.\nCancel current operation and close tab?"), _T("FileZilla"), wxYES_NO | wxICON_QUESTION) != wxYES)
357 return false;
358
359 Freeze();
360
361 pState->m_pCommandQueue->Cancel();
362 pState->GetRecursiveOperationHandler()->StopRecursiveOperation();
363 }
364 else
365 Freeze();
366
367 pState->GetComparisonManager()->SetListings(0, 0);
368
369 if (m_tabs->GetPageCount() == 2)
370 {
371 // Get rid again of tab bar
372 m_tabs->Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(CContextControl::OnTabChanged), 0, this);
373
374 int keep = tab ? 0 : 1;
375 m_tabs->RemovePage(keep);
376
377 size_t j;
378 for (j = 0; j < m_context_controls.size(); j++)
379 {
380 if (m_context_controls[j].tab_index != keep)
381 continue;
382
383 break;
384 }
385
386 m_context_controls[j].pViewSplitter->Reparent(this);
387 ReplaceWindow(m_tabs, m_context_controls[j].pViewSplitter);
388 m_context_controls[j].pViewSplitter->Show();
389 m_context_controls[j].tab_index = 0;
390
391 wxAuiNotebookEx *tabs = m_tabs;
392 m_tabs = 0;
393
394 m_context_controls[i].tab_index = -1;
395 m_context_controls[i].site_bookmarks.clear();
396
397 CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState);
398
399 tabs->Destroy();
400 }
401 else
402 {
403 if (pState == CContextManager::Get()->GetCurrentContext())
404 {
405 int newsel = tab + 1;
406 if (newsel >= (int)m_tabs->GetPageCount())
407 newsel = m_tabs->GetPageCount() - 2;
408
409 for (size_t j = 0; j < m_context_controls.size(); j++)
410 {
411 if (m_context_controls[j].tab_index != newsel)
412 continue;
413 m_tabs->SetSelection(newsel);
414 CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState);
415 }
416 }
417 for (size_t j = 0; j < m_context_controls.size(); j++)
418 {
419 if (m_context_controls[j].tab_index > tab)
420 m_context_controls[j].tab_index--;
421 }
422 m_context_controls[i].tab_index = -1;
423 m_context_controls[i].site_bookmarks.clear();
424 m_tabs->DeletePage(tab);
425 }
426
427 pState->Disconnect();
428
429 Thaw();
430
431 return true;
432}
433
434void CContextControl::OnTabBgDoubleclick(wxAuiNotebookEvent& event)
435{
436 CreateTab();
437}
438
439void CContextControl::OnTabRightclick(wxAuiNotebookEvent& event)
440{
441 wxMenu* pMenu = wxXmlResource::Get()->LoadMenu(_T("ID_MENU_TABCONTEXT"));
442 if (!pMenu)
443 {
444 wxBell();
445 return;
446 }
447
448 if (!m_tabs || m_tabs->GetPageCount() < 2)
449 {
450 pMenu->Enable(XRCID("ID_TABCONTEXT_CLOSE"), false);
451 pMenu->Enable(XRCID("ID_TABCONTEXT_CLOSEOTHERS"), false);
452 pMenu->Enable(XRCID("ID_TABCONTEXT_RENAME"), false);
453 }
454
455 m_right_clicked_tab = event.GetSelection();
456 PopupMenu(pMenu);
457
458 delete pMenu;
459}
460
461//function added
462void CContextControl::OnTabContextRename(wxCommandEvent& event)
463{
464 CInputDialog dlg;
465 if (!dlg.Create(this, _("Rename Tab"), _("Please enter new name for the tab:")))
466 return;
467 if (dlg.ShowModal() != wxID_OK)
468 return;
469
470 for (size_t j = 0; j < m_context_controls.size(); j++) {
471
472 if (m_context_controls[j].tab_index != m_right_clicked_tab)
473 continue;
474
475 m_context_controls[j].pState->SetTitle(dlg.GetValue());
476
477 CContextControl::_context_controls* controls = GetControlsFromState(m_context_controls[j].pState);
478 m_tabs->SetPageText(controls->tab_index, controls->pState->GetTitle());
479
480 break;
481 }
482}
483
484void CContextControl::OnTabContextClose(wxCommandEvent& event)
485{
486 if (m_right_clicked_tab == -1)
487 return;
488
489 // Need to defer event, wxAUI would write to free'd memory
490 // if we'd actually delete tab and potenially the notebook with it
491 wxCommandEvent evt(fzEVT_TAB_CLOSING_DEFERRED, m_right_clicked_tab);
492 AddPendingEvent(evt);
493}
494
495void CContextControl::OnTabContextCloseOthers(wxCommandEvent& event)
496{
497 wxCommandEvent evt(fzEVT_TAB_CLOSING_DEFERRED, -m_right_clicked_tab - 1);
498 AddPendingEvent(evt);
499}
500
501void CContextControl::OnTabClosing_Deferred(wxCommandEvent& event)
502{
503 int tab = event.GetId();
504 if (tab < 0)
505 {
506 tab++;
507 int count = GetTabCount();
508 for (int i = count - 1; i >= 0; i--)
509 {
510 if (i != -tab)
511 CloseTab(i);
512 }
513 }
514 else
515 CloseTab(tab);
516}
517
518
519void CContextControl::OnTabChanged(wxAuiNotebookEvent& event)
520{
521 int i = m_tabs->GetSelection();
522 if (i < 0 || i >= (int)m_context_controls.size())
523 return;
524
525 for (size_t j = 0; j < m_context_controls.size(); j++)
526 {
527 if (m_context_controls[j].tab_index != i)
528 continue;
529
530 CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState);
531 break;
532 }
533}
534
535void CContextControl::OnTabClosing(wxAuiNotebookEvent& event)
536{
537 // Need to defer event, wxAUI would write to free'd memory
538 // if we'd actually delete tab and potenially the notebook with it
539 wxCommandEvent evt(fzEVT_TAB_CLOSING_DEFERRED, event.GetSelection());
540 AddPendingEvent(evt);
541
542 event.Veto();
543}
544
545int CContextControl::GetCurrentTab() const
546{
547 return m_tabs ? m_tabs->GetSelection() : (m_context_controls.empty() ? -1 : 0);
548}
549
550int CContextControl::GetTabCount() const
551{
552 return m_tabs ? m_tabs->GetPageCount() : (m_context_controls.empty() ? 0 : 1);
553}
554
555struct CContextControl::_context_controls* CContextControl::GetControlsFromTabIndex(int i)
556{
557 for (size_t j = 0; j < m_context_controls.size(); j++)
558 {
559 if (m_context_controls[j].tab_index == i)
560 return &m_context_controls[j];
561 }
562
563 return 0;
564}
565
566bool CContextControl::SelectTab(int i)
567{
568 if (i < 0)
569 return false;
570
571 if (!m_tabs)
572 {
573 if (i != 0)
574 return false;
575
576 return true;
577 }
578
579 if ((int)m_tabs->GetPageCount() <= i)
580 return false;
581
582 m_tabs->SetSelection(i);
583
584 return true;
585}
586
587void CContextControl::AdvanceTab(bool forward)
588{
589 if (!m_tabs)
590 return;
591
592 m_tabs->AdvanceTab(forward);
593}
594
595void CContextControl::OnStateChange(CState* pState, enum t_statechange_notifications notification, const wxString& data, const void* data2)
596{
597 if (notification == STATECHANGE_CHANGEDCONTEXT)
598 {
599 if (!pState)
600 {
601 m_current_context_controls = 0;
602 return;
603 }
604
605 // Get current controls for new current context
606 for (m_current_context_controls = 0; m_current_context_controls < (int)m_context_controls.size(); m_current_context_controls++)
607 {
608 if (m_context_controls[m_current_context_controls].pState == pState)
609 break;
610 }
611 if (m_current_context_controls == (int)m_context_controls.size())
612 m_current_context_controls = -1;
613 }
614 else if (notification == STATECHANGE_SERVER)
615 {
616 if (!m_tabs)
617 return;
618
619 CContextControl::_context_controls* controls = GetControlsFromState(pState);
620 if (controls && controls->tab_index != -1)
621 m_tabs->SetPageText(controls->tab_index, controls->pState->GetTitle());
622 }
623}
624
625void CContextControl::OnTabContextNew(wxCommandEvent& event)
626{
627 CreateTab();
628}