Annotation of sbbs/src/sbbs3/ctrl/textfileeditunit.cpp, revision 1.1.1.2

1.1       root        1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
                      2: 
1.1.1.2 ! root        3: /* $Id: TextFileEditUnit.cpp,v 1.5 2008/02/12 09:00:49 rswindell Exp $ */
1.1       root        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:  *                                                                                                                                                     *
1.1.1.2 ! root        9:  * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       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;
1.1.1.2 ! root       68:     Screen->Cursor=crHourGlass;
1.1       root       69:     try {
                     70:         Memo->Lines->LoadFromFile(Filename);
                     71:     } catch(...) { }
1.1.1.2 ! root       72:     Screen->Cursor=crDefault;
1.1       root       73:     ActiveControl=Memo;
                     74:     Memo->SelStart=0;
                     75: }
                     76: //---------------------------------------------------------------------------
                     77: void __fastcall TTextFileEditForm::FontButtonClick(TObject *Sender)
                     78: {
                     79:        TFontDialog *FontDialog=new TFontDialog(this);
                     80: 
                     81:     FontDialog->Font->Assign(Memo->Font);
                     82:     FontDialog->Execute();
                     83:     Memo->Font->Assign(FontDialog->Font);
                     84:     delete FontDialog;
                     85: }
                     86: //---------------------------------------------------------------------------
                     87: 
                     88: 
                     89: 
                     90: 
                     91: 
                     92: 
                     93: void __fastcall TTextFileEditForm::FindDialogFind(TObject *Sender)
                     94: {
                     95:     TFindDialog* Dlg=(TFindDialog*)Sender;
                     96:     TSearchTypes stype;
                     97:     int result;
                     98:     int start;
                     99: 
                    100:     if(Dlg->Options.Contains(frMatchCase))
                    101:         stype << stMatchCase;
                    102:     if(Dlg->Options.Contains(frWholeWord))
                    103:         stype << stWholeWord;
                    104: 
                    105:     start=Memo->SelStart;
                    106: 
                    107:     if(Dlg->Tag)
                    108:         start++;
                    109:     result=Memo->FindText(Dlg->FindText
                    110:         ,start,Memo->Text.Length(),stype);
                    111:     if(result==-1)
                    112:         Beep();
                    113:     else {
                    114:         Memo->SelStart=result;
                    115:         Memo->SelLength=Dlg->FindText.Length();
                    116:     }
                    117:     Dlg->Tag=1;
                    118: }
                    119: //---------------------------------------------------------------------------
                    120: 
                    121: 
                    122: 
                    123: void __fastcall TTextFileEditForm::ReplaceDialogReplace(TObject *Sender)
                    124: {
                    125:     TSearchTypes stype;
                    126:     int result;
                    127:     int start;
                    128: 
                    129:     if(ReplaceDialog->Options.Contains(frMatchCase))
                    130:         stype << stMatchCase;
                    131:     if(ReplaceDialog->Options.Contains(frWholeWord))
                    132:         stype << stWholeWord;
                    133: 
                    134:     if(ReplaceDialog->Options.Contains(frReplaceAll)) {
                    135:         while((result=Memo->FindText(ReplaceDialog->FindText
                    136:             ,Memo->SelStart,Memo->Text.Length(),stype))!=-1) {
                    137:             Memo->SelStart=result;
                    138:             Memo->SelLength=ReplaceDialog->FindText.Length();
                    139:             Memo->SelText=ReplaceDialog->ReplaceText;
                    140:             Memo->SelStart++;
                    141:         }
                    142:         return;
                    143:     }
                    144: 
                    145:     start=Memo->SelStart;
                    146: 
                    147:     if(Memo->SelText==ReplaceDialog->FindText) {
                    148:         Memo->SelText=ReplaceDialog->ReplaceText;
                    149:         ReplaceDialog->Tag=1;
                    150:         return;
                    151:     }
                    152:     result=Memo->FindText(ReplaceDialog->FindText
                    153:         ,start,Memo->Text.Length(),stype);
                    154:     if(result==-1)
                    155:         Beep();
                    156:     else {
                    157:         Memo->SelStart=result;
                    158:         Memo->SelLength=ReplaceDialog->FindText.Length();
                    159:         Memo->SelText=ReplaceDialog->ReplaceText;
                    160:     }
                    161: }
                    162: //---------------------------------------------------------------------------
                    163: 
                    164: 
                    165: void __fastcall TTextFileEditForm::InsertCtrlAExecute(TObject *Sender)
                    166: {
                    167:     Memo->SelText="\1";
                    168: }
                    169: //---------------------------------------------------------------------------
                    170: 
                    171: void __fastcall TTextFileEditForm::FindExecute(TObject *Sender)
                    172: {
                    173:     FindDialog->Options.Clear();
                    174:     FindDialog->Options << frHideUpDown;
                    175:     FindDialog->Tag=0;
                    176:     FindDialog->Execute();
                    177: }
                    178: //---------------------------------------------------------------------------
                    179: 
                    180: void __fastcall TTextFileEditForm::ReplaceExecute(TObject *Sender)
                    181: {
                    182:     ReplaceDialog->Execute();
                    183: }
                    184: //---------------------------------------------------------------------------
                    185: 
                    186: void __fastcall TTextFileEditForm::SelectAllExecute(TObject *Sender)
                    187: {
                    188:     Memo->SelectAll();
                    189: }
                    190: //---------------------------------------------------------------------------
                    191: 
                    192: void __fastcall TTextFileEditForm::FileExitMenuItemClick(TObject *Sender)
                    193: {
                    194:     Close();
                    195: }
                    196: //---------------------------------------------------------------------------
                    197: 
                    198: void __fastcall TTextFileEditForm::SaveExecute(TObject *Sender)
                    199: {
                    200:        int i;
                    201: 
                    202:     if(Memo->ReadOnly==true)
                    203:         return;
                    204: 
                    205: #if 0
                    206:        FILE* fp;
                    207:     if((fp=fopen(Filename.c_str(),"w"))!=NULL) {
                    208:                for(i=0;i<Memo->Lines->Count;i++)
                    209:                fprintf(fp,"%s\n",Memo->Lines->Strings[i].c_str());
                    210:         fclose(fp);
                    211:     }
                    212: #else
                    213:     Memo->Lines->SaveToFile(Filename);
                    214: #endif
                    215: }
                    216: //---------------------------------------------------------------------------
                    217: 
                    218: void __fastcall TTextFileEditForm::CutExecute(TObject *Sender)
                    219: {
                    220:     Memo->CutToClipboard();    
                    221: }
                    222: //---------------------------------------------------------------------------
                    223: 
                    224: void __fastcall TTextFileEditForm::CopyExecute(TObject *Sender)
                    225: {
                    226:     Memo->CopyToClipboard();    
                    227: }
                    228: //---------------------------------------------------------------------------
                    229: 
                    230: void __fastcall TTextFileEditForm::PasteExecute(TObject *Sender)
                    231: {
                    232:     Memo->PasteFromClipboard();
                    233: }
                    234: //---------------------------------------------------------------------------
                    235: 
                    236: void __fastcall TTextFileEditForm::UndoExecute(TObject *Sender)
                    237: {
                    238:     Memo->Undo();
                    239: }
                    240: //---------------------------------------------------------------------------
                    241: 
                    242: void __fastcall TTextFileEditForm::ChangeFontExecute(TObject *Sender)
                    243: {
                    244:     FontDialog->Font->Assign(Memo->Font);
                    245:     FontDialog->Execute();
                    246:     Memo->Font->Assign(FontDialog->Font);
                    247: }
                    248: //---------------------------------------------------------------------------
                    249: 
                    250: void __fastcall TTextFileEditForm::FontDialogApply(TObject *Sender,
                    251:       HWND Wnd)
                    252: {
                    253:     Memo->Font->Assign(FontDialog->Font);
                    254: }
                    255: //---------------------------------------------------------------------------
                    256: 
                    257: 
                    258: 
                    259: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.