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
This commit is contained in:
Alexandre Deckner 2008-10-24 11:50:45 +00:00
parent 500d847a1d
commit 7a249e96f5
2 changed files with 38 additions and 15 deletions

View File

@ -301,6 +301,13 @@ KeymapWindow::MessageReceived(BMessage* message)
static_cast<KeymapListItem*>(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);
}
@ -401,7 +410,7 @@ 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)
{

View File

@ -86,6 +86,7 @@ protected:
void FillUserMaps();
bool SelectCurrentMap(BListView *list);
BString GetActiveKeymapName();
BListView *fSystemListView;
BListView *fUserListView;