From 7a249e96f520c0570ea8e5b245cad027c33c9c91 Mon Sep 17 00:00:00 2001 From: Alexandre Deckner Date: Fri, 24 Oct 2008 11:50:45 +0000 Subject: [PATCH] Few fixes to the keymap preflet to make it good enough for the alpha 1. Lots of things could be rewritten in a cleaner way but i'd rather finish my keymap management patch as i rewrote the preflet for it anyway. For example the '(Current)' item shouldn't be needed anymore but is still there in case the keymap:name attribute read fails or if the original keymap file doesn't exist anymore (for example, applying a user keymap, quiting the preflet, deleting the keymap file, and reloading the preflet) * Revert/apply data wasn't correctly loaded when the first load was on a system keymap. This would allow revert/apply right after starting the preflet. That was the cause of #2659. * fCurrentMapName wasn't updated after a Revert or Apply * Select the active keymap in the lists after reverting. Quick cosmetical fix follows. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28313 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/keymap/KeymapWindow.cpp | 52 ++++++++++++++++++------- src/preferences/keymap/KeymapWindow.h | 1 + 2 files changed, 38 insertions(+), 15 deletions(-) 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;