Keymap preferences now saves an attribute on the Key_map file to indicate
what keymap it came from. This allows us to indicate the current keymap in the list views. I'm not sure how to get the build system to populate that attribute by default though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24924 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3ee7fad0a9
commit
487171f0b9
@ -113,6 +113,7 @@ Keymap::Load(entry_ref &ref)
|
||||
if (err < B_OK) {
|
||||
fprintf(stderr, "error reading keymap chars: %s\n", strerror(err));
|
||||
}
|
||||
strlcpy(fName, ref.name, sizeof(fName));
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -149,6 +150,8 @@ Keymap::Save(entry_ref &ref)
|
||||
|
||||
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
||||
return err;
|
||||
|
||||
err = file.WriteAttr("keymap:name", B_STRING_TYPE, 0, fName, strlen(fName));
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ private:
|
||||
char *fChars;
|
||||
key_map fKeys;
|
||||
uint32 fCharsSize;
|
||||
char fName[B_FILE_NAME_LENGTH];
|
||||
};
|
||||
|
||||
|
||||
|
@ -220,6 +220,11 @@ KeymapWindow::AddMaps(BView *placeholderView)
|
||||
|
||||
FillSystemMaps();
|
||||
FillUserMaps();
|
||||
|
||||
// try and find the current map name in the two list views (if the name was read at all)
|
||||
if (SelectCurrentMap(fSystemListView))
|
||||
if (!SelectCurrentMap(fUserListView))
|
||||
fUserListView->Select(0L);
|
||||
}
|
||||
|
||||
|
||||
@ -443,6 +448,17 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
@ -454,8 +470,25 @@ KeymapWindow::FillUserMaps()
|
||||
while( directory.GetNextRef(&ref) == B_OK ) {
|
||||
fUserListView->AddItem(new KeymapListItem(ref));
|
||||
}
|
||||
|
||||
fUserListView->Select(0);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
KeymapWindow::SelectCurrentMap(BListView *view)
|
||||
{
|
||||
bool found = false;
|
||||
if (fCurrentMapName.Length() > 0) {
|
||||
for (int32 i = 0; i < view->CountItems(); i++) {
|
||||
BStringItem *current = dynamic_cast<BStringItem *>(view->ItemAt(i));
|
||||
if (current && (fCurrentMapName == current->Text())) {
|
||||
found = true;
|
||||
view->Select(i);
|
||||
view->ScrollToSelection();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,10 +14,12 @@
|
||||
#include <Control.h>
|
||||
#include <FilePanel.h>
|
||||
#include <ListView.h>
|
||||
#include <Window.h>
|
||||
#include <MenuBar.h>
|
||||
#include "KeymapTextView.h"
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "Keymap.h"
|
||||
#include "KeymapTextView.h"
|
||||
|
||||
class KeymapListItem;
|
||||
class BBitmap;
|
||||
@ -82,7 +84,8 @@ protected:
|
||||
|
||||
void FillSystemMaps();
|
||||
void FillUserMaps();
|
||||
|
||||
|
||||
bool SelectCurrentMap(BListView *list);
|
||||
|
||||
BListView *fSystemListView;
|
||||
BListView *fUserListView;
|
||||
@ -97,6 +100,7 @@ protected:
|
||||
Keymap fPreviousMap;
|
||||
Keymap fAppliedMap;
|
||||
bool fFirstTime;
|
||||
BString fCurrentMapName;
|
||||
|
||||
BFilePanel *fOpenPanel; // the file panel to open
|
||||
BFilePanel *fSavePanel; // the file panel to save
|
||||
|
Loading…
Reference in New Issue
Block a user