* The Keymap now has a listener mechanism for changes.
* If the current Keymap is changed, the selection and use/revert buttons now actually work. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -55,6 +55,34 @@ print_key(char *chars, int32 offset)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Keymap::Keymap()
|
||||
:
|
||||
fChars(NULL),
|
||||
fCharsSize(0),
|
||||
fModificationMessage(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Keymap::~Keymap()
|
||||
{
|
||||
delete fModificationMessage;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Keymap::SetTarget(BMessenger target, BMessage* modificationMessage)
|
||||
{
|
||||
delete fModificationMessage;
|
||||
|
||||
fTarget = target;
|
||||
fModificationMessage = modificationMessage;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Keymap::DumpKeymap()
|
||||
{
|
||||
@@ -179,11 +207,13 @@ Keymap::Save(entry_ref& ref)
|
||||
|
||||
|
||||
bool
|
||||
Keymap::Equals(const Keymap& map) const
|
||||
Keymap::Equals(const Keymap& other) const
|
||||
{
|
||||
// not really efficient but this is the only way i found
|
||||
// to reliably compare keymaps (used only for apply and revert)
|
||||
return memcmp( &map.fKeys, &fKeys, sizeof(key_map)) == 0;
|
||||
return fCharsSize == other.fCharsSize
|
||||
&& !memcmp(&other.fKeys, &fKeys, sizeof(key_map))
|
||||
&& !memcmp(other.fChars, fChars, fCharsSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -421,6 +451,9 @@ Keymap::SetKey(uint32 keyCode, uint32 modifiers, int8 deadKey,
|
||||
return;
|
||||
|
||||
memcpy(&fChars[offset + 1], bytes, numBytes);
|
||||
|
||||
if (fModificationMessage != NULL)
|
||||
fTarget.SendMessage(fModificationMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,12 +12,20 @@
|
||||
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Entry.h>
|
||||
#include <Messenger.h>
|
||||
|
||||
|
||||
class Keymap {
|
||||
public:
|
||||
Keymap();
|
||||
~Keymap();
|
||||
|
||||
void SetTarget(BMessenger target,
|
||||
BMessage* modificationMessage);
|
||||
|
||||
status_t Load(entry_ref& ref);
|
||||
status_t Save(entry_ref& ref);
|
||||
|
||||
void DumpKeymap();
|
||||
bool IsModifierKey(uint32 keyCode);
|
||||
uint8 IsDeadKey(uint32 keyCode, uint32 modifiers);
|
||||
@@ -43,6 +51,9 @@ private:
|
||||
key_map fKeys;
|
||||
uint32 fCharsSize;
|
||||
char fName[B_FILE_NAME_LENGTH];
|
||||
|
||||
BMessenger fTarget;
|
||||
BMessage* fModificationMessage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -36,17 +36,17 @@
|
||||
static const uint32 kMsgMenuFileOpen = 'mMFO';
|
||||
static const uint32 kMsgMenuFileSave = 'mMFS';
|
||||
static const uint32 kMsgMenuFileSaveAs = 'mMFA';
|
||||
|
||||
static const uint32 kMsgMenuEditUndo = 'mMEU';
|
||||
static const uint32 kMsgMenuEditCut = 'mMEX';
|
||||
static const uint32 kMsgMenuEditCopy = 'mMEC';
|
||||
static const uint32 kMsgMenuEditPaste = 'mMEV';
|
||||
static const uint32 kMsgMenuEditClear = 'mMEL';
|
||||
static const uint32 kMsgMenuEditSelectAll = 'mMEA';
|
||||
|
||||
static const uint32 kMsgMenuFontChanged = 'mMFC';
|
||||
|
||||
static const uint32 kMsgSystemMapSelected = 'SmST';
|
||||
static const uint32 kMsgUserMapSelected = 'UmST';
|
||||
|
||||
static const uint32 kMsgUseKeymap = 'UkyM';
|
||||
static const uint32 kMsgRevertKeymap = 'Rvrt';
|
||||
static const uint32 kMsgKeymapUpdated = 'upkM';
|
||||
|
||||
|
||||
KeymapWindow::KeymapWindow()
|
||||
@@ -82,6 +82,7 @@ KeymapWindow::KeymapWindow()
|
||||
.SetInsets(10, 10, 10, 10)));
|
||||
|
||||
fKeyboardLayoutView->SetTarget(fTextControl->TextView());
|
||||
fTextControl->MakeFocus();
|
||||
AddCommonFilter(new KeymapMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,
|
||||
&fCurrentMap));
|
||||
// TODO: this does not work for some reason, investigate!
|
||||
@@ -89,6 +90,8 @@ 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);
|
||||
@@ -252,9 +255,14 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
|
||||
case kMsgUserMapSelected:
|
||||
{
|
||||
int32 index = fUserListView->CurrentSelection();
|
||||
if (index == 0) {
|
||||
// we can safely ignore the "(Current)" item
|
||||
break;
|
||||
}
|
||||
|
||||
KeymapListItem *keymapListItem =
|
||||
static_cast<KeymapListItem*>(fUserListView->ItemAt(
|
||||
fUserListView->CurrentSelection()));
|
||||
static_cast<KeymapListItem*>(fUserListView->ItemAt(index));
|
||||
if (keymapListItem != NULL) {
|
||||
fCurrentMap.Load(keymapListItem->KeymapEntry());
|
||||
|
||||
@@ -282,6 +290,12 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
_UpdateButtons();
|
||||
break;
|
||||
|
||||
case kMsgKeymapUpdated:
|
||||
_UpdateButtons();
|
||||
fSystemListView->DeselectAll();
|
||||
fUserListView->Select(0L);
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
@@ -381,7 +395,7 @@ KeymapWindow::_CreateMapLists()
|
||||
fUserListView, 0, false, true);
|
||||
|
||||
// '(Current)'
|
||||
KeymapListItem *currentKeymapItem
|
||||
KeymapListItem* currentKeymapItem
|
||||
= static_cast<KeymapListItem*>(fUserListView->FirstItem());
|
||||
if (currentKeymapItem != NULL)
|
||||
fUserListView->AddItem(currentKeymapItem);
|
||||
@@ -410,29 +424,32 @@ KeymapWindow::_UpdateButtons()
|
||||
}
|
||||
|
||||
|
||||
//! Saves previous map to the "Key_map" file.
|
||||
void
|
||||
KeymapWindow::_RevertKeymap()
|
||||
{
|
||||
//saves previous map to the Key_map file
|
||||
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)!=B_OK)
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
|
||||
path.Append("Key_map");
|
||||
|
||||
entry_ref ref;
|
||||
get_ref_for_path(path.Path(), &ref);
|
||||
|
||||
status_t err;
|
||||
if ((err = fPreviousMap.Save(ref)) != B_OK) {
|
||||
printf("error when saving : %s", strerror(err));
|
||||
status_t status = fPreviousMap.Save(ref);
|
||||
if (status != B_OK) {
|
||||
printf("error when saving keymap: %s", strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
fPreviousMap.Use();
|
||||
fAppliedMap.Load(ref);
|
||||
|
||||
// TODO: add = operator
|
||||
fCurrentMap.Load(ref);
|
||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
||||
|
||||
fCurrentMapName = _GetActiveKeymapName();
|
||||
|
||||
if (!_SelectCurrentMap(fSystemListView)
|
||||
@@ -499,12 +516,12 @@ KeymapWindow::_FillUserMaps()
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
|
||||
path.Append("Key_map");
|
||||
|
||||
entry_ref ref;
|
||||
get_ref_for_path(path.Path(), &ref);
|
||||
|
||||
|
||||
fUserListView->AddItem(new KeymapListItem(ref, "(Current)"));
|
||||
|
||||
fCurrentMapName = _GetActiveKeymapName();
|
||||
|
||||
Reference in New Issue
Block a user