* not a "chef d'oeuvre" but revert and apply buttons should behave as
expected now * removed some dead code git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24180 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -154,6 +154,14 @@ Keymap::Save(entry_ref &ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Keymap::Equals(const Keymap& map) 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* we need to know if a key is a modifier key to choose
|
/* we need to know if a key is a modifier key to choose
|
||||||
a valid key when several are pressed together
|
a valid key when several are pressed together
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public:
|
|||||||
bool IsDeadSecondKey(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey);
|
bool IsDeadSecondKey(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey);
|
||||||
void GetChars(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey, char** chars, int32* numBytes);
|
void GetChars(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey, char** chars, int32* numBytes);
|
||||||
status_t Use();
|
status_t Use();
|
||||||
|
bool Equals(const Keymap& map) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *fChars;
|
char *fChars;
|
||||||
key_map fKeys;
|
key_map fKeys;
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ KeymapWindow::KeymapWindow()
|
|||||||
: BWindow(BRect(80, 25, 692, 281), "Keymap", B_TITLED_WINDOW,
|
: BWindow(BRect(80, 25, 692, 281), "Keymap", B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS )
|
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS )
|
||||||
{
|
{
|
||||||
|
fFirstTime = true;
|
||||||
|
|
||||||
// Add the menu bar
|
// Add the menu bar
|
||||||
BMenuBar *menubar = AddMenuBar();
|
BMenuBar *menubar = AddMenuBar();
|
||||||
|
|
||||||
@@ -81,6 +83,7 @@ KeymapWindow::KeymapWindow()
|
|||||||
fRevertButton = new BButton(BRect(442, 200, 515, 220), "revertButton",
|
fRevertButton = new BButton(BRect(442, 200, 515, 220), "revertButton",
|
||||||
"Revert", new BMessage(kMsgRevertKeymap));
|
"Revert", new BMessage(kMsgRevertKeymap));
|
||||||
placeholderView->AddChild(fRevertButton);
|
placeholderView->AddChild(fRevertButton);
|
||||||
|
UpdateButtons();
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
@@ -216,7 +219,6 @@ KeymapWindow::AddMaps(BView *placeholderView)
|
|||||||
fUserListView->SetSelectionMessage(new BMessage(kMsgUserMapSelected));
|
fUserListView->SetSelectionMessage(new BMessage(kMsgUserMapSelected));
|
||||||
|
|
||||||
FillSystemMaps();
|
FillSystemMaps();
|
||||||
|
|
||||||
FillUserMaps();
|
FillUserMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +301,7 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
// Deselect item in other BListView
|
// Deselect item in other BListView
|
||||||
fUserListView->DeselectAll();
|
fUserListView->DeselectAll();
|
||||||
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -308,17 +311,28 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
static_cast<KeymapListItem*>(fUserListView->ItemAt(fUserListView->CurrentSelection()));
|
static_cast<KeymapListItem*>(fUserListView->ItemAt(fUserListView->CurrentSelection()));
|
||||||
if (keymapListItem) {
|
if (keymapListItem) {
|
||||||
fCurrentMap.Load(keymapListItem->KeymapEntry());
|
fCurrentMap.Load(keymapListItem->KeymapEntry());
|
||||||
|
|
||||||
|
if (fFirstTime) {
|
||||||
|
fPreviousMap.Load(keymapListItem->KeymapEntry());
|
||||||
|
fAppliedMap.Load(keymapListItem->KeymapEntry());
|
||||||
|
fFirstTime = false;
|
||||||
|
}
|
||||||
|
|
||||||
fMapView->Invalidate();
|
fMapView->Invalidate();
|
||||||
|
|
||||||
// Deselect item in other BListView
|
// Deselect item in other BListView
|
||||||
fSystemListView->DeselectAll();
|
fSystemListView->DeselectAll();
|
||||||
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kMsgUseKeymap:
|
case kMsgUseKeymap:
|
||||||
UseKeymap();
|
UseKeymap();
|
||||||
|
UpdateButtons();
|
||||||
break;
|
break;
|
||||||
case kMsgRevertKeymap: // do nothing, just like the original
|
case kMsgRevertKeymap:
|
||||||
|
RevertKeymap();
|
||||||
|
UpdateButtons();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -327,6 +341,43 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeymapWindow::UpdateButtons()
|
||||||
|
{
|
||||||
|
fUseButton->SetEnabled(!fCurrentMap.Equals(fAppliedMap));
|
||||||
|
fRevertButton->SetEnabled(!fCurrentMap.Equals(fPreviousMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeymapWindow::RevertKeymap()
|
||||||
|
{
|
||||||
|
//saves previous map to the Key_map file
|
||||||
|
|
||||||
|
printf("REVERT\n");
|
||||||
|
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);
|
||||||
|
|
||||||
|
status_t err;
|
||||||
|
if ((err = fPreviousMap.Save(ref)) != B_OK) {
|
||||||
|
printf("error when saving : %s", strerror(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fPreviousMap.Use();
|
||||||
|
fAppliedMap.Load(ref);
|
||||||
|
|
||||||
|
//select and load it (first item in fUserListView is a ref to Key_map)
|
||||||
|
fUserListView->DeselectAll();
|
||||||
|
fUserListView->Select(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeymapWindow::UseKeymap()
|
KeymapWindow::UseKeymap()
|
||||||
{
|
{
|
||||||
@@ -345,6 +396,7 @@ KeymapWindow::UseKeymap()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fCurrentMap.Use();
|
fCurrentMap.Use();
|
||||||
|
fAppliedMap.Load(ref);
|
||||||
|
|
||||||
fUserListView->Select(0);
|
fUserListView->Select(0);
|
||||||
}
|
}
|
||||||
@@ -407,13 +459,6 @@ KeymapWindow::FillUserMaps()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BEntry*
|
|
||||||
KeymapWindow::CurrentMap()
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MapView::MapView(BRect rect, const char *name, Keymap* keymap)
|
MapView::MapView(BRect rect, const char *name, Keymap* keymap)
|
||||||
: BControl(rect, name, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW),
|
: BControl(rect, name, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW),
|
||||||
fCurrentFont(*be_plain_font),
|
fCurrentFont(*be_plain_font),
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ public:
|
|||||||
void MessageReceived( BMessage* message );
|
void MessageReceived( BMessage* message );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
BMenuBar *AddMenuBar();
|
||||||
|
void AddMaps(BView *placeholderView);
|
||||||
|
void UseKeymap();
|
||||||
|
void RevertKeymap();
|
||||||
|
void UpdateButtons();
|
||||||
|
|
||||||
|
void FillSystemMaps();
|
||||||
|
void FillUserMaps();
|
||||||
|
|
||||||
|
|
||||||
BListView *fSystemListView;
|
BListView *fSystemListView;
|
||||||
BListView *fUserListView;
|
BListView *fUserListView;
|
||||||
// the map that's currently highlighted
|
// the map that's currently highlighted
|
||||||
@@ -83,16 +93,10 @@ protected:
|
|||||||
|
|
||||||
MapView *fMapView;
|
MapView *fMapView;
|
||||||
|
|
||||||
BMenuBar *AddMenuBar();
|
|
||||||
void AddMaps(BView *placeholderView);
|
|
||||||
void UseKeymap();
|
|
||||||
|
|
||||||
void FillSystemMaps();
|
|
||||||
void FillUserMaps();
|
|
||||||
|
|
||||||
BEntry* CurrentMap();
|
|
||||||
|
|
||||||
Keymap fCurrentMap;
|
Keymap fCurrentMap;
|
||||||
|
Keymap fPreviousMap;
|
||||||
|
Keymap fAppliedMap;
|
||||||
|
bool fFirstTime;
|
||||||
|
|
||||||
BFilePanel *fOpenPanel; // the file panel to open
|
BFilePanel *fOpenPanel; // the file panel to open
|
||||||
BFilePanel *fSavePanel; // the file panel to save
|
BFilePanel *fSavePanel; // the file panel to save
|
||||||
|
|||||||
Reference in New Issue
Block a user