1 {Unidad con frame para almacenar y configurar las propiedades de un editor
2  SynEdit. Las propiedades que se manejan son con respecto al coloreado.
3  El frame definido, está pensado para usarse en una ventana de configuración.
4  También incluye una lista para almacenamiento de los archivos recientes
5                                Por Tito Hinostroza  23/11/2013
6 }
7 unit FrameCfgEdit;
8 
9 {$mode objfpc}{$H+}
10 
11 interface
12 
13 uses
14   Classes, SysUtils, Forms, StdCtrls, Dialogs,
15   Spin, SynEdit, Graphics, SynEditMarkupHighAll, SynEditMarkup,
16   ConfigFrame;   //para interceptar TFrame
17 
18 type
19 
20   { TfraCfgEdit }
21 
22   TfraCfgEdit = class(TFrame)
23     cbutFonPan: TColorButton;
24     cbutTxtPan: TColorButton;
25     chkResPalCur: TCheckBox;
26     chkVerPanVer: TCheckBox;
27     chkMarLinAct: TCheckBox;
28     cbutLinAct: TColorButton;
29     chkVerBarDes: TCheckBox;
30     chkVerNumLin: TCheckBox;
31     chkVerMarPle: TCheckBox;
32     cmbTipoLetra: TComboBox;
33     cbutFondo: TColorButton;
34     cbutTexto: TColorButton;
35     GroupBox1: TGroupBox;
36     Label1: TLabel;
37     Label2: TLabel;
38     Label3: TLabel;
39     Label6: TLabel;
40     Label7: TLabel;
41     Label8: TLabel;
42     Label9: TLabel;
43     spTam: TSpinEdit;
44     procedure chkMarLinActChange(Sender: TObject);
45     procedure chkVerPanVerChange(Sender: TObject);
46   private
47     ed: TSynEdit;
48     procedure ConfigEditor;
49   public
50     //configuración del editor
51     TipLet     : string;    //tipo de letra
52     TamLet     : integer;   //tamaño de letra
53     MarLinAct  : boolean;   //marcar línea actual
54     VerBarDes  : boolean;   //ver barras de desplazamiento
55     ResPalCur  : boolean;   //resaltar palabra bajo el cursor
56     cTxtNor    : TColor;    //color de texto normal
57     cFonEdi    : TColor;    //Color de fondo del control de edición
58     cFonSel    : TColor;    //color del fondo de la selección
59     cTxtSel    : TColor;    //color del texto de la selección
60     cLinAct    : TColor;    //color de la línea actual
61     //panel vertical
62     VerPanVer  : boolean;   //ver pánel vertical
63     VerNumLin  : boolean;   //ver número de línea
64     VerMarPle  : boolean;   //ver marcas de plegado
65     cFonPan    : TColor;    //color de fondo del panel vertical
66     cTxtPan    : TColor;    //color de texto del panel vertical
67     ArcRecientes: TStringList;  //Lista de archivos recientes
68 
69     procedure PropToWindow; override;
70     procedure Iniciar(secINI0: string; ed0: TSynEdit); //Inicia el frame
71     //genera constructor y destructor
72     constructor Create(AOwner: TComponent) ; override;
73     destructor Destroy; override;
74   end;
75 
76 implementation
77 {$R *.lfm}
78 
79 { TfraCfgEdit }
80 procedure TfraCfgEdit.Iniciar(secINI0: string; ed0: TSynEdit);
81 begin
82   secINI := secINI0;  //sección INI
83   //asigna referencia necesarias
84   ed := ed0;
85 //  ArcRecientes := ArcRecientes0;
86   OnUpdateChanges := @ConfigEditor;  //manejador de cambios
87   //crea las relaciones variable-control
88   Asoc_Col_TColBut(@cTxtNor, cbutTexto, 'cTxtNor',$000000);
89   Asoc_Col_TColBut(@cFonEdi, cbutFondo, 'cFonEdi',$FFFFFF);
90   Asoc_Col_TColBut(@cLinAct, cbutLinAct, 'cLinAct',clYellow);
91 
92   Asoc_Bol_TChkB(@VerBarDes,chkVerBarDes,'VerBarDes',true);
93   Asoc_Bol_TChkB(@ResPalCur,chkResPalCur,'ResPalCur',true);
94   Asoc_Bol_TChkB(@MarLinAct,chkMarLinAct,'MarLinAct',false);
95 
96   Asoc_Bol_TChkB(@VerPanVer, chkVerPanVer, 'VerPanVer',true);
97   Asoc_Bol_TChkB(@VerNumLin, chkVerNumLin, 'VerNumLin',false);
98   Asoc_Bol_TChkB(@VerMarPle, chkVerMarPle, 'VerMarPle',true);
99   Asoc_Col_TColBut(@cFonPan, cbutFonPan, 'cFonPan',clWhite);
100   Asoc_Col_TColBut(@cTxtPan, cbutTxtPan, 'cTxtPan',clWhite);
101 
102   Asoc_Int_TSpnEdi(@TamLet, spTam, 'TamLet', 10, 5, 20);
103 
104   cmbTipoLetra.Items.Clear;
105   cmbTipoLetra.Items.Add('Courier New');
106   cmbTipoLetra.Items.Add('Fixedsys');
107   cmbTipoLetra.Items.Add('Lucida Console');
108   cmbTipoLetra.Items.Add('Consolas');
109   cmbTipoLetra.Items.Add('Cambria');
110   Asoc_Str_TCmbBox(@TipLet, cmbTipoLetra, 'TipLet', 'Courier New');
111 
112 //  if ArcRecientes0<> nil then Asoc_StrList(@ArcRecientes0, 'recient');
113 //  if ArcRecientes<> nil then
114     Asoc_StrList(@ArcRecientes, 'recient');
115 end;
116 
117 procedure TfraCfgEdit.chkVerPanVerChange(Sender: TObject);
118 begin
119   chkVerNumLin.Enabled:=chkVerPanVer.Checked;
120   chkVerMarPle.Enabled:=chkVerPanVer.Checked;
121   cbutFonPan.Enabled:=chkVerPanVer.Checked;
122   cbutTxtPan.Enabled:=chkVerPanVer.Checked;
123   label2.Enabled:=chkVerPanVer.Checked;
124   label3.Enabled:=chkVerPanVer.Checked;
125 end;
126 procedure TfraCfgEdit.chkMarLinActChange(Sender: TObject);
127 begin
128   label1.Enabled:=chkMarLinAct.Checked;
129   cbutLinAct.Enabled:=chkMarLinAct.Checked;
130 end;
131 
132 procedure TfraCfgEdit.PropToWindow;
133 begin
134    inherited;
135    chkMarLinActChange(self);  //para actualizar
136    chkVerPanVerChange(self);  //para actualizar
137 end;
138 constructor TfraCfgEdit.Create(AOwner: TComponent);
139 begin
140   inherited Create(AOwner);
141   ArcRecientes := TStringList.Create;  //crea lista
142 end;
143 destructor TfraCfgEdit.Destroy;
144 begin
145   FreeAndNil(ArcRecientes);
146   inherited Destroy;
147 end;
148 procedure TfraCfgEdit.ConfigEditor;
149 {Configura el editor con las propiedades almacenadas}
150 var
151   marc: TSynEditMarkup;
152 begin
153    if ed = nil then exit;  //protección
154    //tipo de texto
155    if TipLet <> '' then ed.Font.Name:=TipLet;
156    if (TamLet > 6) and (TamLet < 32) then ed.Font.Size:=Round(TamLet);
157 
158    ed.Font.Color:=cTxtNor;      //color de texto normal
159    ed.Color:=cFonEdi;           //color de fondo
160    if MarLinAct then          //resaltado de línea actual
161      ed.LineHighlightColor.Background:=cLinAct
162    else
163      ed.LineHighlightColor.Background:=clNone;
164    //configura panel vertical
165    ed.Gutter.Visible:=VerPanVer;  //muestra panel vertical
166    ed.Gutter.Parts[1].Visible:=VerNumLin;  //Número de línea
167    ed.Gutter.Parts[4].Visible:=VerMarPle;  //marcas de plegado
168    ed.Gutter.Color:=cFonPan;   //color de fondo del panel
169    ed.Gutter.Parts[1].MarkupInfo.Background:=cFonPan; //fondo del núemro de línea
170    ed.Gutter.Parts[1].MarkupInfo.Foreground:=cTxtPan; //texto del núemro de línea
171 
172    if VerBarDes then  //barras de desplazamiento
173      ed.ScrollBars:= ssBoth
174    else
175      ed.ScrollBars := ssNone;
176    ////////Configura el resaltado de la palabra actual //////////
177    marc := ed.MarkupByClass[TSynEditMarkupHighlightAllCaret];
178    if marc<>nil then begin  //hay marcador
179       marc.Enabled:=ResPalCur;  //configura
180    end;
181    ///////fija color de delimitadores () {} [] ///////////
182    ed.BracketMatchColor.Foreground := clRed;
183 end;
184 
185 end.
186 
187