mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-19 09:01:15 +02:00
NormalizedKeyString redefined as TaggedIdentifier
This commit is contained in:
@@ -535,7 +535,8 @@ const std::vector<NormalizedKeyString> &CommandManager::ExcludedList()
|
||||
};
|
||||
|
||||
std::vector<NormalizedKeyString> result(
|
||||
strings, strings + sizeof(strings)/sizeof(*strings) );
|
||||
std::begin(strings), std::end(strings)
|
||||
);
|
||||
std::sort( result.begin(), result.end() );
|
||||
return result;
|
||||
}();
|
||||
@@ -1053,7 +1054,7 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
||||
gPrefs->SetPath(wxT("/NewKeys"));
|
||||
if (gPrefs->HasEntry(entry->name)) {
|
||||
entry->key =
|
||||
NormalizedKeyString{ gPrefs->Read(entry->name, entry->key.Raw()) };
|
||||
NormalizedKeyString{ gPrefs->ReadObject(entry->name, entry->key) };
|
||||
}
|
||||
gPrefs->SetPath(wxT("/"));
|
||||
|
||||
@@ -1098,7 +1099,8 @@ wxString CommandManager::GetLabel(const CommandListEntry *entry) const
|
||||
wxString label = entry->label;
|
||||
if (!entry->key.empty())
|
||||
{
|
||||
label += wxT("\t") + entry->key.Raw();
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
label += wxT("\t") + entry->key.GET();
|
||||
}
|
||||
|
||||
return label;
|
||||
@@ -1120,7 +1122,8 @@ wxString CommandManager::GetLabelWithDisabledAccel(const CommandListEntry *entry
|
||||
// Dummy accelerator that looks Ok in menus but is non functional.
|
||||
// Note the space before the key.
|
||||
#ifdef __WXMSW__
|
||||
auto key = entry->key.Raw();
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
auto key = entry->key.GET();
|
||||
Accel = wxString("\t ") + key;
|
||||
if( key.StartsWith("Left" )) break;
|
||||
if( key.StartsWith("Right")) break;
|
||||
@@ -1149,7 +1152,8 @@ wxString CommandManager::GetLabelWithDisabledAccel(const CommandListEntry *entry
|
||||
#endif
|
||||
//wxLogDebug("Added Accel:[%s][%s]", entry->label, entry->key );
|
||||
// Normal accelerator.
|
||||
Accel = wxString("\t") + entry->key.Raw();
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
Accel = wxString("\t") + entry->key.GET();
|
||||
}
|
||||
} while (false );
|
||||
label += Accel;
|
||||
@@ -1847,7 +1851,7 @@ void CommandManager::WriteXML(XMLWriter &xmlFile) const
|
||||
xmlFile.StartTag(wxT("command"));
|
||||
xmlFile.WriteAttr(wxT("name"), entry->name);
|
||||
xmlFile.WriteAttr(wxT("label"), label);
|
||||
xmlFile.WriteAttr(wxT("key"), entry->key.Raw());
|
||||
xmlFile.WriteAttr(wxT("key"), entry->key);
|
||||
xmlFile.EndTag(wxT("command"));
|
||||
}
|
||||
|
||||
@@ -1905,7 +1909,8 @@ void CommandManager::CheckDups()
|
||||
if (mCommandList[i]->key == mCommandList[j]->key) {
|
||||
wxString msg;
|
||||
msg.Printf(wxT("key combo '%s' assigned to '%s' and '%s'"),
|
||||
mCommandList[i]->key.Raw(),
|
||||
// using GET to form debug message
|
||||
mCommandList[i]->key.GET(),
|
||||
mCommandList[i]->label.BeforeFirst(wxT('\t')),
|
||||
mCommandList[j]->label.BeforeFirst(wxT('\t')));
|
||||
wxASSERT_MSG(mCommandList[i]->key != mCommandList[j]->key, msg);
|
||||
|
@@ -93,18 +93,6 @@ using SubMenuList = std::vector < std::unique_ptr<SubMenuListEntry> >;
|
||||
// so we don't want the structures to relocate with vector operations.
|
||||
using CommandList = std::vector<std::unique_ptr<CommandListEntry>>;
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<> struct hash< NormalizedKeyString > {
|
||||
size_t operator () (const NormalizedKeyString &str) const // noexcept
|
||||
{
|
||||
auto &stdstr = str.Raw(); // no allocations, a cheap fetch
|
||||
using Hasher = std::hash< wxString >;
|
||||
return Hasher{}( stdstr );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
using CommandKeyHash = std::unordered_map<NormalizedKeyString, CommandListEntry*>;
|
||||
using CommandNameHash = std::unordered_map<wxString, CommandListEntry*>;
|
||||
using CommandIDHash = std::unordered_map<int, CommandListEntry*>;
|
||||
|
@@ -14,7 +14,8 @@
|
||||
|
||||
#include <wx/event.h>
|
||||
|
||||
NormalizedKeyString::NormalizedKeyString(const wxString & key)
|
||||
NormalizedKeyString::NormalizedKeyString( const wxString & key )
|
||||
: NormalizedKeyStringBase( key )
|
||||
{
|
||||
#if defined(__WXMAC__)
|
||||
wxString newkey;
|
||||
@@ -45,16 +46,19 @@ NormalizedKeyString::NormalizedKeyString(const wxString & key)
|
||||
newkey += wxT("Ctrl+");
|
||||
}
|
||||
|
||||
(wxString&)*this = newkey + temp.AfterLast(wxT('+'));
|
||||
(NormalizedKeyStringBase&)*this =
|
||||
newkey + temp.AfterLast(wxT('+'));
|
||||
#else
|
||||
(wxString&)*this = key;
|
||||
(NormalizedKeyStringBase&)*this = key;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxString NormalizedKeyString::Display(bool usesSpecialChars) const
|
||||
{
|
||||
(void)usesSpecialChars;//compiler food
|
||||
wxString newkey = *this;
|
||||
// using GET to manipulate key string as needed for macOS differences
|
||||
// in displaying of it
|
||||
auto newkey = this->GET();
|
||||
#if defined(__WXMAC__)
|
||||
|
||||
if (!usesSpecialChars) {
|
||||
|
@@ -12,38 +12,28 @@
|
||||
#ifndef __AUDACITY_KEYBOARD__
|
||||
#define __AUDACITY_KEYBOARD__
|
||||
|
||||
#include <audacity/Types.h>
|
||||
#include <wx/defs.h>
|
||||
#include <wx/string.h> // to inherit
|
||||
|
||||
class wxKeyEvent;
|
||||
|
||||
struct NormalizedKeyString : private wxString
|
||||
struct NormalizedKeyStringTag;
|
||||
// Case insensitive comparisons
|
||||
using NormalizedKeyStringBase = TaggedIdentifier<NormalizedKeyStringTag, false>;
|
||||
|
||||
struct NormalizedKeyString : NormalizedKeyStringBase
|
||||
{
|
||||
NormalizedKeyString() = default;
|
||||
|
||||
explicit NormalizedKeyString( const wxString &str );
|
||||
explicit NormalizedKeyString( const wxString &key );
|
||||
|
||||
wxString Display(bool usesSpecialChars = false) const;
|
||||
|
||||
const wxString &Raw() const { return *this; }
|
||||
|
||||
bool NoCaseEqual( const NormalizedKeyString &other ) const
|
||||
{ return 0 == this->Raw() .CmpNoCase( other.Raw() ); }
|
||||
|
||||
using wxString::empty;
|
||||
};
|
||||
|
||||
inline bool operator ==
|
||||
( const NormalizedKeyString &a, const NormalizedKeyString &b)
|
||||
{ return a.Raw () == b.Raw(); }
|
||||
|
||||
inline bool operator !=
|
||||
( const NormalizedKeyString &a, const NormalizedKeyString &b)
|
||||
{ return a.Raw () != b.Raw(); }
|
||||
|
||||
inline bool operator <
|
||||
( const NormalizedKeyString &a, const NormalizedKeyString &b)
|
||||
{ return a.Raw () < b.Raw(); }
|
||||
namespace std
|
||||
{
|
||||
template<> struct hash< NormalizedKeyString >
|
||||
: hash< NormalizedKeyStringBase > {};
|
||||
}
|
||||
|
||||
NormalizedKeyString KeyEventToKeyString(const wxKeyEvent & keyEvent);
|
||||
|
||||
|
Reference in New Issue
Block a user