void KeyConfigPrefs::OnFilterKeyDown(wxKeyEvent & e) { wxTextCtrl *t = (wxTextCtrl *)e.GetEventObject(); int keycode = e.GetKeyCode(); // Make sure we can navigate away from the hotkey textctrl. // On Linux and OSX, it an get stuck, but it doesn't hurt // to do it for Windows as well. if (keycode == WXK_TAB) { wxNavigationKeyEvent nevent; nevent.SetWindowChange(e.ControlDown()); nevent.SetDirection(!e.ShiftDown()); nevent.SetEventObject(t); nevent.SetCurrentFocus(t); t->GetParent()->GetEventHandler()->ProcessEvent(nevent); return; } if (mViewType == ViewByKey) { wxString key = KeyStringDisplay(KeyEventToKeyString(e)); t->SetValue(key); if (key != wxEmptyString) { mView->SetFilter(t->GetValue()); } } else { if (keycode == WXK_RETURN) { mFilterPending = false; mView->SetFilter(t->GetValue()); } else { mFilterPending = true; mFilterTimer.Start(500, wxTIMER_ONE_SHOT); e.Skip(); } } }
void KeyConfigPrefs::OnHotkeyKeyDown(wxKeyEvent & e) { wxTextCtrl *t = (wxTextCtrl *)e.GetEventObject(); // Make sure we can navigate away from the hotkey textctrl. // On Linux and OSX, it can get stuck, but it doesn't hurt // to do it for Windows as well. // // Mac note: Don't waste time trying to figure out why the // focus goes back to the prefs tree. Unless Voiceover is // active, buttons on the Mac do not accept focus and all the // controls between this one and the tree control are buttons. if (e.GetKeyCode() == WXK_TAB) { NavigateIn(e.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); return; } t->SetValue(KeyStringDisplay(KeyEventToKeyString(e))); }
// // Process a new set of bindings // void KeyView::RefreshBindings(const wxArrayString & names, const wxArrayString & categories, const wxArrayString & prefixes, const wxArrayString & labels, const wxArrayString & keys) { // Start clean mNodes.Clear(); // Same as in RecalcExtents() but do it inline mLineHeight = 0; mKeyWidth = 0; mCommandWidth = 0; wxString lastcat; wxString lastpfx; int nodecnt = 0; int depth = 1; bool incat = false; bool inpfx = false; // Examine all names...all arrays passed have the same indexes int cnt = (int) names.GetCount(); for (int i = 0; i < cnt; i++) { wxString name = names[i]; int x, y; // Remove any menu code from the category and prefix wxString cat = wxMenuItem::GetLabelFromText(categories[i]); wxString pfx = wxMenuItem::GetLabelFromText(prefixes[i]); // Append "Menu" this node is for a menu title if (cat != wxT("Command")) { cat.Append(wxT(" ")); cat += _("Menu"); } // Process a new category if (cat != lastcat) { // A new category always finishes any current subtree if (inpfx) { // Back to category level depth--; inpfx = false; } // Only time this is not true is during the first iteration if (incat) { // Back to root level depth--; incat = false; } // Remember for next iteration lastcat = cat; // Add a new category node if (cat != wxEmptyString) { KeyNode node; // Fill in the node info node.name = wxEmptyString; // don't associate branches with a command node.category = cat; node.prefix = pfx; node.label = cat; node.index = nodecnt++; node.iscat = true; node.isparent = true; node.depth = depth++; // Add it to the tree mNodes.Add(node); incat = true; // Measure category GetTextExtent(cat, &x, &y); mLineHeight = wxMax(mLineHeight, y); mCommandWidth = wxMax(mCommandWidth, x); } } // Process a new prefix if (pfx != lastpfx) { // Done with prefix branch if (inpfx) { depth--; inpfx = false; } // Remember for next iteration lastpfx = pfx; // Add a new prefix node if (pfx != wxEmptyString) { KeyNode node; // Fill in the node info node.name = wxEmptyString; // don't associate branches with a command node.category = cat; node.prefix = pfx; node.label = pfx; node.index = nodecnt++; node.ispfx = true; node.isparent = true; node.depth = depth++; // Add it to the tree mNodes.Add(node); inpfx = true; } } // Add the key entry KeyNode node; node.category = cat; node.prefix = pfx; // Labels for undo and redo change according to the last command // which can be undone/redone, so give them a special check in order // not to confuse users if (name == wxT("Undo")) { node.label = _("Undo"); } else if (name == wxT("Redo")) { node.label = _("Redo"); } else { // Strip any menu codes from label node.label = wxMenuItem::GetLabelFromText(labels[i].BeforeFirst(wxT('\t'))); } // Fill in remaining info node.name = name; node.key = KeyStringDisplay(keys[i]); node.index = nodecnt++; node.depth = depth; // Add it to the tree mNodes.Add(node); // Measure key GetTextExtent(node.key, &x, &y); mLineHeight = wxMax(mLineHeight, y); mKeyWidth = wxMax(mKeyWidth, x); // Prepend prefix for all view types to determine maximum // column widths wxString label = node.label; if (!node.prefix.IsEmpty()) { label = node.prefix + wxT(" - ") + label; } // Measure label GetTextExtent(label, &x, &y); mLineHeight = wxMax(mLineHeight, y); mCommandWidth = wxMax(mCommandWidth, x); } #if 0 // For debugging for (int j = 0; j < mNodes.GetCount(); j++) { KeyNode & node = mNodes[j]; wxLogDebug(wxT("NODE line %4d index %4d depth %1d open %1d parent %1d cat %1d pfx %1d name %s STR %s | %s | %s"), node.line, node.index, node.depth, node.isopen, node.isparent, node.iscat, node.ispfx, node.name.c_str(), node.category.c_str(), node.prefix.c_str(), node.label.c_str()); } #endif // Update horizontal scrollbar UpdateHScroll(); // Refresh the view lines RefreshLines(); }