FrameCfgSynEdit.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 FrameCfgSynEdit;
  8. {$mode objfpc}{$H+}
  9. interface
  10. uses
  11. Classes, SysUtils, Forms, StdCtrls, Dialogs, SynEdit, Graphics, Spin,
  12. Globales, MiConfigXML, MiConfigBasic, SynEditMarkupHighAll, SynEditMarkup;
  13. type
  14. { TfraCfgSynEdit }
  15. TfraCfgSynEdit = class(TFrame)
  16. cbutFonPan: TColorButton;
  17. cbutResPalCFon: TColorButton;
  18. cbutResPalCTxt: TColorButton;
  19. cbutResPalCBor: TColorButton;
  20. cbutTxtPan: TColorButton;
  21. chkFullWord: TCheckBox;
  22. chkHighCurWord: TCheckBox;
  23. chkVerBarDesH: TCheckBox;
  24. chkVerBarDesV: TCheckBox;
  25. chkVerPanVer: TCheckBox;
  26. chkHighCurLin: TCheckBox;
  27. cbutLinAct: TColorButton;
  28. chkVerNumLin: TCheckBox;
  29. chkVerMarPle: TCheckBox;
  30. cbutBackCol: TColorButton;
  31. cbutTextCol: TColorButton;
  32. cmbTipoLetra: TComboBox;
  33. GroupBox1: TGroupBox;
  34. GroupBox2: TGroupBox;
  35. Label1: TLabel;
  36. Label10: TLabel;
  37. Label11: TLabel;
  38. Label12: TLabel;
  39. Label2: TLabel;
  40. Label3: TLabel;
  41. Label6: TLabel;
  42. Label7: TLabel;
  43. Label8: TLabel;
  44. Label9: TLabel;
  45. spTam: TSpinEdit;
  46. procedure chkHighCurLinChange(Sender: TObject);
  47. procedure chkHighCurWordChange(Sender: TObject);
  48. procedure chkVerPanVerChange(Sender: TObject);
  49. public
  50. //Configuración del editor
  51. TipLet : string; //Tipo de letra
  52. TamLet : integer; //Tamaño de letra
  53. showVertSB : boolean; //Mostrar barra de desplazamiento vertical.
  54. showHoriSB : boolean; //Mostrar barra de desplazamiento horizontal.
  55. MarLinAct : boolean; //marcar línea actual
  56. Autoindent : boolean; //Autotabulación
  57. ResPalAct : boolean; //Resaltar palabra actual
  58. ResPalCFon : TColor; //Color de fondo de la palabra actual
  59. ResPalCTxt : TColor; //Color de texto de la palabra actual
  60. ResPalCBor : TColor; //Color de borde de la palabra actual
  61. ResPalFWord: Boolean; //Activa "palabra completa"
  62. cTxtNor : TColor; //color de texto normal
  63. cFonEdi : TColor; //Color de fondo del control de edición
  64. cFonSel : TColor; //color del fondo de la selección
  65. cTxtSel : TColor; //color del texto de la selección
  66. cLinAct : TColor; //color de la línea actual
  67. //Panel vertical
  68. VerPanVer : boolean; //ver pánel vertical
  69. VerNumLin : boolean; //ver número de línea
  70. VerMarPle : boolean; //ver marcas de plegado
  71. cFonPan : TColor; //color de fondo del panel vertical
  72. cTxtPan : TColor; //color de texto del panel vertical
  73. ArcRecientes: TStringList; //Lista de archivos recientes
  74. procedure PropToWindow;
  75. procedure Iniciar(section: string; cfgFile: TMiConfigXML; colFonDef: TColor =
  76. clWhite); //Inicia el frame
  77. procedure ConfigEditor(ed: TSynEdit);
  78. public
  79. //Genera constructor y destructor
  80. constructor Create(AOwner: TComponent) ; override;
  81. destructor Destroy; override;
  82. end;
  83. implementation
  84. {$R *.lfm}
  85. //const
  86. // MAX_ARC_REC = 5; //si se cambia, actualizar ActualMenusReciente()
  87. procedure TfraCfgSynEdit.Iniciar(section: string; cfgFile: TMiConfigXML;
  88. colFonDef: TColor = clWhite);
  89. var
  90. s: TParElem;
  91. begin
  92. //Asigna referencia necesarias
  93. //Crea las relaciones variable-control
  94. s:=cfgFile.Asoc_Str(section+ '/TipLet' , @TipLet, cmbTipoLetra, 'Courier New');
  95. s:=cfgFile.Asoc_Int(section+ '/TamLet' , @TamLet, spTam, 10);
  96. s:=cfgFile.Asoc_Bol(section+ '/showVertSB', @showVertSB, chkVerBarDesV, true);
  97. s:=cfgFile.Asoc_Bol(section+ '/showHoriSB', @showHoriSB, chkVerBarDesH, true);
  98. s:=cfgFile.Asoc_TCol(section+ '/cTxtNor', @cTxtNor, cbutTextCol, clBlack);
  99. s.categ := 1; //marca como propiedad de tipo "Tema"
  100. s:=cfgFile.Asoc_TCol(section+ '/cFonEdi', @cFonEdi, cbutBackCol, colFonDef);
  101. s.categ := 1; //marca como propiedad de tipo "Tema"
  102. s:=cfgFile.Asoc_TCol(section+ '/cLinAct', @cLinAct, cbutLinAct, clYellow);
  103. s.categ := 1; //marca como propiedad de tipo "Tema"
  104. s:=cfgFile.Asoc_Bol(section+ '/MarLinAct' , @MarLinAct , chkHighCurLin , false);
  105. s:=cfgFile.Asoc_Bol(section+ '/ResPalCur' , @ResPalAct , chkHighCurWord , true);
  106. s.categ := 1;
  107. s:=cfgFile.Asoc_TCol(section+ '/ResPalCFon',@ResPalCFon, cbutResPalCFon, clSkyBlue);
  108. s.categ := 1;
  109. s:=cfgFile.Asoc_TCol(section+ '/ResPalCTxt',@ResPalCTxt, cbutResPalCTxt, clBlack);
  110. s.categ := 1;
  111. s:=cfgFile.Asoc_TCol(section+ '/ResPalCBor',@ResPalCBor, cbutResPalCBor, clSkyBlue);
  112. s.categ := 1;
  113. s:=cfgFile.Asoc_Bol(section+ '/ResPalFWord',@ResPalFWord, chkFullWord, false);
  114. s:=cfgFile.Asoc_Bol(section+ '/VerPanVer', @VerPanVer, chkVerPanVer, true);
  115. s:=cfgFile.Asoc_Bol(section+ '/VerNumLin', @VerNumLin, chkVerNumLin, false);
  116. s:=cfgFile.Asoc_Bol(section+ '/VerMarPle', @VerMarPle, chkVerMarPle, true);
  117. s:=cfgFile.Asoc_TCol(section+ '/cFonPan' , @cFonPan , cbutFonPan , clWhite);
  118. s.categ := 1; //marca como propiedad de tipo "Tema"
  119. s:=cfgFile.Asoc_TCol(section+ '/cTxtPan' , @cTxtPan , cbutTxtPan , clBlack);
  120. s.categ := 1; //marca como propiedad de tipo "Tema"
  121. cfgFile.Asoc_StrList(section+ '/recient', @ArcRecientes);
  122. end;
  123. procedure TfraCfgSynEdit.chkVerPanVerChange(Sender: TObject);
  124. begin
  125. chkVerNumLin.Enabled:=chkVerPanVer.Checked;
  126. chkVerMarPle.Enabled:=chkVerPanVer.Checked;
  127. cbutFonPan.Enabled:=chkVerPanVer.Checked;
  128. cbutTxtPan.Enabled:=chkVerPanVer.Checked;
  129. label2.Enabled:=chkVerPanVer.Checked;
  130. label3.Enabled:=chkVerPanVer.Checked;
  131. end;
  132. procedure TfraCfgSynEdit.chkHighCurLinChange(Sender: TObject);
  133. begin
  134. label1.Enabled:=chkHighCurLin.Checked;
  135. cbutLinAct.Enabled:=chkHighCurLin.Checked;
  136. end;
  137. procedure TfraCfgSynEdit.chkHighCurWordChange(Sender: TObject);
  138. begin
  139. label10.Enabled:=chkHighCurWord.Checked;
  140. cbutResPalCFon.Enabled:=chkHighCurWord.Checked;
  141. end;
  142. procedure TfraCfgSynEdit.PropToWindow;
  143. begin
  144. inherited;
  145. chkHighCurLinChange(self); //para actualizar
  146. chkVerPanVerChange(self); //para actualizar
  147. end;
  148. constructor TfraCfgSynEdit.Create(AOwner: TComponent);
  149. begin
  150. inherited Create(AOwner);
  151. ArcRecientes := TStringList.Create; //crea lista
  152. cmbTipoLetra.Items.Clear;
  153. cmbTipoLetra.Items.Add('Courier New');
  154. cmbTipoLetra.Items.Add('Fixedsys');
  155. cmbTipoLetra.Items.Add('Lucida Console');
  156. cmbTipoLetra.Items.Add('Consolas');
  157. cmbTipoLetra.Items.Add('Cambria');
  158. end;
  159. destructor TfraCfgSynEdit.Destroy;
  160. begin
  161. FreeAndNil(ArcRecientes);
  162. inherited Destroy;
  163. end;
  164. procedure TfraCfgSynEdit.ConfigEditor(ed: TSynEdit);
  165. {Configura el editor con las propiedades almacenadas}
  166. var
  167. marc: TSynEditMarkup;
  168. begin
  169. if ed = nil then exit; //protección
  170. //Tipo de texto
  171. if TipLet <> '' then ed.Font.Name:=TipLet;
  172. if (TamLet > 6) and (TamLet < 32) then ed.Font.Size:=Round(TamLet);
  173. //Colores
  174. ed.Font.Color:=cTxtNor; //color de texto normal
  175. ed.Color:=cFonEdi; //color de fondo
  176. //Resaltado de línea actual
  177. if MarLinAct then
  178. ed.LineHighlightColor.Background:=cLinAct
  179. else
  180. ed.LineHighlightColor.Background:=clNone;
  181. //Configura panel vertical
  182. ed.Gutter.Visible:=VerPanVer; //muestra panel vertical
  183. ed.Gutter.Parts[1].Visible:=VerNumLin; //Número de línea
  184. if ed.Gutter.Parts.Count>4 then
  185. ed.Gutter.Parts[4].Visible:=VerMarPle; //marcas de plegado
  186. ed.Gutter.Color:=cFonPan; //color de fondo del panel
  187. ed.Gutter.Parts[1].MarkupInfo.Background:=cFonPan; //fondo del núemro de línea
  188. ed.Gutter.Parts[1].MarkupInfo.Foreground:=cTxtPan; //texto del núemro de línea
  189. if showVertSB and showHoriSB then //barras de desplazamiento
  190. ed.ScrollBars:= ssBoth
  191. else if showVertSB and not showHoriSB then
  192. ed.ScrollBars:= ssVertical
  193. else if not showVertSB and showHoriSB then
  194. ed.ScrollBars:= ssHorizontal
  195. else
  196. ed.ScrollBars := ssNone;
  197. ////////Configura el resaltado de la palabra actual //////////
  198. marc := ed.MarkupByClass[TSynEditMarkupHighlightAllCaret];
  199. if marc<>nil then begin //hay marcador
  200. marc.Enabled:=ResPalAct; //configura
  201. marc.MarkupInfo.Background := ResPalCFon;
  202. marc.MarkupInfo.FrameColor := ResPalCBor;
  203. marc.MarkupInfo.Foreground := ResPalCTxt;
  204. TSynEditMarkupHighlightAllCaret(marc).FullWord := ResPalFWord;
  205. end;
  206. ///////fija color de delimitadores () {} [] ///////////
  207. ed.BracketMatchColor.Foreground := clRed;
  208. end;
  209. end.