diff --git src/preferences/keymap/KeymapWindow.cpp src/preferences/keymap/KeymapWindow.cpp
index 62924a2..daa368c 100644
|
|
BMenuBar*
|
375 | 375 | KeymapWindow::_CreateMenu() |
376 | 376 | { |
377 | 377 | BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar"); |
378 | | BMenuItem* item; |
379 | 378 | |
380 | 379 | // Create the File menu |
381 | 380 | BMenu* menu = new BMenu(B_TRANSLATE("File")); |
… |
… |
KeymapWindow::_CreateMenu()
|
391 | 390 | |
392 | 391 | // Create keyboard layout menu |
393 | 392 | fLayoutMenu = new BMenu(B_TRANSLATE("Layout")); |
394 | | fLayoutMenu->SetRadioMode(true); |
395 | | fLayoutMenu->AddItem(item = new BMenuItem( |
396 | | fKeyboardLayoutView->GetKeyboardLayout()->Name(), |
397 | | new BMessage(kChangeKeyboardLayout))); |
398 | | item->SetMarked(true); |
399 | | |
400 | 393 | _AddKeyboardLayouts(fLayoutMenu); |
401 | 394 | menuBar->AddItem(fLayoutMenu); |
402 | 395 | |
… |
… |
KeymapWindow::_AddKeyboardLayouts(BMenu* menu)
|
531 | 524 | path.Append("KeyboardLayouts"); |
532 | 525 | |
533 | 526 | BDirectory directory; |
534 | | if (directory.SetTo(path.Path()) == B_OK) { |
535 | | entry_ref ref; |
536 | | while (directory.GetNextRef(&ref) == B_OK) { |
537 | | if (menu->FindItem(ref.name) != NULL) |
538 | | continue; |
| 527 | if (directory.SetTo(path.Path()) == B_OK) |
| 528 | _AddKeyboardLayoutMenu(menu, directory); |
| 529 | } |
| 530 | } |
539 | 531 | |
540 | | BMessage* message = new BMessage(kChangeKeyboardLayout); |
541 | | message->AddRef("ref", &ref); |
542 | 532 | |
543 | | menu->AddItem(new BMenuItem(ref.name, message)); |
544 | | } |
| 533 | /*! Adds a menu populated with the keyboard layouts found in the passed |
| 534 | in directory to the passed in menu. Each subdirectory in the passed |
| 535 | in directory is added as a submenu recursively. |
| 536 | */ |
| 537 | void |
| 538 | KeymapWindow::_AddKeyboardLayoutMenu(BMenu* menu, BDirectory directory) |
| 539 | { |
| 540 | entry_ref ref; |
| 541 | |
| 542 | while (directory.GetNextRef(&ref) == B_OK) { |
| 543 | if (menu->FindItem(ref.name) != NULL) |
| 544 | continue; |
| 545 | |
| 546 | BDirectory subdirectory; |
| 547 | subdirectory.SetTo(&ref); |
| 548 | if (subdirectory.InitCheck() == B_OK) { |
| 549 | BMenu* submenu = new BMenu(ref.name); |
| 550 | |
| 551 | _AddKeyboardLayoutMenu(submenu, subdirectory); |
| 552 | menu->AddItem(submenu); |
| 553 | } else { |
| 554 | BMessage* message = new BMessage(kChangeKeyboardLayout); |
| 555 | |
| 556 | message->AddRef("ref", &ref); |
| 557 | menu->AddItem(new BMenuItem(ref.name, message)); |
545 | 558 | } |
546 | 559 | } |
547 | 560 | } |
548 | 561 | |
549 | 562 | |
| 563 | /*! Sets the keyboard layout with the passed in path and marks the |
| 564 | corresponding menu item. If the path is not found in the menu this method |
| 565 | sets the default keyboard layout and marks the corresponding menu item. |
| 566 | */ |
550 | 567 | status_t |
551 | 568 | KeymapWindow::_SetKeyboardLayout(const char* path) |
552 | 569 | { |
553 | | status_t status = B_OK; |
| 570 | status_t status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path); |
554 | 571 | |
555 | | if (path != NULL && path[0] != '\0') { |
556 | | status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path); |
557 | | if (status == B_OK) { |
558 | | // select item |
559 | | for (int32 i = fLayoutMenu->CountItems(); i-- > 0;) { |
560 | | BMenuItem* item = fLayoutMenu->ItemAt(i); |
561 | | BMessage* message = item->Message(); |
562 | | entry_ref ref; |
563 | | if (message->FindRef("ref", &ref) == B_OK) { |
564 | | BPath layoutPath(&ref); |
565 | | if (layoutPath == path) { |
566 | | item->SetMarked(true); |
567 | | break; |
568 | | } |
569 | | } |
570 | | } |
571 | | } |
572 | | } |
| 572 | // mark a menu item (unmarking all others) |
| 573 | _MarkKeyboardLayoutItem(path, fLayoutMenu); |
573 | 574 | |
574 | | if (path == NULL || status != B_OK) { |
| 575 | if (path == NULL || path[0] == '\0' || status != B_OK) { |
575 | 576 | fKeyboardLayoutView->GetKeyboardLayout()->SetDefault(); |
576 | | fLayoutMenu->ItemAt(0)->SetMarked(true); |
| 577 | BMenuItem* item = fLayoutMenu->FindItem( |
| 578 | fKeyboardLayoutView->GetKeyboardLayout()->Name()); |
| 579 | if (item != NULL) |
| 580 | item->SetMarked(true); |
577 | 581 | } |
578 | 582 | |
579 | 583 | // Refresh currently set layout |
… |
… |
KeymapWindow::_SetKeyboardLayout(const char* path)
|
584 | 588 | } |
585 | 589 | |
586 | 590 | |
| 591 | /*! Marks a keyboard layout item by iterating through the menus recursively |
| 592 | searching for the menu item with the passed in path. This method always |
| 593 | iterates through all menu items and unmarks them. If no item with the |
| 594 | passed in path is found it is up to the caller to set the default keyboard |
| 595 | layout and mark item corresponding to the default keyboard layout path. |
| 596 | */ |
| 597 | void |
| 598 | KeymapWindow::_MarkKeyboardLayoutItem(const char* path, BMenu* menu) |
| 599 | { |
| 600 | BMenuItem* item = NULL; |
| 601 | entry_ref ref; |
| 602 | |
| 603 | for (int32 i = 0; i < menu->CountItems(); i++) { |
| 604 | item = menu->ItemAt(i); |
| 605 | if (item == NULL) |
| 606 | continue; |
| 607 | |
| 608 | // Unmark each item initially |
| 609 | item->SetMarked(false); |
| 610 | |
| 611 | BMenu* submenu = item->Submenu(); |
| 612 | if (submenu != NULL) |
| 613 | _MarkKeyboardLayoutItem(path, submenu); |
| 614 | else { |
| 615 | if (item->Message()->FindRef("ref", &ref) == B_OK) { |
| 616 | BPath layoutPath(&ref); |
| 617 | if (path != NULL && path[0] != '\0' && layoutPath == path) { |
| 618 | // Found it, mark the item |
| 619 | item->SetMarked(true); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | |
587 | 627 | /*! Sets the label of the "Switch Shorcuts" button to make it more |
588 | 628 | descriptive what will happen when you press that button. |
589 | 629 | */ |
… |
… |
KeymapWindow::_LoadSettings(BRect& windowFrame, BString& keyboardLayout)
|
922 | 962 | |
923 | 963 | |
924 | 964 | status_t |
925 | | KeymapWindow::_SaveSettings() const |
| 965 | KeymapWindow::_SaveSettings() |
926 | 966 | { |
927 | 967 | BFile file; |
928 | 968 | status_t status |
… |
… |
KeymapWindow::_SaveSettings() const
|
933 | 973 | BMessage settings('keym'); |
934 | 974 | settings.AddRect("window frame", Frame()); |
935 | 975 | |
936 | | BMenuItem* item = fLayoutMenu->FindMarked(); |
| 976 | BPath path = _GetMarkedKeyboardLayoutPath(fLayoutMenu); |
| 977 | if (path.InitCheck() == B_OK) |
| 978 | settings.AddString("keyboard layout", path.Path()); |
| 979 | |
| 980 | return settings.Flatten(&file); |
| 981 | } |
| 982 | |
| 983 | |
| 984 | /*! Gets the path of the currently marked keyboard layout item |
| 985 | by searching through each of the menus recursively until |
| 986 | a marked item is found. |
| 987 | */ |
| 988 | BPath |
| 989 | KeymapWindow::_GetMarkedKeyboardLayoutPath(BMenu* menu) |
| 990 | { |
| 991 | BPath path; |
| 992 | BMenuItem* item = NULL; |
937 | 993 | entry_ref ref; |
938 | | if (item != NULL && item->Message()->FindRef("ref", &ref) == B_OK) { |
939 | | BPath path(&ref); |
940 | | if (path.InitCheck() == B_OK) |
941 | | settings.AddString("keyboard layout", path.Path()); |
| 994 | |
| 995 | for (int32 i = 0; i < menu->CountItems(); i++) { |
| 996 | item = menu->ItemAt(i); |
| 997 | if (item == NULL) |
| 998 | continue; |
| 999 | |
| 1000 | BMenu* submenu = item->Submenu(); |
| 1001 | if (submenu != NULL) |
| 1002 | return _GetMarkedKeyboardLayoutPath(submenu); |
| 1003 | else { |
| 1004 | if (item->IsMarked() |
| 1005 | && item->Message()->FindRef("ref", &ref) == B_OK) { |
| 1006 | path.SetTo(&ref); |
| 1007 | return path; |
| 1008 | } |
| 1009 | } |
942 | 1010 | } |
943 | 1011 | |
944 | | return settings.Flatten(&file); |
| 1012 | return path; |
945 | 1013 | } |
diff --git src/preferences/keymap/KeymapWindow.h src/preferences/keymap/KeymapWindow.h
index cc6cb4b..acb0305 100644
|
|
protected:
|
40 | 40 | BMenuBar* _CreateMenu(); |
41 | 41 | BView* _CreateMapLists(); |
42 | 42 | void _AddKeyboardLayouts(BMenu* menu); |
| 43 | void _AddKeyboardLayoutMenu(BMenu* menu, |
| 44 | BDirectory directory); |
43 | 45 | status_t _SetKeyboardLayout(const char* path); |
| 46 | void _MarkKeyboardLayoutItem(const char* path, |
| 47 | BMenu* menu); |
44 | 48 | |
45 | 49 | void _UpdateSwitchShortcutButton(); |
46 | 50 | void _UpdateButtons(); |
… |
… |
protected:
|
64 | 68 | status_t _GetSettings(BFile& file, int mode) const; |
65 | 69 | status_t _LoadSettings(BRect& frame, |
66 | 70 | BString& keyboardLayout); |
67 | | status_t _SaveSettings() const; |
| 71 | status_t _SaveSettings(); |
| 72 | BPath _GetMarkedKeyboardLayoutPath(BMenu* menu); |
68 | 73 | |
69 | 74 | private: |
70 | 75 | BListView* fSystemListView; |