Ticket #5535: SE_PersistentWnd.diff

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

Makes StyledEdit use attributes for storing window position and size.

  • 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    entry_ref documentRef;
     333    BPath documentPath(&dir);
     334    documentPath.Append(name);
     335   
     336    int fd = open(documentPath.Path(), O_RDONLY);
     337   
     338    BRect newFrame;
     339    ssize_t bytesRead = fs_read_attr(fd, ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &newFrame, sizeof(BRect));
     340   
     341    close(fd);
     342   
     343    if (-1 == bytesRead)
     344        return;
     345   
     346    MoveTo(newFrame.left, newFrame.top);
     347    ResizeTo(newFrame.right - newFrame.left ,
     348                newFrame.bottom - newFrame.top);
     349}
     350
     351void
     352StyledEditWindow::SaveAttrs()
     353{
     354    if (!fSaveMessage)
     355        return;
     356
     357    entry_ref dir;
     358    const char* name;
     359    if (fSaveMessage->FindRef("directory", &dir) != B_OK
     360        || fSaveMessage->FindString("name", &name) != B_OK)
     361        return;
     362
     363    entry_ref documentRef;
     364    BPath documentPath(&dir);
     365    documentPath.Append(name);
     366   
     367    int fd = open(documentPath.Path(), O_WRONLY);
     368   
     369    BRect frame(Frame());
     370    fs_write_attr(fd, ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &frame, sizeof(BRect));
     371       
     372    close(fd);
     373}
     374
     375
     376void
    318377StyledEditWindow::MessageReceived(BMessage* message)
    319378{
    320379    if (message->WasDropped()) {
     
    768827void
    769828StyledEditWindow::Quit()
    770829{
     830    SaveAttrs();
    771831    styled_edit_app->CloseDocument();
    772832    BWindow::Quit();
    773833}
     
    10351095        fSaveMessage->AddRef("directory", &parentRef);
    10361096        fSaveMessage->AddString("name", name);
    10371097        SetTitle(name);
     1098       
     1099        LoadAttrs();
    10381100    }
    10391101    fTextView->Select(0, 0);
    10401102}
  • 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,