Ticket #3065: styled_patch2.patch

File styled_patch2.patch, 7.8 KB (added by hayarms, 13 years ago)
  • src/apps/stylededit/StyledEditWindow.cpp

     
    1 /*
     1/* 
    22 * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    4  *
     4 * 
    55 * Authors:
    66 *      Mattias Sundblad
    77 *      Andrew Bachmann
    88 *      Philippe Saint-Pierre
    99 *      Jonas Sundström
    10  */
     10 */ 
    1111
    1212
    1313#include "Constants.h"
     
    7070}
    7171
    7272
    73 // #pragma mark -
     73// #pragma mark - 
    7474
    7575
    7676StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
     
    447447            fClearItem->SetEnabled(false);
    448448            break;
    449449        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;
    460489                }
    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);
    477493                } else {
    478                     // no more cleaning from undo now...
    479                     fUndoCleans = false;
     494                    fRevertItem->SetEnabled(fSaveMessage != NULL);
     495                    fSaveItem->SetEnabled(true);
    480496                }
    481                 // set mode
    482                 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);
    491497            } else {
    492                 fRevertItem->SetEnabled(fSaveMessage != NULL);
    493                 fSaveItem->SetEnabled(true);
     498                fDiscardFakeChanged = false;
    494499            }
    495500            break;
    496501
     
    517522    BMessage documents;
    518523    be_roster->GetRecentDocuments(&documents, 9, NULL, APP_SIGNATURE);
    519524
    520     // delete old items..
    521     //    shatty: it would be preferable to keep the old
    522     //            menu around instead of continuously thrashing
    523     //            the menu, but unfortunately there does not
    524     //            seem to be a straightforward way to update it
    525     // going backwards may simplify memory management
     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
    526531    for (int i = fRecentMenu->CountItems(); i-- > 0;) {
    527532        delete fRecentMenu->RemoveItem(i);
    528533    }
     
    863868    int32 currentLine = 0;
    864869    while (currentLine < linesInDocument) {
    865870        float currentHeight = 0;
    866         while (currentHeight < printableRect.Height() && currentLine < linesInDocument) {
     871        while (currentHeight < printableRect.Height()
     872            && currentLine < linesInDocument) {
    867873            currentHeight += fTextView->LineHeight(currentLine);
    868874            if (currentHeight < printableRect.Height())
    869875                currentLine++;
     
    958964    documentPath.Append(name);
    959965    get_ref_for_path(documentPath.Path(), &documentRef);
    960966
    961     return *ref == documentRef;
     967    return (*ref) == documentRef;
    962968}
    963969
    964970
     
    992998    fCaseSensitive = false;
    993999    fWrapAround = false;
    9941000    fBackSearch = false;
     1001   
     1002    // fake changed message flag
     1003    fDiscardFakeChanged = false;
    9951004
    9961005    // add menubar
    9971006    fMenuBar = new BMenuBar(BRect(0, 0, 0, 0), "menubar");
     
    10281037        new BMessage(MENU_NEW), 'N'));
    10291038    menuItem->SetTarget(be_app);
    10301039
    1031     menu->AddItem(menuItem = new BMenuItem(fRecentMenu =
    1032         new BMenu(B_TRANSLATE("Open" B_UTF8_ELLIPSIS)),
    1033             new BMessage(MENU_OPEN)));
     1040    menu->AddItem(menuItem = new BMenuItem(
     1041        fRecentMenu = new BMenu(B_TRANSLATE("Open" B_UTF8_ELLIPSIS)),
     1042        new BMessage(MENU_OPEN)));
    10341043    menuItem->SetShortcut('O', 0);
    10351044    menuItem->SetTarget(be_app);
    10361045    menu->AddSeparatorItem();
     
    10431052    menuItem->SetShortcut('S', B_SHIFT_KEY);
    10441053    menuItem->SetEnabled(true);
    10451054
    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),
    10481058        new BMessage(MENU_REVERT)));
    10491059    fRevertItem->SetEnabled(false);
    1050     menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Close"),
     1060    menu->AddItem(
     1061        menuItem = new BMenuItem(B_TRANSLATE("Close"),
    10511062        new BMessage(MENU_CLOSE), 'W'));
    10521063
    10531064    menu->AddSeparatorItem();
     
    11481159        BLUE, new BMessage(FONT_COLOR)));
    11491160    fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(B_TRANSLATE("Cyan"),
    11501161        CYAN, new BMessage(FONT_COLOR)));
    1151     fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"),
     1162    fFontColorMenu->AddItem(
     1163        fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"),
    11521164        MAGENTA, new BMessage(FONT_COLOR)));
    11531165    fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(B_TRANSLATE("Yellow"),
    11541166        YELLOW, new BMessage(FONT_COLOR)));
     
    13241336
    13251337        BString text;
    13261338        if (status == B_BAD_TYPE)
     1339        {
    13271340            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 {   
    13301346            bs_printf(&text, B_TRANSLATE("Error loading \"%s\":\n\t%s"),
    13311347                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;
    13351366    }
    13361367
    13371368    // update alignment
  • src/apps/stylededit/StyledEditWindow.h

     
    133133            bool                fCaseSensitive;
    134134            bool                fWrapAround;
    135135            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;
    136140
    137141            StyledEditView*     fTextView;
    138142            BScrollView*        fScrollView;