Ticket #7964: Keymap_add_Apple_Aluminum_submenu_2.diff

File Keymap_add_Apple_Aluminum_submenu_2.diff, 12.1 KB (added by jscipione, 13 years ago)

This patch builds on the last patch adding the new Apple Aluminum keyboard layout files to the keymap app. In the last patch marking the menu option was not working correctly. This fixes the menu marking so that it will mark the correct item even if that item is in a submenu. The Layout menu is no longer in RadioMode because that doesn't work with submenus. Instead I go through the menu and mark and unmark items appropriately. Yes there is a goto in the patch but it is not bad. The goto breaks out of an inner loop which is appropriate. The layout menu items are sorted alphabetically even the default Generic 105-key International layout but since I am a bit smarter about finding the default one it no longer has to be the first item in the list.

  • build/jam/HaikuImage

    diff --git build/jam/HaikuImage build/jam/HaikuImage
    index 90b9eee..0a8ecc9 100644
    AddSymlinkToHaikuImage system data Keymaps : Swedish : Finnish ;  
    499499AddSymlinkToHaikuImage system data Keymaps : Slovene : Croatian ;
    500500AddSymlinkToHaikuImage system data Keymaps : US-International : Brazilian ;
    501501
     502# Copy Keyboard Layout files to the image one-by-one
    502503local keyboardLayoutsDir
    503504    = [ FDirName $(HAIKU_TOP) data system data KeyboardLayouts ] ;
    504 local keyboardLayouts = [ Glob $(keyboardLayoutsDir) : [^.]* ] ;
    505 AddFilesToHaikuImage system data KeyboardLayouts : $(keyboardLayouts) ;
     505local keyboardLayoutFiles =
     506    $(keyboardLayoutsDir)/"Generic 104-key"
     507    $(keyboardLayoutsDir)/"Generic 105-key International"
     508    $(keyboardLayoutsDir)/"IBM Laptop International"
     509    $(keyboardLayoutsDir)/"Kinesis Advantage"
     510    $(keyboardLayoutsDir)/"Kinesis Ergo Elan International"
     511    $(keyboardLayoutsDir)/"TypeMatrix 2030" ;
     512AddDirectoryToHaikuImage system data KeyboardLayouts ;
     513AddFilesToHaikuImage system data KeyboardLayouts
     514    : $(keyboardLayoutFiles) ;
     515
     516local appleAluminumDir
     517    = [ FDirName $(keyboardLayoutsDir) Apple\ Aluminum ] ;
     518local appleAluminumFiles =
     519    $(appleAluminumDir)/"Apple Aluminium Extended International"
     520    $(appleAluminumDir)/"Apple Aluminium International"
     521    $(appleAluminumDir)/"Apple Aluminum (US)"
     522    $(appleAluminumDir)/"Apple Aluminum Extended (US)" ;
     523AddDirectoryToHaikuImage system data KeyboardLayouts Apple\ Aluminum ;
     524AddFilesToHaikuImage system data KeyboardLayouts Apple\ Aluminum
     525    : $(appleAluminumFiles) ;
    506526
    507527local driverSettingsFiles = <driver-settings>kernel ;
    508528SEARCH on $(driverSettingsFiles)
  • deleted file data/system/data/KeyboardLayouts/Apple

    diff --git data/system/data/KeyboardLayouts/Apple Aluminium data/system/data/KeyboardLayouts/Apple Aluminium
    deleted file mode 100644
    index dba6cde..0000000
    + -  
    1 name = Apple aluminium
    2 
    3 # Size shortcuts
    4 default-size = 10,10
    5 $back = 17,10
    6 $fn = 10.5,6
    7 $lshift = 13,10
    8 $ctrl = 14,10
    9 $alt = 12,10
    10 $cmd = 14,10
    11 $b = 5,10
    12 $d = 15,10
    13 $e = l12,20,8
    14 $f = 10,20
    15 $two = 20,10
    16 
    17 # Key rows
    18 [ 0,0;  4,5:-; d$fn:0x01; $fn:+12; d$fn:0x00; 5,6:-; 10,6:0x04+2; 5,6:-;
    19     10,6:+4 ]
    20 [ 0,6; 4,5:-; :0x11+12; d$back:+; $b:-; d:+3; $b:-; d:+1; d:0x6a; d:0x23+1 ]
    21 [ 0,16; 4,5:-; d$d:0x26; :+12; d$e:0x47; $b:-; d:0x34-0x36; $b:-; :+3; d:0x25 ]
    22 [ 0,26; 4,5:led-caps; # integrated into caps key
    23     d17,10:0x3b; :+11; :0x33; 50,10:-; :0x48-0x4a; d:0x3a ]
    24 [ 0,36; 4,5:-; d$lshift:0x4b; :0x69; :0x4c+9; d24,10:+1; 15,10:-; d:+1;
    25     15,10:-; :+3; d$f:+1 ]
    26 [ 0,46; 4,5:-; d$ctrl:0x5c; d$alt:0x5d; d$cmd:0x66; 67,10:0x5e; d$cmd:0x67;
    27     d$alt:0x5f; d$ctrl:0x60; $b:-; d:+3; $b:-; $two:+1; :+1 ]
  • new file data/system/data/KeyboardLayouts/Apple

    diff --git data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium Extended International data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium Extended International
    new file mode 100644
    index 0000000..68c96bb
    - +  
     1name = Apple Aluminium Extended International
     2
     3# Size shortcuts
     4default-size = 10,10
     5$back = 17,10
     6$fn = 10.5,6
     7$lshift = 13,10
     8$ctrl = 14,10
     9$alt = 12,10
     10$cmd = 14,10
     11$b = 5,10
     12$d = 15,10
     13$e = l12,20,8
     14$f = 10,20
     15$two = 20,10
     16
     17# Key rows
     18[ 0,0;  4,5:-; d$fn:0x01; $fn:+12; 15.5,6:-; 10,6:0x70068; 10,6:+2; 5,6:-; 10,6:+4; ]
     19[ 0,6; 4,5:-; :0x11+12; d$back:+; $b:-; :-; d:0x20; d:+1; $b:-; d:+1; d:0x6a; d:0x23+1 ]
     20[ 0,16; 4,5:-; d$d:0x26; :+12; d$e:0x47; $b:-; d:0x34-0x36; $b:-; :+3; d:0x25 ]
     21[ 0,26; 4,5:led-caps; # integrated into caps key
     22    d17,10:0x3b; :+11; :0x33; 50,10:-; :0x48-0x4a; d:0x3a ]
     23[ 0,36; 4,5:-; d$lshift:0x4b; :0x69; :0x4c+9; d24,10:+1; 15,10:-; d:+1;
     24    15,10:-; :+3; d$f:+1 ]
     25[ 0,46; 4,5:-; d$ctrl:0x5c; d$alt:0x5d; d$cmd:0x66; 67,10:0x5e; d$cmd:0x67;
     26    d$alt:0x5f; d$ctrl:0x60; $b:-; d:+3; $b:-; $two:+1; :+1 ]
  • new file data/system/data/KeyboardLayouts/Apple

    diff --git data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International
    new file mode 100644
    index 0000000..38758b8
    - +  
     1name = Apple Aluminium International
     2
     3# Size shortcuts
     4default-size = 10,10
     5$back = 17,10
     6$fn = 10.5,6
     7$lshift = 13,10
     8$b = 2,12
     9$d = 15,10
     10$e = l12,20,8
     11$f = 10,20
     12$two = 20,10
     13$last = 10,12
     14$cmd = 14,12
     15$arrow = 10,6
     16
     17# Key rows
     18[ 0,0;  4,5:-; d$fn:0x01; $fn:+12; ]
     19[ 0,6;  4,5:-; :0x11+12; d$back:+; ]
     20[ 0,16; 4,5:-; d$d:0x26; :+12; d$e:0x47; ]
     21[ 0,26; 4,5:led-caps; # integrated into caps key
     22    d17,10:0x3b; :+11; :0x33; ]
     23[ 0,36; 4,5:-; d$lshift:0x4b; :0x69; :0x4c+9; d24,10:+1; ]
     24[ 0,46; 4,5:-; d$last:-; # fn key
     25    d$last:0x5c; d$last:0x5d; d$cmd:0x66; 49,12:0x5e; d$cmd:0x67;
     26    d$last:0x5f; $arrow:-; d$arrow:0x57; $arrow:-; ]
     27[ 121,52; d$arrow:0x61+2; ]
  • new file data/system/data/KeyboardLayouts/Apple

    diff --git data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US) data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US)
    new file mode 100644
    index 0000000..976c71c
    - +  
     1name = Apple Aluminum (US)
     2
     3# Size shortcuts
     4default-size = 10,10
     5$back = 17,10
     6$fn = 10.5,6
     7$b = 2,12
     8$f = 10,20
     9$two = 20,10
     10$last = 10,12
     11$cmd = 14,12
     12$arrow = 10,6
     13
     14# Key rows
     15[ 0,0;  4,5:-; d$fn:0x01; $fn:+12; ]
     16[ 0,6;  4,5:-; :0x11+12; d$back:+; ]
     17[ 0,16; 4,5:-; d17,10:0x26; :+13; ]
     18[ 0,26; 4,5:led-caps; # integrated into caps key
     19    d19,10:0x3b; :+11; d18,10:0x47; ]
     20[ 0,36; 4,5:-; d24,10:0x4b; :+10; d23,10:+1; ]
     21[ 0,46; 4,5:-; d$last:-; # fn key
     22    d$last:0x5c; d$last:0x5d; d$cmd:0x66; 49,12:0x5e; d$cmd:0x67;
     23    d$last:0x5f; $arrow:-; d$arrow:0x57; $arrow:-; ]
     24[ 121,52; d$arrow:0x61+2; ]
  • new file data/system/data/KeyboardLayouts/Apple

    diff --git data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US) data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US)
    new file mode 100644
    index 0000000..c2a753b
    - +  
     1name = Apple Aluminum Extended (US)
     2
     3# Size shortcuts
     4default-size = 10,10
     5$back = 17,10
     6$fn = 10.5,6
     7$shift = 24,10
     8$ctrl = 14,10
     9$alt = 12,10
     10$cmd = 14,10
     11$b = 5,10
     12$f = 10,20
     13$two = 20,10
     14
     15# Key rows
     16[ 0,0;  4,5:-; d$fn:0x01; $fn:+12; 15.5,6:-; 10,6:0x70068; 10,6:+2; 5,6:-; 10,6:+4; ]
     17[ 0,6;  4,5:-; :0x11+12; d$back:+; $b:-; :-; d:0x20; d:+1; $b:-; d:+1; d:0x6a; d:0x23+1 ]
     18[ 0,16; 4,5:-; 0,16; 4,5:-; d17,10:0x26; :+13; $b:-; d:0x34-0x36; $b:-; :+3; d:0x25 ]
     19[ 0,26; 4,5:led-caps; # integrated into caps key
     20    d19,10:0x3b; :+11; d18,10:0x47; 40,10:-; :0x48-0x4a; d:0x3a ]
     21[ 0,36; 4,5:-; d24,10:0x4b; :+10; d23,10:+1; 15,10:-; d:+1; 15,10:-; :+3; d$f:+1 ]
     22[ 0,46; 4,5:-; d$ctrl:0x5c; d$alt:0x5d; d$cmd:0x66; 67,10:0x5e; d$cmd:0x67;
     23    d$alt:0x5f; d$ctrl:0x60; $b:-; d:+3; $b:-; $two:+1; :+1 ]
  • src/preferences/keymap/KeymapWindow.cpp

    diff --git src/preferences/keymap/KeymapWindow.cpp src/preferences/keymap/KeymapWindow.cpp
    index 62924a2..1caaa09 100644
    BMenuBar*  
    375375KeymapWindow::_CreateMenu()
    376376{
    377377    BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar");
    378     BMenuItem* item;
    379378
    380379    // Create the File menu
    381380    BMenu* menu = new BMenu(B_TRANSLATE("File"));
    KeymapWindow::_CreateMenu()  
    391390
    392391    // Create keyboard layout menu
    393392    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 
    400393    _AddKeyboardLayouts(fLayoutMenu);
    401394    menuBar->AddItem(fLayoutMenu);
    402395
    KeymapWindow::_AddKeyboardLayouts(BMenu* menu)  
    537530                if (menu->FindItem(ref.name) != NULL)
    538531                    continue;
    539532
    540                 BMessage* message = new BMessage(kChangeKeyboardLayout);
    541                 message->AddRef("ref", &ref);
     533                BDirectory subdirectory;
     534                subdirectory.SetTo(&ref);
     535                if (subdirectory.InitCheck() == B_OK) {
     536                    // item is a submenu, add children menuitems to submenu
     537                    // then add the submenu to menu
     538                    BMenu* submenu = new BMenu(ref.name);
     539
     540                    entry_ref subref;
     541                    while (subdirectory.GetNextRef(&subref) == B_OK) {
     542                        if (submenu->FindItem(subref.name) != NULL)
     543                            continue;
    542544
    543                 menu->AddItem(new BMenuItem(ref.name, message));
     545                        BMessage* message = new BMessage(kChangeKeyboardLayout);
     546                        message->AddRef("ref", &subref);
     547
     548                        submenu->AddItem(new BMenuItem(subref.name, message));
     549                    }
     550                    menu->AddItem(submenu);
     551                } else {
     552                    // item is a menuitem, add to menu
     553                    BMessage* message = new BMessage(kChangeKeyboardLayout);
     554                    message->AddRef("ref", &ref);
     555
     556                    menu->AddItem(new BMenuItem(ref.name, message));
     557                }
    544558            }
    545559        }
    546560    }
    KeymapWindow::_AddKeyboardLayouts(BMenu* menu)  
    550564status_t
    551565KeymapWindow::_SetKeyboardLayout(const char* path)
    552566{
    553     status_t status = B_OK;
     567    status_t status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path);
     568    BMenuItem* item = NULL;
     569    BMessage* message = NULL;
     570    entry_ref ref;
    554571
    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;
     572    // mark a menu item
     573    for (int32 i = fLayoutMenu->CountItems(); i-- > 0;) {
     574        item = fLayoutMenu->ItemAt(i);
     575        if (item == NULL)
     576            continue;
     577
     578        // Set the item as marked initially
     579        item->SetMarked(false);
     580
     581        BMenu* submenu = item->Submenu();
     582        if (submenu != NULL) {
     583            // item is a submenu
     584            BMenuItem* subitem = NULL;
     585
     586            for (int32 j = submenu->CountItems(); j-- > 0;) {
     587                subitem = submenu->ItemAt(j);
     588                if (subitem == NULL)
     589                    continue;
     590
     591                subitem->SetMarked(false);
     592                message = subitem->Message();
    563593                if (message->FindRef("ref", &ref) == B_OK) {
    564594                    BPath layoutPath(&ref);
    565                     if (layoutPath == path) {
    566                         item->SetMarked(true);
    567                         break;
    568                     }
     595                    if (path != NULL && path[0] != '\0' && layoutPath == path)
     596                        subitem->SetMarked(true);
    569597                }
    570598            }
     599        } else {
     600            // item is a menuitem
     601            message = item->Message();
     602            if (message->FindRef("ref", &ref) == B_OK) {
     603                BPath layoutPath(&ref);
     604                if (path != NULL && path[0] != '\0' && layoutPath == path)
     605                    item->SetMarked(true);
     606            }
    571607        }
    572608    }
    573609
    574     if (path == NULL || status != B_OK) {
     610    if (path == NULL || path[0] == '\0' || status != B_OK) {
    575611        fKeyboardLayoutView->GetKeyboardLayout()->SetDefault();
    576         fLayoutMenu->ItemAt(0)->SetMarked(true);
     612        item = fLayoutMenu->FindItem(
     613            fKeyboardLayoutView->GetKeyboardLayout()->Name());
     614        if (item != NULL)
     615            item->SetMarked(true);
    577616    }
    578617
    579618    // Refresh currently set layout
    KeymapWindow::_SaveSettings() const  
    933972    BMessage settings('keym');
    934973    settings.AddRect("window frame", Frame());
    935974
    936     BMenuItem* item = fLayoutMenu->FindMarked();
     975    BMenuItem* item = NULL;
    937976    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());
     977
     978    for (int32 i = fLayoutMenu->CountItems(); i-- > 0;) {
     979        item = fLayoutMenu->ItemAt(i);
     980        if (item == NULL)
     981            continue;
     982
     983        BMenu* submenu = item->Submenu();
     984        if (submenu != NULL) {
     985            // item is a submenu
     986            BMenuItem* subitem = NULL;
     987
     988            for (int32 j = submenu->CountItems(); j-- > 0;) {
     989                subitem = submenu->ItemAt(j);
     990                if (subitem != NULL && subitem->IsMarked()
     991                     && subitem->Message()->FindRef("ref", &ref) == B_OK) {
     992                    BPath path(&ref);
     993                    if (path.InitCheck() == B_OK) {
     994                        settings.AddString("keyboard layout", path.Path());
     995                        goto done;
     996                    }
     997                }
     998            }
     999        } else {
     1000            // item is a menuitem
     1001            if (item->IsMarked()
     1002                && item->Message()->FindRef("ref", &ref) == B_OK) {
     1003                BPath path(&ref);
     1004                if (path.InitCheck() == B_OK) {
     1005                    settings.AddString("keyboard layout", path.Path());
     1006                    goto done;
     1007                }
     1008            }
     1009        }
    9421010    }
    9431011
     1012done:
    9441013    return settings.Flatten(&file);
    9451014}