* Applied patch by x-ist that adds StyledEdit storing its window position and

size per document in a se-info attribute.
* Minor style changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36656 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-05-06 15:35:50 +00:00
parent 1d99c58c7b
commit a723b3d499
2 changed files with 86 additions and 12 deletions
+72 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009, Haiku, Inc. All Rights Reserved. * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,6 +9,7 @@
* Jonas Sundström * Jonas Sundström
*/ */
#include "Constants.h" #include "Constants.h"
#include "ColorMenuItem.h" #include "ColorMenuItem.h"
#include "FindWindow.h" #include "FindWindow.h"
@@ -26,6 +27,7 @@
#include <Debug.h> #include <Debug.h>
#include <File.h> #include <File.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <fs_attr.h>
#include <Locale.h> #include <Locale.h>
#include <Menu.h> #include <Menu.h>
#include <MenuBar.h> #include <MenuBar.h>
@@ -44,9 +46,12 @@ using namespace BPrivate;
const float kLineViewWidth = 30.0; const float kLineViewWidth = 30.0;
#define ATTRNAME_SE_INFO "se-info"
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "StyledEditWindow" #define TR_CONTEXT "StyledEditWindow"
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{ {
@@ -80,6 +85,7 @@ StyledEditWindow::~StyledEditWindow()
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "Menus" #define TR_CONTEXT "Menus"
void void
StyledEditWindow::InitWindow(uint32 encoding) StyledEditWindow::InitWindow(uint32 encoding)
{ {
@@ -314,6 +320,61 @@ StyledEditWindow::InitWindow(uint32 encoding)
} }
void
StyledEditWindow::LoadAttrs()
{
if (!fSaveMessage)
return;
entry_ref dir;
const char* name;
if (fSaveMessage->FindRef("directory", &dir) != B_OK
|| fSaveMessage->FindString("name", &name) != B_OK)
return;
BPath documentPath(&dir);
documentPath.Append(name);
BNode documentNode(documentPath.Path());
if (documentNode.InitCheck() != B_OK)
return;
BRect newFrame(Frame());
ssize_t bytesRead = documentNode.ReadAttr(ATTRNAME_SE_INFO, B_RECT_TYPE,
0, &newFrame, sizeof(BRect));
if (bytesRead < 0)
return;
MoveTo(newFrame.left, newFrame.top);
ResizeTo(newFrame.Width(), newFrame.Height());
}
void
StyledEditWindow::SaveAttrs()
{
if (!fSaveMessage)
return;
entry_ref dir;
const char* name;
if (fSaveMessage->FindRef("directory", &dir) != B_OK
|| fSaveMessage->FindString("name", &name) != B_OK)
return;
BPath documentPath(&dir);
documentPath.Append(name);
BNode documentNode(documentPath.Path());
if (documentNode.InitCheck() != B_OK)
return;
BRect frame(Frame());
documentNode.WriteAttr(ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &frame,
sizeof(BRect));
}
void void
StyledEditWindow::MessageReceived(BMessage* message) StyledEditWindow::MessageReceived(BMessage* message)
{ {
@@ -768,6 +829,7 @@ StyledEditWindow::MenusBeginning()
void void
StyledEditWindow::Quit() StyledEditWindow::Quit()
{ {
SaveAttrs();
styled_edit_app->CloseDocument(); styled_edit_app->CloseDocument();
BWindow::Quit(); BWindow::Quit();
} }
@@ -791,6 +853,7 @@ bs_printf(BString* string, const char* format, ...)
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "QuitAlert" #define TR_CONTEXT "QuitAlert"
bool bool
StyledEditWindow::QuitRequested() StyledEditWindow::QuitRequested()
{ {
@@ -821,6 +884,7 @@ StyledEditWindow::QuitRequested()
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "SaveAlert" #define TR_CONTEXT "SaveAlert"
status_t status_t
StyledEditWindow::Save(BMessage* message) StyledEditWindow::Save(BMessage* message)
{ {
@@ -900,6 +964,7 @@ StyledEditWindow::Save(BMessage* message)
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "Open_and_SaveAsPanel" #define TR_CONTEXT "Open_and_SaveAsPanel"
status_t status_t
StyledEditWindow::SaveAs(BMessage* message) StyledEditWindow::SaveAs(BMessage* message)
{ {
@@ -953,6 +1018,7 @@ StyledEditWindow::SaveAs(BMessage* message)
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "LoadAlert" #define TR_CONTEXT "LoadAlert"
status_t status_t
StyledEditWindow::_LoadFile(entry_ref* ref) StyledEditWindow::_LoadFile(entry_ref* ref)
{ {
@@ -1035,6 +1101,8 @@ StyledEditWindow::OpenFile(entry_ref* ref)
fSaveMessage->AddRef("directory", &parentRef); fSaveMessage->AddRef("directory", &parentRef);
fSaveMessage->AddString("name", name); fSaveMessage->AddString("name", name);
SetTitle(name); SetTitle(name);
LoadAttrs();
} }
fTextView->Select(0, 0); fTextView->Select(0, 0);
} }
@@ -1043,6 +1111,7 @@ StyledEditWindow::OpenFile(entry_ref* ref)
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "RevertToSavedAlert" #define TR_CONTEXT "RevertToSavedAlert"
void void
StyledEditWindow::RevertToSaved() StyledEditWindow::RevertToSaved()
{ {
@@ -1407,6 +1476,8 @@ StyledEditWindow::SetFontStyle(const char* fontFamily, const char* fontStyle)
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "Menus" #define TR_CONTEXT "Menus"
void void
StyledEditWindow::_UpdateCleanUndoRedoSaveRevert() StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
{ {
+5 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Haiku, Inc. All Rights Reserved. * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -16,6 +16,7 @@
#include <String.h> #include <String.h>
#include <Message.h> #include <Message.h>
struct entry_ref; struct entry_ref;
class BMenu; class BMenu;
@@ -48,6 +49,8 @@ class StyledEditWindow : public BWindow {
private: private:
void InitWindow(uint32 encoding = 0); void InitWindow(uint32 encoding = 0);
void LoadAttrs();
void SaveAttrs();
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch); bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
void FindSelection(); void FindSelection();
bool Replace(BString findthis, BString replacewith, bool casesens, bool Replace(BString findthis, BString replacewith, bool casesens,
@@ -123,5 +126,5 @@ class StyledEditWindow : public BWindow {
BMenu *fSavePanelEncodingMenu; BMenu *fSavePanelEncodingMenu;
}; };
#endif // STYLED_EDIT_WINDOW_H
#endif // STYLED_EDIT_WINDOW_H