* The Keymap preferences app will now memorize its window frame and chosen
layout. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,7 +31,8 @@ KeyboardLayout::KeyboardLayout()
|
|||||||
fKeys(NULL),
|
fKeys(NULL),
|
||||||
fKeyCount(0),
|
fKeyCount(0),
|
||||||
fKeyCapacity(0),
|
fKeyCapacity(0),
|
||||||
fIndicators(5, true)
|
fIndicators(5, true),
|
||||||
|
fIsDefault(true)
|
||||||
{
|
{
|
||||||
SetDefault();
|
SetDefault();
|
||||||
}
|
}
|
||||||
@@ -147,6 +148,9 @@ KeyboardLayout::Load(entry_ref& ref)
|
|||||||
data[size] = '\0';
|
data[size] = '\0';
|
||||||
|
|
||||||
status = _InitFrom(data);
|
status = _InitFrom(data);
|
||||||
|
if (status == B_OK)
|
||||||
|
fIsDefault = false;
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -278,6 +282,7 @@ KeyboardLayout::SetDefault()
|
|||||||
|
|
||||||
_InitFrom(kIBMLaptop);
|
_InitFrom(kIBMLaptop);
|
||||||
#endif
|
#endif
|
||||||
|
fIsDefault = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -417,7 +422,7 @@ KeyboardLayout::_GetPair(const parse_state& state, const char*& data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
_Trim(name, false);
|
_Trim(name, false);
|
||||||
_Trim(value, true);
|
_Trim(value, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
status_t Load(entry_ref& ref);
|
status_t Load(entry_ref& ref);
|
||||||
|
|
||||||
void SetDefault();
|
void SetDefault();
|
||||||
|
bool IsDefault() const { return fIsDefault; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum parse_mode {
|
enum parse_mode {
|
||||||
@@ -112,6 +113,7 @@ private:
|
|||||||
BSize fDefaultKeySize;
|
BSize fDefaultKeySize;
|
||||||
int32 fAlternateIndex[3];
|
int32 fAlternateIndex[3];
|
||||||
BObjectList<Indicator> fIndicators;
|
BObjectList<Indicator> fIndicators;
|
||||||
|
bool fIsDefault;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEYBOARD_LAYOUT_H
|
#endif // KEYBOARD_LAYOUT_H
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
@@ -123,26 +124,13 @@ KeymapWindow::KeymapWindow()
|
|||||||
fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, &ref,
|
fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, &ref,
|
||||||
B_FILE_NODE, false, NULL);
|
B_FILE_NODE, false, NULL);
|
||||||
|
|
||||||
BScreen screen(this);
|
BRect windowFrame;
|
||||||
|
BString keyboardLayout;
|
||||||
|
_LoadSettings(windowFrame, keyboardLayout);
|
||||||
|
_SetKeyboardLayout(keyboardLayout.String());
|
||||||
|
|
||||||
float width = Frame().Width();
|
ResizeTo(windowFrame.Width(), windowFrame.Height());
|
||||||
float height = Frame().Height();
|
MoveTo(windowFrame.LeftTop());
|
||||||
|
|
||||||
// Make sure we can fit on screen
|
|
||||||
if (screen.Frame().Width() < Frame().Width())
|
|
||||||
width = screen.Frame().Width();
|
|
||||||
if (screen.Frame().Height() < Frame().Height())
|
|
||||||
height = screen.Frame().Height();
|
|
||||||
|
|
||||||
// See if we can use a larger default size
|
|
||||||
if (screen.Frame().Width() > 1200) {
|
|
||||||
width = 900;
|
|
||||||
height = 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: store and restore position and size!
|
|
||||||
ResizeTo(width, height);
|
|
||||||
MoveTo(BAlert::AlertPosition(width, height));
|
|
||||||
|
|
||||||
// TODO: this might be a bug in the interface kit, but scrolling to
|
// TODO: this might be a bug in the interface kit, but scrolling to
|
||||||
// selection does not correctly work unless the window is shown.
|
// selection does not correctly work unless the window is shown.
|
||||||
@@ -168,7 +156,7 @@ KeymapWindow::KeymapWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KeymapWindow::~KeymapWindow(void)
|
KeymapWindow::~KeymapWindow()
|
||||||
{
|
{
|
||||||
delete fOpenPanel;
|
delete fOpenPanel;
|
||||||
delete fSavePanel;
|
delete fSavePanel;
|
||||||
@@ -178,6 +166,8 @@ KeymapWindow::~KeymapWindow(void)
|
|||||||
bool
|
bool
|
||||||
KeymapWindow::QuitRequested()
|
KeymapWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
_SaveSettings();
|
||||||
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -231,18 +221,11 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
case kChangeKeyboardLayout:
|
case kChangeKeyboardLayout:
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
if (message->FindRef("ref", &ref) == B_OK
|
BPath path;
|
||||||
&& fKeyboardLayoutView->GetKeyboardLayout()->Load(ref)
|
if (message->FindRef("ref", &ref) == B_OK)
|
||||||
== B_OK) {
|
path.SetTo(&ref);
|
||||||
fKeyboardLayoutView->SetKeyboardLayout(
|
|
||||||
fKeyboardLayoutView->GetKeyboardLayout());
|
|
||||||
} else {
|
|
||||||
fKeyboardLayoutView->GetKeyboardLayout()->SetDefault();
|
|
||||||
fLayoutMenu->ItemAt(0)->SetMarked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
fKeyboardLayoutView->SetKeyboardLayout(
|
_SetKeyboardLayout(path.Path());
|
||||||
fKeyboardLayoutView->GetKeyboardLayout());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +540,43 @@ KeymapWindow::_AddKeyboardLayouts(BMenu* menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeymapWindow::_SetKeyboardLayout(const char* path)
|
||||||
|
{
|
||||||
|
status_t status = B_OK;
|
||||||
|
|
||||||
|
if (path != NULL && path[0] != '\0') {
|
||||||
|
status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path);
|
||||||
|
if (status == B_OK) {
|
||||||
|
// select item
|
||||||
|
for (int32 i = fLayoutMenu->CountItems(); i-- > 0;) {
|
||||||
|
BMenuItem* item = fLayoutMenu->ItemAt(i);
|
||||||
|
BMessage* message = item->Message();
|
||||||
|
entry_ref ref;
|
||||||
|
if (message->FindRef("ref", &ref) == B_OK) {
|
||||||
|
BPath layoutPath(&ref);
|
||||||
|
if (layoutPath == path) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path == NULL || status != B_OK) {
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout()->SetDefault();
|
||||||
|
fLayoutMenu->ItemAt(0)->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh currently set layout
|
||||||
|
fKeyboardLayoutView->SetKeyboardLayout(
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout());
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Sets the label of the "Switch Shorcuts" button to make it more
|
/*! Sets the label of the "Switch Shorcuts" button to make it more
|
||||||
descriptive what will happen when you press that button.
|
descriptive what will happen when you press that button.
|
||||||
*/
|
*/
|
||||||
@@ -828,3 +848,91 @@ KeymapWindow::_SelectCurrentMap()
|
|||||||
fUserListView->Select(0L);
|
fUserListView->Select(0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeymapWindow::_GetSettings(BFile& file, int mode) const
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path,
|
||||||
|
(mode & O_ACCMODE) != O_RDONLY);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
path.Append("Keymap settings");
|
||||||
|
|
||||||
|
return file.SetTo(path.Path(), mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeymapWindow::_LoadSettings(BRect& windowFrame, BString& keyboardLayout)
|
||||||
|
{
|
||||||
|
BScreen screen(this);
|
||||||
|
|
||||||
|
windowFrame.Set(-1, -1, 799, 329);
|
||||||
|
// See if we can use a larger default size
|
||||||
|
if (screen.Frame().Width() > 1200) {
|
||||||
|
windowFrame.right = 899;
|
||||||
|
windowFrame.bottom = 349;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboardLayout = "";
|
||||||
|
|
||||||
|
BFile file;
|
||||||
|
status_t status = _GetSettings(file, B_READ_ONLY);
|
||||||
|
if (status == B_OK) {
|
||||||
|
BMessage settings;
|
||||||
|
status = settings.Unflatten(&file);
|
||||||
|
if (status == B_OK) {
|
||||||
|
BRect frame;
|
||||||
|
if (settings.FindRect("window frame", &frame) == B_OK)
|
||||||
|
windowFrame = frame;
|
||||||
|
|
||||||
|
settings.FindString("keyboard layout", &keyboardLayout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!screen.Frame().Contains(windowFrame)) {
|
||||||
|
// Make sure the window is not larger than the screen
|
||||||
|
if (windowFrame.Width() > screen.Frame().Width())
|
||||||
|
windowFrame.right = windowFrame.left + screen.Frame().Width();
|
||||||
|
if (windowFrame.Height() > screen.Frame().Height())
|
||||||
|
windowFrame.bottom = windowFrame.top + screen.Frame().Height();
|
||||||
|
|
||||||
|
// Make sure the window is on screen (and center if it isn't)
|
||||||
|
if (windowFrame.left < screen.Frame().left
|
||||||
|
|| windowFrame.right > screen.Frame().right
|
||||||
|
|| windowFrame.top < screen.Frame().top
|
||||||
|
|| windowFrame.bottom > screen.Frame().bottom) {
|
||||||
|
windowFrame.OffsetTo(BAlert::AlertPosition(windowFrame.Width(),
|
||||||
|
windowFrame.Height()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeymapWindow::_SaveSettings() const
|
||||||
|
{
|
||||||
|
BFile file;
|
||||||
|
status_t status
|
||||||
|
= _GetSettings(file, B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
BMessage settings('keym');
|
||||||
|
settings.AddRect("window frame", Frame());
|
||||||
|
|
||||||
|
BMenuItem* item = fLayoutMenu->FindMarked();
|
||||||
|
entry_ref ref;
|
||||||
|
if (item != NULL && item->Message()->FindRef("ref", &ref) == B_OK) {
|
||||||
|
BPath path(&ref);
|
||||||
|
if (path.InitCheck() == B_OK)
|
||||||
|
settings.AddString("keyboard layout", path.Path());
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings.Flatten(&file);
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Keymap.h"
|
#include "Keymap.h"
|
||||||
|
|
||||||
|
|
||||||
class BMenu;
|
class BMenu;
|
||||||
class BMenuBar;
|
class BMenuBar;
|
||||||
class BMenuField;
|
class BMenuField;
|
||||||
@@ -39,6 +40,7 @@ protected:
|
|||||||
BMenuBar* _CreateMenu();
|
BMenuBar* _CreateMenu();
|
||||||
BView* _CreateMapLists();
|
BView* _CreateMapLists();
|
||||||
void _AddKeyboardLayouts(BMenu* menu);
|
void _AddKeyboardLayouts(BMenu* menu);
|
||||||
|
status_t _SetKeyboardLayout(const char* path);
|
||||||
|
|
||||||
void _UpdateSwitchShortcutButton();
|
void _UpdateSwitchShortcutButton();
|
||||||
void _UpdateButtons();
|
void _UpdateButtons();
|
||||||
@@ -59,6 +61,12 @@ protected:
|
|||||||
bool _SelectCurrentMap(BListView *list);
|
bool _SelectCurrentMap(BListView *list);
|
||||||
void _SelectCurrentMap();
|
void _SelectCurrentMap();
|
||||||
|
|
||||||
|
status_t _GetSettings(BFile& file, int mode) const;
|
||||||
|
status_t _LoadSettings(BRect& frame,
|
||||||
|
BString& keyboardLayout);
|
||||||
|
status_t _SaveSettings() const;
|
||||||
|
|
||||||
|
private:
|
||||||
BListView* fSystemListView;
|
BListView* fSystemListView;
|
||||||
BListView* fUserListView;
|
BListView* fUserListView;
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
|
|||||||
Reference in New Issue
Block a user