* 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:
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -129,7 +135,7 @@ StyledEditWindow::InitWindow(uint32 encoding)
|
|||||||
true, true, B_PLAIN_BORDER);
|
true, true, B_PLAIN_BORDER);
|
||||||
AddChild(fScrollView);
|
AddChild(fScrollView);
|
||||||
fTextView->MakeFocus(true);
|
fTextView->MakeFocus(true);
|
||||||
|
|
||||||
// Add "File"-menu:
|
// Add "File"-menu:
|
||||||
BMenu* menu = new BMenu(TR("File"));
|
BMenu* menu = new BMenu(TR("File"));
|
||||||
fMenuBar->AddItem(menu);
|
fMenuBar->AddItem(menu);
|
||||||
@@ -272,7 +278,7 @@ StyledEditWindow::InitWindow(uint32 encoding)
|
|||||||
if (get_font_family(i, &family) == B_OK) {
|
if (get_font_family(i, &family) == B_OK) {
|
||||||
subMenu = new BMenu(family);
|
subMenu = new BMenu(family);
|
||||||
subMenu->SetRadioMode(true);
|
subMenu->SetRadioMode(true);
|
||||||
fFontMenu->AddItem(menuItem = new BMenuItem(subMenu,
|
fFontMenu->AddItem(menuItem = new BMenuItem(subMenu,
|
||||||
new BMessage(FONT_FAMILY)));
|
new BMessage(FONT_FAMILY)));
|
||||||
|
|
||||||
int32 numStyles = count_font_styles(family);
|
int32 numStyles = count_font_styles(family);
|
||||||
@@ -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()
|
||||||
{
|
{
|
||||||
@@ -799,7 +862,7 @@ StyledEditWindow::QuitRequested()
|
|||||||
|
|
||||||
BString alertText;
|
BString alertText;
|
||||||
bs_printf(&alertText, TR("Save changes to the document \"%s\"? "), Title());
|
bs_printf(&alertText, TR("Save changes to the document \"%s\"? "), Title());
|
||||||
|
|
||||||
int32 index = _ShowAlert(alertText, TR("Cancel"), TR("Don't save"), TR("Save"),
|
int32 index = _ShowAlert(alertText, TR("Cancel"), TR("Don't save"), TR("Save"),
|
||||||
B_WARNING_ALERT);
|
B_WARNING_ALERT);
|
||||||
|
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -862,7 +926,7 @@ StyledEditWindow::Save(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = fTextView->WriteStyledEditFile(&file);
|
status = fTextView->WriteStyledEditFile(&file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -32,7 +33,7 @@ class StyledEditWindow : public BWindow {
|
|||||||
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
|
StyledEditWindow(BRect frame, int32 id, uint32 encoding = 0);
|
||||||
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
|
StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding = 0);
|
||||||
virtual ~StyledEditWindow();
|
virtual ~StyledEditWindow();
|
||||||
|
|
||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
@@ -40,17 +41,19 @@ class StyledEditWindow : public BWindow {
|
|||||||
|
|
||||||
status_t Save(BMessage *message = 0);
|
status_t Save(BMessage *message = 0);
|
||||||
status_t SaveAs(BMessage *message = 0);
|
status_t SaveAs(BMessage *message = 0);
|
||||||
void OpenFile(entry_ref *ref);
|
void OpenFile(entry_ref *ref);
|
||||||
status_t PageSetup(const char *documentname);
|
status_t PageSetup(const char *documentname);
|
||||||
void Print(const char *documentname);
|
void Print(const char *documentname);
|
||||||
void SearchAllWindows(BString find, BString replace, bool casesens);
|
void SearchAllWindows(BString find, BString replace, bool casesens);
|
||||||
bool IsDocumentEntryRef(const entry_ref *ref);
|
bool IsDocumentEntryRef(const entry_ref *ref);
|
||||||
|
|
||||||
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,
|
||||||
bool wrap, bool backsearch);
|
bool wrap, bool backsearch);
|
||||||
void ReplaceAll(BString find, BString replace, bool casesens);
|
void ReplaceAll(BString find, BString replace, bool casesens);
|
||||||
void SetFontSize(float fontSize);
|
void SetFontSize(float fontSize);
|
||||||
@@ -65,7 +68,7 @@ class StyledEditWindow : public BWindow {
|
|||||||
|
|
||||||
BMenuBar *fMenuBar;
|
BMenuBar *fMenuBar;
|
||||||
BMessage *fPrintSettings;
|
BMessage *fPrintSettings;
|
||||||
BMessage *fSaveMessage;
|
BMessage *fSaveMessage;
|
||||||
BMenu *fRecentMenu;
|
BMenu *fRecentMenu;
|
||||||
|
|
||||||
BMenu *fFontMenu;
|
BMenu *fFontMenu;
|
||||||
@@ -123,5 +126,5 @@ class StyledEditWindow : public BWindow {
|
|||||||
BMenu *fSavePanelEncodingMenu;
|
BMenu *fSavePanelEncodingMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STYLED_EDIT_WINDOW_H
|
|
||||||
|
|
||||||
|
#endif // STYLED_EDIT_WINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user