style cleanup ; undo, revert, redo, save, quit functions fixed up ; no more extra windows ; quit when all windows are closed ; fix grey lines when scrolling
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1848 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
96462df1ad
commit
ed48868f63
@ -2,13 +2,8 @@
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
#ifndef _GRAPHICS_DEFS_H
|
||||
#include <GraphicsDefs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _SUPPORT_DEFS_H
|
||||
#include <SupportDefs.h>
|
||||
#endif
|
||||
|
||||
//See if this takes care of some problems with closing the application
|
||||
//by clicking the windowtab
|
||||
@ -17,7 +12,6 @@
|
||||
//seems to work, 021021
|
||||
#define APP_SIGNATURE "application/x-vnd.obos.styled-edit"
|
||||
|
||||
const float MENU_BAR_HEIGHT= 19.0;
|
||||
const float TEXT_INSET= 3.0;
|
||||
|
||||
/*Messages for window registry with application*/
|
||||
@ -73,8 +67,4 @@ const uint32 DISABLE_ITEMS ='DIit';
|
||||
const uint32 CHANGE_WINDOW ='CHwi';
|
||||
const uint32 TEXT_CHANGED ='TEch';
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
@ -1,66 +1,68 @@
|
||||
|
||||
#ifndef CONSTANTS_H
|
||||
#include <Autolock.h>
|
||||
#include "Constants.h"
|
||||
#endif
|
||||
|
||||
#ifndef STYLED_EDIT_APP
|
||||
#include "StyledEditApp.h"
|
||||
#endif
|
||||
#include "StyledEditWindow.h"
|
||||
|
||||
BRect windowRect(7,25,599,399);
|
||||
|
||||
BRect windowRect(50,50,599,399);
|
||||
StyledEditApp * styled_edit_app;
|
||||
|
||||
StyledEditApp::StyledEditApp()
|
||||
: BApplication(APP_SIGNATURE)
|
||||
{
|
||||
|
||||
new StyledEditWindow(windowRect);
|
||||
fOpenPanel= new BFilePanel;
|
||||
|
||||
fWindowCount= 0;
|
||||
fNext_Untitled_Window= 1;
|
||||
styled_edit_app = this;
|
||||
} /***StyledEditApp::StyledEditApp()***/
|
||||
|
||||
|
||||
void StyledEditApp::MessageReceived(BMessage *message){
|
||||
void
|
||||
StyledEditApp::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MENU_NEW:
|
||||
OpenDocument();
|
||||
break;
|
||||
case MENU_OPEN:
|
||||
fOpenPanel->Show(); //
|
||||
break;
|
||||
case WINDOW_REGISTRY_ADD:
|
||||
{
|
||||
bool need_id= false;
|
||||
BMessage reply(WINDOW_REGISTRY_ADDED);
|
||||
|
||||
if(message->FindBool("need_id", &need_id)== B_OK)
|
||||
{
|
||||
if(need_id)
|
||||
{
|
||||
reply.AddInt32("new_window_number", fNext_Untitled_Window);
|
||||
fNext_Untitled_Window++;
|
||||
}
|
||||
fWindowCount++;
|
||||
}
|
||||
reply.AddRect("rect",windowRect);
|
||||
windowRect.OffsetBy(20,20);
|
||||
message->SendReply(&reply);
|
||||
break;
|
||||
}
|
||||
case WINDOW_REGISTRY_SUB:
|
||||
fWindowCount--;
|
||||
if (!fWindowCount)
|
||||
{
|
||||
Quit();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StyledEditApp::RefsReceived(BMessage *message){
|
||||
void
|
||||
StyledEditApp::OpenDocument()
|
||||
{
|
||||
new StyledEditWindow(windowRect,fNext_Untitled_Window++);
|
||||
windowRect.OffsetBy(20,20); // todo: wrap around screen
|
||||
fWindowCount++;
|
||||
}
|
||||
|
||||
void
|
||||
StyledEditApp::OpenDocument(entry_ref * ref)
|
||||
{
|
||||
new StyledEditWindow(windowRect,ref);
|
||||
windowRect.OffsetBy(20,20); // todo: wrap around screen
|
||||
fWindowCount++;
|
||||
}
|
||||
|
||||
void
|
||||
StyledEditApp::CloseDocument()
|
||||
{
|
||||
fWindowCount--;
|
||||
if (fWindowCount == 0) {
|
||||
BAutolock lock(this);
|
||||
Quit();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StyledEditApp::RefsReceived(BMessage *message)
|
||||
{
|
||||
int32 refNum;
|
||||
entry_ref ref;
|
||||
status_t err;
|
||||
@ -69,20 +71,32 @@ void StyledEditApp::RefsReceived(BMessage *message){
|
||||
do {
|
||||
if((err= message->FindRef("refs", refNum, &ref)) != B_OK)
|
||||
return;
|
||||
new StyledEditWindow(windowRect, &ref);
|
||||
OpenDocument(&ref);
|
||||
refNum++;
|
||||
} while(1);
|
||||
} /***StyledEditApp::RefsReceived();***/
|
||||
|
||||
int32 StyledEditApp::NumberOfWindows(){
|
||||
void
|
||||
StyledEditApp::ReadyToRun()
|
||||
{
|
||||
if (fWindowCount == 0) {
|
||||
OpenDocument();
|
||||
}
|
||||
}
|
||||
|
||||
int32
|
||||
StyledEditApp::NumberOfWindows()
|
||||
{
|
||||
|
||||
return fWindowCount;
|
||||
|
||||
}/***StyledEditApp::NumberOfWindows()***/
|
||||
|
||||
int main(){
|
||||
StyledEditApp StyledEdit;
|
||||
StyledEdit.Run();
|
||||
int
|
||||
main()
|
||||
{
|
||||
StyledEditApp styledEdit;
|
||||
styledEdit.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2,21 +2,25 @@
|
||||
#ifndef STYLED_EDIT_APP
|
||||
#define STYLED_EDIT_APP
|
||||
|
||||
#ifndef _APPLICATION_H
|
||||
#include <Application.h>
|
||||
#endif
|
||||
#include <Message.h>
|
||||
#include <FilePanel.h>
|
||||
|
||||
#ifndef STYLED_EDIT_WINDOW_H
|
||||
#include "StyledEditWindow.h"
|
||||
#endif
|
||||
class StyledEditWindow;
|
||||
|
||||
class StyledEditApp: public BApplication{
|
||||
class StyledEditApp
|
||||
: public BApplication
|
||||
{
|
||||
public:
|
||||
StyledEditApp();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void RefsReceived(BMessage *message);
|
||||
int32 NumberOfWindows();
|
||||
virtual void ReadyToRun();
|
||||
|
||||
int32 NumberOfWindows();
|
||||
void OpenDocument();
|
||||
void OpenDocument(entry_ref * ref);
|
||||
void CloseDocument();
|
||||
|
||||
private:
|
||||
BFilePanel *fOpenPanel;
|
||||
@ -24,9 +28,7 @@ class StyledEditApp: public BApplication{
|
||||
int32 fNext_Untitled_Window;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
extern StyledEditApp * styled_edit_app;
|
||||
|
||||
#endif // STYLED_EDIT_APP
|
||||
|
@ -1,36 +1,27 @@
|
||||
#ifndef STYLED_EDIT_VIEW_H
|
||||
#include "StyledEditView.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MESSAGE_H
|
||||
#include <Message.h>
|
||||
#endif
|
||||
|
||||
#ifndef CONSTANTS_H
|
||||
#include "Constants.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MESSENGER_H
|
||||
#include <Messenger.h>
|
||||
#endif
|
||||
|
||||
#ifndef _RECT_H
|
||||
#include <Rect.h>
|
||||
#endif
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
#include "StyledEditView.h"
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler) : BTextView(viewFrame, "textview",
|
||||
textBounds, B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW){
|
||||
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *handler)
|
||||
: BTextView(viewFrame, "textview", textBounds,
|
||||
B_FOLLOW_ALL, B_FRAME_EVENTS|B_WILL_DRAW)
|
||||
{
|
||||
fHandler= handler;
|
||||
fMessenger= new BMessenger(handler);
|
||||
fSuppressChanges = false;
|
||||
}/***StyledEditView()***/
|
||||
|
||||
StyledEditView::~StyledEditView(){
|
||||
|
||||
}/***~StyledEditView***/
|
||||
|
||||
void StyledEditView::FrameResized(float width, float height){
|
||||
void
|
||||
StyledEditView::FrameResized(float width, float height)
|
||||
{
|
||||
BTextView::FrameResized(width, height);
|
||||
|
||||
if(DoesWordWrap()){
|
||||
@ -42,8 +33,27 @@ void StyledEditView::FrameResized(float width, float height){
|
||||
}
|
||||
}
|
||||
|
||||
void StyledEditView::Select(int32 start, int32 finish){
|
||||
status_t
|
||||
StyledEditView::GetStyledText(BPositionIO * stream)
|
||||
{
|
||||
status_t result = B_OK;
|
||||
fSuppressChanges = true;
|
||||
result = BTranslationUtils::GetStyledText(stream, this, NULL);
|
||||
fSuppressChanges = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
StyledEditView::Reset()
|
||||
{
|
||||
fSuppressChanges = true;
|
||||
SetText("");
|
||||
fSuppressChanges = false;
|
||||
}
|
||||
|
||||
void
|
||||
StyledEditView::Select(int32 start, int32 finish)
|
||||
{
|
||||
if(start==finish)
|
||||
fChangeMessage= new BMessage(DISABLE_ITEMS);
|
||||
else
|
||||
@ -54,40 +64,20 @@ void StyledEditView::Select(int32 start, int32 finish){
|
||||
BTextView::Select(start, finish);
|
||||
}
|
||||
|
||||
void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs){
|
||||
|
||||
void StyledEditView::InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs)
|
||||
{
|
||||
if (!fSuppressChanges)
|
||||
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
|
||||
|
||||
BTextView::InsertText(text, length, offset, runs);
|
||||
|
||||
}/****StyledEditView::InsertText()***/
|
||||
|
||||
void StyledEditView::DeleteText(int32 start, int32 finish){
|
||||
|
||||
void StyledEditView::DeleteText(int32 start, int32 finish)
|
||||
{
|
||||
if (!fSuppressChanges)
|
||||
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
|
||||
|
||||
BTextView::DeleteText(start, finish);
|
||||
|
||||
}/***StyledEditView::DeleteText***/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
#ifndef STYLED_EDIT_VIEW_H
|
||||
#define STYLED_EDIT_VIEW_H
|
||||
|
||||
#ifndef _TEXTVIEW_H
|
||||
#include <TextView.h>
|
||||
#endif
|
||||
#include <DataIO.h>
|
||||
|
||||
class StyledEditView : public BTextView {
|
||||
public:
|
||||
@ -12,6 +11,9 @@ class StyledEditView : public BTextView {
|
||||
|
||||
virtual void Select(int32 start, int32 finish);
|
||||
virtual void FrameResized(float width, float height);
|
||||
|
||||
virtual void Reset();
|
||||
virtual status_t GetStyledText(BPositionIO * stream);
|
||||
protected:
|
||||
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs);
|
||||
virtual void DeleteText(int32 start, int32 finish);
|
||||
@ -20,15 +22,7 @@ class StyledEditView : public BTextView {
|
||||
BHandler *fHandler;
|
||||
BMessage *fChangeMessage;
|
||||
BMessenger *fMessenger;
|
||||
bool fSuppressChanges;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // STYLED_EDIT_VIEW_H
|
||||
|
@ -1,81 +1,37 @@
|
||||
// Be-defined headers
|
||||
|
||||
#ifndef _ALERT_H
|
||||
#include <Alert.h>
|
||||
#endif
|
||||
|
||||
#ifndef _CLIPBOARD_H
|
||||
#include <Autolock.h>
|
||||
#include <Debug.h>
|
||||
#include <Clipboard.h>
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include <File.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MENU_H
|
||||
#include <Menu.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MENU_ITEM_H
|
||||
#include <MenuItem.h>
|
||||
#endif
|
||||
|
||||
#ifndef _PRINTSESSION_H
|
||||
#include <PrintJob.h>
|
||||
#endif
|
||||
|
||||
#ifndef _SCROLL_VIEW_H
|
||||
#include <ScrollView.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STRING_H
|
||||
#include <String.h>
|
||||
#endif
|
||||
|
||||
#ifndef _TRANSLATION_UTILS_H
|
||||
#include <TranslationUtils.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WINDOW_H
|
||||
#include <Window.h>
|
||||
#endif
|
||||
|
||||
//****** Application defined header files************/.
|
||||
#ifndef CONSTANTS_H
|
||||
#include "Constants.h"
|
||||
#endif
|
||||
|
||||
#ifndef COLOR_MENU_ITEM_H
|
||||
#include "ColorMenuItem.h"
|
||||
#endif
|
||||
|
||||
#ifndef FIND_WINDOW_H
|
||||
#include "FindWindow.h"
|
||||
#endif
|
||||
|
||||
#ifndef REPLACE_WINDOW_H
|
||||
#include "ReplaceWindow.h"
|
||||
#endif
|
||||
|
||||
#ifndef STYLED_EDIT_APP
|
||||
#include "StyledEditApp.h"
|
||||
#endif
|
||||
|
||||
#ifndef STYLED_EDIT_VIEW_H
|
||||
#include "StyledEditView.h"
|
||||
#endif
|
||||
|
||||
#ifndef STYLED_EDIT_WINDOW_H
|
||||
#include "StyledEditWindow.h"
|
||||
#endif
|
||||
|
||||
StyledEditWindow::StyledEditWindow(BRect frame)
|
||||
: BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0){
|
||||
StyledEditWindow::StyledEditWindow(BRect frame, int32 id)
|
||||
: BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0)
|
||||
{
|
||||
InitWindow();
|
||||
BString unTitled;
|
||||
unTitled.SetTo("Untitled ");
|
||||
unTitled << id;
|
||||
SetTitle(unTitled.String());
|
||||
fSaveItem->SetEnabled(true); // allow saving empty files
|
||||
Show();
|
||||
} /***StyledEditWindow()***/
|
||||
|
||||
@ -87,9 +43,8 @@ StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref)
|
||||
Show();
|
||||
} /***StyledEditWindow()***/
|
||||
|
||||
StyledEditWindow::~StyledEditWindow(){
|
||||
Unregister();
|
||||
|
||||
StyledEditWindow::~StyledEditWindow()
|
||||
{
|
||||
if (fSaveMessage)
|
||||
delete fSaveMessage;
|
||||
if (fPrintSettings)
|
||||
@ -98,14 +53,22 @@ StyledEditWindow::~StyledEditWindow(){
|
||||
delete fSavePanel;
|
||||
} /***~StyledEditWindow()***/
|
||||
|
||||
void StyledEditWindow::InitWindow(){
|
||||
|
||||
void
|
||||
StyledEditWindow::InitWindow()
|
||||
{
|
||||
fPrintSettings= NULL;
|
||||
fSaveMessage= NULL;
|
||||
fEnableItems= false;
|
||||
fFirstEdit= true;
|
||||
fUnDoneFlag= false;
|
||||
fTextSaved= true; //initial state, no text changed.
|
||||
|
||||
// undo modes
|
||||
fUndoFlag = false;
|
||||
fCanUndo = false;
|
||||
fRedoFlag = false;
|
||||
fCanRedo = false;
|
||||
|
||||
// clean modes
|
||||
fUndoCleans = false;
|
||||
fRedoCleans = false;
|
||||
fClean = true;
|
||||
|
||||
//search- state
|
||||
fReplaceString= "";
|
||||
@ -115,10 +78,7 @@ void StyledEditWindow::InitWindow(){
|
||||
fBackSearch= false;
|
||||
|
||||
//add menubar
|
||||
BRect menuBarRect;
|
||||
|
||||
menuBarRect= Bounds();
|
||||
fMenuBar= new BMenuBar(menuBarRect,"menubar");
|
||||
fMenuBar = new BMenuBar(BRect(0,0,0,0),"menubar");
|
||||
|
||||
AddChild(fMenuBar);
|
||||
|
||||
@ -128,7 +88,7 @@ void StyledEditWindow::InitWindow(){
|
||||
|
||||
viewFrame= Bounds();
|
||||
|
||||
viewFrame.top = MENU_BAR_HEIGHT; //021021
|
||||
viewFrame.top = fMenuBar->Bounds().Height()+1; //021021
|
||||
viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
viewFrame.left = B_V_SCROLL_BAR_WIDTH-15; //021021
|
||||
viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
||||
@ -144,7 +104,7 @@ void StyledEditWindow::InitWindow(){
|
||||
fTextView->SetStylable(true);
|
||||
|
||||
|
||||
fScrollView= new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, true, true, B_NO_BORDER);
|
||||
fScrollView= new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, true, true, B_PLAIN_BORDER);
|
||||
AddChild(fScrollView);
|
||||
fTextView->MakeFocus(true);
|
||||
|
||||
@ -158,6 +118,8 @@ void StyledEditWindow::InitWindow(){
|
||||
fMenuBar->AddItem(menu);
|
||||
|
||||
menu->AddItem(menuItem= new BMenuItem("New", new BMessage(MENU_NEW), 'N'));
|
||||
menuItem->SetTarget(be_app);
|
||||
|
||||
menu->AddItem(menuItem= new BMenuItem(new BMenu("Open..."), new BMessage(MENU_OPEN)));
|
||||
menuItem->SetShortcut('O',0);
|
||||
menuItem->SetTarget(be_app);
|
||||
@ -185,7 +147,6 @@ void StyledEditWindow::InitWindow(){
|
||||
|
||||
menu->AddItem(fUndoItem= new BMenuItem("Can't Undo", new BMessage(B_UNDO), 'Z'));
|
||||
fUndoItem->SetEnabled(false);
|
||||
fUndoItem-> SetTarget(fTextView);
|
||||
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(fCutItem= new BMenuItem("Cut", new BMessage(B_CUT), 'X'));
|
||||
@ -311,45 +272,15 @@ void StyledEditWindow::InitWindow(){
|
||||
fWrapItem->SetMarked(true);
|
||||
/***************************MENUS ADDED***********************/
|
||||
|
||||
|
||||
fSavePanel= new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false);
|
||||
Register(true);
|
||||
|
||||
} /***StyledEditWindow::Initwindow()***/
|
||||
|
||||
void StyledEditWindow::MessageReceived(BMessage *message){
|
||||
void
|
||||
StyledEditWindow::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what){
|
||||
case WINDOW_REGISTRY_ADDED:
|
||||
{
|
||||
|
||||
BRect rect;
|
||||
if (message->FindInt32("new_window_number", &fWindow_Id) == B_OK)
|
||||
{
|
||||
if (!fSaveMessage)
|
||||
{
|
||||
BString unTitled;
|
||||
unTitled.SetTo("Untitled ");
|
||||
unTitled << fWindow_Id;
|
||||
const char *title= unTitled.String();
|
||||
SetTitle(title);
|
||||
}
|
||||
}
|
||||
if (message->FindRect("rect", &rect) == B_OK)
|
||||
{
|
||||
MoveTo(rect.LeftTop());
|
||||
ResizeTo(rect.Width(), rect.Height());
|
||||
}
|
||||
Minimize(false);
|
||||
}
|
||||
break;
|
||||
/************file menu:***************/
|
||||
case MENU_NEW:
|
||||
{
|
||||
BRect newViewFrame;
|
||||
newViewFrame= Frame();
|
||||
new StyledEditWindow(newViewFrame);
|
||||
}
|
||||
break;
|
||||
case MENU_SAVE:
|
||||
{
|
||||
if(!fSaveMessage)
|
||||
@ -368,9 +299,11 @@ void StyledEditWindow::InitWindow(){
|
||||
RevertToSaved();
|
||||
break;
|
||||
case MENU_CLOSE:{
|
||||
if(this->QuitRequested())
|
||||
if(this->QuitRequested()) {
|
||||
BAutolock lock(this);
|
||||
Quit();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MENU_PAGESETUP:
|
||||
PageSetup(fTextView->Window()->Title());
|
||||
@ -383,6 +316,14 @@ void StyledEditWindow::InitWindow(){
|
||||
break;
|
||||
/*********commands from the "Edit"-menu:**************/
|
||||
case B_UNDO:
|
||||
ASSERT(fCanUndo || fCanRedo);
|
||||
ASSERT(!(fCanUndo && fCanRedo));
|
||||
if (fCanUndo) {
|
||||
fUndoFlag = true;
|
||||
}
|
||||
if (fCanRedo) {
|
||||
fRedoFlag = true;
|
||||
}
|
||||
fTextView->Undo(be_clipboard);
|
||||
break;
|
||||
case B_CUT:
|
||||
@ -536,23 +477,52 @@ void StyledEditWindow::InitWindow(){
|
||||
break;
|
||||
case TEXT_CHANGED:
|
||||
{
|
||||
fSaveItem-> SetEnabled(true);
|
||||
fTextSaved= false;
|
||||
|
||||
if(fFirstEdit){
|
||||
if (fUndoFlag) {
|
||||
if (fUndoCleans) {
|
||||
// we cleaned!
|
||||
fClean = true;
|
||||
fUndoCleans = false;
|
||||
} else if (fClean) {
|
||||
// if we were clean
|
||||
// then a redo will make us clean again
|
||||
fRedoCleans = true;
|
||||
fClean = false;
|
||||
}
|
||||
// set mode
|
||||
fCanUndo = false;
|
||||
fCanRedo = true;
|
||||
fUndoItem->SetLabel("Redo Typing");
|
||||
fUndoItem->SetEnabled(true);
|
||||
fUndoFlag = false;
|
||||
} else {
|
||||
if (fRedoFlag && fRedoCleans) {
|
||||
// we cleaned!
|
||||
fClean = true;
|
||||
fRedoCleans = false;
|
||||
} else if (fClean) {
|
||||
// if we were clean
|
||||
// then an undo will make us clean again
|
||||
fUndoCleans = true;
|
||||
fClean = false;
|
||||
} else {
|
||||
// no more cleaning from undo now...
|
||||
fUndoCleans = false;
|
||||
}
|
||||
// set mode
|
||||
fCanUndo = true;
|
||||
fCanRedo = false;
|
||||
fUndoItem->SetLabel("Undo Typing");
|
||||
fUndoItem->SetEnabled(true);
|
||||
fRedoFlag = false;
|
||||
}
|
||||
|
||||
if (fUnDoneFlag){
|
||||
fUndoItem->SetLabel("Redo Typing");
|
||||
fUnDoneFlag= false;
|
||||
if (fClean) {
|
||||
fRevertItem->SetEnabled(false);
|
||||
fSaveItem->SetEnabled(fSaveMessage == NULL);
|
||||
} else {
|
||||
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
||||
fSaveItem->SetEnabled(true);
|
||||
}
|
||||
else{
|
||||
fUndoItem->SetLabel("Undo Typing");
|
||||
fUnDoneFlag= true;
|
||||
}
|
||||
|
||||
// clear flags
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -562,26 +532,20 @@ void StyledEditWindow::InitWindow(){
|
||||
}/***StyledEditWindow::MessageReceived() ***/
|
||||
|
||||
|
||||
void StyledEditWindow::Register(bool need_id) {
|
||||
BMessenger messenger(APP_SIGNATURE);
|
||||
BMessage message(WINDOW_REGISTRY_ADD);
|
||||
|
||||
message.AddBool("need_id", need_id);
|
||||
messenger.SendMessage(&message, this);
|
||||
}/***Register()***/
|
||||
|
||||
|
||||
void StyledEditWindow::Unregister(void){
|
||||
BMessenger messenger(APP_SIGNATURE);
|
||||
messenger.SendMessage(new BMessage(WINDOW_REGISTRY_SUB));
|
||||
}/***Unregister()***/
|
||||
|
||||
|
||||
bool StyledEditWindow::QuitRequested(){
|
||||
void
|
||||
StyledEditWindow::Quit()
|
||||
{
|
||||
styled_edit_app->CloseDocument();
|
||||
BWindow::Quit();
|
||||
}
|
||||
|
||||
bool
|
||||
StyledEditWindow::QuitRequested()
|
||||
{
|
||||
int32 buttonIndex= 0;
|
||||
|
||||
if(!fTextSaved){
|
||||
if (fClean) return true;
|
||||
|
||||
BAlert *saveAlert;
|
||||
BString alertText;
|
||||
alertText.SetTo("Save changes to the document ");
|
||||
@ -592,26 +556,23 @@ bool StyledEditWindow::QuitRequested(){
|
||||
saveAlert->SetShortcut(0, B_ESCAPE);
|
||||
buttonIndex= saveAlert->Go();
|
||||
|
||||
|
||||
if(buttonIndex==0) //"cancel": dont save, dont close the window
|
||||
if (buttonIndex==0) { //"cancel": dont save, dont close the window
|
||||
return false;
|
||||
else if(buttonIndex==1) // "don't save": just close the window
|
||||
} else if(buttonIndex==1) { // "don't save": just close the window
|
||||
return true;
|
||||
else if(!fSaveMessage){ //save as
|
||||
} else if(!fSaveMessage) { //save as
|
||||
DispatchMessage(new BMessage(MENU_SAVEAS), this);
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
DispatchMessage(new BMessage(B_SAVE_REQUESTED), this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return true;
|
||||
|
||||
}/***QuitRequested()***/
|
||||
|
||||
status_t StyledEditWindow::Save(BMessage *message){
|
||||
status_t
|
||||
StyledEditWindow::Save(BMessage *message)
|
||||
{
|
||||
entry_ref ref;
|
||||
const char *name;
|
||||
status_t err;
|
||||
@ -654,14 +615,18 @@ status_t StyledEditWindow::Save(BMessage *message){
|
||||
}
|
||||
}
|
||||
|
||||
// clear clean modes
|
||||
fSaveItem->SetEnabled(false);
|
||||
fTextSaved= true;
|
||||
fRevertItem-> SetEnabled(true);
|
||||
fRevertItem->SetEnabled(false);
|
||||
fUndoCleans = false;
|
||||
fRedoCleans = false;
|
||||
fClean = true;
|
||||
return err;
|
||||
} /***Save()***/
|
||||
|
||||
void StyledEditWindow::OpenFile(entry_ref *ref){
|
||||
|
||||
void
|
||||
StyledEditWindow::OpenFile(entry_ref *ref)
|
||||
{
|
||||
BFile file;
|
||||
status_t fileinit;
|
||||
|
||||
@ -669,7 +634,7 @@ void StyledEditWindow::OpenFile(entry_ref *ref){
|
||||
|
||||
if(fileinit== B_OK){
|
||||
status_t result;
|
||||
result= BTranslationUtils::GetStyledText(&file, fTextView, NULL); //he he he :)
|
||||
result = fTextView->GetStyledText(&file); //he he he :)
|
||||
|
||||
if(result==B_OK){
|
||||
fSaveMessage= new BMessage(B_SAVE_REQUESTED);
|
||||
@ -685,14 +650,14 @@ void StyledEditWindow::OpenFile(entry_ref *ref){
|
||||
fSaveMessage->AddRef("directory",&parentRef);
|
||||
fSaveMessage->AddString("name", name);
|
||||
SetTitle(name);
|
||||
fRevertItem-> SetEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}/*** StyledEditWindow::OpenFile() ***/
|
||||
|
||||
void StyledEditWindow::RevertToSaved(){
|
||||
//translationutils here as well
|
||||
void
|
||||
StyledEditWindow::RevertToSaved()
|
||||
{ //translationutils here as well
|
||||
entry_ref ref;
|
||||
const char *name;
|
||||
|
||||
@ -702,12 +667,27 @@ void StyledEditWindow::RevertToSaved(){
|
||||
BDirectory dir(&ref);
|
||||
|
||||
BFile file(&dir, name, B_READ_ONLY | B_CREATE_FILE);
|
||||
fTextView->SetText(""); //clear the textview...
|
||||
BTranslationUtils::GetStyledText(&file, fTextView, NULL); //and fill it from the file
|
||||
fTextView->Reset(); //clear the textview...
|
||||
fTextView->GetStyledText(&file); //and fill it from the file
|
||||
|
||||
// clear undo modes
|
||||
fUndoItem->SetLabel("Can't Undo");
|
||||
fUndoItem->SetEnabled(false);
|
||||
fUndoFlag = false;
|
||||
fCanUndo = false;
|
||||
fRedoFlag = false;
|
||||
fCanRedo = false;
|
||||
// clear clean modes
|
||||
fSaveItem->SetEnabled(false);
|
||||
fRevertItem->SetEnabled(false);
|
||||
fUndoCleans = false;
|
||||
fRedoCleans = false;
|
||||
fClean = true;
|
||||
}/***StyledEditWindow::RevertToSaved()***/
|
||||
|
||||
status_t StyledEditWindow::PageSetup(const char *documentname){
|
||||
|
||||
status_t
|
||||
StyledEditWindow::PageSetup(const char *documentname)
|
||||
{
|
||||
status_t result= B_ERROR;
|
||||
|
||||
BPrintJob printJob(documentname);
|
||||
@ -727,8 +707,9 @@ status_t StyledEditWindow::PageSetup(const char *documentname){
|
||||
return result;
|
||||
}/***StyledEditWindow::PageSetup()***/
|
||||
|
||||
void StyledEditWindow::Print(const char *documentname){
|
||||
|
||||
void
|
||||
StyledEditWindow::Print(const char *documentname)
|
||||
{
|
||||
BPrintJob printJob(documentname);
|
||||
|
||||
if (fPrintSettings== NULL){
|
||||
@ -775,8 +756,9 @@ void StyledEditWindow::Print(const char *documentname){
|
||||
}
|
||||
}/***StyledEditWindow::Print()***/
|
||||
|
||||
bool StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool backsearch){
|
||||
|
||||
bool
|
||||
StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool backsearch)
|
||||
{
|
||||
int32 start;
|
||||
int32 finish;
|
||||
int32 strlen;
|
||||
@ -801,19 +783,19 @@ bool StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool bac
|
||||
else
|
||||
start= viewText.IFindFirst(string, textFinish); //i.e this one...
|
||||
|
||||
|
||||
if(start!= B_ERROR) {
|
||||
finish= start+ strlen;
|
||||
fTextView->Select(start, finish);
|
||||
fTextView->ScrollToSelection();
|
||||
return true;
|
||||
} else
|
||||
} else {
|
||||
return false;
|
||||
|
||||
}
|
||||
}/***StyledEditWindow::Search***/
|
||||
|
||||
void StyledEditWindow::FindSelection(){
|
||||
|
||||
void
|
||||
StyledEditWindow::FindSelection()
|
||||
{
|
||||
int32 selectionStart, selectionFinish;
|
||||
fTextView->GetSelection(&selectionStart,&selectionFinish);
|
||||
|
||||
@ -828,8 +810,9 @@ void StyledEditWindow::FindSelection(){
|
||||
|
||||
}/***StyledEditWindow::FindSelection()***/
|
||||
|
||||
void StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch){
|
||||
|
||||
void
|
||||
StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch)
|
||||
{
|
||||
int32 start;
|
||||
int32 replaceLength;
|
||||
int32 findLength;
|
||||
@ -862,15 +845,17 @@ void StyledEditWindow::Replace(BString findthis, BString replaceWith, bool case
|
||||
|
||||
}/***StyledEditWindow::Replace()***/
|
||||
|
||||
void StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens){
|
||||
|
||||
void
|
||||
StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens)
|
||||
{
|
||||
while(Search(findIt, caseSens, true, false))
|
||||
Replace(findIt, replaceWith, caseSens, true, false);
|
||||
|
||||
}/***StyledEditWindow::ReplaceAll()***/
|
||||
|
||||
void StyledEditWindow::SearchAllWindows(BString find, BString replace, bool casesens){
|
||||
|
||||
void
|
||||
StyledEditWindow::SearchAllWindows(BString find, BString replace, bool casesens)
|
||||
{
|
||||
int32 numWindows;
|
||||
numWindows= be_app->CountWindows();
|
||||
|
||||
@ -893,8 +878,9 @@ void StyledEditWindow::SearchAllWindows(BString find, BString replace, bool case
|
||||
}/***StyledEditWindow::SearchAllWindows***/
|
||||
|
||||
|
||||
void StyledEditWindow::SetFontSize(float fontSize){
|
||||
|
||||
void
|
||||
StyledEditWindow::SetFontSize(float fontSize)
|
||||
{
|
||||
uint32 sameProperties;
|
||||
BFont font;
|
||||
|
||||
@ -903,7 +889,9 @@ void StyledEditWindow::SetFontSize(float fontSize){
|
||||
fTextView->SetFontAndColor(&font,B_FONT_SIZE);
|
||||
}/***StyledEditWindow::SetFontSize()***/
|
||||
|
||||
void StyledEditWindow::SetFontColor(rgb_color *color){
|
||||
void
|
||||
StyledEditWindow::SetFontColor(rgb_color *color)
|
||||
{
|
||||
uint32 sameProperties;
|
||||
BFont font;
|
||||
|
||||
@ -912,7 +900,9 @@ void StyledEditWindow::SetFontColor(rgb_color *color){
|
||||
|
||||
}/***StyledEditWindow::SetFontColor()***/
|
||||
|
||||
void StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle){
|
||||
void
|
||||
StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
|
||||
{
|
||||
BFont font;
|
||||
uint32 sameProperties;
|
||||
|
||||
@ -925,4 +915,3 @@ void StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyl
|
||||
superItem->SetMarked(true);
|
||||
|
||||
}/***StyledEditWindow::SetFontStyle()***/
|
||||
|
||||
|
@ -1,47 +1,25 @@
|
||||
|
||||
#ifndef STYLED_EDIT_WINDOW_H
|
||||
#define STYLED_EDIT_WINDOW_H
|
||||
|
||||
#ifndef _FILE_PANEL_H
|
||||
#include <FilePanel.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MENUBAR_H
|
||||
#include <MenuBar.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MESSAGE_H
|
||||
#include <Message.h>
|
||||
#endif
|
||||
|
||||
#ifndef _RECT_H
|
||||
#include <Rect.h>
|
||||
#endif
|
||||
|
||||
#ifndef _STRING_H
|
||||
#include <String.h>
|
||||
#endif
|
||||
|
||||
#ifndef _TEXTVIEW_H
|
||||
#include <TextView.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WINDOW_H
|
||||
#include <Window.h>
|
||||
#endif
|
||||
|
||||
#ifndef STYLED_EDIT_VIEW_H
|
||||
#include "StyledEditView.h"
|
||||
#endif
|
||||
class StyledEditView;
|
||||
|
||||
|
||||
class StyledEditWindow: public BWindow{
|
||||
class StyledEditWindow
|
||||
: public BWindow
|
||||
{
|
||||
public:
|
||||
StyledEditWindow(BRect frame);
|
||||
StyledEditWindow(BRect frame, int32 id);
|
||||
StyledEditWindow(BRect frame, entry_ref *ref);
|
||||
~StyledEditWindow();
|
||||
|
||||
|
||||
virtual void Quit();
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
@ -53,8 +31,6 @@ class StyledEditWindow: public BWindow{
|
||||
|
||||
private:
|
||||
void InitWindow();
|
||||
void Register(bool need_id);
|
||||
void Unregister(void);
|
||||
bool Search(BString searchfor, bool casesens, bool wrap, bool backsearch);
|
||||
void FindSelection();
|
||||
void Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
|
||||
@ -64,7 +40,6 @@ class StyledEditWindow: public BWindow{
|
||||
void SetFontStyle(const char *fontFamily, const char *fontStyle);
|
||||
void RevertToSaved();
|
||||
|
||||
|
||||
BMenuBar *fMenuBar;
|
||||
BMessage *fPrintSettings;
|
||||
BMessage *fSaveMessage;
|
||||
@ -77,18 +52,26 @@ class StyledEditWindow: public BWindow{
|
||||
BMenuItem *fWrapItem;
|
||||
BString fStringToFind;
|
||||
BString fReplaceString;
|
||||
bool fEnableItems;
|
||||
bool fFirstEdit;
|
||||
bool fTextSaved;
|
||||
bool fUnDoneFlag;
|
||||
|
||||
// undo modes
|
||||
bool fUndoFlag; // we just did an undo action
|
||||
bool fCanUndo; // we can do an undo action next
|
||||
bool fRedoFlag; // we just did a redo action
|
||||
bool fCanRedo; // we can do a redo action next
|
||||
|
||||
// clean modes
|
||||
bool fUndoCleans; // an undo action will put us in a clean state
|
||||
bool fRedoCleans; // a redo action will put us in a clean state
|
||||
bool fClean; // we are in a clean state
|
||||
|
||||
bool fCaseSens;
|
||||
bool fWrapAround;
|
||||
bool fBackSearch;
|
||||
|
||||
StyledEditView *fTextView;
|
||||
BScrollView *fScrollView;
|
||||
BFilePanel *fSavePanel;
|
||||
int32 fWindow_Id;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // STYLED_EDIT_WINDOW_H
|
||||
|
Loading…
Reference in New Issue
Block a user