* Now switches the keymap according to the language. If there is no matching
keymap, it falls back to US-International, as before. +alpha git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41773 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -127,7 +127,8 @@ compare_void_list_items(const void* _a, const void* _b)
|
|||||||
BootPromptWindow::BootPromptWindow()
|
BootPromptWindow::BootPromptWindow()
|
||||||
:
|
:
|
||||||
BWindow(BRect(0, 0, 530, 400), "",
|
BWindow(BRect(0, 0, 530, 400), "",
|
||||||
B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_CLOSABLE)
|
B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_CLOSABLE),
|
||||||
|
fDefaultKeymapItem(NULL)
|
||||||
{
|
{
|
||||||
SetSizeLimits(450, 16384, 350, 16384);
|
SetSizeLimits(450, 16384, 350, 16384);
|
||||||
|
|
||||||
@@ -210,7 +211,14 @@ BootPromptWindow::MessageReceived(BMessage* message)
|
|||||||
MutableLocaleRoster::Default()->SetPreferredLanguages(
|
MutableLocaleRoster::Default()->SetPreferredLanguages(
|
||||||
&preferredLanguages);
|
&preferredLanguages);
|
||||||
_InitCatalog(true);
|
_InitCatalog(true);
|
||||||
// TODO: select default keymap by language
|
|
||||||
|
// Select default keymap by language
|
||||||
|
BLanguage language(item->Language());
|
||||||
|
BMenuItem* item = _KeymapItemForLanguage(language);
|
||||||
|
if (item != NULL) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
_ActivateKeymap(item->Message());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Calling it here is a cheap way of preventing the user to have
|
// Calling it here is a cheap way of preventing the user to have
|
||||||
// no item selected. Always the current item will be selected.
|
// no item selected. Always the current item will be selected.
|
||||||
@@ -218,12 +226,8 @@ BootPromptWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_KEYMAP_SELECTED:
|
case MSG_KEYMAP_SELECTED:
|
||||||
{
|
_ActivateKeymap(message);
|
||||||
entry_ref ref;
|
|
||||||
if (message->FindRef("ref", &ref) == B_OK)
|
|
||||||
_StoreKeymap(ref);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -341,7 +345,7 @@ BootPromptWindow::_PopulateLanguages()
|
|||||||
|
|
||||||
delete language;
|
delete language;
|
||||||
} else
|
} else
|
||||||
printf("failed to get BLanguage for %s\n", languageID);
|
fprintf(stderr, "failed to get BLanguage for %s\n", languageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
fLanguagesListView->SortItems(compare_void_list_items);
|
fLanguagesListView->SortItems(compare_void_list_items);
|
||||||
@@ -374,6 +378,10 @@ BootPromptWindow::_PopulateKeymaps()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// US-International is the default keymap, if we could not found a
|
||||||
|
// matching one
|
||||||
|
BString usInternational("US-International");
|
||||||
|
|
||||||
// Populate the menu
|
// Populate the menu
|
||||||
BDirectory directory;
|
BDirectory directory;
|
||||||
if (directory.SetTo(path.Path()) == B_OK) {
|
if (directory.SetTo(path.Path()) == B_OK) {
|
||||||
@@ -386,14 +394,21 @@ BootPromptWindow::_PopulateKeymaps()
|
|||||||
|
|
||||||
if (currentName == ref.name)
|
if (currentName == ref.name)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
|
if (usInternational == ref.name)
|
||||||
|
fDefaultKeymapItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BootPromptWindow::_StoreKeymap(const entry_ref& ref) const
|
BootPromptWindow::_ActivateKeymap(const BMessage* message) const
|
||||||
{
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
if (message == NULL || message->FindRef("ref", &ref) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
// Load and use the new keymap
|
// Load and use the new keymap
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
if (keymap.Load(ref) != B_OK) {
|
if (keymap.Load(ref) != B_OK) {
|
||||||
@@ -428,3 +443,26 @@ BootPromptWindow::_GetCurrentKeymapRef(entry_ref& ref) const
|
|||||||
|
|
||||||
return get_ref_for_path(path.Path(), &ref);
|
return get_ref_for_path(path.Path(), &ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMenuItem*
|
||||||
|
BootPromptWindow::_KeymapItemForLanguage(BLanguage& language) const
|
||||||
|
{
|
||||||
|
BLanguage english("en");
|
||||||
|
BString name;
|
||||||
|
if (language.GetName(name, &english) != B_OK)
|
||||||
|
return fDefaultKeymapItem;
|
||||||
|
|
||||||
|
BMenu* menu = fKeymapsMenuField->Menu();
|
||||||
|
for (int32 i = 0; i < menu->CountItems(); i++) {
|
||||||
|
BMenuItem* item = menu->ItemAt(i);
|
||||||
|
BMessage* message = item->Message();
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
if (message->FindRef("ref", &ref) == B_OK
|
||||||
|
&& name == ref.name)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fDefaultKeymapItem;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
|
class BLanguage;
|
||||||
class BListView;
|
class BListView;
|
||||||
class BMenuItem;
|
class BMenuItem;
|
||||||
class BMenuField;
|
class BMenuField;
|
||||||
@@ -28,14 +29,17 @@ private:
|
|||||||
void _UpdateStrings();
|
void _UpdateStrings();
|
||||||
void _PopulateLanguages();
|
void _PopulateLanguages();
|
||||||
void _PopulateKeymaps();
|
void _PopulateKeymaps();
|
||||||
void _StoreKeymap(const entry_ref& ref) const;
|
void _ActivateKeymap(const BMessage* message) const;
|
||||||
status_t _GetCurrentKeymapRef(entry_ref& ref) const;
|
status_t _GetCurrentKeymapRef(entry_ref& ref) const;
|
||||||
|
BMenuItem* _KeymapItemForLanguage(
|
||||||
|
BLanguage& language) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BTextView* fInfoTextView;
|
BTextView* fInfoTextView;
|
||||||
BStringView* fLanguagesLabelView;
|
BStringView* fLanguagesLabelView;
|
||||||
BListView* fLanguagesListView;
|
BListView* fLanguagesListView;
|
||||||
BMenuField* fKeymapsMenuField;
|
BMenuField* fKeymapsMenuField;
|
||||||
|
BMenuItem* fDefaultKeymapItem;
|
||||||
BButton* fDesktopButton;
|
BButton* fDesktopButton;
|
||||||
BButton* fInstallerButton;
|
BButton* fInstallerButton;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user