diff --git a/src/preferences/keymap/Keymap.cpp b/src/preferences/keymap/Keymap.cpp index 3540eec2c9..cc951c27dd 100644 --- a/src/preferences/keymap/Keymap.cpp +++ b/src/preferences/keymap/Keymap.cpp @@ -609,6 +609,29 @@ Keymap::SetKey(uint32 keyCode, uint32 modifiers, int8 deadKey, } +Keymap& +Keymap::operator=(const Keymap& other) +{ + delete[] fChars; + delete fModificationMessage; + + fChars = new(std::nothrow) char[other.fCharsSize]; + if (fChars != NULL) { + memcpy(fChars, other.fChars, other.fCharsSize); + fCharsSize = other.fCharsSize; + } else + fCharsSize = 0; + + memcpy(&fKeys, &other.fKeys, sizeof(key_map)); + strlcpy(fName, other.fName, sizeof(fName)); + + fTarget = other.fTarget; + + if (other.fModificationMessage != NULL) + fModificationMessage = new BMessage(*other.fModificationMessage); +} + + int32 Keymap::_Offset(uint32 keyCode, uint32 modifiers, uint32* _table) { diff --git a/src/preferences/keymap/Keymap.h b/src/preferences/keymap/Keymap.h index 28c3123b30..1b6325eafc 100644 --- a/src/preferences/keymap/Keymap.h +++ b/src/preferences/keymap/Keymap.h @@ -49,6 +49,8 @@ public: const key_map& Map() const { return fKeys; } key_map& Map() { return fKeys; } + Keymap& operator=(const Keymap& other); + private: int32 _Offset(uint32 keyCode, uint32 modifiers, uint32* _table = NULL); @@ -63,4 +65,4 @@ private: }; -#endif //KEYMAP_H +#endif // KEYMAP_H diff --git a/src/preferences/keymap/KeymapWindow.cpp b/src/preferences/keymap/KeymapWindow.cpp index 77bcf117d7..2233b95ca1 100644 --- a/src/preferences/keymap/KeymapWindow.cpp +++ b/src/preferences/keymap/KeymapWindow.cpp @@ -95,8 +95,6 @@ KeymapWindow::KeymapWindow() _UpdateButtons(); - fCurrentMap.SetTarget(this, new BMessage(kMsgKeymapUpdated)); - // Make sure the user keymap directory exists BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); @@ -150,8 +148,9 @@ KeymapWindow::KeymapWindow() = static_cast(fUserListView->FirstItem()); fCurrentMap.Load(current->EntryRef()); - fPreviousMap.Load(current->EntryRef()); - fAppliedMap.Load(current->EntryRef()); + fPreviousMap = fCurrentMap; + fAppliedMap = fCurrentMap; + fCurrentMap.SetTarget(this, new BMessage(kMsgKeymapUpdated)); _UpdateShortcutButton(); @@ -506,10 +505,9 @@ KeymapWindow::_RevertKeymap() } fPreviousMap.Use(); - fAppliedMap.Load(ref); - - // TODO: add = operator fCurrentMap.Load(ref); + fAppliedMap = fCurrentMap; + fKeyboardLayoutView->SetKeymap(&fCurrentMap); fCurrentMapName = _GetActiveKeymapName();