[haiku-commits] r35656 - haiku/trunk/src/apps/stylededit

  • From: pulkomandy@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Feb 2010 13:35:49 +0100 (CET)

Author: pulkomandy
Date: 2010-02-28 13:35:49 +0100 (Sun, 28 Feb 2010)
New Revision: 35656
Changeset: http://dev.haiku-os.org/changeset/35656/haiku

Modified:
   haiku/trunk/src/apps/stylededit/FindWindow.cpp
   haiku/trunk/src/apps/stylededit/FindWindow.h
   haiku/trunk/src/apps/stylededit/Jamfile
   haiku/trunk/src/apps/stylededit/ReplaceWindow.cpp
   haiku/trunk/src/apps/stylededit/ReplaceWindow.h
   haiku/trunk/src/apps/stylededit/StyledEditApp.cpp
   haiku/trunk/src/apps/stylededit/StyledEditApp.h
   haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
Log:
Patch by mt : localize stylededit. Thanks !


Modified: haiku/trunk/src/apps/stylededit/FindWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/FindWindow.cpp      2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/FindWindow.cpp      2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -12,57 +12,55 @@
 #include "FindWindow.h"
 
 #include <Button.h>
+#include <Catalog.h>
 #include <CheckBox.h>
+#include <GroupLayoutBuilder.h>
+#include <GridLayoutBuilder.h>
+#include <Locale.h>
+#include <LayoutBuilder.h>
 #include <String.h>
 #include <TextControl.h>
 
 
-FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
+#undef TR_CONTEXT
+#define TR_CONTEXT "FindandReplaceWindow"
+
+FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
        bool caseState, bool wrapState, bool backState)
        : BWindow(frame, "FindWindow", B_MODAL_WINDOW,
-               B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE)
+               B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | 
B_AUTO_UPDATE_SIZE_LIMITS,
+               B_CURRENT_WORKSPACE)
 {
        AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
-       
-       fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
-       fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
-       AddChild(fFindView);
 
-       font_height height;
-       fFindView->GetFontHeight(&height);
-       float lineHeight = height.ascent + height.descent + height.leading;
+       fSearchString = new BTextControl("", TR("Find:"), NULL, NULL);
+       fCaseSensBox = new BCheckBox("", TR("Case-sensitive"), NULL);
+       fWrapBox = new BCheckBox("", TR("Wrap-around search"), NULL);
+       fBackSearchBox = new BCheckBox("", TR("Search backwards"), NULL);
+       fCancelButton = new BButton("", TR("Cancel"), new 
BMessage(B_QUIT_REQUESTED));
+       fSearchButton = new BButton("", TR("Find"), new BMessage(MSG_SEARCH));
 
-       float findWidth = fFindView->StringWidth("Find:") + 6;
+       SetLayout(new BGroupLayout(B_HORIZONTAL)); 
+       AddChild(BGroupLayoutBuilder(B_VERTICAL, 4)
+               .Add(BGridLayoutBuilder(6, 2)
+                               .Add(fSearchString->CreateLabelLayoutItem(), 0, 
0)
+                               .Add(fSearchString->CreateTextViewLayoutItem(), 
1, 0)
+                               .Add(fCaseSensBox, 1, 1)
+                               .Add(fWrapBox, 1, 2)
+                               .Add(fBackSearchBox, 1, 3)
+                               )
+               .AddGroup(B_HORIZONTAL, 10) 
+                       .AddGlue() 
+                       .Add(fCancelButton) 
+                       .Add(fSearchButton) 
+               .End() 
+               .SetInsets(10, 10, 10, 10) 
+       ); 
 
-       float searchBottom = 12 + 2 + lineHeight + 2 + 1;
-       float buttonTop = frame.Height() - 19 - lineHeight;
-       float wrapBoxTop = (buttonTop + searchBottom - lineHeight) / 2;
-       float wrapBoxBottom = (buttonTop + searchBottom + lineHeight) / 2;
-       float caseBoxTop = (searchBottom + wrapBoxTop - lineHeight) / 2;
-       float caseBoxBottom = (searchBottom + wrapBoxTop + lineHeight) / 2;
-       float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2;
-       float backBoxBottom = (buttonTop + wrapBoxBottom + lineHeight) / 2;
-
-       fFindView->AddChild(fSearchString = new BTextControl(BRect(14, 12,
-               frame.Width() - 10, searchBottom), "", "Find:", NULL, NULL));
-       fSearchString->SetDivider(findWidth);
-
-       fFindView->AddChild(fCaseSensBox = new BCheckBox(BRect(16 + findWidth, 
caseBoxTop,
-               frame.Width() - 12, caseBoxBottom), "", "Case-sensitive", 
NULL));
-       fFindView->AddChild(fWrapBox = new BCheckBox(BRect(16 + findWidth, 
wrapBoxTop,
-               frame.Width() - 12, wrapBoxBottom), "", "Wrap-around search", 
NULL));
-       fFindView->AddChild(fBackSearchBox = new BCheckBox(BRect(16 + findWidth,
-               backBoxTop, frame.Width() - 12, backBoxBottom), "", "Search 
backwards", NULL));
-       
-       fFindView->AddChild(fCancelButton = new BButton(BRect(142, buttonTop, 
212,
-               frame.Height() - 7), "", "Cancel", new 
BMessage(B_QUIT_REQUESTED)));
-       fFindView->AddChild(fSearchButton = new BButton(BRect(221, buttonTop, 
291,
-               frame.Height() - 7), "", "Find", new BMessage(MSG_SEARCH)));
-
        fSearchButton->MakeDefault(true);
        fHandler = _handler;
 
-       const char *text = searchString->String();
+       const char* text = searchString->String();
 
        fSearchString->SetText(text);
        fSearchString->MakeFocus(true);
@@ -74,7 +72,7 @@
 
 
 void
-FindWindow::MessageReceived(BMessage *msg)
+FindWindow::MessageReceived(BMessage* msg)
 {
        switch (msg->what) {
                case B_QUIT_REQUESTED:
@@ -92,7 +90,7 @@
 
 
 void
-FindWindow::DispatchMessage(BMessage *message, BHandler *handler)
+FindWindow::DispatchMessage(BMessage* message, BHandler* handler)
 {
        if (message->what == B_KEY_DOWN) {
                int8 key;

Modified: haiku/trunk/src/apps/stylededit/FindWindow.h
===================================================================
--- haiku/trunk/src/apps/stylededit/FindWindow.h        2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/FindWindow.h        2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -16,7 +16,6 @@
 class BButton;
 class BCheckBox;
 class BTextControl;
-class BView;
 
 
 class FindWindow : public BWindow {
@@ -30,7 +29,6 @@
        private:
                void                    _SendMessage();
 
-               BView                   *fFindView;
                BTextControl    *fSearchString;
                BCheckBox               *fCaseSensBox;
                BCheckBox               *fWrapBox;

Modified: haiku/trunk/src/apps/stylededit/Jamfile
===================================================================
--- haiku/trunk/src/apps/stylededit/Jamfile     2010-02-28 11:20:29 UTC (rev 
35655)
+++ haiku/trunk/src/apps/stylededit/Jamfile     2010-02-28 12:35:49 UTC (rev 
35656)
@@ -16,6 +16,17 @@
        StyledEditApp.cpp
        StyledEditView.cpp
        StyledEditWindow.cpp
-       : be translation tracker libtextencoding.so $(TARGET_LIBSUPC++)
+       : be translation tracker libtextencoding.so liblocale.so 
$(TARGET_LIBSUPC++)
        : $(styled_edit_rsrc)
        ;
+
+DoCatalogs StyledEdit :
+       x-vnd.Haiku-StyledEdit
+       :
+       FindWindow.cpp
+       ReplaceWindow.cpp
+       StyledEditApp.cpp
+       StyledEditWindow.cpp
+       : en.catalog
+       :
+;

Modified: haiku/trunk/src/apps/stylededit/ReplaceWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/ReplaceWindow.cpp   2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/ReplaceWindow.cpp   2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -12,69 +12,72 @@
 #include "ReplaceWindow.h"
 
 #include <Button.h>
+#include <Catalog.h>
 #include <CheckBox.h>
+#include <GroupLayoutBuilder.h>
+#include <GridLayoutBuilder.h>
 #include <Handler.h>
+#include <Locale.h>
+#include <LayoutBuilder.h>
 #include <Message.h>
 #include <Messenger.h>
-#include <Rect.h>
 #include <String.h>
 #include <TextControl.h>
-#include <View.h>
 
 
-ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString 
*searchString,
-       BString *replaceString, bool caseState, bool wrapState, bool backState)
+#undef TR_CONTEXT
+#define TR_CONTEXT "FindandReplaceWindow"
+
+ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
+       BString* searchString,  BString *replaceString,
+       bool caseState, bool wrapState, bool backState)
        : BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW,
-               B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) 
+               B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | 
B_AUTO_UPDATE_SIZE_LIMITS,
+               B_CURRENT_WORKSPACE) 
 {
        AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
        
-       fReplaceView = new BView(Bounds(), "ReplaceView", B_FOLLOW_ALL, 
B_WILL_DRAW);
-       fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
-       AddChild(fReplaceView);
+       fSearchString = new BTextControl("", TR("Find:"), NULL, NULL);
+       fReplaceString = new BTextControl("", TR("Replace with:"), NULL, NULL);
+       fCaseSensBox = new BCheckBox("", TR("Case-sensitive"), NULL);
+       fWrapBox = new BCheckBox("", TR("Wrap-around search"), NULL);
+       fBackSearchBox = new BCheckBox("", TR("Search backwards"), NULL); 
+       fAllWindowsBox = new BCheckBox("", TR("Replace in all windows"),
+               new BMessage(CHANGE_WINDOW));
+       fUIchange = false;
 
-       char* findLabel = "Find:";
-       float findWidth = fReplaceView->StringWidth(findLabel);
-       fReplaceView->AddChild(fSearchString = new BTextControl(BRect(5, 10, 
290, 50), "",
-               findLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, 
B_WILL_DRAW | B_NAVIGABLE));
-       
-       char* replaceWithLabel = "Replace with:";
-       float replaceWithWidth = fReplaceView->StringWidth(replaceWithLabel);
-       fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 
290, 50), "",
-               replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE));
-       float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : 
findWidth) + TEXT_INSET;
-       fSearchString->SetDivider(maxWidth);
-       fReplaceString->SetDivider(maxWidth);
+       fReplaceAllButton = new BButton("", TR("Replace all"),
+               new BMessage(MSG_REPLACE_ALL));
+       fCancelButton = new BButton("", TR("Cancel"), new 
BMessage(B_QUIT_REQUESTED));
+       fReplaceButton = new BButton("", TR("Replace"), new 
BMessage(MSG_REPLACE));
 
-       fReplaceView->AddChild(fCaseSensBox = new BCheckBox(BRect(maxWidth + 8, 
60, 290, 52),
-               "", "Case-sensitive", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, 
B_WILL_DRAW | B_NAVIGABLE));
-       fReplaceView->AddChild(fWrapBox = new BCheckBox(BRect(maxWidth + 8, 80, 
290, 70),
-               "", "Wrap-around search", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE));
-       fReplaceView->AddChild(fBackSearchBox = new BCheckBox(BRect(maxWidth + 
8, 100, 290, 95),
-               "", "Search backwards", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE)); 
-       fReplaceView->AddChild(fAllWindowsBox = new BCheckBox(BRect(maxWidth + 
8, 120, 290, 95),
-               "", "Replace in all windows", new BMessage(CHANGE_WINDOW),
-               B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE));
-       fUIchange = false;
+       SetLayout(new BGroupLayout(B_HORIZONTAL)); 
+       AddChild(BGroupLayoutBuilder(B_VERTICAL, 4)
+               .Add(BGridLayoutBuilder(6, 2)
+                               .Add(fSearchString->CreateLabelLayoutItem(), 0, 
0)
+                               .Add(fSearchString->CreateTextViewLayoutItem(), 
1, 0)
+                               .Add(fReplaceString->CreateLabelLayoutItem(), 
0, 1)
+                               
.Add(fReplaceString->CreateTextViewLayoutItem(), 1, 1)
+                               .Add(fCaseSensBox, 1, 2)
+                               .Add(fWrapBox, 1, 3)
+                               .Add(fBackSearchBox, 1, 4)
+                               .Add(fAllWindowsBox, 1, 5)
+                               )
+               .AddGroup(B_HORIZONTAL, 10) 
+                       .Add(fReplaceAllButton) 
+                       .AddGlue() 
+                       .Add(fCancelButton) 
+                       .Add(fReplaceButton) 
+               .End() 
+               .SetInsets(10, 10, 10, 10) 
+       ); 
 
-       fReplaceView->AddChild(fReplaceAllButton = new BButton(BRect(10, 150, 
98, 166),
-               "", "Replace all", new BMessage(MSG_REPLACE_ALL), B_FOLLOW_LEFT 
| B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE));
-       fReplaceView->AddChild(fCancelButton = new BButton(BRect(141, 150, 211, 
166),
-               "", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_LEFT | 
B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE));
-       fReplaceView->AddChild(fReplaceButton = new BButton(BRect(221, 150, 
291, 166),
-               "", "Replace", new BMessage(MSG_REPLACE), B_FOLLOW_LEFT | 
B_FOLLOW_TOP,
-               B_WILL_DRAW | B_NAVIGABLE));
        fReplaceButton->MakeDefault(true);
 
        fHandler = _handler;
 
-       const char *searchtext = searchString->String();
-       const char *replacetext = replaceString->String(); 
+       const char* searchtext = searchString->String();
+       const char* replacetext = replaceString->String(); 
 
        fSearchString->SetText(searchtext);
        fReplaceString->SetText(replacetext);
@@ -87,7 +90,7 @@
 
 
 void
-ReplaceWindow::MessageReceived(BMessage *msg)
+ReplaceWindow::MessageReceived(BMessage* msg)
 {
        switch (msg->what) {
                case MSG_REPLACE:
@@ -126,7 +129,7 @@
 
 
 void
-ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler)
+ReplaceWindow::DispatchMessage(BMessage* message, BHandler* handler)
 {
        if (message->what == B_KEY_DOWN) {
                int8 key;

Modified: haiku/trunk/src/apps/stylededit/ReplaceWindow.h
===================================================================
--- haiku/trunk/src/apps/stylededit/ReplaceWindow.h     2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/ReplaceWindow.h     2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -13,7 +13,6 @@
 #include <Window.h>
 
 
-class BView;
 class BString;
 class BButton;
 class BHandler;
@@ -35,7 +34,6 @@
                void                    _SendMessage(uint32 what);
                void                    _ChangeUI();            
 
-               BView                   *fReplaceView;
                BTextControl    *fSearchString;
                BTextControl    *fReplaceString;
                BCheckBox               *fCaseSensBox;

Modified: haiku/trunk/src/apps/stylededit/StyledEditApp.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditApp.cpp   2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/StyledEditApp.cpp   2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -15,6 +15,8 @@
 
 #include <Alert.h>
 #include <Autolock.h>
+#include <Catalog.h>
+#include <Locale.h>
 #include <MenuBar.h>
 #include <CharacterSet.h>
 #include <CharacterSetRoster.h>
@@ -49,7 +51,7 @@
                if (top + gWindowRect.Height() > screenBorder.bottom)
                        top = 26;
 
-               gWindowRect.OffsetTo(BPoint(left,top)); 
+               gWindowRect.OffsetTo(BPoint(left, top));        
        }
 
 
@@ -71,24 +73,28 @@
                        top = top - ((int)left % 15) + 26;
                }
 
-               gWindowRect.OffsetTo(BPoint(left,top)); 
+               gWindowRect.OffsetTo(BPoint(left, top));        
        }
 }
 
 
 //     #pragma mark -
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "Open_and_SaveAsPanel"
 
 StyledEditApp::StyledEditApp()
        : BApplication(APP_SIGNATURE),
        fOpenPanel(NULL)
 {
+       be_locale->GetAppCatalog(&fCatalog);
+
        fOpenPanel = new BFilePanel();
-       BMenuBar *menuBar =
+       BMenuBar* menuBar =
                
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
 
        fOpenAsEncoding = 0;
-       fOpenPanelEncodingMenu= new BMenu("Encoding");
+       fOpenPanelEncodingMenu= new BMenu(TR("Encoding"));
        menuBar->AddItem(fOpenPanelEncodingMenu);
        fOpenPanelEncodingMenu->SetRadioMode(true);
 
@@ -97,7 +103,7 @@
        while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
                BString name;
                if (charset.GetFontID() == B_UNICODE_UTF8)
-                       name = "Default";
+                       name = TR("Default");
                else
                        name = charset.GetPrintName();
 
@@ -107,7 +113,8 @@
                        name.Append(mime);
                        name.Append(")");
                }
-               BMenuItem* item = new BMenuItem(name.String(), new 
BMessage(OPEN_AS_ENCODING));
+               BMenuItem* item =
+                       new BMenuItem(name.String(), new 
BMessage(OPEN_AS_ENCODING));
                item->SetTarget(this);
                fOpenPanelEncodingMenu->AddItem(item);
                if (charset.GetFontID() == fOpenAsEncoding)
@@ -129,7 +136,7 @@
 
 
 void
-StyledEditApp::MessageReceived(BMessage *message)
+StyledEditApp::MessageReceived(BMessage* message)
 {
        switch (message->what) {
                case MENU_NEW:
@@ -231,7 +238,7 @@
 
 
 void
-StyledEditApp::RefsReceived(BMessage *message)
+StyledEditApp::RefsReceived(BMessage* message)
 {
        int32 index = 0;
        entry_ref ref;

Modified: haiku/trunk/src/apps/stylededit/StyledEditApp.h
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditApp.h     2010-02-28 11:20:29 UTC 
(rev 35655)
+++ haiku/trunk/src/apps/stylededit/StyledEditApp.h     2010-02-28 12:35:49 UTC 
(rev 35656)
@@ -12,6 +12,7 @@
 
 
 #include <Application.h>
+#include <Catalog.h>
 
 
 struct entry_ref;
@@ -48,6 +49,7 @@
                int32                   fWindowCount;
                int32                   fNextUntitledWindow;
                bool                    fBadArguments;
+               BCatalog                fCatalog;
 };
 
 extern StyledEditApp* styled_edit_app;

Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-02-28 
11:20:29 UTC (rev 35655)
+++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-02-28 
12:35:49 UTC (rev 35656)
@@ -19,12 +19,14 @@
 
 #include <Alert.h>
 #include <Autolock.h>
+#include <Catalog.h>
 #include <CharacterSet.h>
 #include <CharacterSetRoster.h>
 #include <Clipboard.h>
 #include <Debug.h>
 #include <File.h>
 #include <FilePanel.h>
+#include <Locale.h>
 #include <Menu.h>
 #include <MenuBar.h>
 #include <MenuItem.h>
@@ -42,12 +44,14 @@
 
 const float kLineViewWidth = 30.0;
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "StyledEditWindow"
 
 StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
        : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
 {
        InitWindow(encoding);
-       BString unTitled("Untitled ");
+       BString unTitled(TR("Untitled "));
        unTitled << id;
        SetTitle(unTitled.String());
        fSaveItem->SetEnabled(true);
@@ -56,7 +60,7 @@
 }
 
 
-StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref, uint32 
encoding)
+StyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 
encoding)
        : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
 {
        InitWindow(encoding);
@@ -73,6 +77,9 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "Menus"
+
 void
 StyledEditWindow::InitWindow(uint32 encoding)
 {
@@ -124,79 +131,97 @@
        fTextView->MakeFocus(true);
        
        // Add "File"-menu:
-       BMenu* menu = new BMenu("File");
+       BMenu* menu = new BMenu(TR("File"));
        fMenuBar->AddItem(menu);
 
        BMenuItem* menuItem;
-       menu->AddItem(menuItem = new BMenuItem("New", new BMessage(MENU_NEW), 
'N'));
+       menu->AddItem(menuItem = new BMenuItem(TR("New"),
+               new BMessage(MENU_NEW), 'N'));
        menuItem->SetTarget(be_app);
 
-       menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu("Open" 
B_UTF8_ELLIPSIS),
-               new BMessage(MENU_OPEN)));
+       menu->AddItem(menuItem = new BMenuItem(fRecentMenu =
+               new BMenu(TR("Open" B_UTF8_ELLIPSIS)), new 
BMessage(MENU_OPEN)));
        menuItem->SetShortcut('O', 0);
        menuItem->SetTarget(be_app);
        menu->AddSeparatorItem();
 
-       menu->AddItem(fSaveItem = new BMenuItem("Save", new 
BMessage(MENU_SAVE), 'S'));
+       menu->AddItem(fSaveItem = new BMenuItem(TR("Save"),
+               new BMessage(MENU_SAVE), 'S'));
        fSaveItem->SetEnabled(false);
-       menu->AddItem(menuItem = new BMenuItem("Save as" B_UTF8_ELLIPSIS, new 
BMessage(MENU_SAVEAS)));
-       menuItem->SetShortcut('S',B_SHIFT_KEY);
+       menu->AddItem(menuItem = new BMenuItem(TR("Save as" B_UTF8_ELLIPSIS),
+               new BMessage(MENU_SAVEAS)));
+       menuItem->SetShortcut('S', B_SHIFT_KEY);
        menuItem->SetEnabled(true);
 
-       menu->AddItem(fRevertItem = new BMenuItem("Revert to saved" 
B_UTF8_ELLIPSIS,
+       menu->AddItem(fRevertItem =
+               new BMenuItem(TR("Revert to saved" B_UTF8_ELLIPSIS),
                new BMessage(MENU_REVERT)));
        fRevertItem->SetEnabled(false);
-       menu->AddItem(menuItem = new BMenuItem("Close", new 
BMessage(MENU_CLOSE), 'W'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Close"),
+               new BMessage(MENU_CLOSE), 'W'));
 
        menu->AddSeparatorItem();
-       menu->AddItem(menuItem = new BMenuItem("Page setup" B_UTF8_ELLIPSIS, 
new BMessage(MENU_PAGESETUP)));
-       menu->AddItem(menuItem = new BMenuItem("Print" B_UTF8_ELLIPSIS, new 
BMessage(MENU_PRINT), 'P'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Page setup" B_UTF8_ELLIPSIS),
+               new BMessage(MENU_PAGESETUP)));
+       menu->AddItem(menuItem = new BMenuItem(TR("Print" B_UTF8_ELLIPSIS),
+               new BMessage(MENU_PRINT), 'P'));
 
        menu->AddSeparatorItem();
-       menu->AddItem(menuItem = new BMenuItem("Quit", new BMessage(MENU_QUIT), 
'Q'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Quit"),
+               new BMessage(MENU_QUIT), 'Q'));
 
        // Add the "Edit"-menu:
-       menu = new BMenu("Edit");
+       menu = new BMenu(TR("Edit"));
        fMenuBar->AddItem(menu);
 
-       menu->AddItem(fUndoItem = new BMenuItem("Can't undo", new 
BMessage(B_UNDO), 'Z'));
+       menu->AddItem(fUndoItem = new BMenuItem(TR("Can't undo"),
+               new BMessage(B_UNDO), 'Z'));
        fUndoItem->SetEnabled(false);
 
        menu->AddSeparatorItem();
-       menu->AddItem(fCutItem = new BMenuItem("Cut", new BMessage(B_CUT), 
'X'));
+       menu->AddItem(fCutItem = new BMenuItem(TR("Cut"), new BMessage(B_CUT), 
'X'));
        fCutItem->SetEnabled(false);
        fCutItem->SetTarget(fTextView);
 
-       menu->AddItem(fCopyItem = new BMenuItem("Copy", new BMessage(B_COPY), 
'C'));
+       menu->AddItem(fCopyItem = new BMenuItem(TR("Copy"),
+               new BMessage(B_COPY), 'C'));
        fCopyItem->SetEnabled(false);
        fCopyItem->SetTarget(fTextView);
 
-       menu->AddItem(menuItem = new BMenuItem("Paste", new BMessage(B_PASTE), 
'V'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Paste"),
+               new BMessage(B_PASTE), 'V'));
        menuItem->SetTarget(fTextView);
-       menu->AddItem(fClearItem = new BMenuItem("Clear", new 
BMessage(MENU_CLEAR)));
+       menu->AddItem(fClearItem = new BMenuItem(TR("Clear"),
+               new BMessage(MENU_CLEAR)));
        fClearItem->SetEnabled(false);
        fClearItem->SetTarget(fTextView);
 
        menu->AddSeparatorItem();
-       menu->AddItem(menuItem = new BMenuItem("Select all", new 
BMessage(B_SELECT_ALL), 'A'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Select all"),
+               new BMessage(B_SELECT_ALL), 'A'));
        menuItem->SetTarget(fTextView);
 
        menu->AddSeparatorItem();
-       menu->AddItem(menuItem = new BMenuItem("Find" B_UTF8_ELLIPSIS, new 
BMessage(MENU_FIND),'F'));
-       menu->AddItem(fFindAgainItem= new BMenuItem("Find again",new 
BMessage(MENU_FIND_AGAIN),'G'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Find" B_UTF8_ELLIPSIS),
+               new BMessage(MENU_FIND), 'F'));
+       menu->AddItem(fFindAgainItem= new BMenuItem(TR("Find again"),
+               new BMessage(MENU_FIND_AGAIN), 'G'));
        fFindAgainItem->SetEnabled(false);
 
-       menu->AddItem(menuItem = new BMenuItem("Find selection", new 
BMessage(MENU_FIND_SELECTION),'H'));
-       menu->AddItem(menuItem = new BMenuItem("Replace" B_UTF8_ELLIPSIS, new 
BMessage(MENU_REPLACE),'R'));
-       menu->AddItem(fReplaceSameItem = new BMenuItem("Replace same", new 
BMessage(MENU_REPLACE_SAME),'T'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Find selection"),
+               new BMessage(MENU_FIND_SELECTION), 'H'));
+       menu->AddItem(menuItem = new BMenuItem(TR("Replace" B_UTF8_ELLIPSIS),
+               new BMessage(MENU_REPLACE), 'R'));
+       menu->AddItem(fReplaceSameItem = new BMenuItem(TR("Replace same"),
+               new BMessage(MENU_REPLACE_SAME), 'T'));
        fReplaceSameItem->SetEnabled(false);
 
        // Add the "Font"-menu:
-       fFontMenu = new BMenu("Font");
+       fFontMenu = new BMenu(TR("Font"));
        fMenuBar->AddItem(fFontMenu);
 
        //"Size"-subMenu
-       fFontSizeMenu = new BMenu("Size");
+       fFontSizeMenu = new BMenu(TR("Size"));
        fFontSizeMenu->SetRadioMode(true);
        fFontMenu->AddItem(fFontSizeMenu);
 
@@ -214,18 +239,25 @@
        }
 
        // "Color"-subMenu
-       fFontColorMenu = new BMenu("Color");
+       fFontColorMenu = new BMenu(TR("Color"));
        fFontColorMenu->SetRadioMode(true);
        fFontMenu->AddItem(fFontColorMenu);
 
-       fFontColorMenu->AddItem(fBlackItem = new BMenuItem("Black", new 
BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fBlackItem = new BMenuItem(TR("Black"),
+               new BMessage(FONT_COLOR)));
        fBlackItem->SetMarked(true);
-       fFontColorMenu->AddItem(fRedItem = new ColorMenuItem("Red", RED, new 
BMessage(FONT_COLOR)));
-       fFontColorMenu->AddItem(fGreenItem = new ColorMenuItem("Green", GREEN, 
new BMessage(FONT_COLOR)));
-       fFontColorMenu->AddItem(fBlueItem = new ColorMenuItem("Blue", BLUE, new 
BMessage(FONT_COLOR)));
-       fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem("Cyan", CYAN, new 
BMessage(FONT_COLOR)));
-       fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem("Magenta", 
MAGENTA, new BMessage(FONT_COLOR)));
-       fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem("Yellow", 
YELLOW, new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fRedItem = new ColorMenuItem(TR("Red"), RED,
+               new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fGreenItem = new ColorMenuItem(TR("Green"), 
GREEN,
+               new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fBlueItem = new ColorMenuItem(TR("Blue"), BLUE,
+               new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(TR("Cyan"), CYAN,
+               new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(TR("Magenta"), 
MAGENTA,
+               new BMessage(FONT_COLOR)));
+       fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(TR("Yellow"), 
YELLOW,
+               new BMessage(FONT_COLOR)));
        fFontMenu->AddSeparatorItem();
 
        // Available fonts
@@ -256,20 +288,24 @@
        }
 
        // Add the "Document"-menu:
-       menu = new BMenu("Document");
+       menu = new BMenu(TR("Document"));
        fMenuBar->AddItem(menu);
 
        // "Align"-subMenu:
-       subMenu = new BMenu("Align");
+       subMenu = new BMenu(TR("Align"));
        subMenu->SetRadioMode(true);
 
-       subMenu->AddItem(fAlignLeft = new BMenuItem("Left", new 
BMessage(ALIGN_LEFT)));
+       subMenu->AddItem(fAlignLeft = new BMenuItem(TR("Left"),
+               new BMessage(ALIGN_LEFT)));
        fAlignLeft->SetMarked(true);
 
-       subMenu->AddItem(fAlignCenter = new BMenuItem("Center", new 
BMessage(ALIGN_CENTER)));
-       subMenu->AddItem(fAlignRight = new BMenuItem("Right", new 
BMessage(ALIGN_RIGHT)));
+       subMenu->AddItem(fAlignCenter = new BMenuItem(TR("Center"),
+               new BMessage(ALIGN_CENTER)));
+       subMenu->AddItem(fAlignRight = new BMenuItem(TR("Right"),
+               new BMessage(ALIGN_RIGHT)));
        menu->AddItem(subMenu);
-       menu->AddItem(fWrapItem = new BMenuItem("Wrap lines", new 
BMessage(WRAP_LINES)));
+       menu->AddItem(fWrapItem = new BMenuItem(TR("Wrap lines"),
+               new BMessage(WRAP_LINES)));
        fWrapItem->SetMarked(true);
 
        fSavePanel = NULL;
@@ -279,7 +315,7 @@
 
 
 void
-StyledEditWindow::MessageReceived(BMessage *message)
+StyledEditWindow::MessageReceived(BMessage* message)
 {
        if (message->WasDropped()) {
                entry_ref ref;
@@ -502,7 +538,7 @@
                {
                        BRect textRect(fTextView->Bounds());
                        textRect.OffsetTo(B_ORIGIN);
-                       textRect.InsetBy(TEXT_INSET,TEXT_INSET);
+                       textRect.InsetBy(TEXT_INSET, TEXT_INSET);
                        if (fTextView->DoesWordWrap()) {
                                fTextView->SetWordWrap(false);
                                fWrapItem->SetMarked(false);
@@ -534,15 +570,15 @@
                                        fClean = true;
                                        fUndoCleans = false;
                                } else if (fClean) {
-                                  // if we were clean
-                                  // then a redo will make us clean again
-                                  fRedoCleans = true;
-                                  fClean = false;
+                                       // if we were clean
+                                       // then a redo will make us clean again
+                                       fRedoCleans = true;
+                                       fClean = false;
                                }
                                // set mode
                                fCanUndo = false;
                                fCanRedo = true;
-                               fUndoItem->SetLabel("Redo typing");
+                               fUndoItem->SetLabel(TR("Redo typing"));
                                fUndoItem->SetEnabled(true);
                                fUndoFlag = false;
                        } else {
@@ -562,7 +598,7 @@
                                // set mode
                                fCanUndo = true;
                                fCanRedo = false;
-                               fUndoItem->SetLabel("Undo typing");
+                               fUndoItem->SetLabel(TR("Undo typing"));
                                fUndoItem->SetEnabled(true);
                                fRedoFlag = false;
                        }
@@ -579,7 +615,8 @@
                        void* ptr;
                        if (message->FindPointer("source", &ptr) == B_OK
                                && fSavePanelEncodingMenu != NULL) {
-                               
fTextView->SetEncoding((uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr));
+                               fTextView->SetEncoding(
+                                       
(uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr));
                        }
                        break;
 
@@ -736,15 +773,34 @@
 }
 
 
+// This is temporary solution for building BString with printf like format.
+// will be removed in the future.
+static void
+bs_printf(BString* string, const char* format, ...)
+{
+       va_list         ap;
+       va_start(ap, format);
+       char*   buf;
+       vasprintf(&buf, format, ap);
+       string->SetTo(buf);
+       free(buf);
+       va_end(ap);
+}
+
+
+#undef TR_CONTEXT
+#define TR_CONTEXT "QuitAlert"
+
 bool
 StyledEditWindow::QuitRequested()
 {
        if (fClean)
                return true;
 
-       BString alertText("Save changes to the document \"");
-       alertText<< Title() <<"\"? ";
-       int32 index = _ShowAlert(alertText, "Cancel", "Don't save", "Save",
+       BString alertText;
+       bs_printf(&alertText, TR("Save changes to the document \"%s\"? "), 
Title());
+       
+       int32 index = _ShowAlert(alertText, TR("Cancel"), TR("Don't save"), 
TR("Save"),
                B_WARNING_ALERT);
 
        if (index == 0)
@@ -762,8 +818,11 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "SaveAlert"
+
 status_t
-StyledEditWindow::Save(BMessage *message)
+StyledEditWindow::Save(BMessage* message)
 {
        if (!message)
                message = fSaveMessage;
@@ -788,10 +847,10 @@
        }
 
        if (status != B_OK) {
-               BString alertText("Error saving \"");
-               alertText << name << "\":\n" << strerror(status);
+               BString alertText;
+               bs_printf(&alertText, TR("Error saving \"%s\":\n%s"), name, 
strerror(status));
 
-               _ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);
+               _ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT);
                return status;
        }
 
@@ -816,8 +875,11 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "Open_and_SaveAsPanel"
+
 status_t
-StyledEditWindow::SaveAs(BMessage *message)
+StyledEditWindow::SaveAs(BMessage* message)
 {
        if (fSavePanel == NULL) {
                entry_ref* directory = NULL;
@@ -834,7 +896,7 @@
                BMenuBar* menuBar = dynamic_cast<BMenuBar*>(
                        fSavePanel->Window()->FindView("MenuBar"));
 
-               fSavePanelEncodingMenu= new BMenu("Encoding");
+               fSavePanelEncodingMenu= new BMenu(TR("Encoding"));
                menuBar->AddItem(fSavePanelEncodingMenu);
                fSavePanelEncodingMenu->SetRadioMode(true);
 
@@ -848,7 +910,8 @@
                                name.Append(mime);
                                name.Append(")");
                        }
-                       BMenuItem * item = new BMenuItem(name.String(), new 
BMessage(SAVE_AS_ENCODING));
+                       BMenuItem * item = new BMenuItem(name.String(),
+                               new BMessage(SAVE_AS_ENCODING));
                        item->SetTarget(this);
                        fSavePanelEncodingMenu->AddItem(item);
                        if (charset.GetFontID() == fTextView->GetEncoding())
@@ -865,6 +928,9 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "LoadAlert"
+
 status_t
 StyledEditWindow::_LoadFile(entry_ref* ref)
 {
@@ -892,16 +958,15 @@
                BEntry entry(ref, true);
                char name[B_FILE_NAME_LENGTH];
                if (entry.GetName(name) != B_OK)
-                       strcpy(name, "???");
+                       strcpy(name, TR("???"));
 
-               BString text("Error loading \"");
-               text << name << "\":\n\t";
+               BString text;
                if (status == B_BAD_TYPE)
-                       text << "Unsupported format";
+                       bs_printf(&text, TR("Error loading 
\"%s\":\n\tUnsupported format"), name);
                else
-                       text << strerror(status);
+                       bs_printf(&text, TR("Error loading \"%s\":\n\t%s"), 
name, strerror(status));
 
-               _ShowAlert(text, "OK", "", "", B_STOP_ALERT);
+               _ShowAlert(text, TR("OK"), "", "", B_STOP_ALERT);
                return status;
        }
 
@@ -953,11 +1018,14 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "RevertToSavedAlert"
+
 void
 StyledEditWindow::RevertToSaved()
 {
        entry_ref ref;
-       const char *name;
+       const char* name;
 
        fSaveMessage->FindRef("directory", &ref);
        fSaveMessage->FindString("name", &name);
@@ -972,23 +1040,26 @@
                status = entry.GetRef(&ref);
 
        if (status != B_OK || !entry.Exists()) {
-               BString alertText("Cannot revert, file not found: \"");
-               alertText << name << "\".";
-               _ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);
+               BString alertText;
+               bs_printf(&alertText, TR("Cannot revert, file not found: 
\"%s\"."), name);
+               _ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT);
                return;
        }
 
-       BString alertText("Revert to the last version of \"");
-       alertText << Title() << "\"? ";
-       if (_ShowAlert(alertText, "Cancel", "OK", "", B_WARNING_ALERT) != 1)
+       BString alertText;
+       bs_printf(&alertText, TR("Revert to the last version of \"%s\"? "), 
Title());
+       if (_ShowAlert(alertText, TR("Cancel"), TR("OK"), "", B_WARNING_ALERT) 
!= 1)
                return;
 
        fTextView->Reset();
        if (_LoadFile(&ref) != B_OK)
                return;
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "Menus"
+
        // clear undo modes
-       fUndoItem->SetLabel("Can't undo");
+       fUndoItem->SetLabel(TR("Can't undo"));
        fUndoItem->SetEnabled(false);
        fUndoFlag = false;
        fCanUndo = false;
@@ -1089,7 +1160,8 @@
                                top = fTextView->TextHeight(0, firstLineOnPage 
- 1);
 
                        float bottom = fTextView->TextHeight(0, printLine - 1);
-                       BRect textRect(0.0, top + TEXT_INSET, 
printableRect.Width(), bottom + TEXT_INSET);
+                       BRect textRect(0.0, top + TEXT_INSET,
+                               printableRect.Width(), bottom + TEXT_INSET);
                        printJob.DrawView(fTextView, textRect, B_ORIGIN);
                        printJob.SpoolPage();
                }
@@ -1213,7 +1285,7 @@
        if (viewText.Length() < textFinish)
                textFinish = viewText.Length();
 
-       fTextView->Select(textStart,textFinish);
+       fTextView->Select(textStart, textFinish);
        fTextView->ScrollToSelection();
 
        _UpdateCleanUndoRedoSaveRevert();
@@ -1226,14 +1298,14 @@
        int32 numWindows;
        numWindows = be_app->CountWindows();
 
-       BMessage *message;
+       BMessage* message;
        message= new BMessage(MSG_REPLACE_ALL);
        message->AddString("FindText", find);
        message->AddString("ReplaceText", replace);
        message->AddBool("casesens", caseSensitive);
 
        while (numWindows >= 0) {
-               StyledEditWindow *window = dynamic_cast<StyledEditWindow *>(
+               StyledEditWindow* window = dynamic_cast<StyledEditWindow *>(
                        be_app->WindowAt(numWindows));
 
                BMessenger messenger(window);
@@ -1259,7 +1331,7 @@
 
 
 void
-StyledEditWindow::SetFontColor(const rgb_color *color)
+StyledEditWindow::SetFontColor(const rgb_color* color)
 {
        uint32 sameProperties;
        BFont font;
@@ -1272,7 +1344,7 @@
 
 
 void
-StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
+StyledEditWindow::SetFontStyle(const char* fontFamily, const char* fontStyle)
 {
        BFont font;
        uint32 sameProperties;
@@ -1311,6 +1383,8 @@
 }
 
 
+#undef TR_CONTEXT
+#define TR_CONTEXT "Menus"
 void
 StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
 {
@@ -1319,7 +1393,7 @@
        fRedoCleans = false;
        fRevertItem->SetEnabled(fSaveMessage != NULL);
        fSaveItem->SetEnabled(true);
-       fUndoItem->SetLabel("Can't Undo");
+       fUndoItem->SetLabel(TR("Can't Undo"));
        fUndoItem->SetEnabled(false);
        fCanUndo = false;
        fCanRedo = false;


Other related posts:

  • » [haiku-commits] r35656 - haiku/trunk/src/apps/stylededit - pulkomandy