Ticket #3065: styled_patch2.patch
File styled_patch2.patch, 7.8 KB (added by , 14 years ago) |
---|
-
src/apps/stylededit/StyledEditWindow.cpp
1 /* 1 /* 2 2 * Copyright 2002-2010, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 * 4 * 5 5 * Authors: 6 6 * Mattias Sundblad 7 7 * Andrew Bachmann 8 8 * Philippe Saint-Pierre 9 9 * Jonas Sundström 10 */ 10 */ 11 11 12 12 13 13 #include "Constants.h" … … 70 70 } 71 71 72 72 73 // #pragma mark - 73 // #pragma mark - 74 74 75 75 76 76 StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) … … 447 447 fClearItem->SetEnabled(false); 448 448 break; 449 449 case TEXT_CHANGED: 450 if (fUndoFlag) { 451 if (fUndoCleans) { 452 // we cleaned! 453 fClean = true; 454 fUndoCleans = false; 455 } else if (fClean) { 456 // if we were clean 457 // then a redo will make us clean again 458 fRedoCleans = true; 459 fClean = false; 450 if (!fDiscardFakeChanged) 451 { 452 if (fUndoFlag) { 453 if (fUndoCleans) { 454 // we cleaned! 455 fClean = true; 456 fUndoCleans = false; 457 } else if (fClean) { 458 // if we were clean 459 // then a redo will make us clean again 460 fRedoCleans = true; 461 fClean = false; 462 } 463 // set mode 464 fCanUndo = false; 465 fCanRedo = true; 466 fUndoItem->SetLabel(B_TRANSLATE("Redo typing")); 467 fUndoItem->SetEnabled(true); 468 fUndoFlag = false; 469 } else { 470 if (fRedoFlag && fRedoCleans) { 471 // we cleaned! 472 fClean = true; 473 fRedoCleans = false; 474 } else if (fClean) { 475 // if we were clean 476 // then an undo will make us clean again 477 fUndoCleans = true; 478 fClean = false; 479 } else { 480 // no more cleaning from undo now... 481 fUndoCleans = false; 482 } 483 // set mode 484 fCanUndo = true; 485 fCanRedo = false; 486 fUndoItem->SetLabel(B_TRANSLATE("Undo typing")); 487 fUndoItem->SetEnabled(true); 488 fRedoFlag = false; 460 489 } 461 // set mode 462 fCanUndo = false; 463 fCanRedo = true; 464 fUndoItem->SetLabel(B_TRANSLATE("Redo typing")); 465 fUndoItem->SetEnabled(true); 466 fUndoFlag = false; 467 } else { 468 if (fRedoFlag && fRedoCleans) { 469 // we cleaned! 470 fClean = true; 471 fRedoCleans = false; 472 } else if (fClean) { 473 // if we were clean 474 // then an undo will make us clean again 475 fUndoCleans = true; 476 fClean = false; 490 if (fClean) { 491 fRevertItem->SetEnabled(false); 492 fSaveItem->SetEnabled(fSaveMessage == NULL); 477 493 } else { 478 // no more cleaning from undo now...479 f UndoCleans = false;494 fRevertItem->SetEnabled(fSaveMessage != NULL); 495 fSaveItem->SetEnabled(true); 480 496 } 481 // set mode482 fCanUndo = true;483 fCanRedo = false;484 fUndoItem->SetLabel(B_TRANSLATE("Undo typing"));485 fUndoItem->SetEnabled(true);486 fRedoFlag = false;487 }488 if (fClean) {489 fRevertItem->SetEnabled(false);490 fSaveItem->SetEnabled(fSaveMessage == NULL);491 497 } else { 492 fRevertItem->SetEnabled(fSaveMessage != NULL); 493 fSaveItem->SetEnabled(true); 498 fDiscardFakeChanged = false; 494 499 } 495 500 break; 496 501 … … 517 522 BMessage documents; 518 523 be_roster->GetRecentDocuments(&documents, 9, NULL, APP_SIGNATURE); 519 524 520 // 521 // 522 // 523 // 524 // 525 // 525 // delete old items.. 526 // shatty: it would be preferable to keep the old 527 // menu around instead of continuously thrashing 528 // the menu, but unfortunately there does not 529 // seem to be a straightforward way to update it 530 // going backwards may simplify memory management 526 531 for (int i = fRecentMenu->CountItems(); i-- > 0;) { 527 532 delete fRecentMenu->RemoveItem(i); 528 533 } … … 863 868 int32 currentLine = 0; 864 869 while (currentLine < linesInDocument) { 865 870 float currentHeight = 0; 866 while (currentHeight < printableRect.Height() && currentLine < linesInDocument) { 871 while (currentHeight < printableRect.Height() 872 && currentLine < linesInDocument) { 867 873 currentHeight += fTextView->LineHeight(currentLine); 868 874 if (currentHeight < printableRect.Height()) 869 875 currentLine++; … … 958 964 documentPath.Append(name); 959 965 get_ref_for_path(documentPath.Path(), &documentRef); 960 966 961 return *ref== documentRef;967 return (*ref) == documentRef; 962 968 } 963 969 964 970 … … 992 998 fCaseSensitive = false; 993 999 fWrapAround = false; 994 1000 fBackSearch = false; 1001 1002 // fake changed message flag 1003 fDiscardFakeChanged = false; 995 1004 996 1005 // add menubar 997 1006 fMenuBar = new BMenuBar(BRect(0, 0, 0, 0), "menubar"); … … 1028 1037 new BMessage(MENU_NEW), 'N')); 1029 1038 menuItem->SetTarget(be_app); 1030 1039 1031 menu->AddItem(menuItem = new BMenuItem( fRecentMenu =1032 new BMenu(B_TRANSLATE("Open" B_UTF8_ELLIPSIS)),1033 1040 menu->AddItem(menuItem = new BMenuItem( 1041 fRecentMenu = new BMenu(B_TRANSLATE("Open" B_UTF8_ELLIPSIS)), 1042 new BMessage(MENU_OPEN))); 1034 1043 menuItem->SetShortcut('O', 0); 1035 1044 menuItem->SetTarget(be_app); 1036 1045 menu->AddSeparatorItem(); … … 1043 1052 menuItem->SetShortcut('S', B_SHIFT_KEY); 1044 1053 menuItem->SetEnabled(true); 1045 1054 1046 menu->AddItem(fRevertItem = 1047 new BMenuItem(B_TRANSLATE("Revert to saved" B_UTF8_ELLIPSIS), 1055 menu->AddItem( 1056 fRevertItem = new BMenuItem( 1057 B_TRANSLATE("Revert to saved" B_UTF8_ELLIPSIS), 1048 1058 new BMessage(MENU_REVERT))); 1049 1059 fRevertItem->SetEnabled(false); 1050 menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Close"), 1060 menu->AddItem( 1061 menuItem = new BMenuItem(B_TRANSLATE("Close"), 1051 1062 new BMessage(MENU_CLOSE), 'W')); 1052 1063 1053 1064 menu->AddSeparatorItem(); … … 1148 1159 BLUE, new BMessage(FONT_COLOR))); 1149 1160 fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(B_TRANSLATE("Cyan"), 1150 1161 CYAN, new BMessage(FONT_COLOR))); 1151 fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"), 1162 fFontColorMenu->AddItem( 1163 fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"), 1152 1164 MAGENTA, new BMessage(FONT_COLOR))); 1153 1165 fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(B_TRANSLATE("Yellow"), 1154 1166 YELLOW, new BMessage(FONT_COLOR))); … … 1324 1336 1325 1337 BString text; 1326 1338 if (status == B_BAD_TYPE) 1339 { 1327 1340 bs_printf(&text, 1328 B_TRANSLATE("Error loading \"%s\":\n\tUnsupported format"), name); 1329 else 1341 B_TRANSLATE("Error loading \"%s\":\n\t" 1342 "Unsupported format.\n" 1343 "The file may contain raw data."), name); 1344 _ShowAlert(text, B_TRANSLATE("OK"), "", "", B_WARNING_ALERT); 1345 } else { 1330 1346 bs_printf(&text, B_TRANSLATE("Error loading \"%s\":\n\t%s"), 1331 1347 name, strerror(status)); 1332 1333 _ShowAlert(text, B_TRANSLATE("OK"), "", "", B_STOP_ALERT); 1334 return status; 1348 _ShowAlert(text, B_TRANSLATE("OK"), "", "", B_STOP_ALERT); 1349 return status; 1350 } 1351 1352 // If the type of the file is bad we display it as binary data 1353 status = file.Seek(0, SEEK_SET); 1354 if (status != B_OK) 1355 { 1356 return status; 1357 } 1358 char buf[1024]; 1359 ssize_t read_data; 1360 while ((read_data = file.Read(buf, 1023)) > 0) 1361 { 1362 buf[(int)read_data] = '\0'; 1363 fTextView->Insert(buf, (const text_run_array*) NULL); 1364 } 1365 fDiscardFakeChanged = true; 1335 1366 } 1336 1367 1337 1368 // update alignment -
src/apps/stylededit/StyledEditWindow.h
133 133 bool fCaseSensitive; 134 134 bool fWrapAround; 135 135 bool fBackSearch; 136 // When loading a binary file a fake changed message 137 // is generated from the StyleEditView 138 // and with this flag we ignore this message 139 bool fDiscardFakeChanged; 136 140 137 141 StyledEditView* fTextView; 138 142 BScrollView* fScrollView;