mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
NormalizedKeyString redefined as TaggedIdentifier
This commit is contained in:
parent
3eeb91f23a
commit
11c8377460
@ -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);
|
||||
|
||||
|
@ -661,8 +661,8 @@ bool KeyConfigPrefs::Commit()
|
||||
const auto &key = mNewKeys[i];
|
||||
|
||||
if (gPrefs->HasEntry(name)) {
|
||||
if (key != NormalizedKeyString{ gPrefs->Read(name, key.Raw()) } ) {
|
||||
gPrefs->Write(name, key.Raw());
|
||||
if (key != NormalizedKeyString{ gPrefs->ReadObject(name, key) } ) {
|
||||
gPrefs->Write(name, key);
|
||||
}
|
||||
if (key == dkey) {
|
||||
gPrefs->DeleteEntry(name);
|
||||
@ -670,7 +670,7 @@ bool KeyConfigPrefs::Commit()
|
||||
}
|
||||
else {
|
||||
if (key != dkey) {
|
||||
gPrefs->Write(name, key.Raw());
|
||||
gPrefs->Write(name, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,25 +142,29 @@ BEGIN_POPUP_MENU(TrackMenuTable)
|
||||
OnMoveUpID,
|
||||
_("Move Track &Up") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveUp")).Raw()),
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
GetKeyFromName(wxT("TrackMoveUp")).GET()),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveDownID,
|
||||
_("Move Track &Down") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveDown")).Raw()),
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
GetKeyFromName(wxT("TrackMoveDown")).GET()),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveTopID,
|
||||
_("Move Track to &Top") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveTop")).Raw()),
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
GetKeyFromName(wxT("TrackMoveTop")).GET()),
|
||||
OnMoveTrack)
|
||||
POPUP_MENU_ITEM(
|
||||
OnMoveBottomID,
|
||||
_("Move Track to &Bottom") + wxT("\t") +
|
||||
(GetActiveProject()->GetCommandManager()->
|
||||
GetKeyFromName(wxT("TrackMoveBottom")).Raw()),
|
||||
// using GET to compose menu item name for wxWidgets
|
||||
GetKeyFromName(wxT("TrackMoveBottom")).GET()),
|
||||
OnMoveTrack)
|
||||
END_POPUP_MENU()
|
||||
|
||||
|
@ -288,7 +288,7 @@ KeyView::GetNameByKey(const NormalizedKeyString & key) const
|
||||
// Search the nodes for the key
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
if (key.NoCaseEqual( mNodes[i].key))
|
||||
if ( key == mNodes[i].key )
|
||||
{
|
||||
return mNodes[i].name;
|
||||
}
|
||||
@ -308,7 +308,7 @@ KeyView::GetIndexByKey(const NormalizedKeyString & key) const
|
||||
// Search the nodes for the key
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
if (key.NoCaseEqual( mNodes[i].key))
|
||||
if ( key == mNodes[i].key )
|
||||
{
|
||||
return mNodes[i].index;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user