replace all still has problems but I am sleepy...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1867 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -132,13 +132,13 @@ StyledEditWindow::InitWindow()
|
|||||||
menu->AddItem(menuItem= new BMenuItem("Save As...", new BMessage(MENU_SAVEAS)));
|
menu->AddItem(menuItem= new BMenuItem("Save As...", new BMessage(MENU_SAVEAS)));
|
||||||
menuItem->SetEnabled(true);
|
menuItem->SetEnabled(true);
|
||||||
|
|
||||||
menu->AddItem(fRevertItem= new BMenuItem("Revert to Saved", new BMessage(MENU_REVERT)));
|
menu->AddItem(fRevertItem= new BMenuItem("Revert to Saved...", new BMessage(MENU_REVERT)));
|
||||||
fRevertItem->SetEnabled(false);
|
fRevertItem->SetEnabled(false);
|
||||||
menu->AddItem(menuItem= new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W'));
|
menu->AddItem(menuItem= new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W'));
|
||||||
|
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
menu->AddItem(menuItem= new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, new BMessage(MENU_PAGESETUP)));
|
menu->AddItem(menuItem= new BMenuItem("Page Setup...", new BMessage(MENU_PAGESETUP)));
|
||||||
menu->AddItem(menuItem= new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_PRINT), 'P'));
|
menu->AddItem(menuItem= new BMenuItem("Print...", new BMessage(MENU_PRINT), 'P'));
|
||||||
|
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
menu->AddItem(menuItem= new BMenuItem("Quit", new BMessage(MENU_QUIT), 'Q'));
|
menu->AddItem(menuItem= new BMenuItem("Quit", new BMessage(MENU_QUIT), 'Q'));
|
||||||
@@ -274,17 +274,7 @@ 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 = 0; // build lazily
|
||||||
fSavePanelTextView =
|
|
||||||
dynamic_cast<BTextControl*>(fSavePanel->Window()->FindView("text view"));
|
|
||||||
BMenuBar * menuBar =
|
|
||||||
dynamic_cast<BMenuBar*>(fSavePanel->Window()->FindView("MenuBar"));
|
|
||||||
|
|
||||||
fSavePanelEncodingMenu= new BMenu("Encoding");
|
|
||||||
menuBar->AddItem(fSavePanelEncodingMenu);
|
|
||||||
|
|
||||||
// TODO: add encodings
|
|
||||||
|
|
||||||
} /***StyledEditWindow::Initwindow()***/
|
} /***StyledEditWindow::Initwindow()***/
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -669,8 +659,20 @@ StyledEditWindow::Save(BMessage *message)
|
|||||||
status_t
|
status_t
|
||||||
StyledEditWindow::SaveAs()
|
StyledEditWindow::SaveAs()
|
||||||
{
|
{
|
||||||
|
if (fSavePanel == 0) {
|
||||||
|
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false);
|
||||||
|
fSavePanelTextView =
|
||||||
|
dynamic_cast<BTextControl*>(fSavePanel->Window()->FindView("text view"));
|
||||||
|
BMenuBar * menuBar =
|
||||||
|
dynamic_cast<BMenuBar*>(fSavePanel->Window()->FindView("MenuBar"));
|
||||||
|
|
||||||
|
fSavePanelEncodingMenu= new BMenu("Encoding");
|
||||||
|
menuBar->AddItem(fSavePanelEncodingMenu);
|
||||||
|
}
|
||||||
|
|
||||||
// it's own scope allows the lock to be released before Show()
|
// it's own scope allows the lock to be released before Show()
|
||||||
{
|
{
|
||||||
|
// TODO: add encodings
|
||||||
BAutolock lock(fSavePanel->Window());
|
BAutolock lock(fSavePanel->Window());
|
||||||
if (lock.IsLocked()) {
|
if (lock.IsLocked()) {
|
||||||
fSavePanelTextView->SetText(Title());
|
fSavePanelTextView->SetText(Title());
|
||||||
@@ -834,28 +836,46 @@ StyledEditWindow::Search(BString string, bool casesens, bool wrap, bool backsear
|
|||||||
int32 finish;
|
int32 finish;
|
||||||
int32 strlen;
|
int32 strlen;
|
||||||
|
|
||||||
start= B_ERROR;
|
start = B_ERROR;
|
||||||
|
|
||||||
strlen= string.Length();
|
strlen = string.Length();
|
||||||
if (strlen== 0)
|
if (strlen== 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BString viewText;
|
BString viewText(fTextView->Text());
|
||||||
viewText.SetTo(fTextView->Text());
|
|
||||||
int32 textStart, textFinish;
|
int32 textStart, textFinish;
|
||||||
fTextView->GetSelection(&textStart, &textFinish);
|
fTextView->GetSelection(&textStart, &textFinish);
|
||||||
//case insensitive, non wrap seems to be default in SE...
|
if (backsearch == true) {
|
||||||
if(casesens== true)
|
if (casesens == true) {
|
||||||
start= viewText.FindFirst(string, textFinish);
|
start = viewText.FindLast(string, textStart);
|
||||||
else if(wrap== true)
|
} else {
|
||||||
start= viewText.IFindFirst(string);
|
start = viewText.IFindLast(string, textStart);
|
||||||
else if(backsearch== true)
|
}
|
||||||
start= viewText.IFindLast(string, textStart);
|
} else {
|
||||||
else
|
if (casesens == true) {
|
||||||
start= viewText.IFindFirst(string, textFinish); //i.e this one...
|
start = viewText.FindFirst(string, textFinish);
|
||||||
|
} else {
|
||||||
if(start!= B_ERROR) {
|
start = viewText.IFindFirst(string, textFinish);
|
||||||
finish= start+ strlen;
|
}
|
||||||
|
}
|
||||||
|
if ((start == B_ERROR) && (wrap == true)) {
|
||||||
|
if (backsearch == true) {
|
||||||
|
if (casesens == true) {
|
||||||
|
start = viewText.FindLast(string, viewText.Length());
|
||||||
|
} else {
|
||||||
|
start = viewText.IFindLast(string, viewText.Length());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (casesens == true) {
|
||||||
|
start = viewText.FindFirst(string, 0);
|
||||||
|
} else {
|
||||||
|
start = viewText.IFindFirst(string, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start != B_ERROR) {
|
||||||
|
finish = start + strlen;
|
||||||
fTextView->Select(start, finish);
|
fTextView->Select(start, finish);
|
||||||
fTextView->ScrollToSelection();
|
fTextView->ScrollToSelection();
|
||||||
return true;
|
return true;
|
||||||
@@ -877,51 +897,55 @@ StyledEditWindow::FindSelection()
|
|||||||
viewText= fTextView->Text();
|
viewText= fTextView->Text();
|
||||||
|
|
||||||
viewText.CopyInto(fStringToFind, selectionStart, selectionLength);
|
viewText.CopyInto(fStringToFind, selectionStart, selectionLength);
|
||||||
Search(fStringToFind, false, false, false);
|
Search(fStringToFind, fCaseSens, fWrapAround, fBackSearch);
|
||||||
|
|
||||||
}/***StyledEditWindow::FindSelection()***/
|
}/***StyledEditWindow::FindSelection()***/
|
||||||
|
|
||||||
void
|
bool
|
||||||
StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch)
|
StyledEditWindow::Replace(BString findthis, BString replaceWith, bool casesens, bool wrap, bool backsearch)
|
||||||
{
|
{
|
||||||
int32 start;
|
if (Search(findthis, casesens, wrap, backsearch)) {
|
||||||
int32 replaceLength;
|
int32 start, finish;
|
||||||
int32 findLength;
|
fTextView->GetSelection(&start, &finish);
|
||||||
|
|
||||||
start= B_ERROR;
|
|
||||||
|
|
||||||
findLength= findthis.Length();
|
|
||||||
replaceLength= replaceWith.Length();
|
|
||||||
|
|
||||||
BString viewText;
|
|
||||||
viewText.SetTo(fTextView->Text());
|
|
||||||
|
|
||||||
int32 textStart, textFinish;
|
|
||||||
fTextView->GetSelection(&textStart, &textFinish);
|
|
||||||
|
|
||||||
if(casesens== true)
|
|
||||||
start= viewText.FindFirst(findthis, textFinish);
|
|
||||||
else if(wrap== true)
|
|
||||||
start= viewText.IFindFirst(findthis);
|
|
||||||
else if(backsearch== true)
|
|
||||||
start= viewText.IFindLast(findthis, textStart);
|
|
||||||
else
|
|
||||||
start= viewText.IFindFirst(findthis, textFinish);
|
|
||||||
|
|
||||||
if (start!= B_ERROR) {
|
|
||||||
fTextView->Delete(start, start+ findLength);
|
|
||||||
fTextView->Insert(start, replaceWith.String(), replaceLength);
|
|
||||||
fTextView->Select(start, start+ replaceLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fTextView->Delete(start, start + findthis.Length());
|
||||||
|
fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
|
||||||
|
fTextView->Select(start, start + replaceWith.Length());
|
||||||
|
fTextView->ScrollToSelection();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}/***StyledEditWindow::Replace()***/
|
}/***StyledEditWindow::Replace()***/
|
||||||
|
|
||||||
void
|
void
|
||||||
StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens)
|
StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSens)
|
||||||
{
|
{
|
||||||
while(Search(findIt, caseSens, true, false))
|
int32 start;
|
||||||
Replace(findIt, replaceWith, caseSens, true, false);
|
int32 oldstart;
|
||||||
|
|
||||||
|
BString viewText(fTextView->Text());
|
||||||
|
int32 textStart, textFinish;
|
||||||
|
fTextView->GetSelection(&textStart, &textFinish);
|
||||||
|
|
||||||
|
// we search backwards because we are disturbing everything after the point we insert
|
||||||
|
start = viewText.Length();
|
||||||
|
while (start > 0) {
|
||||||
|
oldstart = start;
|
||||||
|
if (caseSens)
|
||||||
|
start = viewText.FindLast(findIt.String(),start);
|
||||||
|
else
|
||||||
|
start = viewText.IFindLast(findIt.String(),start);
|
||||||
|
if (start == B_ERROR)
|
||||||
|
break; // done
|
||||||
|
if (oldstart != start) {
|
||||||
|
fTextView->Delete(start, start + findIt.Length());
|
||||||
|
fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
|
||||||
|
} else {
|
||||||
|
start--; // we prefer not to get stuck
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}/***StyledEditWindow::ReplaceAll()***/
|
}/***StyledEditWindow::ReplaceAll()***/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ private:
|
|||||||
void InitWindow();
|
void InitWindow();
|
||||||
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);
|
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(rgb_color *color);
|
void SetFontColor(rgb_color *color);
|
||||||
|
|||||||
Reference in New Issue
Block a user