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