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