diff --git a/src/preferences/keymap/KeymapWindow.cpp b/src/preferences/keymap/KeymapWindow.cpp index 073f0423a8..a178f83c02 100644 --- a/src/preferences/keymap/KeymapWindow.cpp +++ b/src/preferences/keymap/KeymapWindow.cpp @@ -301,6 +301,13 @@ KeymapWindow::MessageReceived(BMessage* message) static_cast(fSystemListView->ItemAt(fSystemListView->CurrentSelection())); if (keymapListItem) { fCurrentMap.Load(keymapListItem->KeymapEntry()); + + if (fFirstTime) { + fPreviousMap.Load(keymapListItem->KeymapEntry()); + fAppliedMap.Load(keymapListItem->KeymapEntry()); + fFirstTime = false; + } + fMapView->Invalidate(); // Deselect item in other BListView @@ -375,9 +382,11 @@ KeymapWindow::RevertKeymap() fPreviousMap.Use(); fAppliedMap.Load(ref); - //select and load it (first item in fUserListView is a ref to Key_map) - fUserListView->DeselectAll(); - fUserListView->Select(0); + fCurrentMapName = GetActiveKeymapName(); + + if (!SelectCurrentMap(fSystemListView)) + if (!SelectCurrentMap(fUserListView)) + fUserListView->Select(0L); } @@ -400,8 +409,8 @@ KeymapWindow::UseKeymap() } fCurrentMap.Use(); fAppliedMap.Load(ref); - - fUserListView->Select(0); + + fCurrentMapName = GetActiveKeymapName(); } @@ -446,16 +455,7 @@ KeymapWindow::FillUserMaps() fUserListView->AddItem(new KeymapListItem(ref, "(Current)")); - BNode node(&ref); - char name[B_FILE_NAME_LENGTH]; - name[0] = '\0'; - if (node.InitCheck() == B_OK) { - ssize_t readSize = node.ReadAttr("keymap:name", B_STRING_TYPE, 0, name, sizeof(name) - 1); - if (readSize > 0) { - name[readSize] = '\0'; - fCurrentMapName = name; - } - } + fCurrentMapName = GetActiveKeymapName(); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; @@ -471,6 +471,28 @@ KeymapWindow::FillUserMaps() } +BString +KeymapWindow::GetActiveKeymapName() +{ + BString mapName = "(Current)"; //safe default + + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return mapName; + + path.Append("Key_map"); + + entry_ref ref; + get_ref_for_path(path.Path(), &ref); + BNode node(&ref); + + if (node.InitCheck() == B_OK) + node.ReadAttrString("keymap:name", &mapName); + + return mapName; +} + + bool KeymapWindow::SelectCurrentMap(BListView *view) { diff --git a/src/preferences/keymap/KeymapWindow.h b/src/preferences/keymap/KeymapWindow.h index 6621f88a8c..9bb6abf242 100644 --- a/src/preferences/keymap/KeymapWindow.h +++ b/src/preferences/keymap/KeymapWindow.h @@ -86,6 +86,7 @@ protected: void FillUserMaps(); bool SelectCurrentMap(BListView *list); + BString GetActiveKeymapName(); BListView *fSystemListView; BListView *fUserListView;