Applied patch from "HOST", with a few small style fixes myself.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22163 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood
2007-09-04 03:08:40 +00:00
parent af73a9fb93
commit f303cd6cc2
13 changed files with 305 additions and 349 deletions
+4 -2
View File
@@ -7,14 +7,14 @@
* Andrew Bachmann * Andrew Bachmann
*/ */
#include "ColorMenuItem.h" #include "ColorMenuItem.h"
#include <Message.h>
ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message) ColorMenuItem::ColorMenuItem(const char *label, rgb_color color, BMessage *message)
: BMenuItem(label, message, 0, 0) : BMenuItem(label, message, 0, 0)
, fItemColor(color)
{ {
fItemColor = color;
} }
@@ -22,9 +22,11 @@ void
ColorMenuItem::DrawContent() ColorMenuItem::DrawContent()
{ {
BMenu *menu = Menu(); BMenu *menu = Menu();
if (menu) {
rgb_color menuColor = menu->HighColor(); rgb_color menuColor = menu->HighColor();
menu->SetHighColor(fItemColor); menu->SetHighColor(fItemColor);
BMenuItem::DrawContent(); BMenuItem::DrawContent();
menu->SetHighColor(menuColor); menu->SetHighColor(menuColor);
} }
}
+4 -3
View File
@@ -13,12 +13,13 @@
#include <MenuItem.h> #include <MenuItem.h>
class BMessage;
class ColorMenuItem: public BMenuItem { class ColorMenuItem: public BMenuItem {
public: public:
ColorMenuItem(const char *label, rgb_color color, BMessage *message); ColorMenuItem(const char *label, rgb_color color, BMessage *message);
void DrawContent();
protected:
virtual void DrawContent();
private: private:
rgb_color fItemColor; rgb_color fItemColor;
+1
View File
@@ -76,3 +76,4 @@ const uint32 SAVE_AS_ENCODING = 'FPse';
const uint32 SAVE_THEN_QUIT = 'FPsq'; const uint32 SAVE_THEN_QUIT = 'FPsq';
#endif // CONSTANTS_H #endif // CONSTANTS_H
+5 -6
View File
@@ -18,10 +18,9 @@
FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
bool *caseState, bool *wrapState, bool *backState) bool caseState, bool wrapState, bool backState)
: BWindow(frame, "FindWindow", B_MODAL_WINDOW, : BWindow(frame, "FindWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE)
B_CURRENT_WORKSPACE)
{ {
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
@@ -68,9 +67,9 @@ FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString,
fSearchString->SetText(text); fSearchString->SetText(text);
fSearchString->MakeFocus(true); fSearchString->MakeFocus(true);
fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF); fCaseSensBox->SetValue(caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF); fWrapBox->SetValue(wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF); fBackSearchBox->SetValue(backState ? B_CONTROL_ON : B_CONTROL_OFF);
} }
+4 -8
View File
@@ -12,6 +12,7 @@
#include <Window.h> #include <Window.h>
class BButton; class BButton;
class BCheckBox; class BCheckBox;
class BTextControl; class BTextControl;
@@ -21,10 +22,10 @@ class BView;
class FindWindow : public BWindow { class FindWindow : public BWindow {
public: public:
FindWindow(BRect frame, BHandler* handler, BString *searchString, FindWindow(BRect frame, BHandler* handler, BString *searchString,
bool *caseState, bool *wrapState, bool *backState); bool caseState, bool wrapState, bool backState);
virtual void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler* handler); void DispatchMessage(BMessage* message, BHandler* handler);
private: private:
void _SendMessage(); void _SendMessage();
@@ -42,8 +43,3 @@ class FindWindow : public BWindow {
#endif // FIND_WINDOW_H #endif // FIND_WINDOW_H
+21 -25
View File
@@ -11,19 +11,21 @@
#include "Constants.h" #include "Constants.h"
#include "ReplaceWindow.h" #include "ReplaceWindow.h"
#include <Messenger.h>
#include <Button.h> #include <Button.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Handler.h>
#include <Message.h>
#include <Messenger.h>
#include <Rect.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
#include <Window.h> #include <View.h>
ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState) BString *replaceString, bool caseState, bool wrapState, bool backState)
: BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW, : BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE)
B_CURRENT_WORKSPACE)
{ {
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
@@ -41,7 +43,7 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "", fReplaceView->AddChild(fReplaceString = new BTextControl(BRect(5, 35, 290, 50), "",
replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, replaceWithLabel, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE)); B_WILL_DRAW | B_NAVIGABLE));
float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + 1; float maxWidth = (replaceWithWidth > findWidth ? replaceWithWidth : findWidth) + TEXT_INSET;
fSearchString->SetDivider(maxWidth); fSearchString->SetDivider(maxWidth);
fReplaceString->SetDivider(maxWidth); fReplaceString->SetDivider(maxWidth);
@@ -78,9 +80,9 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchStr
fReplaceString->SetText(replacetext); fReplaceString->SetText(replacetext);
fSearchString->MakeFocus(true); fSearchString->MakeFocus(true);
fCaseSensBox->SetValue(*caseState ? B_CONTROL_ON : B_CONTROL_OFF); fCaseSensBox->SetValue(caseState ? B_CONTROL_ON : B_CONTROL_OFF);
fWrapBox->SetValue(*wrapState ? B_CONTROL_ON : B_CONTROL_OFF); fWrapBox->SetValue(wrapState ? B_CONTROL_ON : B_CONTROL_OFF);
fBackSearchBox->SetValue(*backState ? B_CONTROL_ON : B_CONTROL_OFF); fBackSearchBox->SetValue(backState ? B_CONTROL_ON : B_CONTROL_OFF);
} }
@@ -108,22 +110,16 @@ ReplaceWindow::MessageReceived(BMessage *msg)
void void
ReplaceWindow::_ChangeUI() ReplaceWindow::_ChangeUI()
{ {
if (!fUIchange) { fWrapBox->SetEnabled(fUIchange);
fReplaceAllButton->MakeDefault(true); fWrapBox->SetValue(fUIchange ? B_CONTROL_OFF : B_CONTROL_ON);
fReplaceButton->SetEnabled(false);
fWrapBox->SetValue(B_CONTROL_ON); fBackSearchBox->SetEnabled(fUIchange);
fWrapBox->SetEnabled(false);
fBackSearchBox->SetEnabled(false); fReplaceButton->SetEnabled(fUIchange);
fUIchange = true; fUIchange ? fReplaceButton->MakeDefault(true)
} else { : fReplaceAllButton->MakeDefault(true);
fReplaceButton->MakeDefault(true);
fReplaceButton->SetEnabled(true); fUIchange = !fUIchange;
fReplaceAllButton->SetEnabled(true);
fWrapBox->SetValue(B_CONTROL_OFF);
fWrapBox->SetEnabled(true);
fBackSearchBox->SetEnabled(true);
fUIchange = false;
}
} }
+15 -12
View File
@@ -11,23 +11,25 @@
#include <Window.h> #include <Window.h>
#include <Rect.h>
#include <Handler.h>
#include <String.h> class BView;
#include <Message.h> class BString;
#include <View.h> class BButton;
#include <TextControl.h> class BHandler;
#include <CheckBox.h> class BMessage;
#include <Button.h> class BCheckBox;
class BTextControl;
class ReplaceWindow : public BWindow { class ReplaceWindow : public BWindow {
public: public:
ReplaceWindow(BRect frame, BHandler *_handler,BString *searchString, ReplaceWindow(BRect frame, BHandler *_handler,
BString *replaceString, bool *caseState, bool *wrapState, bool *backState); BString *searchString, BString *replaceString,
bool caseState, bool wrapState, bool backState);
virtual void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
virtual void DispatchMessage(BMessage* message, BHandler *handler); void DispatchMessage(BMessage* message, BHandler *handler);
private: private:
void _SendMessage(uint32 what); void _SendMessage(uint32 what);
@@ -48,3 +50,4 @@ class ReplaceWindow : public BWindow {
}; };
#endif // REPLACE_WINDOW_H #endif // REPLACE_WINDOW_H
+27 -11
View File
@@ -8,25 +8,33 @@
*/ */
#include <Alert.h>
#include <Autolock.h>
#include <Path.h>
#include <MenuItem.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <Screen.h>
#include <stdio.h>
#include "Constants.h" #include "Constants.h"
#include "StyledEditApp.h" #include "StyledEditApp.h"
#include "StyledEditWindow.h" #include "StyledEditWindow.h"
#include <Alert.h>
#include <Autolock.h>
#include <MenuBar.h>
#include <CharacterSet.h>
#include <CharacterSetRoster.h>
#include <FilePanel.h>
#include <MenuItem.h>
#include <Message.h>
#include <Path.h>
#include <Screen.h>
#include <stdio.h>
using namespace BPrivate; using namespace BPrivate;
StyledEditApp * styled_edit_app; StyledEditApp * styled_edit_app;
BRect gWindowRect(7-15, 26-15, 507, 426); BRect gWindowRect(7-15, 26-15, 507, 426);
namespace
{
void void
cascade() cascade()
{ {
@@ -64,6 +72,7 @@ uncascade()
gWindowRect.OffsetTo(BPoint(left,top)); gWindowRect.OffsetTo(BPoint(left,top));
} }
}
// #pragma mark - // #pragma mark -
@@ -71,6 +80,7 @@ uncascade()
StyledEditApp::StyledEditApp() StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE) : BApplication(APP_SIGNATURE)
, fOpenPanel(NULL)
{ {
fOpenPanel = new BFilePanel(); fOpenPanel = new BFilePanel();
BMenuBar *menuBar = BMenuBar *menuBar =
@@ -110,6 +120,12 @@ StyledEditApp::StyledEditApp()
} }
StyledEditApp::~StyledEditApp()
{
delete fOpenPanel;
}
void void
StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler) StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
{ {
@@ -128,7 +144,7 @@ StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
if (msg->FindString("cwd", &cwd) != B_OK) if (msg->FindString("cwd", &cwd) != B_OK)
cwd = ""; cwd = "";
ArgvReceived(argc, argv, cwd); ArgvReceivedEx(argc, argv, cwd);
} else } else
BApplication::DispatchMessage(msg, handler); BApplication::DispatchMessage(msg, handler);
} }
@@ -205,7 +221,7 @@ StyledEditApp::RefsReceived(BMessage *message)
void void
StyledEditApp::ArgvReceived(int32 argc, const char* argv[], const char* cwd) StyledEditApp::ArgvReceivedEx(int32 argc, const char* argv[], const char* cwd)
{ {
for (int i = 1 ; (i < argc) ; i++) { for (int i = 1 ; (i < argc) ; i++) {
BPath path; BPath path;
+17 -7
View File
@@ -11,27 +11,36 @@
#include <Application.h> #include <Application.h>
#include <Message.h>
#include <FilePanel.h>
struct entry_ref;
class BMenu;
class BHandler;
class BMessage;
class BFilePanel;
class StyledEditWindow; class StyledEditWindow;
class StyledEditApp : public BApplication { class StyledEditApp : public BApplication {
public: public:
StyledEditApp(); StyledEditApp();
virtual void MessageReceived(BMessage *message); ~StyledEditApp();
void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
virtual void DispatchMessage(BMessage *an_event, BHandler *handler); void MessageReceived(BMessage *message);
void RefsReceived(BMessage *message);
void ReadyToRun();
void DispatchMessage(BMessage *an_event, BHandler *handler);
int32 NumberOfWindows(); int32 NumberOfWindows();
void OpenDocument(); void OpenDocument();
void OpenDocument(entry_ref * ref); void OpenDocument(entry_ref * ref);
void CloseDocument(); void CloseDocument();
private:
void ArgvReceivedEx(int32 argc, const char *argv[], const char * cwd);
private: private:
BFilePanel *fOpenPanel; BFilePanel *fOpenPanel;
BMenu *fOpenPanelEncodingMenu; BMenu *fOpenPanelEncodingMenu;
@@ -44,3 +53,4 @@ class StyledEditApp : public BApplication {
extern StyledEditApp* styled_edit_app; extern StyledEditApp* styled_edit_app;
#endif // STYLED_EDIT_APP #endif // STYLED_EDIT_APP
+46 -63
View File
@@ -12,18 +12,20 @@
#include "Constants.h" #include "Constants.h"
#include "StyledEditView.h" #include "StyledEditView.h"
#include <Message.h>
#include <Messenger.h>
#include <Rect.h>
#include <Region.h>
#include <TranslationUtils.h>
#include <Node.h>
#include <stdio.h>
#include <stdlib.h>
#include <CharacterSet.h> #include <CharacterSet.h>
#include <CharacterSetRoster.h> #include <CharacterSetRoster.h>
#include <DataIO.h>
#include <File.h>
#include <Message.h>
#include <Messenger.h>
#include <Node.h>
#include <Rect.h>
#include <TranslationUtils.h>
#include <UTF8.h> #include <UTF8.h>
#include <stdio.h>
#include <stdlib.h>
using namespace BPrivate; using namespace BPrivate;
@@ -32,7 +34,6 @@ StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds, BHandler *hand
: BTextView(viewFrame, "textview", textBounds, : BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW) B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW)
{ {
fHandler = handler;
fMessenger = new BMessenger(handler); fMessenger = new BMessenger(handler);
fSuppressChanges = false; fSuppressChanges = false;
} }
@@ -45,34 +46,21 @@ StyledEditView::~StyledEditView()
void void
StyledEditView::FrameResized(float width, float height) StyledEditView::Select(int32 start, int32 finish)
{ {
BTextView::FrameResized(width, height); fMessenger->SendMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
if (DoesWordWrap()) { BTextView::Select(start, finish);
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
} }
/* // I tried to do some sort of intelligent resize thing but it just doesn't work
// so we revert to the R5 stylededit yucky practice of setting the text rect to
// some crazy large number when word wrap is turned off :-(
else if (textRect.Width() > TextRect().Width()) {
SetTextRect(textRect);
}
BRegion region; void
GetTextRegion(0,TextLength(),&region); StyledEditView::Reset()
float textWidth = region.Frame().Width(); {
if (textWidth < textRect.Width()) { fSuppressChanges = true;
BRect textRect(B_ORIGIN,BPoint(textWidth+TEXT_INSET*2,Bounds().Height())); SetText("");
textRect.InsetBy(TEXT_INSET,TEXT_INSET); fEncoding = "";
SetTextRect(textRect); fSuppressChanges = false;
}
*/
} }
@@ -144,39 +132,18 @@ StyledEditView::WriteStyledEditFile(BFile* file)
} }
void
StyledEditView::Reset()
{
fSuppressChanges = true;
SetText("");
fEncoding = "";
fSuppressChanges = false;
}
void
StyledEditView::Select(int32 start, int32 finish)
{
fChangeMessage = new BMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
fMessenger->SendMessage(fChangeMessage);
BTextView::Select(start, finish);
}
void void
StyledEditView::SetEncoding(uint32 encoding) StyledEditView::SetEncoding(uint32 encoding)
{ {
if (encoding == 0) {
fEncoding = ""; fEncoding = "";
if (encoding == 0)
return; return;
}
const BCharacterSet* set = BCharacterSetRoster::GetCharacterSetByFontID(encoding); const BCharacterSet* set
= BCharacterSetRoster::GetCharacterSetByFontID(encoding);
if (set != NULL) if (set != NULL)
fEncoding = set->GetName(); fEncoding = set->GetName();
else
fEncoding = "";
} }
@@ -186,7 +153,8 @@ StyledEditView::GetEncoding() const
if (fEncoding == "") if (fEncoding == "")
return 0; return 0;
const BCharacterSet* set = BCharacterSetRoster::FindCharacterSetByName(fEncoding.String()); const BCharacterSet* set =
BCharacterSetRoster::FindCharacterSetByName(fEncoding.String());
if(set != NULL) if(set != NULL)
return set->GetFontID(); return set->GetFontID();
@@ -194,23 +162,38 @@ StyledEditView::GetEncoding() const
} }
void
StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(TEXT_CHANGED);
BTextView::DeleteText(start, finish);
}
void void
StyledEditView::InsertText(const char *text, int32 length, int32 offset, StyledEditView::InsertText(const char *text, int32 length, int32 offset,
const text_run_array *runs) const text_run_array *runs)
{ {
if (!fSuppressChanges) if (!fSuppressChanges)
fMessenger->SendMessage(new BMessage(TEXT_CHANGED)); fMessenger->SendMessage(TEXT_CHANGED);
BTextView::InsertText(text, length, offset, runs); BTextView::InsertText(text, length, offset, runs);
} }
void void
StyledEditView::DeleteText(int32 start, int32 finish) StyledEditView::FrameResized(float width, float height)
{ {
if (!fSuppressChanges) BTextView::FrameResized(width, height);
fMessenger-> SendMessage(new BMessage(TEXT_CHANGED));
BTextView::DeleteText(start, finish); if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
}
} }
+20 -17
View File
@@ -11,37 +11,40 @@
#define STYLED_EDIT_VIEW_H #define STYLED_EDIT_VIEW_H
#include <File.h>
#include <DataIO.h>
#include <String.h> #include <String.h>
#include <TextView.h> #include <TextView.h>
class BFile;
class BHandler;
class BMessanger;
class StyledEditView : public BTextView { class StyledEditView : public BTextView {
public: public:
StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); StyledEditView(BRect viewframe, BRect textframe,
virtual ~StyledEditView(); BHandler *handler);
~StyledEditView();
virtual void Select(int32 start, int32 finish); void Select(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
virtual void Reset(); void Reset();
virtual status_t GetStyledText(BPositionIO * stream); status_t GetStyledText(BPositionIO * stream);
virtual status_t WriteStyledEditFile(BFile * file); status_t WriteStyledEditFile(BFile * file);
virtual void SetEncoding(uint32 encoding); void SetEncoding(uint32 encoding);
virtual uint32 GetEncoding() const; uint32 GetEncoding() const;
protected:
virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL);
virtual void DeleteText(int32 start, int32 finish);
private: private:
BHandler *fHandler; void DeleteText(int32 start, int32 finish);
BMessage *fChangeMessage; void FrameResized(float width, float height);
void InsertText(const char *text, int32 length, int32 offset,
const text_run_array *runs = NULL);
BMessenger *fMessenger; BMessenger *fMessenger;
bool fSuppressChanges; bool fSuppressChanges;
BString fEncoding; BString fEncoding;
}; };
#endif // STYLED_EDIT_VIEW_H #endif // STYLED_EDIT_VIEW_H
+53 -115
View File
@@ -18,24 +18,26 @@
#include <Alert.h> #include <Alert.h>
#include <Autolock.h> #include <Autolock.h>
#include <Debug.h>
#include <Clipboard.h>
#include <File.h>
#include <Menu.h>
#include <MenuItem.h>
#include <PrintJob.h>
#include <Roster.h>
#include <ScrollView.h>
#include <String.h>
#include <TextControl.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <CharacterSet.h> #include <CharacterSet.h>
#include <CharacterSetRoster.h> #include <CharacterSetRoster.h>
#include <Clipboard.h>
#include <Debug.h>
#include <File.h>
#include <FilePanel.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <PrintJob.h>
#include <Rect.h>
#include <ScrollView.h>
#include <TextControl.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <Roster.h>
#include <stdlib.h> #include <stdlib.h>
using namespace BPrivate; using namespace BPrivate;
@@ -43,8 +45,7 @@ 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)
{ {
InitWindow(encoding); InitWindow(encoding);
BString unTitled; BString unTitled("Untitled ");
unTitled.SetTo("Untitled ");
unTitled << id; unTitled << id;
SetTitle(unTitled.String()); SetTitle(unTitled.String());
fSaveItem->SetEnabled(true); fSaveItem->SetEnabled(true);
@@ -365,7 +366,7 @@ StyledEditWindow::MessageReceived(BMessage *message)
{ {
BRect findWindowFrame(100, 100, 400, 235); BRect findWindowFrame(100, 100, 400, 235);
BWindow* window = new FindWindow(findWindowFrame, this, BWindow* window = new FindWindow(findWindowFrame, this,
&fStringToFind, &fCaseSens, &fWrapAround, &fBackSearch); &fStringToFind, fCaseSens, fWrapAround, fBackSearch);
window->Show(); window->Show();
break; break;
} }
@@ -388,31 +389,23 @@ StyledEditWindow::MessageReceived(BMessage *message)
{ {
BRect replaceWindowFrame(100, 100, 400, 284); BRect replaceWindowFrame(100, 100, 400, 284);
BWindow* window = new ReplaceWindow(replaceWindowFrame, this, BWindow* window = new ReplaceWindow(replaceWindowFrame, this,
&fStringToFind, &fReplaceString, &fCaseSens, &fWrapAround, &fBackSearch); &fStringToFind, &fReplaceString, fCaseSens, fWrapAround, fBackSearch);
window->Show(); window->Show();
break; break;
} }
case MSG_REPLACE: case MSG_REPLACE:
{ {
BString findIt; message->FindBool("casesens", &fCaseSens);
BString replaceWith; message->FindBool("wrap", &fWrapAround);
bool caseSens, wrap, backSearch; message->FindBool("backsearch", &fBackSearch);
message->FindBool("casesens", &caseSens); message->FindString("FindText", &fStringToFind);
message->FindBool("wrap", &wrap); message->FindString("ReplaceText", &fReplaceString);
message->FindBool("backsearch", &backSearch);
message->FindString("FindText", &findIt);
message->FindString("ReplaceText", &replaceWith);
fStringToFind = findIt;
fFindAgainItem->SetEnabled(true); fFindAgainItem->SetEnabled(true);
fReplaceString = replaceWith;
fReplaceSameItem->SetEnabled(true); fReplaceSameItem->SetEnabled(true);
fCaseSens = caseSens;
fWrapAround = wrap;
fBackSearch = backSearch;
Replace(findIt, replaceWith, caseSens, wrap, backSearch); Replace(fStringToFind, fReplaceString, fCaseSens, fWrapAround, fBackSearch);
break; break;
} }
case MENU_REPLACE_SAME: case MENU_REPLACE_SAME:
@@ -421,25 +414,20 @@ StyledEditWindow::MessageReceived(BMessage *message)
case MSG_REPLACE_ALL: case MSG_REPLACE_ALL:
{ {
BString findIt; message->FindBool("casesens", &fCaseSens);
BString replaceWith; message->FindString("FindText",&fStringToFind);
bool caseSens, allWindows; message->FindString("ReplaceText",&fReplaceString);
message->FindBool("casesens", &caseSens); bool allWindows;
message->FindString("FindText",&findIt);
message->FindString("ReplaceText",&replaceWith);
message->FindBool("allwindows", &allWindows); message->FindBool("allwindows", &allWindows);
fStringToFind = findIt;
fFindAgainItem->SetEnabled(true); fFindAgainItem->SetEnabled(true);
fReplaceString = replaceWith;
fReplaceSameItem->SetEnabled(true); fReplaceSameItem->SetEnabled(true);
fCaseSens = caseSens;
if (allWindows) if (allWindows)
SearchAllWindows(findIt, replaceWith, caseSens); SearchAllWindows(fStringToFind, fReplaceString, fCaseSens);
else else
ReplaceAll(findIt, replaceWith,caseSens); ReplaceAll(fStringToFind, fReplaceString, fCaseSens);
break; break;
} }
@@ -508,70 +496,35 @@ StyledEditWindow::MessageReceived(BMessage *message)
case ALIGN_LEFT: case ALIGN_LEFT:
fTextView->SetAlignment(B_ALIGN_LEFT); fTextView->SetAlignment(B_ALIGN_LEFT);
fClean = false; _UpdateCleanUndoRedoSaveRevert();
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
fTextView->SetAlignment(B_ALIGN_CENTER); fTextView->SetAlignment(B_ALIGN_CENTER);
fClean = false; _UpdateCleanUndoRedoSaveRevert();
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
fTextView->SetAlignment(B_ALIGN_RIGHT); fTextView->SetAlignment(B_ALIGN_RIGHT);
fClean = false; _UpdateCleanUndoRedoSaveRevert();
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
break; break;
case WRAP_LINES: case WRAP_LINES:
{
BRect textRect(fTextView->Bounds());
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
if (fTextView->DoesWordWrap()) { if (fTextView->DoesWordWrap()) {
fTextView->SetWordWrap(false); fTextView->SetWordWrap(false);
fWrapItem->SetMarked(false); fWrapItem->SetMarked(false);
BRect textRect;
textRect = fTextView->Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
// the width comes from stylededit R5. TODO: find a better way // the width comes from stylededit R5. TODO: find a better way
textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y)); textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y));
fTextView->SetTextRect(textRect);
} else { } else {
fTextView->SetWordWrap(true); fTextView->SetWordWrap(true);
fWrapItem->SetMarked(true); fWrapItem->SetMarked(true);
BRect textRect;
textRect = fTextView->Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
fTextView->SetTextRect(textRect);
} }
fClean = false; fTextView->SetTextRect(textRect);
fUndoCleans = false;
fRedoCleans = false; _UpdateCleanUndoRedoSaveRevert();
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
break; break;
}
case ENABLE_ITEMS: case ENABLE_ITEMS:
fCutItem->SetEnabled(true); fCutItem->SetEnabled(true);
fCopyItem->SetEnabled(true); fCopyItem->SetEnabled(true);
@@ -1303,15 +1256,7 @@ StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSensi
fTextView->Select(textStart,textFinish); fTextView->Select(textStart,textFinish);
fTextView->ScrollToSelection(); fTextView->ScrollToSelection();
fClean = false; _UpdateCleanUndoRedoSaveRevert();
fUndoCleans = false;
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
} }
@@ -1348,15 +1293,8 @@ StyledEditWindow::SetFontSize(float fontSize)
fTextView->GetFontAndColor(&font, &sameProperties); fTextView->GetFontAndColor(&font, &sameProperties);
font.SetSize(fontSize); font.SetSize(fontSize);
fTextView->SetFontAndColor(&font, B_FONT_SIZE); fTextView->SetFontAndColor(&font, B_FONT_SIZE);
fClean = false;
fUndoCleans = false; _UpdateCleanUndoRedoSaveRevert();
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
} }
@@ -1368,15 +1306,8 @@ StyledEditWindow::SetFontColor(const rgb_color *color)
fTextView->GetFontAndColor(&font, &sameProperties, NULL, NULL); fTextView->GetFontAndColor(&font, &sameProperties, NULL, NULL);
fTextView->SetFontAndColor(&font, 0, color); fTextView->SetFontAndColor(&font, 0, color);
fClean = false;
fUndoCleans = false; _UpdateCleanUndoRedoSaveRevert();
fRedoCleans = false;
fRevertItem->SetEnabled(fSaveMessage != NULL);
fSaveItem->SetEnabled(true);
fUndoItem->SetLabel("Can't Undo");
fUndoItem->SetEnabled(false);
fCanUndo = false;
fCanRedo = false;
} }
@@ -1407,6 +1338,12 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
if (superItem != NULL) if (superItem != NULL)
superItem->SetMarked(true); superItem->SetMarked(true);
_UpdateCleanUndoRedoSaveRevert();
}
void
StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
{
fClean = false; fClean = false;
fUndoCleans = false; fUndoCleans = false;
fRedoCleans = false; fRedoCleans = false;
@@ -1417,3 +1354,4 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
fCanUndo = false; fCanUndo = false;
fCanRedo = false; fCanRedo = false;
} }
+20 -12
View File
@@ -10,27 +10,32 @@
#define STYLED_EDIT_WINDOW_H #define STYLED_EDIT_WINDOW_H
#include <FilePanel.h>
#include <MenuBar.h>
#include <Message.h>
#include <Rect.h>
#include <String.h>
#include <TextView.h>
#include <Window.h> #include <Window.h>
#include <String.h>
#include <Message.h>
struct entry_ref;
class BMenu;
class BMessage;
class BMenuBar;
class BMenuItem;
class BFilePanel;
class BScrollView;
class StyledEditView; class StyledEditView;
class StyledEditWindow : public BWindow { class StyledEditWindow : public BWindow {
public: public:
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(); ~StyledEditWindow();
virtual void Quit(); void Quit();
virtual bool QuitRequested(); bool QuitRequested();
virtual void MessageReceived(BMessage *message); void MessageReceived(BMessage *message);
virtual void MenusBeginning(); void MenusBeginning();
status_t Save(BMessage *message = 0); status_t Save(BMessage *message = 0);
status_t SaveAs(BMessage *message = 0); status_t SaveAs(BMessage *message = 0);
@@ -43,13 +48,15 @@ class StyledEditWindow : public BWindow {
void InitWindow(uint32 encoding = 0); void InitWindow(uint32 encoding = 0);
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 wrap, bool backsearch); bool Replace(BString findthis, BString replacewith, bool casesens,
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);
void SetFontColor(const rgb_color *color); void SetFontColor(const rgb_color *color);
void SetFontStyle(const char *fontFamily, const char *fontStyle); void SetFontStyle(const char *fontFamily, const char *fontStyle);
status_t _LoadFile(entry_ref* ref); status_t _LoadFile(entry_ref* ref);
void RevertToSaved(); void RevertToSaved();
void _UpdateCleanUndoRedoSaveRevert();
BMenuBar *fMenuBar; BMenuBar *fMenuBar;
BMessage *fPrintSettings; BMessage *fPrintSettings;
@@ -111,3 +118,4 @@ class StyledEditWindow : public BWindow {
}; };
#endif // STYLED_EDIT_WINDOW_H #endif // STYLED_EDIT_WINDOW_H