Ticket #5480: StyledEdit.patch
File StyledEdit.patch, 30.8 KB (added by , 14 years ago) |
---|
-
StyledEditWindow.cpp
19 19 20 20 #include <Alert.h> 21 21 #include <Autolock.h> 22 #include <Catalog.h> 22 23 #include <CharacterSet.h> 23 24 #include <CharacterSetRoster.h> 24 25 #include <Clipboard.h> 25 26 #include <Debug.h> 26 27 #include <File.h> 27 28 #include <FilePanel.h> 29 #include <Locale.h> 28 30 #include <Menu.h> 29 31 #include <MenuBar.h> 30 32 #include <MenuItem.h> … … 42 44 43 45 const float kLineViewWidth = 30.0; 44 46 47 #undef TR_CONTEXT 48 #define TR_CONTEXT "StyledEditWindow" 45 49 46 50 StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) 47 51 : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) 48 52 { 49 53 InitWindow(encoding); 50 BString unTitled( "Untitled ");54 BString unTitled(TR("Untitled ")); 51 55 unTitled << id; 52 56 SetTitle(unTitled.String()); 53 57 fSaveItem->SetEnabled(true); … … 56 60 } 57 61 58 62 59 StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding)63 StyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 encoding) 60 64 : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) 61 65 { 62 66 InitWindow(encoding); … … 73 77 } 74 78 75 79 80 #undef TR_CONTEXT 81 #define TR_CONTEXT "Menus" 82 76 83 void 77 84 StyledEditWindow::InitWindow(uint32 encoding) 78 85 { … … 124 131 fTextView->MakeFocus(true); 125 132 126 133 // Add "File"-menu: 127 BMenu* menu = new BMenu( "File");134 BMenu* menu = new BMenu(TR("File")); 128 135 fMenuBar->AddItem(menu); 129 136 130 137 BMenuItem* menuItem; 131 menu->AddItem(menuItem = new BMenuItem("New", new BMessage(MENU_NEW), 'N')); 138 menu->AddItem(menuItem = new BMenuItem(TR("New"), 139 new BMessage(MENU_NEW), 'N')); 132 140 menuItem->SetTarget(be_app); 133 141 134 menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu( "Open" B_UTF8_ELLIPSIS),142 menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu(TR("Open…")), 135 143 new BMessage(MENU_OPEN))); 136 144 menuItem->SetShortcut('O', 0); 137 145 menuItem->SetTarget(be_app); 138 146 menu->AddSeparatorItem(); 139 147 140 menu->AddItem(fSaveItem = new BMenuItem("Save", new BMessage(MENU_SAVE), 'S')); 148 menu->AddItem(fSaveItem = new BMenuItem(TR("Save"), 149 new BMessage(MENU_SAVE), 'S')); 141 150 fSaveItem->SetEnabled(false); 142 menu->AddItem(menuItem = new BMenuItem("Save as" B_UTF8_ELLIPSIS, new BMessage(MENU_SAVEAS))); 151 menu->AddItem(menuItem = new BMenuItem(TR("Save as…"), 152 new BMessage(MENU_SAVEAS))); 143 153 menuItem->SetShortcut('S',B_SHIFT_KEY); 144 154 menuItem->SetEnabled(true); 145 155 146 menu->AddItem(fRevertItem = new BMenuItem( "Revert to saved" B_UTF8_ELLIPSIS,156 menu->AddItem(fRevertItem = new BMenuItem(TR("Revert to saved…"), 147 157 new BMessage(MENU_REVERT))); 148 158 fRevertItem->SetEnabled(false); 149 menu->AddItem(menuItem = new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W')); 159 menu->AddItem(menuItem = new BMenuItem(TR("Close"), 160 new BMessage(MENU_CLOSE), 'W')); 150 161 151 162 menu->AddSeparatorItem(); 152 menu->AddItem(menuItem = new BMenuItem("Page setup" B_UTF8_ELLIPSIS, new BMessage(MENU_PAGESETUP))); 153 menu->AddItem(menuItem = new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_PRINT), 'P')); 163 menu->AddItem(menuItem = new BMenuItem(TR("Page setup…"), 164 new BMessage(MENU_PAGESETUP))); 165 menu->AddItem(menuItem = new BMenuItem(TR("Print…"), 166 new BMessage(MENU_PRINT), 'P')); 154 167 155 168 menu->AddSeparatorItem(); 156 menu->AddItem(menuItem = new BMenuItem("Quit", new BMessage(MENU_QUIT), 'Q')); 169 menu->AddItem(menuItem = new BMenuItem(TR("Quit"), 170 new BMessage(MENU_QUIT), 'Q')); 157 171 158 172 // Add the "Edit"-menu: 159 menu = new BMenu( "Edit");173 menu = new BMenu(TR("Edit")); 160 174 fMenuBar->AddItem(menu); 161 175 162 menu->AddItem(fUndoItem = new BMenuItem("Can't undo", new BMessage(B_UNDO), 'Z')); 176 menu->AddItem(fUndoItem = new BMenuItem(TR("Can't undo"), 177 new BMessage(B_UNDO), 'Z')); 163 178 fUndoItem->SetEnabled(false); 164 179 165 180 menu->AddSeparatorItem(); 166 menu->AddItem(fCutItem = new BMenuItem( "Cut", new BMessage(B_CUT), 'X'));181 menu->AddItem(fCutItem = new BMenuItem(TR("Cut"), new BMessage(B_CUT), 'X')); 167 182 fCutItem->SetEnabled(false); 168 183 fCutItem->SetTarget(fTextView); 169 184 170 menu->AddItem(fCopyItem = new BMenuItem("Copy", new BMessage(B_COPY), 'C')); 185 menu->AddItem(fCopyItem = new BMenuItem(TR("Copy"), 186 new BMessage(B_COPY), 'C')); 171 187 fCopyItem->SetEnabled(false); 172 188 fCopyItem->SetTarget(fTextView); 173 189 174 menu->AddItem(menuItem = new BMenuItem("Paste", new BMessage(B_PASTE), 'V')); 190 menu->AddItem(menuItem = new BMenuItem(TR("Paste"), 191 new BMessage(B_PASTE), 'V')); 175 192 menuItem->SetTarget(fTextView); 176 menu->AddItem(fClearItem = new BMenuItem("Clear", new BMessage(MENU_CLEAR))); 193 menu->AddItem(fClearItem = new BMenuItem(TR("Clear"), 194 new BMessage(MENU_CLEAR))); 177 195 fClearItem->SetEnabled(false); 178 196 fClearItem->SetTarget(fTextView); 179 197 180 198 menu->AddSeparatorItem(); 181 menu->AddItem(menuItem = new BMenuItem("Select all", new BMessage(B_SELECT_ALL), 'A')); 199 menu->AddItem(menuItem = new BMenuItem(TR("Select all"), 200 new BMessage(B_SELECT_ALL), 'A')); 182 201 menuItem->SetTarget(fTextView); 183 202 184 203 menu->AddSeparatorItem(); 185 menu->AddItem(menuItem = new BMenuItem("Find" B_UTF8_ELLIPSIS, new BMessage(MENU_FIND),'F')); 186 menu->AddItem(fFindAgainItem= new BMenuItem("Find again",new BMessage(MENU_FIND_AGAIN),'G')); 204 menu->AddItem(menuItem = new BMenuItem(TR("Find…"), 205 new BMessage(MENU_FIND),'F')); 206 menu->AddItem(fFindAgainItem= new BMenuItem(TR("Find again"), 207 new BMessage(MENU_FIND_AGAIN),'G')); 187 208 fFindAgainItem->SetEnabled(false); 188 209 189 menu->AddItem(menuItem = new BMenuItem("Find selection", new BMessage(MENU_FIND_SELECTION),'H')); 190 menu->AddItem(menuItem = new BMenuItem("Replace" B_UTF8_ELLIPSIS, new BMessage(MENU_REPLACE),'R')); 191 menu->AddItem(fReplaceSameItem = new BMenuItem("Replace same", new BMessage(MENU_REPLACE_SAME),'T')); 210 menu->AddItem(menuItem = new BMenuItem(TR("Find selection"), 211 new BMessage(MENU_FIND_SELECTION),'H')); 212 menu->AddItem(menuItem = new BMenuItem(TR("Replace…"), 213 new BMessage(MENU_REPLACE),'R')); 214 menu->AddItem(fReplaceSameItem = new BMenuItem(TR("Replace same"), 215 new BMessage(MENU_REPLACE_SAME),'T')); 192 216 fReplaceSameItem->SetEnabled(false); 193 217 194 218 // Add the "Font"-menu: 195 fFontMenu = new BMenu( "Font");219 fFontMenu = new BMenu(TR("Font")); 196 220 fMenuBar->AddItem(fFontMenu); 197 221 198 222 //"Size"-subMenu 199 fFontSizeMenu = new BMenu( "Size");223 fFontSizeMenu = new BMenu(TR("Size")); 200 224 fFontSizeMenu->SetRadioMode(true); 201 225 fFontMenu->AddItem(fFontSizeMenu); 202 226 … … 214 238 } 215 239 216 240 // "Color"-subMenu 217 fFontColorMenu = new BMenu( "Color");241 fFontColorMenu = new BMenu(TR("Color")); 218 242 fFontColorMenu->SetRadioMode(true); 219 243 fFontMenu->AddItem(fFontColorMenu); 220 244 221 fFontColorMenu->AddItem(fBlackItem = new BMenuItem("Black", new BMessage(FONT_COLOR))); 245 fFontColorMenu->AddItem(fBlackItem = new BMenuItem(TR("Black"), 246 new BMessage(FONT_COLOR))); 222 247 fBlackItem->SetMarked(true); 223 fFontColorMenu->AddItem(fRedItem = new ColorMenuItem("Red", RED, new BMessage(FONT_COLOR))); 224 fFontColorMenu->AddItem(fGreenItem = new ColorMenuItem("Green", GREEN, new BMessage(FONT_COLOR))); 225 fFontColorMenu->AddItem(fBlueItem = new ColorMenuItem("Blue", BLUE, new BMessage(FONT_COLOR))); 226 fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem("Cyan", CYAN, new BMessage(FONT_COLOR))); 227 fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem("Magenta", MAGENTA, new BMessage(FONT_COLOR))); 228 fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR))); 248 fFontColorMenu->AddItem(fRedItem = new ColorMenuItem(TR("Red"), RED, 249 new BMessage(FONT_COLOR))); 250 fFontColorMenu->AddItem(fGreenItem = new ColorMenuItem(TR("Green"), GREEN, 251 new BMessage(FONT_COLOR))); 252 fFontColorMenu->AddItem(fBlueItem = new ColorMenuItem(TR("Blue"), BLUE, 253 new BMessage(FONT_COLOR))); 254 fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(TR("Cyan"), CYAN, 255 new BMessage(FONT_COLOR))); 256 fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(TR("Magenta"), MAGENTA, 257 new BMessage(FONT_COLOR))); 258 fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(TR("Yellow"), YELLOW, 259 new BMessage(FONT_COLOR))); 229 260 fFontMenu->AddSeparatorItem(); 230 261 231 262 // Available fonts … … 256 287 } 257 288 258 289 // Add the "Document"-menu: 259 menu = new BMenu( "Document");290 menu = new BMenu(TR("Document")); 260 291 fMenuBar->AddItem(menu); 261 292 262 293 // "Align"-subMenu: 263 subMenu = new BMenu( "Align");294 subMenu = new BMenu(TR("Align")); 264 295 subMenu->SetRadioMode(true); 265 296 266 subMenu->AddItem(fAlignLeft = new BMenuItem("Left", new BMessage(ALIGN_LEFT))); 297 subMenu->AddItem(fAlignLeft = new BMenuItem(TR("Left"), 298 new BMessage(ALIGN_LEFT))); 267 299 fAlignLeft->SetMarked(true); 268 300 269 subMenu->AddItem(fAlignCenter = new BMenuItem("Center", new BMessage(ALIGN_CENTER))); 270 subMenu->AddItem(fAlignRight = new BMenuItem("Right", new BMessage(ALIGN_RIGHT))); 301 subMenu->AddItem(fAlignCenter = new BMenuItem(TR("Center"), 302 new BMessage(ALIGN_CENTER))); 303 subMenu->AddItem(fAlignRight = new BMenuItem(TR("Right"), 304 new BMessage(ALIGN_RIGHT))); 271 305 menu->AddItem(subMenu); 272 menu->AddItem(fWrapItem = new BMenuItem("Wrap lines", new BMessage(WRAP_LINES))); 306 menu->AddItem(fWrapItem = new BMenuItem(TR("Wrap lines"), 307 new BMessage(WRAP_LINES))); 273 308 fWrapItem->SetMarked(true); 274 309 275 310 fSavePanel = NULL; … … 279 314 280 315 281 316 void 282 StyledEditWindow::MessageReceived(BMessage *message)317 StyledEditWindow::MessageReceived(BMessage* message) 283 318 { 284 319 if (message->WasDropped()) { 285 320 entry_ref ref; … … 502 537 { 503 538 BRect textRect(fTextView->Bounds()); 504 539 textRect.OffsetTo(B_ORIGIN); 505 textRect.InsetBy(TEXT_INSET, TEXT_INSET);540 textRect.InsetBy(TEXT_INSET, TEXT_INSET); 506 541 if (fTextView->DoesWordWrap()) { 507 542 fTextView->SetWordWrap(false); 508 543 fWrapItem->SetMarked(false); … … 534 569 fClean = true; 535 570 fUndoCleans = false; 536 571 } else if (fClean) { 537 538 539 540 572 // if we were clean 573 // then a redo will make us clean again 574 fRedoCleans = true; 575 fClean = false; 541 576 } 542 577 // set mode 543 578 fCanUndo = false; 544 579 fCanRedo = true; 545 fUndoItem->SetLabel( "Redo typing");580 fUndoItem->SetLabel(TR("Redo typing")); 546 581 fUndoItem->SetEnabled(true); 547 582 fUndoFlag = false; 548 583 } else { … … 562 597 // set mode 563 598 fCanUndo = true; 564 599 fCanRedo = false; 565 fUndoItem->SetLabel( "Undo typing");600 fUndoItem->SetLabel(TR("Undo typing")); 566 601 fUndoItem->SetEnabled(true); 567 602 fRedoFlag = false; 568 603 } … … 579 614 void* ptr; 580 615 if (message->FindPointer("source", &ptr) == B_OK 581 616 && fSavePanelEncodingMenu != NULL) { 582 fTextView->SetEncoding((uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr)); 617 fTextView->SetEncoding( 618 (uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr)); 583 619 } 584 620 break; 585 621 … … 736 772 } 737 773 738 774 775 // This is temporary solution for building BString with printf like format. 776 // will be removed in the future. 777 static void 778 bs_printf(BString* string, const char* format, ...) 779 { 780 va_list ap; 781 va_start(ap, format); 782 char* buf; 783 vasprintf(&buf, format, ap); 784 string->SetTo(buf); 785 free(buf); 786 va_end(ap); 787 } 788 789 790 #undef TR_CONTEXT 791 #define TR_CONTEXT "QuitAlert" 792 739 793 bool 740 794 StyledEditWindow::QuitRequested() 741 795 { 742 796 if (fClean) 743 797 return true; 744 798 745 BString alertText("Save changes to the document \""); 746 alertText<< Title() <<"\"? "; 747 int32 index = _ShowAlert(alertText, "Cancel", "Don't save", "Save", 799 BString alertText; 800 bs_printf(&alertText, TR("Save changes to the document \"%s\"? "), Title()); 801 802 int32 index = _ShowAlert(alertText, TR("Cancel"), TR("Don't save"), TR("Save"), 748 803 B_WARNING_ALERT); 749 804 750 805 if (index == 0) … … 762 817 } 763 818 764 819 820 #undef TR_CONTEXT 821 #define TR_CONTEXT "SaveAlert" 822 765 823 status_t 766 StyledEditWindow::Save(BMessage *message)824 StyledEditWindow::Save(BMessage* message) 767 825 { 768 826 if (!message) 769 827 message = fSaveMessage; … … 788 846 } 789 847 790 848 if (status != B_OK) { 791 BString alertText ("Error saving \"");792 alertText << name << "\":\n" << strerror(status);849 BString alertText; 850 bs_printf(&alertText, TR("Error saving \"%s\":\n%s"), name, strerror(status)); 793 851 794 _ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);852 _ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT); 795 853 return status; 796 854 } 797 855 … … 816 874 } 817 875 818 876 877 #undef TR_CONTEXT 878 #define TR_CONTEXT "Open_and_SaveAsPanel" 879 819 880 status_t 820 StyledEditWindow::SaveAs(BMessage *message)881 StyledEditWindow::SaveAs(BMessage* message) 821 882 { 822 883 if (fSavePanel == NULL) { 823 884 entry_ref* directory = NULL; … … 834 895 BMenuBar* menuBar = dynamic_cast<BMenuBar*>( 835 896 fSavePanel->Window()->FindView("MenuBar")); 836 897 837 fSavePanelEncodingMenu= new BMenu( "Encoding");898 fSavePanelEncodingMenu= new BMenu(TR("Encoding")); 838 899 menuBar->AddItem(fSavePanelEncodingMenu); 839 900 fSavePanelEncodingMenu->SetRadioMode(true); 840 901 … … 848 909 name.Append(mime); 849 910 name.Append(")"); 850 911 } 851 BMenuItem * item = new BMenuItem(name.String(), new BMessage(SAVE_AS_ENCODING)); 912 BMenuItem * item = new BMenuItem(name.String(), 913 new BMessage(SAVE_AS_ENCODING)); 852 914 item->SetTarget(this); 853 915 fSavePanelEncodingMenu->AddItem(item); 854 916 if (charset.GetFontID() == fTextView->GetEncoding()) … … 865 927 } 866 928 867 929 930 #undef TR_CONTEXT 931 #define TR_CONTEXT "LoadAlert" 932 868 933 status_t 869 934 StyledEditWindow::_LoadFile(entry_ref* ref) 870 935 { … … 892 957 BEntry entry(ref, true); 893 958 char name[B_FILE_NAME_LENGTH]; 894 959 if (entry.GetName(name) != B_OK) 895 strcpy(name, "???");960 strcpy(name, TR("???")); 896 961 897 BString text("Error loading \""); 898 text << name << "\":\n\t"; 962 BString text; 899 963 if (status == B_BAD_TYPE) 900 text << "Unsupported format";964 bs_printf(&text, TR("Error loading \"%s\":\n\tUnsupported format"), name); 901 965 else 902 text << strerror(status);966 bs_printf(&text, TR("Error loading \"%s\":\n\t%s"), name, strerror(status)); 903 967 904 _ShowAlert(text, "OK", "", "", B_STOP_ALERT);968 _ShowAlert(text, TR("OK"), "", "", B_STOP_ALERT); 905 969 return status; 906 970 } 907 971 … … 953 1017 } 954 1018 955 1019 1020 #undef TR_CONTEXT 1021 #define TR_CONTEXT "RevertToSavedAlert" 1022 956 1023 void 957 1024 StyledEditWindow::RevertToSaved() 958 1025 { 959 1026 entry_ref ref; 960 const char *name;1027 const char* name; 961 1028 962 1029 fSaveMessage->FindRef("directory", &ref); 963 1030 fSaveMessage->FindString("name", &name); … … 972 1039 status = entry.GetRef(&ref); 973 1040 974 1041 if (status != B_OK || !entry.Exists()) { 975 BString alertText ("Cannot revert, file not found: \"");976 alertText << name << "\".";977 _ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);1042 BString alertText; 1043 bs_printf(&alertText, TR("Cannot revert, file not found: \"%s\"."), name); 1044 _ShowAlert(alertText, TR("OK"), "", "", B_STOP_ALERT); 978 1045 return; 979 1046 } 980 1047 981 BString alertText ("Revert to the last version of \"");982 alertText << Title() << "\"? ";983 if (_ShowAlert(alertText, "Cancel", "OK", "", B_WARNING_ALERT) != 1)1048 BString alertText; 1049 bs_printf(&alertText, TR("Revert to the last version of \"%s\"? "), Title()); 1050 if (_ShowAlert(alertText, TR("Cancel"), TR("OK"), "", B_WARNING_ALERT) != 1) 984 1051 return; 985 1052 986 1053 fTextView->Reset(); 987 1054 if (_LoadFile(&ref) != B_OK) 988 1055 return; 989 1056 1057 #undef TR_CONTEXT 1058 #define TR_CONTEXT "Menus" 1059 990 1060 // clear undo modes 991 fUndoItem->SetLabel( "Can't undo");1061 fUndoItem->SetLabel(TR("Can't undo")); 992 1062 fUndoItem->SetEnabled(false); 993 1063 fUndoFlag = false; 994 1064 fCanUndo = false; … … 1089 1159 top = fTextView->TextHeight(0, firstLineOnPage - 1); 1090 1160 1091 1161 float bottom = fTextView->TextHeight(0, printLine - 1); 1092 BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); 1162 BRect textRect(0.0, top + TEXT_INSET, 1163 printableRect.Width(), bottom + TEXT_INSET); 1093 1164 printJob.DrawView(fTextView, textRect, B_ORIGIN); 1094 1165 printJob.SpoolPage(); 1095 1166 } … … 1213 1284 if (viewText.Length() < textFinish) 1214 1285 textFinish = viewText.Length(); 1215 1286 1216 fTextView->Select(textStart, textFinish);1287 fTextView->Select(textStart, textFinish); 1217 1288 fTextView->ScrollToSelection(); 1218 1289 1219 1290 _UpdateCleanUndoRedoSaveRevert(); … … 1226 1297 int32 numWindows; 1227 1298 numWindows = be_app->CountWindows(); 1228 1299 1229 BMessage *message;1300 BMessage* message; 1230 1301 message= new BMessage(MSG_REPLACE_ALL); 1231 1302 message->AddString("FindText", find); 1232 1303 message->AddString("ReplaceText", replace); 1233 1304 message->AddBool("casesens", caseSensitive); 1234 1305 1235 1306 while (numWindows >= 0) { 1236 StyledEditWindow *window = dynamic_cast<StyledEditWindow *>(1307 StyledEditWindow* window = dynamic_cast<StyledEditWindow *>( 1237 1308 be_app->WindowAt(numWindows)); 1238 1309 1239 1310 BMessenger messenger(window); … … 1259 1330 1260 1331 1261 1332 void 1262 StyledEditWindow::SetFontColor(const rgb_color *color)1333 StyledEditWindow::SetFontColor(const rgb_color* color) 1263 1334 { 1264 1335 uint32 sameProperties; 1265 1336 BFont font; … … 1272 1343 1273 1344 1274 1345 void 1275 StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)1346 StyledEditWindow::SetFontStyle(const char* fontFamily, const char* fontStyle) 1276 1347 { 1277 1348 BFont font; 1278 1349 uint32 sameProperties; … … 1311 1382 } 1312 1383 1313 1384 1385 #undef TR_CONTEXT 1386 #define TR_CONTEXT "Menus" 1314 1387 void 1315 1388 StyledEditWindow::_UpdateCleanUndoRedoSaveRevert() 1316 1389 { … … 1319 1392 fRedoCleans = false; 1320 1393 fRevertItem->SetEnabled(fSaveMessage != NULL); 1321 1394 fSaveItem->SetEnabled(true); 1322 fUndoItem->SetLabel( "Can't Undo");1395 fUndoItem->SetLabel(TR("Can't Undo")); 1323 1396 fUndoItem->SetEnabled(false); 1324 1397 fCanUndo = false; 1325 1398 fCanRedo = false; -
ReplaceWindow.cpp
12 12 #include "ReplaceWindow.h" 13 13 14 14 #include <Button.h> 15 #include <Catalog.h> 15 16 #include <CheckBox.h> 17 #include <GroupLayoutBuilder.h> 18 #include <GridLayoutBuilder.h> 16 19 #include <Handler.h> 20 #include <Locale.h> 21 #include <LayoutBuilder.h> 17 22 #include <Message.h> 18 23 #include <Messenger.h> 19 #include <Rect.h>20 24 #include <String.h> 21 25 #include <TextControl.h> 22 #include <View.h>23 26 24 27 25 ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, 26 BString *replaceString, bool caseState, bool wrapState, bool backState) 28 #undef TR_CONTEXT 29 #define TR_CONTEXT "FindandReplaceWindow" 30 31 ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler, 32 BString* searchString, BString *replaceString, 33 bool caseState, bool wrapState, bool backState) 27 34 : BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW, 28 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) 35 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, 36 B_CURRENT_WORKSPACE) 29 37 { 30 38 AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); 31 39 32 fReplaceView = new BView(Bounds(), "ReplaceView", B_FOLLOW_ALL, B_WILL_DRAW); 33 fReplaceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 34 AddChild(fReplaceView); 40 fSearchString = new BTextControl("", TR("Find:"), NULL, NULL); 41 fReplaceString = new BTextControl("", TR("Replace with:"), NULL, NULL); 42 fCaseSensBox = new BCheckBox("", TR("Case-sensitive"), NULL); 43 fWrapBox = new BCheckBox("", TR("Wrap-around search"), NULL); 44 fBackSearchBox = new BCheckBox("", TR("Search backwards"), NULL); 45 fAllWindowsBox = new BCheckBox("", TR("Replace in all windows"), 46 new BMessage(CHANGE_WINDOW)); 47 fUIchange = false; 35 48 36 char* findLabel = "Find:"; 37 float findWidth = fReplaceView->StringWidth(findLabel); 38 fReplaceView->AddChild(fSearchString = new BTextControl(BRect(5, 10, 290, 50), "", 39 findLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); 40 41 char* replaceWithLabel = "Replace with:"; 42 float replaceWithWidth = fReplaceView->StringWidth(replaceWithLabel); 43 fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "", 44 replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, 45 B_WILL_DRAW | B_NAVIGABLE)); 46 float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + TEXT_INSET; 47 fSearchString->SetDivider(maxWidth); 48 fReplaceString->SetDivider(maxWidth); 49 fReplaceAllButton = new BButton("", TR("Replace all"), 50 new BMessage(MSG_REPLACE_ALL)); 51 fCancelButton = new BButton("", TR("Cancel"), new BMessage(B_QUIT_REQUESTED)); 52 fReplaceButton = new BButton("", TR("Replace"), new BMessage(MSG_REPLACE)); 49 53 50 fReplaceView->AddChild(fCaseSensBox = new BCheckBox(BRect(maxWidth + 8, 60, 290, 52), 51 "", "Case-sensitive", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); 52 fReplaceView->AddChild(fWrapBox = new BCheckBox(BRect(maxWidth + 8, 80, 290, 70), 53 "", "Wrap-around search", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, 54 B_WILL_DRAW | B_NAVIGABLE)); 55 fReplaceView->AddChild(fBackSearchBox = new BCheckBox(BRect(maxWidth + 8, 100, 290, 95), 56 "", "Search backwards", NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, 57 B_WILL_DRAW | B_NAVIGABLE)); 58 fReplaceView->AddChild(fAllWindowsBox = new BCheckBox(BRect(maxWidth + 8, 120, 290, 95), 59 "", "Replace in all windows", new BMessage(CHANGE_WINDOW), 60 B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)); 61 fUIchange = false; 54 SetLayout(new BGroupLayout(B_HORIZONTAL)); 55 AddChild(BGroupLayoutBuilder(B_VERTICAL, 4) 56 .Add(BGridLayoutBuilder(6, 2) 57 .Add(fSearchString->CreateLabelLayoutItem(), 0, 0) 58 .Add(fSearchString->CreateTextViewLayoutItem(), 1, 0) 59 .Add(fReplaceString->CreateLabelLayoutItem(), 0, 1) 60 .Add(fReplaceString->CreateTextViewLayoutItem(), 1, 1) 61 .Add(fCaseSensBox, 1, 2) 62 .Add(fWrapBox, 1, 3) 63 .Add(fBackSearchBox, 1, 4) 64 .Add(fAllWindowsBox, 1, 5) 65 ) 66 .AddGroup(B_HORIZONTAL, 10) 67 .Add(fReplaceAllButton) 68 .AddGlue() 69 .Add(fCancelButton) 70 .Add(fReplaceButton) 71 .End() 72 .SetInsets(10, 10, 10, 10) 73 ); 62 74 63 fReplaceView->AddChild(fReplaceAllButton = new BButton(BRect(10, 150, 98, 166),64 "", "Replace all", new BMessage(MSG_REPLACE_ALL), B_FOLLOW_LEFT | B_FOLLOW_TOP,65 B_WILL_DRAW | B_NAVIGABLE));66 fReplaceView->AddChild(fCancelButton = new BButton(BRect(141, 150, 211, 166),67 "", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_LEFT | B_FOLLOW_TOP,68 B_WILL_DRAW | B_NAVIGABLE));69 fReplaceView->AddChild(fReplaceButton = new BButton(BRect(221, 150, 291, 166),70 "", "Replace", new BMessage(MSG_REPLACE), B_FOLLOW_LEFT | B_FOLLOW_TOP,71 B_WILL_DRAW | B_NAVIGABLE));72 75 fReplaceButton->MakeDefault(true); 73 76 74 77 fHandler = _handler; 75 78 76 const char *searchtext = searchString->String();77 const char *replacetext = replaceString->String();79 const char* searchtext = searchString->String(); 80 const char* replacetext = replaceString->String(); 78 81 79 82 fSearchString->SetText(searchtext); 80 83 fReplaceString->SetText(replacetext); … … 87 90 88 91 89 92 void 90 ReplaceWindow::MessageReceived(BMessage *msg)93 ReplaceWindow::MessageReceived(BMessage* msg) 91 94 { 92 95 switch (msg->what) { 93 96 case MSG_REPLACE: … … 126 129 127 130 128 131 void 129 ReplaceWindow::DispatchMessage(BMessage *message, BHandler *handler)132 ReplaceWindow::DispatchMessage(BMessage* message, BHandler* handler) 130 133 { 131 134 if (message->what == B_KEY_DOWN) { 132 135 int8 key; -
ReplaceWindow.h
13 13 #include <Window.h> 14 14 15 15 16 class BView;17 16 class BString; 18 17 class BButton; 19 18 class BHandler; … … 35 34 void _SendMessage(uint32 what); 36 35 void _ChangeUI(); 37 36 38 BView *fReplaceView;39 37 BTextControl *fSearchString; 40 38 BTextControl *fReplaceString; 41 39 BCheckBox *fCaseSensBox; -
FindWindow.cpp
12 12 #include "FindWindow.h" 13 13 14 14 #include <Button.h> 15 #include <Catalog.h> 15 16 #include <CheckBox.h> 17 #include <GroupLayoutBuilder.h> 18 #include <GridLayoutBuilder.h> 19 #include <Locale.h> 20 #include <LayoutBuilder.h> 16 21 #include <String.h> 17 22 #include <TextControl.h> 18 23 19 24 20 FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, 25 #undef TR_CONTEXT 26 #define TR_CONTEXT "FindandReplaceWindow" 27 28 FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString, 21 29 bool caseState, bool wrapState, bool backState) 22 30 : BWindow(frame, "FindWindow", B_MODAL_WINDOW, 23 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) 31 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, 32 B_CURRENT_WORKSPACE) 24 33 { 25 34 AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); 26 27 fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);28 fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));29 AddChild(fFindView);30 35 31 font_height height; 32 fFindView->GetFontHeight(&height); 33 float lineHeight = height.ascent + height.descent + height.leading; 36 fSearchString = new BTextControl("", TR("Find:"), NULL, NULL); 37 fCaseSensBox = new BCheckBox("", TR("Case-sensitive"), NULL); 38 fWrapBox = new BCheckBox("", TR("Wrap-around search"), NULL); 39 fBackSearchBox = new BCheckBox("", TR("Search backwards"), NULL); 40 fCancelButton = new BButton("", TR("Cancel"), new BMessage(B_QUIT_REQUESTED)); 41 fSearchButton = new BButton("", TR("Find"), new BMessage(MSG_SEARCH)); 34 42 35 float findWidth = fFindView->StringWidth("Find:") + 6; 43 SetLayout(new BGroupLayout(B_HORIZONTAL)); 44 AddChild(BGroupLayoutBuilder(B_VERTICAL, 4) 45 .Add(BGridLayoutBuilder(6, 2) 46 .Add(fSearchString->CreateLabelLayoutItem(), 0, 0) 47 .Add(fSearchString->CreateTextViewLayoutItem(), 1, 0) 48 .Add(fCaseSensBox, 1, 1) 49 .Add(fWrapBox, 1, 2) 50 .Add(fBackSearchBox, 1, 3) 51 ) 52 .AddGroup(B_HORIZONTAL, 10) 53 .AddGlue() 54 .Add(fCancelButton) 55 .Add(fSearchButton) 56 .End() 57 .SetInsets(10, 10, 10, 10) 58 ); 36 59 37 float searchBottom = 12 + 2 + lineHeight + 2 + 1;38 float buttonTop = frame.Height() - 19 - lineHeight;39 float wrapBoxTop = (buttonTop + searchBottom - lineHeight) / 2;40 float wrapBoxBottom = (buttonTop + searchBottom + lineHeight) / 2;41 float caseBoxTop = (searchBottom + wrapBoxTop - lineHeight) / 2;42 float caseBoxBottom = (searchBottom + wrapBoxTop + lineHeight) / 2;43 float backBoxTop = (buttonTop + wrapBoxBottom - lineHeight) / 2;44 float backBoxBottom = (buttonTop + wrapBoxBottom + lineHeight) / 2;45 46 fFindView->AddChild(fSearchString = new BTextControl(BRect(14, 12,47 frame.Width() - 10, searchBottom), "", "Find:", NULL, NULL));48 fSearchString->SetDivider(findWidth);49 50 fFindView->AddChild(fCaseSensBox = new BCheckBox(BRect(16 + findWidth, caseBoxTop,51 frame.Width() - 12, caseBoxBottom), "", "Case-sensitive", NULL));52 fFindView->AddChild(fWrapBox = new BCheckBox(BRect(16 + findWidth, wrapBoxTop,53 frame.Width() - 12, wrapBoxBottom), "", "Wrap-around search", NULL));54 fFindView->AddChild(fBackSearchBox = new BCheckBox(BRect(16 + findWidth,55 backBoxTop, frame.Width() - 12, backBoxBottom), "", "Search backwards", NULL));56 57 fFindView->AddChild(fCancelButton = new BButton(BRect(142, buttonTop, 212,58 frame.Height() - 7), "", "Cancel", new BMessage(B_QUIT_REQUESTED)));59 fFindView->AddChild(fSearchButton = new BButton(BRect(221, buttonTop, 291,60 frame.Height() - 7), "", "Find", new BMessage(MSG_SEARCH)));61 62 60 fSearchButton->MakeDefault(true); 63 61 fHandler = _handler; 64 62 65 const char *text = searchString->String();63 const char* text = searchString->String(); 66 64 67 65 fSearchString->SetText(text); 68 66 fSearchString->MakeFocus(true); … … 74 72 75 73 76 74 void 77 FindWindow::MessageReceived(BMessage *msg)75 FindWindow::MessageReceived(BMessage* msg) 78 76 { 79 77 switch (msg->what) { 80 78 case B_QUIT_REQUESTED: … … 92 90 93 91 94 92 void 95 FindWindow::DispatchMessage(BMessage *message, BHandler *handler)93 FindWindow::DispatchMessage(BMessage* message, BHandler* handler) 96 94 { 97 95 if (message->what == B_KEY_DOWN) { 98 96 int8 key; -
StyledEditApp.cpp
15 15 16 16 #include <Alert.h> 17 17 #include <Autolock.h> 18 #include <Catalog.h> 19 #include <Locale.h> 18 20 #include <MenuBar.h> 19 21 #include <CharacterSet.h> 20 22 #include <CharacterSetRoster.h> … … 49 51 if (top + gWindowRect.Height() > screenBorder.bottom) 50 52 top = 26; 51 53 52 gWindowRect.OffsetTo(BPoint(left, top));54 gWindowRect.OffsetTo(BPoint(left, top)); 53 55 } 54 56 55 57 … … 71 73 top = top - ((int)left % 15) + 26; 72 74 } 73 75 74 gWindowRect.OffsetTo(BPoint(left, top));76 gWindowRect.OffsetTo(BPoint(left, top)); 75 77 } 76 78 } 77 79 78 80 79 81 // #pragma mark - 80 82 83 #undef TR_CONTEXT 84 #define TR_CONTEXT "Open_and_SaveAsPanel" 81 85 82 86 StyledEditApp::StyledEditApp() 83 87 : BApplication(APP_SIGNATURE), 84 88 fOpenPanel(NULL) 85 89 { 90 be_locale->GetAppCatalog(&fCatalog); 91 86 92 fOpenPanel = new BFilePanel(); 87 BMenuBar *menuBar =93 BMenuBar* menuBar = 88 94 dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar")); 89 95 90 96 fOpenAsEncoding = 0; 91 fOpenPanelEncodingMenu= new BMenu( "Encoding");97 fOpenPanelEncodingMenu= new BMenu(TR("Encoding")); 92 98 menuBar->AddItem(fOpenPanelEncodingMenu); 93 99 fOpenPanelEncodingMenu->SetRadioMode(true); 94 100 … … 97 103 while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { 98 104 BString name; 99 105 if (charset.GetFontID() == B_UNICODE_UTF8) 100 name = "Default";106 name = TR("Default"); 101 107 else 102 108 name = charset.GetPrintName(); 103 109 … … 107 113 name.Append(mime); 108 114 name.Append(")"); 109 115 } 110 BMenuItem* item = new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING)); 116 BMenuItem* item = 117 new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING)); 111 118 item->SetTarget(this); 112 119 fOpenPanelEncodingMenu->AddItem(item); 113 120 if (charset.GetFontID() == fOpenAsEncoding) … … 129 136 130 137 131 138 void 132 StyledEditApp::MessageReceived(BMessage *message)139 StyledEditApp::MessageReceived(BMessage* message) 133 140 { 134 141 switch (message->what) { 135 142 case MENU_NEW: … … 231 238 232 239 233 240 void 234 StyledEditApp::RefsReceived(BMessage *message)241 StyledEditApp::RefsReceived(BMessage* message) 235 242 { 236 243 int32 index = 0; 237 244 entry_ref ref; -
FindWindow.h
16 16 class BButton; 17 17 class BCheckBox; 18 18 class BTextControl; 19 class BView;20 19 21 20 22 21 class FindWindow : public BWindow { … … 30 29 private: 31 30 void _SendMessage(); 32 31 33 BView *fFindView;34 32 BTextControl *fSearchString; 35 33 BCheckBox *fCaseSensBox; 36 34 BCheckBox *fWrapBox; -
StyledEditApp.h
12 12 13 13 14 14 #include <Application.h> 15 #include <Catalog.h> 15 16 16 17 17 18 struct entry_ref; … … 48 49 int32 fWindowCount; 49 50 int32 fNextUntitledWindow; 50 51 bool fBadArguments; 52 BCatalog fCatalog; 51 53 }; 52 54 53 55 extern StyledEditApp* styled_edit_app; -
Jamfile
16 16 StyledEditApp.cpp 17 17 StyledEditView.cpp 18 18 StyledEditWindow.cpp 19 : be translation tracker libtextencoding.so $(TARGET_LIBSUPC++)19 : be translation tracker libtextencoding.so liblocale.so $(TARGET_LIBSUPC++) 20 20 : $(styled_edit_rsrc) 21 21 ; 22 23 DoCatalogs StyledEdit : 24 x-vnd.Haiku-StyledEdit 25 : 26 FindWindow.cpp 27 ReplaceWindow.cpp 28 StyledEditApp.cpp 29 StyledEditWindow.cpp 30 : en.catalog 31 : 32 ;