|
|
1.1 ! root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ ! 2: ! 3: /* $Id: TextFileEditUnit.cpp,v 1.2 2000/11/15 04:15:44 rswindell Exp $ */ ! 4: ! 5: /**************************************************************************** ! 6: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 7: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 8: * * ! 9: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 10: * * ! 11: * This program is free software; you can redistribute it and/or * ! 12: * modify it under the terms of the GNU General Public License * ! 13: * as published by the Free Software Foundation; either version 2 * ! 14: * of the License, or (at your option) any later version. * ! 15: * See the GNU General Public License for more details: gpl.txt or * ! 16: * http://www.fsf.org/copyleft/gpl.html * ! 17: * * ! 18: * Anonymous FTP access to the most recent released source is available at * ! 19: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 20: * * ! 21: * Anonymous CVS access to the development source and modification history * ! 22: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 24: * (just hit return, no password is necessary) * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 26: * * ! 27: * For Synchronet coding style and modification guidelines, see * ! 28: * http://www.synchro.net/source.html * ! 29: * * ! 30: * You are encouraged to submit any modifications (preferably in Unix diff * ! 31: * format) via e-mail to [email protected] * ! 32: * * ! 33: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 34: ****************************************************************************/ ! 35: ! 36: //--------------------------------------------------------------------------- ! 37: #include <vcl.h> ! 38: #pragma hdrstop ! 39: ! 40: #include <stdio.h> ! 41: #include "TextFileEditUnit.h" ! 42: //--------------------------------------------------------------------------- ! 43: #pragma package(smart_init) ! 44: #pragma resource "*.dfm" ! 45: TTextFileEditForm *TextFileEditForm; ! 46: //--------------------------------------------------------------------------- ! 47: __fastcall TTextFileEditForm::TTextFileEditForm(TComponent* Owner) ! 48: : TForm(Owner) ! 49: { ! 50: } ! 51: //--------------------------------------------------------------------------- ! 52: void __fastcall TTextFileEditForm::FormShow(TObject *Sender) ! 53: { ! 54: char str[256]; ! 55: ! 56: if(Memo->ReadOnly) { ! 57: Save->Enabled=false; ! 58: Cut->Enabled=false; ! 59: Undo->Enabled=false; ! 60: Paste->Enabled=false; ! 61: InsertCtrlA->Enabled=false; ! 62: CancelButton->Enabled=false; ! 63: Panel->Visible=false; ! 64: EditReplaceMenuItem->Enabled=false; ! 65: ReplacePopupMenuItem->Enabled=false; ! 66: } ! 67: Caption=Caption+AnsiString(" - ")+Filename.UpperCase(); ! 68: try { ! 69: Memo->Lines->LoadFromFile(Filename); ! 70: } catch(...) { } ! 71: ActiveControl=Memo; ! 72: Memo->SelStart=0; ! 73: } ! 74: //--------------------------------------------------------------------------- ! 75: void __fastcall TTextFileEditForm::FontButtonClick(TObject *Sender) ! 76: { ! 77: TFontDialog *FontDialog=new TFontDialog(this); ! 78: ! 79: FontDialog->Font->Assign(Memo->Font); ! 80: FontDialog->Execute(); ! 81: Memo->Font->Assign(FontDialog->Font); ! 82: delete FontDialog; ! 83: } ! 84: //--------------------------------------------------------------------------- ! 85: ! 86: ! 87: ! 88: ! 89: ! 90: ! 91: void __fastcall TTextFileEditForm::FindDialogFind(TObject *Sender) ! 92: { ! 93: TFindDialog* Dlg=(TFindDialog*)Sender; ! 94: TSearchTypes stype; ! 95: int result; ! 96: int start; ! 97: ! 98: if(Dlg->Options.Contains(frMatchCase)) ! 99: stype << stMatchCase; ! 100: if(Dlg->Options.Contains(frWholeWord)) ! 101: stype << stWholeWord; ! 102: ! 103: start=Memo->SelStart; ! 104: ! 105: if(Dlg->Tag) ! 106: start++; ! 107: result=Memo->FindText(Dlg->FindText ! 108: ,start,Memo->Text.Length(),stype); ! 109: if(result==-1) ! 110: Beep(); ! 111: else { ! 112: Memo->SelStart=result; ! 113: Memo->SelLength=Dlg->FindText.Length(); ! 114: } ! 115: Dlg->Tag=1; ! 116: } ! 117: //--------------------------------------------------------------------------- ! 118: ! 119: ! 120: ! 121: void __fastcall TTextFileEditForm::ReplaceDialogReplace(TObject *Sender) ! 122: { ! 123: TSearchTypes stype; ! 124: int result; ! 125: int start; ! 126: ! 127: if(ReplaceDialog->Options.Contains(frMatchCase)) ! 128: stype << stMatchCase; ! 129: if(ReplaceDialog->Options.Contains(frWholeWord)) ! 130: stype << stWholeWord; ! 131: ! 132: if(ReplaceDialog->Options.Contains(frReplaceAll)) { ! 133: while((result=Memo->FindText(ReplaceDialog->FindText ! 134: ,Memo->SelStart,Memo->Text.Length(),stype))!=-1) { ! 135: Memo->SelStart=result; ! 136: Memo->SelLength=ReplaceDialog->FindText.Length(); ! 137: Memo->SelText=ReplaceDialog->ReplaceText; ! 138: Memo->SelStart++; ! 139: } ! 140: return; ! 141: } ! 142: ! 143: start=Memo->SelStart; ! 144: ! 145: if(Memo->SelText==ReplaceDialog->FindText) { ! 146: Memo->SelText=ReplaceDialog->ReplaceText; ! 147: ReplaceDialog->Tag=1; ! 148: return; ! 149: } ! 150: result=Memo->FindText(ReplaceDialog->FindText ! 151: ,start,Memo->Text.Length(),stype); ! 152: if(result==-1) ! 153: Beep(); ! 154: else { ! 155: Memo->SelStart=result; ! 156: Memo->SelLength=ReplaceDialog->FindText.Length(); ! 157: Memo->SelText=ReplaceDialog->ReplaceText; ! 158: } ! 159: } ! 160: //--------------------------------------------------------------------------- ! 161: ! 162: ! 163: void __fastcall TTextFileEditForm::InsertCtrlAExecute(TObject *Sender) ! 164: { ! 165: Memo->SelText="\1"; ! 166: } ! 167: //--------------------------------------------------------------------------- ! 168: ! 169: void __fastcall TTextFileEditForm::FindExecute(TObject *Sender) ! 170: { ! 171: FindDialog->Options.Clear(); ! 172: FindDialog->Options << frHideUpDown; ! 173: FindDialog->Tag=0; ! 174: FindDialog->Execute(); ! 175: } ! 176: //--------------------------------------------------------------------------- ! 177: ! 178: void __fastcall TTextFileEditForm::ReplaceExecute(TObject *Sender) ! 179: { ! 180: ReplaceDialog->Execute(); ! 181: } ! 182: //--------------------------------------------------------------------------- ! 183: ! 184: void __fastcall TTextFileEditForm::SelectAllExecute(TObject *Sender) ! 185: { ! 186: Memo->SelectAll(); ! 187: } ! 188: //--------------------------------------------------------------------------- ! 189: ! 190: void __fastcall TTextFileEditForm::FileExitMenuItemClick(TObject *Sender) ! 191: { ! 192: Close(); ! 193: } ! 194: //--------------------------------------------------------------------------- ! 195: ! 196: void __fastcall TTextFileEditForm::SaveExecute(TObject *Sender) ! 197: { ! 198: int i; ! 199: ! 200: if(Memo->ReadOnly==true) ! 201: return; ! 202: ! 203: #if 0 ! 204: FILE* fp; ! 205: if((fp=fopen(Filename.c_str(),"w"))!=NULL) { ! 206: for(i=0;i<Memo->Lines->Count;i++) ! 207: fprintf(fp,"%s\n",Memo->Lines->Strings[i].c_str()); ! 208: fclose(fp); ! 209: } ! 210: #else ! 211: Memo->Lines->SaveToFile(Filename); ! 212: #endif ! 213: } ! 214: //--------------------------------------------------------------------------- ! 215: ! 216: void __fastcall TTextFileEditForm::CutExecute(TObject *Sender) ! 217: { ! 218: Memo->CutToClipboard(); ! 219: } ! 220: //--------------------------------------------------------------------------- ! 221: ! 222: void __fastcall TTextFileEditForm::CopyExecute(TObject *Sender) ! 223: { ! 224: Memo->CopyToClipboard(); ! 225: } ! 226: //--------------------------------------------------------------------------- ! 227: ! 228: void __fastcall TTextFileEditForm::PasteExecute(TObject *Sender) ! 229: { ! 230: Memo->PasteFromClipboard(); ! 231: } ! 232: //--------------------------------------------------------------------------- ! 233: ! 234: void __fastcall TTextFileEditForm::UndoExecute(TObject *Sender) ! 235: { ! 236: Memo->Undo(); ! 237: } ! 238: //--------------------------------------------------------------------------- ! 239:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.