wxMaxima
Loading...
Searching...
No Matches
Functions
SymbolShortcuts.cpp File Reference

Keyboard shortcuts that type a symbol into the worksheet (GH #2578). More...

#include "SymbolShortcuts.h"
#include <wx/accel.h>
#include <wx/event.h>
#include <wx/log.h>
#include <wx/tokenzr.h>
Include dependency graph for SymbolShortcuts.cpp:

Functions

std::vector< wxString > wxm::SplitIntoSymbols (const wxString &text)
 Splits text into the symbols a sidebar shows as one button each.
 
wxString wxm::JoinSymbols (const std::vector< wxString > &symbols)
 Joins symbols into a string SplitIntoSymbols() splits into the same symbols.
 
std::vector< SymbolShortcut > wxm::ParseSymbolShortcuts (const wxString &stored)
 Reads the shortcuts list the configuration stores.
 
wxString wxm::SerializeSymbolShortcuts (const std::vector< SymbolShortcut > &shortcuts)
 The inverse of ParseSymbolShortcuts().
 
bool wxm::IsUsableShortcut (int flags, int keyCode)
 Would this shortcut leave ordinary typing alone?
 
wxString wxm::NormalizeShortcut (const wxString &shortcut)
 Brings a shortcut a human typed into the raw form we store.
 
wxString wxm::ShortcutFromKeyEvent (const wxKeyEvent &event)
 The shortcut a key press is, in raw form, or an empty string.
 
bool wxm::SameShortcut (const wxString &a, const wxString &b)
 Do the two raw shortcuts name the same key combination?
 
wxString wxm::ShortcutForDisplay (const wxString &rawShortcut)
 The shortcut in the user's language, for display ("Strg+Alt+T").
 
wxString wxm::SymbolForKeyEvent (const std::vector< SymbolShortcut > &shortcuts, const wxKeyEvent &event)
 The symbol whose shortcut the key event is, or an empty string.
 

Detailed Description

Keyboard shortcuts that type a symbol into the worksheet (GH #2578).

Function Documentation

◆ IsUsableShortcut()

bool wxm::IsUsableShortcut ( int  flags,
int  keyCode 
)

Would this shortcut leave ordinary typing alone?

It needs Ctrl, Alt (or, on the Mac, Cmd or Ctrl) or has to be a function key: anything else would be needed for typing text.

◆ JoinSymbols()

wxString wxm::JoinSymbols ( const std::vector< wxString > &  symbols)

Joins symbols into a string SplitIntoSymbols() splits into the same symbols.

Without separators, which is what older wxMaxima versions expect of the list of additional symbols, except for a space in front of a symbol that would otherwise merge with the one before it.

◆ NormalizeShortcut()

wxString wxm::NormalizeShortcut ( const wxString &  shortcut)

Brings a shortcut a human typed into the raw form we store.

Returns an empty string if wxWidgets can't parse it, or if it is a key a symbol must not take over (see IsUsableShortcut()).

◆ ParseSymbolShortcuts()

std::vector< SymbolShortcut > wxm::ParseSymbolShortcuts ( const wxString &  stored)

Reads the shortcuts list the configuration stores.

One "symbol<TAB>shortcut" per line. Lines that don't have this form, or whose shortcut wxWidgets can't parse, are skipped.

◆ ShortcutFromKeyEvent()

wxString wxm::ShortcutFromKeyEvent ( const wxKeyEvent &  event)

The shortcut a key press is, in raw form, or an empty string.

Empty for a bare modifier key (the user is still holding down the start of a combination) and for keys IsUsableShortcut() turns down.

◆ SplitIntoSymbols()

std::vector< wxString > wxm::SplitIntoSymbols ( const wxString &  text)

Splits text into the symbols a sidebar shows as one button each.

A combining mark, a variation selector or the low half of a UTF-16 surrogate pair (wxString is UTF-16 on Windows) stays with the character before it, and a zero-width joiner joins its neighbours on both sides. So "Øt̄§" gives the three symbols "Ø", "t̄" and "§". A combining mark with nothing before it, or a space before it, is a symbol of its own. Spaces only separate symbols.

◆ SymbolForKeyEvent()

wxString wxm::SymbolForKeyEvent ( const std::vector< SymbolShortcut > &  shortcuts,
const wxKeyEvent &  event 
)

The symbol whose shortcut the key event is, or an empty string.

Linear in the number of shortcuts; a user has a handful of them, and this runs once per key press.