| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Common.h>
- #include "Editor.h"
- #include "WinInterface.h"
- #include "TextsWin.h"
- #include "Tools.h"
- #include <CoreMain.h>
- #include "VCLCommon.h"
- #include "WinConfiguration.h"
- #include "HelpWin.h"
- #include <CommDlg.hpp>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "TB2Dock"
- #pragma link "TBX"
- #pragma link "TB2Item"
- #pragma link "TB2Toolbar"
- #pragma link "TBXStatusBars"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------------
- TForm * __fastcall ShowEditorForm(const AnsiString FileName, TCustomForm * ParentForm,
- TNotifyEvent OnFileChanged, TNotifyEvent OnFileReload, TNotifyEvent OnClose,
- const AnsiString Caption)
- {
- TEditorForm * Dialog = new TEditorForm(Application);
- try
- {
- Dialog->FileName = FileName;
- Dialog->ParentForm = ParentForm;
- Dialog->Caption = Caption.IsEmpty() ? FileName : Caption;
- Dialog->OnFileChanged = OnFileChanged;
- Dialog->OnFileReload = OnFileReload;
- Dialog->OnWindowClose = OnClose;
- Dialog->Show();
- }
- catch(...)
- {
- delete Dialog;
- throw;
- }
- return Dialog;
- }
- //---------------------------------------------------------------------------
- void __fastcall ReconfigureEditorForm(TForm * Form)
- {
- TEditorForm * Editor = dynamic_cast<TEditorForm *>(Form);
- assert(Editor != NULL);
- Editor->ApplyConfiguration();
- }
- //---------------------------------------------------------------------------
- class TRichEdit20 : public TRichEdit
- {
- public:
- virtual __fastcall TRichEdit20(TComponent * AOwner);
- void __fastcall SetFormat(AnsiString FontName, int FontHeight,
- TFontCharset FontCharset, TFontStyles FontStyles, unsigned int TabSize,
- bool AWordWrap);
- int __fastcall FindText(const AnsiString SearchStr, int StartPos, int Length,
- TSearchTypes Options, bool Down);
- void __fastcall Redo();
- __property bool SupportsUpSearch = { read = FVersion20 };
- __property bool CanRedo = { read = GetCanRedo };
- protected:
- virtual void __fastcall CreateWnd(void);
- virtual void __fastcall CreateParams(TCreateParams & Params);
- virtual void __fastcall DestroyWnd();
- bool __fastcall GetCanRedo();
- void __fastcall ApplyTabSize();
- private:
- HINSTANCE FLibrary;
- bool FVersion20;
- bool FWordWrap;
- unsigned int FTabSize;
- };
- //---------------------------------------------------------------------------
- __fastcall TRichEdit20::TRichEdit20(TComponent * AOwner) :
- TRichEdit(AOwner),
- FLibrary(0),
- FVersion20(false),
- FTabSize(0),
- FWordWrap(true)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::SetFormat(AnsiString FontName, int FontHeight,
- TFontCharset FontCharset, TFontStyles FontStyles, unsigned int TabSize,
- bool AWordWrap)
- {
- bool RecalculateTabs = (Font->Name != FontName) || (Font->Height != FontHeight) ||
- (TabSize != FTabSize);
- LockWindowUpdate(Handle);
- Font->Name = FontName;
- Font->Height = FontHeight;
- Font->Charset = FontCharset;
- Font->Style = FontStyles;
- DefAttributes->Assign(Font);
- FTabSize = TabSize;
- if (RecalculateTabs && HandleAllocated())
- {
- ApplyTabSize();
- }
- if (FWordWrap != AWordWrap)
- {
- if (Visible)
- {
- // Undocumented usage of EM_SETTARGETDEVICE.
- // But note that it is used by MFC in CRichEditView::WrapChanged()
- SendMessage(Handle, EM_SETTARGETDEVICE, 0, (AWordWrap ? 0 : 1));
- }
- else
- {
- WordWrap = AWordWrap;
- }
- FWordWrap = AWordWrap;
- }
- LockWindowUpdate(NULL);
- }
- //---------------------------------------------------------------------------
- int __fastcall TRichEdit20::FindText(const AnsiString SearchStr, int StartPos,
- int /*Length*/, TSearchTypes Options, bool Down)
- {
- int Result;
- if (FVersion20)
- {
- ::FINDTEXTEX Find;
- memset(&Find, 0, sizeof(Find));
- Find.chrg.cpMin = StartPos;
- Find.chrg.cpMax = -1;
- Find.lpstrText = SearchStr.c_str();
- unsigned int Flags =
- FLAGMASK(Options.Contains(stWholeWord), FT_WHOLEWORD) |
- FLAGMASK(Options.Contains(stMatchCase), FT_MATCHCASE) |
- FLAGMASK(Down, FR_DOWN);
- Result = SendMessage(Handle, EM_FINDTEXTEX, Flags, (LPARAM)&Find);
- }
- else
- {
- assert(Down);
- Result = TRichEdit::FindText(SearchStr, StartPos, Text.Length(), Options);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::Redo()
- {
- assert(FVersion20);
- SendMessage(Handle, EM_REDO, 0, 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::CreateWnd(void)
- {
- TRichEdit::CreateWnd();
- ApplyTabSize();
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::CreateParams(TCreateParams & Params)
- {
- const char RichEditModuleName[] = "RICHED20.DLL";
- long int OldError;
- OldError = SetErrorMode(SEM_NOOPENFILEERRORBOX);
- FLibrary = LoadLibrary(RichEditModuleName);
- SetErrorMode(OldError);
- FVersion20 = (FLibrary != 0);
- if (!FVersion20)
- {
- // fallback to richedit 1.0
- TRichEdit::CreateParams(Params);
- }
- else
- {
- TCustomMemo::CreateParams(Params);
- CreateSubClass(Params, RICHEDIT_CLASS);
- Params.Style = Params.Style |
- (HideScrollBars ? 0 : ES_DISABLENOSCROLL) |
- (HideSelection ? 0 : ES_NOHIDESEL);
- Params.WindowClass.style = Params.WindowClass.style &
- ~(CS_HREDRAW | CS_VREDRAW);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::DestroyWnd()
- {
- TRichEdit::DestroyWnd();
- if (FLibrary != 0)
- {
- FreeLibrary(FLibrary);
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TRichEdit20::GetCanRedo()
- {
- return FVersion20 && (SendMessage(Handle, EM_CANREDO, 0, 0) != 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TRichEdit20::ApplyTabSize()
- {
- if (FTabSize > 0)
- {
- HDC DC = GetDC(Handle);
- SaveDC(DC);
- SetMapMode(DC, MM_TEXT);
- SelectObject(DC, Font->Handle);
- int LogPixelsX = GetDeviceCaps(DC, LOGPIXELSX);
- SIZE Size;
- GetTextExtentPoint(DC, AnsiString::StringOfChar('X', FTabSize).c_str(),
- FTabSize, &Size);
- RestoreDC(DC, -1);
- ReleaseDC(Handle, DC);
- unsigned int TabTwips = MulDiv(Size.cx, 1440, LogPixelsX);
- // save selection
- CHARRANGE CharRange;
- SendMessage(Handle, EM_EXGETSEL, 0, (LPARAM)&CharRange);
- CHARRANGE CharRangeAll;
- CharRangeAll.cpMin = 0;
- CharRangeAll.cpMax = -1;
- SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM)&CharRangeAll);
- PARAFORMAT2 ParaFormat;
- ParaFormat.cbSize = sizeof(ParaFormat);
- ParaFormat.dwMask = PFM_TABSTOPS;
- ParaFormat.cTabCount = MAX_TAB_STOPS;
- for (int i = 0; i < ParaFormat.cTabCount; i++)
- {
- ParaFormat.rgxTabs[i] = (i + 1) * TabTwips;
- }
- SendMessage(Handle, EM_SETPARAFORMAT, 0, (LPARAM)&ParaFormat);
- // restore selection
- SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM)&CharRange);
- }
- }
- //---------------------------------------------------------------------------
- class TFindDialogEx : public TFindDialog
- {
- public:
- __fastcall virtual TFindDialogEx(TComponent * AOwner) : TFindDialog(AOwner)
- {
- FHelpMsg = RegisterWindowMessage(HELPMSGSTRING);
- }
- protected:
- unsigned int FHelpMsg;
- virtual bool __fastcall MessageHook(TMessage & Msg)
- {
- bool Result = false;
- if (Msg.Msg == FHelpMsg)
- {
- Application->HelpKeyword(HELP_EDITOR_FIND);
- Result = true;
- }
- if (!Result)
- {
- Result = TFindDialog::MessageHook(Msg);
- }
- return Result;
- }
- };
- //---------------------------------------------------------------------------
- class TReplaceDialogEx : public TReplaceDialog
- {
- public:
- __fastcall virtual TReplaceDialogEx(TComponent * AOwner) : TReplaceDialog(AOwner)
- {
- FHelpMsg = RegisterWindowMessage(HELPMSGSTRING);
- }
- protected:
- unsigned int FHelpMsg;
- virtual bool __fastcall MessageHook(TMessage & Msg)
- {
- bool Result = false;
- if (Msg.Msg == FHelpMsg)
- {
- Application->HelpKeyword(HELP_EDITOR_REPLACE);
- Result = true;
- }
- if (!Result)
- {
- Result = TReplaceDialog::MessageHook(Msg);
- }
- return Result;
- }
- };
- //---------------------------------------------------------------------------
- __fastcall TEditorForm::TEditorForm(TComponent* Owner)
- : TForm(Owner)
- {
- EditorMemo = new TRichEdit20(this);
- EditorMemo->Parent = this;
- EditorMemo->Align = alClient;
- EditorMemo->HideSelection = false;
- EditorMemo->PlainText = true;
- EditorMemo->PopupMenu = EditorPopup;
- EditorMemo->ScrollBars = ssBoth;
- EditorMemo->WantTabs = true;
- EditorMemo->OnChange = EditorMemoChange;
- EditorMemo->OnKeyUp = EditorMemoKeyUp;
- EditorMemo->OnMouseUp = EditorMemoMouseUp;
- FParentForm = NULL;
- FCaretPos.x = -1;
- FCaretPos.y = -1;
- FLastFindDialog = NULL;
- FCloseAnnounced = false;
- ApplyConfiguration();
- FFindDialog = new TFindDialogEx(this);
- FFindDialog->OnFind = FindDialogFind;
- FReplaceDialog = new TReplaceDialogEx(this);
- FReplaceDialog->OnFind = FindDialogFind;
- FReplaceDialog->OnReplace = FindDialogFind;
- UseSystemSettings(this);
- }
- //---------------------------------------------------------------------------
- __fastcall TEditorForm::~TEditorForm()
- {
- // see FormClose for explanation
- if (!FCloseAnnounced)
- {
- DoWindowClose();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::SetFileName(const AnsiString value)
- {
- if (value != FFileName)
- {
- FFileName = value;
- if (Visible)
- {
- LoadFile();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::SetParentForm(TCustomForm * value)
- {
- if (FParentForm != value)
- {
- FParentForm = value;
- if (value)
- {
- Width = value->BoundsRect.Width();
- Height = value->BoundsRect.Height();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::EditorActionsUpdate(TBasicAction *Action,
- bool &Handled)
- {
- Handled = true;
- if (Action == SaveAction)
- {
- SaveAction->Enabled = EditorMemo->Modified;
- }
- else if (Action == FindNextAction)
- {
- FindNextAction->Enabled =
- FLastFindDialog != NULL || !FFindDialog->FindText.IsEmpty();
- }
- else if (Action == EditRedo)
- {
- EditRedo->Enabled = EditorMemo->CanRedo;
- }
- else if (Action == PreferencesAction || Action == CloseAction ||
- Action == FindAction || Action == ReplaceAction || Action == GoToLineAction ||
- Action == HelpAction || Action == ReloadAction)
- {
- ((TAction *)Action)->Enabled = true;
- }
- else
- {
- Handled = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::EditorActionsExecute(TBasicAction *Action,
- bool &Handled)
- {
- Handled = true;
- if (Action == SaveAction)
- {
- assert(!FFileName.IsEmpty());
- EditorMemo->Lines->SaveToFile(FFileName);
- if (FOnFileChanged)
- {
- FOnFileChanged(this);
- }
- EditorMemo->Modified = false;
- UpdateControls();
- }
- else if (Action == PreferencesAction)
- {
- DoPreferencesDialog(pmEditor);
- }
- else if (Action == CloseAction)
- {
- Close();
- }
- else if (Action == ReloadAction)
- {
- Reload();
- }
- else if (Action == FindAction || Action == ReplaceAction)
- {
- StartFind(Action == FindAction);
- }
- else if (Action == FindNextAction)
- {
- if (!FLastFindDialog)
- {
- FLastFindDialog = FFindDialog;
- }
- Find();
- }
- else if (Action == GoToLineAction)
- {
- GoToLine();
- }
- else if (Action == EditRedo)
- {
- EditorMemo->Redo();
- }
- else if (Action == EditPaste)
- {
- // original source: http://home.att.net/~robertdunn/FAQs/Faqs.html
- // tell the Rich Edit control to insert unformatted text (CF_TEXT)
- REPASTESPECIAL RepasteSpecial = { 0, 0 };
- SendMessage(EditorMemo->Handle, EM_PASTESPECIAL, CF_TEXT,
- (LPARAM)&RepasteSpecial);
- }
- else if (Action == HelpAction)
- {
- FormHelp(this);
- }
- else
- {
- Handled = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::FormCloseQuery(TObject * /*Sender*/,
- bool &CanClose)
- {
- if (EditorMemo->Modified)
- {
- SetFocus();
- int Answer = MessageDialog(LoadStr(SAVE_CHANGES), qtConfirmation,
- qaYes | qaNo | qaCancel);
- CanClose = (Answer != qaCancel);
- if (Answer == qaYes)
- {
- SaveAction->Execute();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::ApplyConfiguration()
- {
- bool PrevModified = EditorMemo->Modified;
- assert(Configuration);
- EditorMemo->SetFormat(WinConfiguration->Editor.FontName,
- WinConfiguration->Editor.FontHeight, (TFontCharset)WinConfiguration->Editor.FontCharset,
- IntToFontStyles(WinConfiguration->Editor.FontStyle), WinConfiguration->Editor.TabSize,
- WinConfiguration->Editor.WordWrap);
- EditorMemo->Modified = PrevModified;
- EditorMemo->ClearUndo();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::UpdateControls()
- {
- TPoint ACaretPos = EditorMemo->CaretPos;
- if (ACaretPos.x != FCaretPos.x || ACaretPos.y != FCaretPos.y)
- {
- FCaretPos = ACaretPos;
- int Count = EditorMemo->Lines->Count;
- StatusBar->Panels->Items[0]->Caption = FMTLOAD(EDITOR_LINE_STATUS,
- ((int)FCaretPos.y+1, Count));
- StatusBar->Panels->Items[1]->Caption = FMTLOAD(EDITOR_COLUMN_STATUS,
- ((int)FCaretPos.x+1));
- AnsiString Character;
- if (FCaretPos.y >= 0 && FCaretPos.y < EditorMemo->Lines->Count)
- {
- AnsiString Line = EditorMemo->Lines->Strings[FCaretPos.y];
- if (FCaretPos.x+1 <= Line.Length())
- {
- Character = FMTLOAD(EDITOR_CHARACTER_STATUS2,
- (int((unsigned char)Line[FCaretPos.x+1]), int((unsigned char)Line[FCaretPos.x+1])));
- }
- }
- StatusBar->Panels->Items[2]->Caption = Character;
- }
- StatusBar->Panels->Items[3]->Caption =
- (EditorMemo->Modified ? LoadStr(EDITOR_MODIFIED) : AnsiString(""));
- EditorActions->UpdateAction(SaveAction);
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::EditorMemoMouseUp(TObject * /*Sender*/,
- TMouseButton /*Button*/, TShiftState /*Shift*/, int /*X*/, int /*Y*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::EditorMemoKeyUp(TObject * /*Sender*/,
- WORD & /*Key*/, TShiftState /*Shift*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::EditorMemoChange(TObject * /*Sender*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::FindDialogFind(TObject * /*Sender*/)
- {
- Find();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::Find()
- {
- int NewPos;
- int Replacements = 0;
- do
- {
- assert(FLastFindDialog);
- TSearchTypes SearchTypes;
- // length condition is there to improve performance when large
- // block is selected in editor
- if (FLastFindDialog == FReplaceDialog &&
- (FReplaceDialog->Options.Contains(frReplace) ||
- FReplaceDialog->Options.Contains(frReplaceAll)) &&
- FReplaceDialog->FindText.Length() == EditorMemo->SelLength &&
- AnsiSameText(FReplaceDialog->FindText, EditorMemo->SelText))
- {
- EditorMemo->SelText = FReplaceDialog->ReplaceText;
- Replacements++;
- }
- TEditorConfiguration EditorConfiguration = WinConfiguration->Editor;
- EditorConfiguration.FindText = FLastFindDialog->FindText;
- EditorConfiguration.ReplaceText = FReplaceDialog->ReplaceText;
- EditorConfiguration.FindMatchCase = FLastFindDialog->Options.Contains(frMatchCase);
- EditorConfiguration.FindWholeWord = FLastFindDialog->Options.Contains(frWholeWord);
- EditorConfiguration.FindDown = FLastFindDialog->Options.Contains(frDown);
- WinConfiguration->Editor = EditorConfiguration;
- if (EditorConfiguration.FindMatchCase)
- {
- SearchTypes << stMatchCase;
- }
- if (EditorConfiguration.FindWholeWord)
- {
- SearchTypes << stWholeWord;
- }
- NewPos = EditorMemo->FindText(EditorConfiguration.FindText,
- EditorMemo->SelLength ? EditorMemo->SelStart+1 : EditorMemo->SelStart,
- EditorMemo->Text.Length(), SearchTypes, EditorConfiguration.FindDown);
- if (NewPos >= 0)
- {
- EditorMemo->SelStart = NewPos;
- EditorMemo->SelLength = EditorConfiguration.FindText.Length();
- }
- if (FLastFindDialog->Handle)
- {
- PositionFindDialog(true);
- }
- if (NewPos < 0)
- {
- if ((Replacements == 0) || FReplaceDialog->Options.Contains(frReplaceAll))
- {
- // now Screen->ActiveForm can be NULL when other form was meanwhile
- // activated and then focus was returned back to "find" dialog
- // (non VCL form)
- if (Screen->ActiveForm != this)
- {
- SetFocus();
- FLastFindDialog->Execute();
- }
- if (Replacements == 0)
- {
- MessageDialog(FMTLOAD(EDITOR_FIND_END, (EditorConfiguration.FindText)), qtInformation, qaOK, HELP_NONE);
- }
- else if (FReplaceDialog->Options.Contains(frReplaceAll))
- {
- MessageDialog(FMTLOAD(EDITOR_REPLACE_END, (Replacements)), qtInformation, qaOK, HELP_NONE);
- }
- }
- }
- }
- while (NewPos >= 0 && FLastFindDialog == FReplaceDialog &&
- FReplaceDialog->Options.Contains(frReplaceAll));
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::FormShow(TObject * /*Sender*/)
- {
- LoadFile();
- CutFormToDesktop(this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::LoadFile()
- {
- EditorMemo->Lines->LoadFromFile(FFileName);
- EditorMemo->Modified = false;
- FCaretPos.x = -1;
- ApplyConfiguration();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TEditorForm::CursorInUpperPart()
- {
- HFONT OldFont;
- void *DC;
- TTextMetric TM;
- TRect Rect;
- DC = GetDC(EditorMemo->Handle);
- OldFont = SelectObject(DC, EditorMemo->Font->Handle);
- try
- {
- GetTextMetrics(DC, &TM);
- EditorMemo->Perform(EM_GETRECT, 0, ((int)&Rect));
- }
- __finally
- {
- SelectObject(DC, OldFont);
- ReleaseDC(EditorMemo->Handle, DC);
- }
- int VisibleLines = (Rect.Bottom - Rect.Top) / (TM.tmHeight + TM.tmExternalLeading);
- int FirstLine = SendMessage(EditorMemo->Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
- TPoint CaretPos = EditorMemo->CaretPos;
- return (CaretPos.y - FirstLine) < VisibleLines / 2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::PositionFindDialog(bool VerticalOnly)
- {
- assert(FLastFindDialog);
- if (!VerticalOnly)
- {
- FLastFindDialog->Left = Left + EditorMemo->Left + EditorMemo->Width / 2 - 100;
- }
- FLastFindDialog->Top = Top + EditorMemo->Top + (EditorMemo->Height / 4) +
- (CursorInUpperPart() ? (EditorMemo->Height / 2) : 0) - 40;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::StartFind(bool Find)
- {
- AnsiString Text = EditorMemo->SelText;
- TFindOptions Options;
- Options << frShowHelp;
- if (Text.IsEmpty())
- {
- Text = WinConfiguration->Editor.FindText;
- }
- TFindDialog * Dialog = Find ? FFindDialog : FReplaceDialog;
- if (FLastFindDialog && Dialog != FLastFindDialog && FLastFindDialog->Handle)
- {
- FLastFindDialog->CloseDialog();
- }
- FLastFindDialog = Dialog;
- if (!Text.IsEmpty())
- {
- FLastFindDialog->FindText = Text;
- }
- FReplaceDialog->ReplaceText = WinConfiguration->Editor.ReplaceText;
- if (WinConfiguration->Editor.FindMatchCase)
- {
- Options << frMatchCase;
- }
- if (WinConfiguration->Editor.FindWholeWord)
- {
- Options << frWholeWord;
- }
- if (EditorMemo->SupportsUpSearch)
- {
- if (WinConfiguration->Editor.FindDown)
- {
- Options << frDown;
- }
- }
- else
- {
- Options << frHideUpDown; // not implemented
- Options << frDown;
- }
- FLastFindDialog->Options = Options;
- if (!FLastFindDialog->Handle)
- {
- PositionFindDialog(false);
- }
- FLastFindDialog->Execute();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::GoToLine()
- {
- AnsiString Str;
- if (InputDialog(LoadStr(EDITOR_GO_TO_LINE), LoadStr(EDITOR_LINE_NUMBER), Str))
- {
- int Line = StrToIntDef(Str, -1);
- if (Line <= 0 || Line > EditorMemo->Lines->Count)
- {
- throw Exception(LoadStr(EDITOR_INVALID_LINE));
- }
- else
- {
- EditorMemo->CaretPos = TPoint(0, Line-1);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::FormClose(TObject * /*Sender*/,
- TCloseAction & Action)
- {
- // Preferably announce closure here as this is called from within TForm::Close(),
- // so the annoucement will be synchronous (and editor manager thus
- // will consider the form to be really closed and will not block
- // application closure).
- // However FormClose is not called when form is closed due to
- // application exit, so there is last resort call from destructor.
- DoWindowClose();
- FCloseAnnounced = true;
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::DoWindowClose()
- {
- if (FOnWindowClose != NULL)
- {
- try
- {
- FOnWindowClose(this);
- }
- catch(Exception & E)
- {
- ShowExtendedException(&E);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::CreateParams(TCreateParams & Params)
- {
- TForm::CreateParams(Params);
- Params.WndParent = GetDesktopWindow();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorForm::Reload()
- {
- if (!EditorMemo->Modified ||
- (MessageDialog(LoadStr(EDITOR_MODIFIED_RELOAD), qtConfirmation,
- qaOK | qaCancel) != qaCancel))
- {
- if (FOnFileReload)
- {
- FOnFileReload(this);
- }
- LoadFile();
- }
- }
- //---------------------------------------------------------------------------
|