/** * Pushes a browse state to the browse stack. */ internal void Push(AbstractBrowseState state) { if (_showingState) { return; } // remove entries on the top of the stack int removeCount = _browseStack.Count - _browseStackPos - 1; if (removeCount > 0) { for (int i = _browseStackPos + 1; i < _browseStack.Count; i++) { AbstractBrowseState oldState = (AbstractBrowseState)_browseStack [i]; oldState.Dispose(); } _browseStack.RemoveRange(_browseStackPos + 1, removeCount); } while (_browseStack.Count > _maxBrowseStackSize) { AbstractBrowseState oldState = (AbstractBrowseState)_browseStack [0]; oldState.Dispose(); _browseStack.RemoveAt(0); _browseStackPos--; } if (_browseStack.Count > 0) { SaveSelectedResource(_browseStack.Count - 1); } _browseStack.Add(state); _browseStackPos++; }
/** * Save the currently selected resource at the specified position * in the browse stack. */ private void SaveSelectedResource(int browseStackPos) { if (browseStackPos < 0 || browseStackPos >= _browseStack.Count) { return; } AbstractBrowseState browseState = (AbstractBrowseState)_browseStack [browseStackPos]; IResourceList selection = _owner.SelectedResources; if (selection.Count > 0 && selection.ResourceIds [0] != -1) { browseState.SetSelectedResource(selection [0]); } else { browseState.SetSelectedResource(null); } }
/** * Shows the browse state at the current stack position, or the previous * valid browse state. */ internal void ShowCurrentBrowseState() { _showingState = true; try { while (_browseStackPos >= 0) { AbstractBrowseState state = (AbstractBrowseState)_browseStack [_browseStackPos]; // if the state failed to show, switch to previous state if (state.Show(_owner)) { break; } _browseStack.Remove(state); _browseStackPos--; } } finally { _showingState = false; } }