Ticket #5535: SE_PersistenWnd2.diff

File SE_PersistenWnd2.diff, 2.5 KB (added by x-ist, 14 years ago)

Second try, Now using BNode..

  • StyledEditWindow.cpp

     
    2626#include <Debug.h>
    2727#include <File.h>
    2828#include <FilePanel.h>
     29#include <fs_attr.h>
    2930#include <Locale.h>
    3031#include <Menu.h>
    3132#include <MenuBar.h>
     
    4445
    4546const float kLineViewWidth = 30.0;
    4647
     48#define ATTRNAME_SE_INFO "se-info"
     49
    4750#undef TR_CONTEXT
    4851#define TR_CONTEXT "StyledEditWindow"
    4952
     
    315318
    316319
    317320void
     321StyledEditWindow::LoadAttrs()
     322{
     323    if (!fSaveMessage)
     324        return;
     325
     326    entry_ref dir;
     327    const char* name;
     328    if (fSaveMessage->FindRef("directory", &dir) != B_OK
     329        || fSaveMessage->FindString("name", &name) != B_OK)
     330        return;
     331
     332    BPath documentPath(&dir);
     333    documentPath.Append(name);
     334
     335    BNode documentNode(documentPath.Path());
     336    if (documentNode.InitCheck() != B_OK)
     337        return;
     338   
     339    BRect newFrame(Frame());
     340    ssize_t bytesRead = documentNode.ReadAttr(ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &newFrame, sizeof(BRect));
     341   
     342    if (bytesRead == -1)
     343        return;
     344   
     345    MoveTo(newFrame.left, newFrame.top);
     346    ResizeTo(newFrame.Width(), newFrame.Height());
     347}
     348
     349void
     350StyledEditWindow::SaveAttrs()
     351{
     352    if (!fSaveMessage)
     353        return;
     354
     355    entry_ref dir;
     356    const char* name;
     357    if (fSaveMessage->FindRef("directory", &dir) != B_OK
     358        || fSaveMessage->FindString("name", &name) != B_OK)
     359        return;
     360
     361    BPath documentPath(&dir);
     362    documentPath.Append(name);
     363
     364    BNode documentNode(documentPath.Path());
     365    if (documentNode.InitCheck() != B_OK)
     366        return;
     367   
     368    BRect frame(Frame());   
     369    documentNode.WriteAttr(ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &frame, sizeof(BRect));
     370}
     371
     372
     373void
    318374StyledEditWindow::MessageReceived(BMessage* message)
    319375{
    320376    if (message->WasDropped()) {
     
    768824void
    769825StyledEditWindow::Quit()
    770826{
     827    SaveAttrs();
    771828    styled_edit_app->CloseDocument();
    772829    BWindow::Quit();
    773830}
     
    10351092        fSaveMessage->AddRef("directory", &parentRef);
    10361093        fSaveMessage->AddString("name", name);
    10371094        SetTitle(name);
     1095       
     1096        LoadAttrs();
    10381097    }
    10391098    fTextView->Select(0, 0);
    10401099}
  • StyledEditWindow.h

     
    4848
    4949    private:
    5050        void            InitWindow(uint32 encoding = 0);
     51        void            LoadAttrs();
     52        void            SaveAttrs();       
    5153        bool            Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
    5254        void            FindSelection();
    5355        bool            Replace(BString findthis, BString replacewith, bool casesens,