Sets the view type
| 411 | // Sets the view type |
| 412 | // |
| 413 | void |
| 414 | KeyView::SetView(ViewByType type) |
| 415 | { |
| 416 | int index = LineToIndex(GetSelection()); |
| 417 | |
| 418 | // Handle an existing selection |
| 419 | if (index != wxNOT_FOUND) |
| 420 | { |
| 421 | // Cache the currently selected node |
| 422 | KeyNode & node = mNodes[index]; |
| 423 | |
| 424 | // Expand branches if switching to Tree view and a line |
| 425 | // is currently selected |
| 426 | if (type == ViewByTree) |
| 427 | { |
| 428 | // Cache the node's depth |
| 429 | int depth = node.depth; |
| 430 | |
| 431 | // Search for its parents, setting each one as open |
| 432 | for (int i = node.index - 1; i >= 0 && depth > 1; i--) |
| 433 | { |
| 434 | if (mNodes[i].depth < depth) |
| 435 | { |
| 436 | mNodes[i].isopen = true; |
| 437 | depth = mNodes[i].depth; |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // Unselect any currently selected line...do even if none selected |
| 444 | SelectNode(-1); |
| 445 | |
| 446 | // Save NEW type |
| 447 | mViewType = type; |
| 448 | |
| 449 | // Refresh the view lines |
| 450 | RefreshLines(); |
| 451 | |
| 452 | // Reselect old node (if possible) |
| 453 | if (index != wxNOT_FOUND) |
| 454 | { |
| 455 | SelectNode(index); |
| 456 | } |
| 457 | |
| 458 | // ensure that a node is selected so that when the keyview is the focus, |
| 459 | // this is indicated visually, and the Narrator screen reader reads it. |
| 460 | if ((GetSelection() == wxNOT_FOUND)) |
| 461 | { |
| 462 | SelectNode(LineToIndex(0)); |
| 463 | } |
| 464 | |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | // |
| 469 | // Sets the filter |