mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Fixed duplicate hotkey issue with newly-added commands
This commit is contained in:
parent
adb7a2bdef
commit
a8b19b0d81
4 changed files with 61 additions and 29 deletions
|
@ -33,9 +33,9 @@ namespace IDE
|
|||
mKeyCode.ToString(strBuffer);
|
||||
}
|
||||
|
||||
public static void ToString(List<KeyState> keyStates, String strBuffer)
|
||||
public static void ToString(Span<KeyState> keyStates, String strBuffer)
|
||||
{
|
||||
for (int i < keyStates.Count)
|
||||
for (int i < keyStates.Length)
|
||||
{
|
||||
if (i > 0)
|
||||
strBuffer.Append(", ");
|
||||
|
@ -105,10 +105,28 @@ namespace IDE
|
|||
{
|
||||
public enum ContextFlags
|
||||
{
|
||||
None = 0,
|
||||
MainWindow = 1,
|
||||
WorkWindow = 2,
|
||||
Editor = 4,
|
||||
case None = 0,
|
||||
MainWindow = 1,
|
||||
WorkWindow = 2,
|
||||
Editor = 4;
|
||||
|
||||
public void ContextToString(String str)
|
||||
{
|
||||
bool isFirst = true;
|
||||
|
||||
void AddFlagStr(StringView flagStr)
|
||||
{
|
||||
if (isFirst)
|
||||
{
|
||||
str.Append(", ");
|
||||
isFirst = false;
|
||||
}
|
||||
str.Append(flagStr);
|
||||
}
|
||||
|
||||
if (this.HasFlag(.Editor))
|
||||
AddFlagStr("Editor");
|
||||
}
|
||||
}
|
||||
|
||||
public String mName ~ delete _;
|
||||
|
|
|
@ -1095,6 +1095,35 @@ namespace IDE
|
|||
List<String> allocatedStrs = scope .();
|
||||
defer { ClearAndDeleteItems(allocatedStrs); }
|
||||
|
||||
Dictionary<String, Entry> mappedEntries = scope .();
|
||||
|
||||
void AddEntry(List<Entry> newEntries, Entry entry, bool isNew)
|
||||
{
|
||||
newEntries.Add(entry);
|
||||
|
||||
// Delete previous command bindings when we are adding new entries
|
||||
let keyEntryStr = scope String();
|
||||
KeyState.ToString(entry.mKeys, keyEntryStr);
|
||||
//keyEntryStr.Append(" ");
|
||||
//entry.mContextFlags.To keyEntryStr);
|
||||
|
||||
String* keyPtr;
|
||||
Entry* valuePtr;
|
||||
if (mappedEntries.TryAdd(keyEntryStr, out keyPtr, out valuePtr))
|
||||
{
|
||||
*keyPtr = new String(keyEntryStr);
|
||||
*valuePtr = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isNew)
|
||||
{
|
||||
newEntries.Remove(*valuePtr);
|
||||
delete *valuePtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Entry> newEntries = new .();
|
||||
for (let cmdStr in sd.Enumerate())
|
||||
{
|
||||
|
@ -1123,20 +1152,23 @@ namespace IDE
|
|||
keyList.CopyTo(keyArr);
|
||||
entry.mKeys = keyArr;
|
||||
|
||||
newEntries.Add(entry);
|
||||
usedCommands.Add(entry.mCommand);
|
||||
AddEntry(newEntries, entry, false);
|
||||
}
|
||||
|
||||
for (var entry in mEntries)
|
||||
{
|
||||
if (usedCommands.Contains(entry.mCommand))
|
||||
continue;
|
||||
newEntries.Add(entry);
|
||||
mEntries[@entry.Index] = null;
|
||||
AddEntry(newEntries, entry, true);
|
||||
}
|
||||
|
||||
DeleteContainerAndItems!(mEntries);
|
||||
mEntries = newEntries;
|
||||
|
||||
for (let keyEntryStr in mappedEntries.Keys)
|
||||
delete keyEntryStr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,24 +186,6 @@ namespace IDE.ui
|
|||
category.Open(true, true);
|
||||
}
|
||||
|
||||
void CommandContextToString(IDECommand.ContextFlags contextFlags, String str)
|
||||
{
|
||||
bool isFirst = true;
|
||||
|
||||
void AddFlagStr(StringView flagStr)
|
||||
{
|
||||
if (isFirst)
|
||||
{
|
||||
str.Append(", ");
|
||||
isFirst = false;
|
||||
}
|
||||
str.Append(flagStr);
|
||||
}
|
||||
|
||||
if (contextFlags.HasFlag(.Editor))
|
||||
AddFlagStr("Editor");
|
||||
}
|
||||
|
||||
void UpdateKeyStates()
|
||||
{
|
||||
Debug.Assert((CategoryType)mPropPage.mCategoryType == .Keys);
|
||||
|
@ -223,7 +205,7 @@ namespace IDE.ui
|
|||
let keyEntryStr = new String();
|
||||
KeyState.ToString(keys, keyEntryStr);
|
||||
keyEntryStr.Append(" ");
|
||||
CommandContextToString(keyEntry.mContextFlags, keyEntryStr);
|
||||
keyEntry.mContextFlags.ContextToString(keyEntryStr);
|
||||
|
||||
String* keyPtr;
|
||||
KeyEntry* valuePtr;
|
||||
|
@ -253,7 +235,7 @@ namespace IDE.ui
|
|||
let keyEntryStr = scope String();
|
||||
KeyState.ToString(keys, keyEntryStr);
|
||||
keyEntryStr.Append(" ");
|
||||
CommandContextToString(keyEntry.mContextFlags, keyEntryStr);
|
||||
keyEntry.mContextFlags.ContextToString(keyEntryStr);
|
||||
|
||||
if (mappedEntries.TryGet(keyEntryStr, var keyPtr, var valuePtr))
|
||||
{
|
||||
|
|
|
@ -193,7 +193,7 @@ namespace IDE.ui
|
|||
{
|
||||
if (keyEvent.mKeyCode == .Escape)
|
||||
{
|
||||
if (mPanel.mQuickFind.mWidgetWindow != null)
|
||||
if (mPanel.mQuickFind?.mWidgetWindow != null)
|
||||
{
|
||||
mPanel.mQuickFind.Close();
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue