Ticket #4689: stylededit-shortcuts-2-v2.diff

File stylededit-shortcuts-2-v2.diff, 3.6 KB (added by negusnyul, 13 years ago)
  • src/apps/stylededit/StyledEditWindow.cpp

     
    311311                BMenuItem* item = static_cast<BMenuItem*>(ptr);
    312312                fontFamily = item->Label();
    313313            }
     314
     315            BFont font;
     316            font.SetFamilyAndStyle(fontFamily, fontStyle);
     317            fItalicItem->SetMarked(font.Face() & B_ITALIC_FACE);
     318            fBoldItem->SetMarked(font.Face() & B_BOLD_FACE);
     319
    314320            _SetFontStyle(fontFamily, fontStyle);
    315321            break;
    316322        }
     
    329335                        fontFamily = super_item->Label();
    330336                }
    331337            }
     338
     339            BFont font;
     340            font.SetFamilyAndStyle(fontFamily, fontStyle);
     341            fItalicItem->SetMarked(font.Face() & B_ITALIC_FACE);
     342            fBoldItem->SetMarked(font.Face() & B_BOLD_FACE);
     343
    332344            _SetFontStyle(fontFamily, fontStyle);
    333345            break;
    334346        }
     347        case SET_ITALIC:
     348        {
     349            uint32 sameProperties;
     350            BFont font;
     351
     352            fTextView->GetFontAndColor(&font, &sameProperties);     
     353            if(fItalicItem->IsMarked())
     354                font.SetFace(B_REGULAR_FACE);
     355            fItalicItem->SetMarked(!fItalicItem->IsMarked());
     356
     357            font_family family;
     358            font_style style;
     359            font.GetFamilyAndStyle(&family, &style);
     360
     361            _SetFontStyle(family, style);
     362            break;
     363        }
     364        case SET_BOLD:
     365        {
     366            uint32 sameProperties;
     367            BFont font;
     368
     369            fTextView->GetFontAndColor(&font, &sameProperties);
     370            if(fBoldItem->IsMarked())
     371                font.SetFace(B_REGULAR_FACE);
     372            fBoldItem->SetMarked(!fBoldItem->IsMarked());
     373
     374            font_family family;
     375            font_style style;
     376            font.GetFamilyAndStyle(&family, &style);
     377
     378            _SetFontStyle(family, style);
     379            break;
     380        }
    335381        case FONT_COLOR:
    336382        {
    337383            void* ptr;
     
    587633        }
    588634    }
    589635
     636    fBoldItem->SetMarked(font.Face() & B_BOLD_FACE);
     637    fItalicItem->SetMarked(font.Face() & B_ITALIC_FACE);
     638
    590639    switch (fTextView->Alignment()) {
    591640        case B_ALIGN_LEFT:
    592641        default:
     
    11061155        YELLOW, new BMessage(FONT_COLOR)));
    11071156    fFontMenu->AddSeparatorItem();
    11081157
     1158    // "Bold" & "Italic" menu items
     1159    fFontMenu->AddItem(fBoldItem = new BMenuItem(B_TRANSLATE("Bold"),
     1160        new BMessage(SET_BOLD)));
     1161    fFontMenu->AddItem(fItalicItem = new BMenuItem(B_TRANSLATE("Italic"),
     1162        new BMessage(SET_ITALIC)));
     1163    fBoldItem->SetShortcut('B', 0);
     1164    fItalicItem->SetShortcut('I', 0);
     1165    fFontMenu->AddSeparatorItem();
     1166
    11091167    // Available fonts
    11101168
    11111169    fCurrentFontItem = 0;
     
    15221580    }
    15231581
    15241582    font.SetFamilyAndStyle(fontFamily, fontStyle);
     1583
     1584    uint16 face = 0;
     1585
     1586    if (!(font.Face() & B_REGULAR_FACE))
     1587        face = font.Face();
     1588
     1589    if (fBoldItem->IsMarked())
     1590        face |= B_BOLD_FACE;
     1591
     1592    if (fItalicItem->IsMarked())
     1593        face |= B_ITALIC_FACE;
     1594
     1595    font.SetFace(face);
     1596
    15251597    fTextView->SetFontAndColor(&font);
    15261598
    15271599    BMenuItem* superItem;
  • src/apps/stylededit/StyledEditWindow.h

     
    106106            BMenuItem*          fMagentaItem;
    107107            BMenuItem*          fYellowItem;
    108108
     109            BMenuItem*          fBoldItem;
     110            BMenuItem*          fItalicItem;
     111
    109112            BMenuItem*          fWrapItem;
    110113            BMenuItem*          fAlignLeft;
    111114            BMenuItem*          fAlignCenter;
  • src/apps/stylededit/Constants.h

     
    4848const uint32 FONT_FAMILY                = 'FFch';
    4949const uint32 FONT_STYLE                 = 'FSch';
    5050const uint32 FONT_COLOR                 = 'Fcol';
     51const uint32 SET_ITALIC                 = 'Fita';
     52const uint32 SET_BOLD                   = 'Fbld';
    5153
    5254// fontcolors
    5355const rgb_color BLACK                   = {0, 0, 0, 255};