Skip to content

Commit

Permalink
MGR: Save and restore selected items by key values when refreshing.
Browse files Browse the repository at this point in the history
svn path=/trunk/boinc/; revision=15959
  • Loading branch information
Charlie Fenton committed Sep 4, 2008
1 parent 096337a commit 104a4be
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 32 deletions.
15 changes: 15 additions & 0 deletions checkin_notes
Original file line number Diff line number Diff line change
Expand Up @@ -7183,3 +7183,18 @@ David 4 Sep 2008
Makefile.am
cert_sig.C,h (new)
crypt.C,h

Charlie 3 Sep 2008
MGR: Save and restore selected items by key values when refreshing, to
prevent wrong items from becoming selected when projects, tasks or
transfers are added to or deleted from the list in Advanced View.

clientgui/
AdvancedFrame.cpp,.h
AsyncRPC.cpp
BOINCBaseFrame.cpp,.h
BOINCBaseView.cpp,.h
BOINCListCtrl.cpp,.h
ViewProjects.cpp,.h
ViewTransfers.cpp,.h
ViewWork.cpp,.h
47 changes: 47 additions & 0 deletions clientgui/AdvancedFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,38 @@ bool CAdvancedFrame::RestoreViewState() {
}


void CAdvancedFrame::SaveSelections() {
wxWindow* pwndNotebookPage = NULL;
CBOINCBaseView* pView = NULL;

wxASSERT(m_pNotebook);

pwndNotebookPage = m_pNotebook->GetPage(m_pNotebook->GetSelection());
wxASSERT(pwndNotebookPage);

pView = wxDynamicCast(pwndNotebookPage, CBOINCBaseView);
// wxASSERT(pView);

pView->SaveSelections();
}


void CAdvancedFrame::RestoreSelections() {
wxWindow* pwndNotebookPage = NULL;
CBOINCBaseView* pView = NULL;

wxASSERT(m_pNotebook);

pwndNotebookPage = m_pNotebook->GetPage(m_pNotebook->GetSelection());
wxASSERT(pwndNotebookPage);

pView = wxDynamicCast(pwndNotebookPage, CBOINCBaseView);
wxASSERT(pView);

pView->RestoreSelections();
}


void CAdvancedFrame::SaveWindowDimensions() {
wxString strBaseConfigLocation = wxString(wxT("/"));
wxConfigBase* pConfig = wxConfigBase::Get(FALSE);
Expand Down Expand Up @@ -1706,6 +1738,9 @@ void CAdvancedFrame::OnConnect(CFrameEvent& WXUNUSED(event)) {
ACCT_MGR_INFO ami;
PROJECT_INIT_STATUS pis;
CC_STATUS status;
wxWindow* pwndNotebookPage = NULL;
CBOINCBaseView* pView = NULL;
int iItemCount = 0, iIndex;

wxASSERT(m_pNotebook);
wxASSERT(pDoc);
Expand Down Expand Up @@ -1737,6 +1772,18 @@ void CAdvancedFrame::OnConnect(CFrameEvent& WXUNUSED(event)) {
wxGetApp().StartBOINCScreensaverTest();
}

// Clear selected rows in all tab pages when connecting to a different host
iItemCount = (int)m_pNotebook->GetPageCount() - 1;
for (iIndex = 0; iIndex <= iItemCount; iIndex++) {
pwndNotebookPage = m_pNotebook->GetPage(iIndex);
wxASSERT(wxDynamicCast(pwndNotebookPage, CBOINCBaseView));

pView = wxDynamicCast(pwndNotebookPage, CBOINCBaseView);
wxASSERT(pView);

pView->ClearSelections();
}

pDoc->ForceCacheUpdate();

pDoc->rpc.get_project_init_status(pis);
Expand Down
2 changes: 2 additions & 0 deletions clientgui/AdvancedFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class CAdvancedFrame : public CBOINCBaseFrame
bool SaveViewState();
bool RestoreState();
bool RestoreViewState();
virtual void SaveSelections();
virtual void RestoreSelections();

void SaveWindowDimensions();
void RestoreWindowDimensions();
Expand Down
17 changes: 14 additions & 3 deletions clientgui/AsyncRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ void CMainDocument::HandleCompletedRPC() {
*(current_rpc_request.resultPtr) = retval;
}

// We must get the frame immediately before using it,
// since it may have been changed by SetActiveGUI().
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();

// Remember the key values of currently selected items, then deselect all
if (pFrame) {
pFrame->SaveSelections();
}

// Post-processing
if (! retval) {
switch (current_rpc_request.which_rpc) {
Expand Down Expand Up @@ -737,9 +746,6 @@ void CMainDocument::HandleCompletedRPC() {
if (crr_eventHandler) {
crr_eventHandler->ProcessEvent(*crr_event);
} else {
// We must get the frame immediately before using it,
// since it may have been changed by SetActiveGUI().
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
if (pFrame) {
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
pFrame->ProcessEvent(*crr_event);
Expand All @@ -749,6 +755,11 @@ void CMainDocument::HandleCompletedRPC() {
delete crr_event;
crr_event = NULL;
}

// Find the previously selected items by their key values and reselect them
if (pFrame) {
pFrame->RestoreSelections();
}
}


Expand Down
8 changes: 8 additions & 0 deletions clientgui/BOINCBaseFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ void CBOINCBaseFrame::OnUpdateMessages(CFrameEvent& ) {
}


void CBOINCBaseFrame::SaveSelections() {
}


void CBOINCBaseFrame::RestoreSelections() {
}


void CBOINCBaseFrame::FireInitialize() {
CFrameEvent event(wxEVT_FRAME_INITIALIZED, this);
AddPendingEvent(event);
Expand Down
3 changes: 3 additions & 0 deletions clientgui/BOINCBaseFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class CBOINCBaseFrame : public wxFrame {
virtual void OnCloseWindow( wxCommandEvent& event );
virtual void OnExit( wxCommandEvent& event );
void OnUpdateMessages( CFrameEvent& event );
virtual void SaveSelections();
virtual void RestoreSelections();


int GetReminderFrequency() { return m_iReminderFrequency; }
wxString GetDialupConnectionName() { return m_strNetworkDialupConnectionName; }
Expand Down
141 changes: 117 additions & 24 deletions clientgui/BOINCBaseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ CBOINCBaseView::~CBOINCBaseView() {
if (m_SortArrows) {
delete m_SortArrows;
}
m_arrSelectedKeys1.Empty();
m_arrSelectedKeys2.Empty();
}


Expand Down Expand Up @@ -170,6 +172,21 @@ const int CBOINCBaseView::GetViewRefreshRate() {
}


wxString CBOINCBaseView::GetKeyValue1(int) {
return wxEmptyString;
}


wxString CBOINCBaseView::GetKeyValue2(int) {
return wxEmptyString;
}


int CBOINCBaseView::FindRowIndexByKeyValues(wxString& key1, wxString& key2) {
return -1;
}


bool CBOINCBaseView::FireOnSaveState(wxConfigBase* pConfig) {
return OnSaveState(pConfig);
}
Expand Down Expand Up @@ -422,7 +439,8 @@ int CBOINCBaseView::SynchronizeCache() {

iRowTotal = GetDocCount();
iColumnTotal = m_pListPane->GetColumnCount();

Freeze(); // To reduce flicker

for (iRowIndex = 0; iRowIndex < iRowTotal; iRowIndex++) {
bNeedRefreshData = false;

Expand All @@ -441,8 +459,10 @@ int CBOINCBaseView::SynchronizeCache() {
}

if (bNeedSort) {
sortData(); // Will mark entire list as needing refresh
sortData(); // Will mark moved items as needing refresh
}

Thaw();
return 0;
}

Expand All @@ -455,6 +475,9 @@ bool CBOINCBaseView::SynchronizeCacheItem(wxInt32 WXUNUSED(iRowIndex), wxInt32 W
void CBOINCBaseView::OnColClick(wxListEvent& event) {
wxListItem item;
int newSortColumn = event.GetColumn();
wxArrayInt selections;
int i, j, m;


item.SetMask(wxLIST_MASK_IMAGE);
if (newSortColumn == m_iSortColumn) {
Expand All @@ -471,7 +494,31 @@ void CBOINCBaseView::OnColClick(wxListEvent& event) {

item.SetImage(m_bReverseSort ? 0 : 1);
m_pListPane->SetColumn(newSortColumn, item);

Freeze(); // To reduce flicker
// Remember which cache elements are selected and deselect them
m_bIgnoreUIEvents = true;
i = -1;
while (1) {
i = m_pListPane->GetNextSelected(i);
if (i < 0) break;
selections.Add(m_iSortedIndexes[i]);
m_pListPane->SelectRow(i, false);
}

sortData();

// Reselect previously selected cache elements in the sorted list
m = (int)selections.GetCount();
for (i=0; i<m; i++) {
if (selections[i] >= 0) {
j = m_iSortedIndexes.Index(selections[i]);
m_pListPane->SelectRow(j, true);
}
}
m_bIgnoreUIEvents = false;

Thaw();
}


Expand All @@ -482,39 +529,20 @@ void CBOINCBaseView::InitSort() {
item.SetMask(wxLIST_MASK_IMAGE);
item.SetImage(m_bReverseSort ? 0 : 1);
m_pListPane->SetColumn(m_iSortColumn, item);
Freeze(); // To reduce flicker
sortData();
Thaw();
}


void CBOINCBaseView::sortData() {
if (m_iSortColumn < 0) return;

wxArrayInt oldSortedIndexes(m_iSortedIndexes);
wxArrayInt selections;
int i, j, m, n = (int)m_iSortedIndexes.GetCount();

// Remember which cache elements are selected and deselect them
m_bIgnoreUIEvents = true;
i = -1;
while (1) {
i = m_pListPane->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (i < 0) break;
selections.Add(m_iSortedIndexes[i]);
m_pListPane->SetItemState(i, 0, wxLIST_STATE_SELECTED);
}
int i, n = (int)m_iSortedIndexes.GetCount();

std::stable_sort(m_iSortedIndexes.begin(), m_iSortedIndexes.end(), m_funcSortCompare);

// Reselect previously selected cache elements in the sorted list
m = (int)selections.GetCount();
for (i=0; i<m; i++) {
if (selections[i] >= 0) {
j = m_iSortedIndexes.Index(selections[i]);
m_pListPane->SetItemState(j, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
}
m_bIgnoreUIEvents = false;

// Refresh rows which have moved
for (i=0; i<n; i++) {
if (m_iSortedIndexes[i] != oldSortedIndexes[i]) {
Expand All @@ -538,6 +566,71 @@ void CBOINCBaseView::EmptyTasks() {
}


void CBOINCBaseView::ClearSavedSelections() {
m_arrSelectedKeys1.Empty();
m_arrSelectedKeys2.Empty();
}


// Save the key values of the currently selected rows for later restore
void CBOINCBaseView::SaveSelections() {
int currentTabView = wxGetApp().GetCurrentViewPage();
if (! (currentTabView & (VW_PROJ | VW_TASK | VW_XFER))) {
return;
}

m_bIgnoreUIEvents = true;
wxArrayInt arrSelRows;
int i = -1;
while (1) {
i = m_pListPane->GetNextSelected(i);
if (i < 0) break;
arrSelRows.Add(i);
m_pListPane->SelectRow(i, false);
}

m_arrSelectedKeys1.Empty();
m_arrSelectedKeys2.Empty();
for(unsigned int i=0; i< arrSelRows.GetCount();i++) {
m_arrSelectedKeys1.Add(GetKeyValue1(arrSelRows[i]));
m_arrSelectedKeys2.Add(GetKeyValue2(arrSelRows[i]));
}
m_bIgnoreUIEvents = false;
}

// Select all rows, that were formerly selected
void CBOINCBaseView::RestoreSelections() {
int currentTabView = wxGetApp().GetCurrentViewPage();
if (! (currentTabView & (VW_PROJ | VW_TASK | VW_XFER))) {
return;
}

ClearSelections();
m_bIgnoreUIEvents = true;
for(unsigned int i=0;i < m_arrSelectedKeys1.size();i++) {
int index = FindRowIndexByKeyValues(m_arrSelectedKeys1[i], m_arrSelectedKeys2[i]);
if(index >=0) {
m_pListPane->SelectRow(index, true);
}
}
m_bIgnoreUIEvents = false;
}


void CBOINCBaseView::ClearSelections() {
if (!m_pListPane) return;

m_bIgnoreUIEvents = true;
int i = -1;
while (1) {
i = m_pListPane->GetNextSelected(i);
if (i < 0) break;
m_pListPane->SelectRow(i, false);
}
m_bIgnoreUIEvents = false;
}


void CBOINCBaseView::PreUpdateSelection(){
}

Expand Down
Loading

0 comments on commit 104a4be

Please sign in to comment.