1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit editor_dividerdraw_options;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
StdCtrls, ExtCtrls, Graphics, Spin, ColorBox, CheckLst, LCLType,
// IdeIntf
EditorSyntaxHighlighterDef, IDEOptionsIntf, IDEOptEditorIntf,
// SynEdit
SynEditHighlighter,
// IDE
EditorOptions, LazarusIDEStrConsts;
type
{ TEditorDividerDrawOptionsFrame }
TEditorDividerDrawOptionsFrame = class(TAbstractIDEOptionsEditor)
DividerConfigListBox: TCheckListBox;
LanguageLabel: TLabel;
TopLvlPanel: TPanel;
TopLvlColorCheckBox: TCheckBox;
NestLvlColorCheckBox: TCheckBox;
TopLvlColorBox: TColorBox;
NestLvlColorBox: TColorBox;
DividerSpinLabel: TLabel;
TopLvlColorLabel: TLabel;
NestLvlColorLabel: TLabel;
LanguageComboBox: TComboBox;
DividerConfPanel: TPanel;
DividerSpinPanel: TPanel;
DividerSpinEdit: TSpinEdit;
NestLvlPanel: TPanel;
procedure LanguageComboBoxChange(Sender: TObject);
procedure LanguageComboBoxExit(Sender: TObject);
procedure LanguageComboBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DividerConfigListBoxKeyUp(Sender: TObject; var {%H-}Key: Word; {%H-}Shift: TShiftState);
procedure DividerConfigListBoxClick(Sender: TObject);
procedure DividerSpinEditChange(Sender: TObject);
procedure NestLvlColorBoxChange(Sender: TObject);
procedure NestLvlColorCheckBoxChange(Sender: TObject);
procedure TopLvlColorBoxChange(Sender: TObject);
procedure TopLvlColorCheckBoxChange(Sender: TObject);
private
FHighlighters: array[TLazSyntaxHighlighter] of TSrcIDEHighlighter;
FCurHighlighter: TSrcIDEHighlighter;
FCurDividerConf: TSynDividerDrawConfig;
FCurDivInfo: TEditorOptionsDividerRecord;
protected
function GetHighlighter(SynType: TLazSyntaxHighlighter;
CreateIfNotExists: Boolean): TSrcIDEHighlighter;
procedure ClearHighlighters;
public
destructor Destroy; override;
function GetTitle: String; override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
implementation
{$R *.lfm}
{ TEditorDividerDrawOptionsFrame }
procedure TEditorDividerDrawOptionsFrame.LanguageComboBoxChange(Sender: TObject);
var
ComboBox: TComboBox absolute Sender;
begin
if ComboBox.Items.IndexOf(ComboBox.Text) >= 0 then
LanguageComboBoxExit(Sender);
end;
procedure TEditorDividerDrawOptionsFrame.LanguageComboBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Key = VK_S) then
LanguageComboBoxExit(Sender);
end;
procedure TEditorDividerDrawOptionsFrame.LanguageComboBoxExit(Sender: TObject);
var
ComboBox: TComboBox absolute Sender;
tp: TLazSyntaxHighlighter;
i: Integer;
begin
tp := EditorOpts.HighlighterList
[EditorOpts.HighlighterList.FindByName(ComboBox.Text)].TheType;
FCurHighlighter := GetHighlighter(tp, True);
FCurDivInfo := EditorOptionsDividerDefaults[tp];
DividerConfigListBox.Clear;
for i := 0 to FCurDivInfo.Count - 1 do begin
DividerConfigListBox.Items.add(FCurDivInfo.Info^[i].Name);
DividerConfigListBox.Checked[i] :=
FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth > 0;
end;
DividerConfigListBox.ItemIndex := 0;
DividerConfigListBoxClick(Sender);
end;
procedure TEditorDividerDrawOptionsFrame.DividerConfigListBoxKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
DividerConfigListBoxClick(Sender);
end;
procedure TEditorDividerDrawOptionsFrame.DividerConfigListBoxClick(Sender: TObject);
var
i: LongInt;
NewDiv: TSynDividerDrawConfig;
b: Boolean;
begin
if not assigned(FCurHighlighter) then exit;
for i := 0 to FCurDivInfo.Count - 1 do begin
if DividerConfigListBox.Checked[i] then begin
if FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth = 0 then begin
if FCurDivInfo.Info^[i].MaxLevel > 0 then
FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth := FCurDivInfo.Info^[i].MaxLevel
else
FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth := 1;
end;
end else begin
if FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth > 0 then
FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth := 0;
end;
end;
i := DividerConfigListBox.ItemIndex;
if (i < 0) or (i >= FCurDivInfo.Count) then exit;
NewDiv := FCurHighlighter.DividerDrawConfig[i];
FCurDividerConf := nil;
b := FCurDivInfo.Info^[i].BoolOpt;
DividerSpinPanel.Visible := not b;
NestLvlPanel.Visible := not b;
DividerSpinEdit.Value := NewDiv.MaxDrawDepth;
TopLvlColorBox.Selected := NewDiv.TopColor;
TopLvlColorBox.Tag := TopLvlColorBox.Selected;
TopLvlColorCheckBox.Checked := NewDiv.TopColor = clDefault;
TopLvlPanel.Enabled := NewDiv.MaxDrawDepth > 0;
NestLvlColorBox.Selected := NewDiv.NestColor;
NestLvlColorBox.Tag := NestLvlColorBox.Selected;
NestLvlColorCheckBox.Checked := NewDiv.NestColor = clDefault;
NestLvlPanel.Enabled := NewDiv.MaxDrawDepth > 1;
FCurDividerConf := NewDiv;
end;
procedure TEditorDividerDrawOptionsFrame.DividerSpinEditChange(Sender: TObject);
var
Spin: TSpinEdit absolute Sender;
i: Integer;
begin
if not assigned(FCurDividerConf) then exit;
FCurDividerConf.MaxDrawDepth := Spin.Value;
TopLvlPanel.Enabled := FCurDividerConf.MaxDrawDepth > 0;
NestLvlPanel.Enabled := FCurDividerConf.MaxDrawDepth > 1;
for i := 0 to DividerConfigListBox.Count - 1 do
DividerConfigListBox.Checked[i] :=
FCurHighlighter.DividerDrawConfig[i].MaxDrawDepth > 0;
end;
procedure TEditorDividerDrawOptionsFrame.NestLvlColorBoxChange(Sender: TObject);
begin
if not assigned(FCurDividerConf) then exit;
FCurDividerConf.NestColor := NestLvlColorBox.Selected;
if NestLvlColorBox.Selected <> clDefault then
NestLvlColorBox.Tag := NestLvlColorBox.Selected;
NestLvlColorCheckBox.Checked := NestLvlColorBox.Selected = clDefault;
end;
procedure TEditorDividerDrawOptionsFrame.NestLvlColorCheckBoxChange(Sender: TObject);
begin
if not assigned(FCurDividerConf) then exit;
if NestLvlColorCheckBox.Checked then begin
FCurDividerConf.NestColor := clDefault;
if NestLvlColorBox.Selected <> clDefault then
NestLvlColorBox.Selected := clDefault;
end else begin
FCurDividerConf.NestColor := NestLvlColorBox.Tag;
if NestLvlColorBox.Selected <> NestLvlColorBox.Tag then
NestLvlColorBox.Selected := NestLvlColorBox.Tag;
end;
end;
procedure TEditorDividerDrawOptionsFrame.TopLvlColorBoxChange(Sender: TObject);
begin
if not assigned(FCurDividerConf) then exit;
FCurDividerConf.TopColor := TopLvlColorBox.Selected;
if TopLvlColorBox.Selected <> clDefault then
TopLvlColorBox.Tag := TopLvlColorBox.Selected;
TopLvlColorCheckBox.Checked := TopLvlColorBox.Selected = clDefault;
end;
procedure TEditorDividerDrawOptionsFrame.TopLvlColorCheckBoxChange(Sender: TObject);
begin
if not assigned(FCurDividerConf) then exit;
if TopLvlColorCheckBox.Checked then begin
FCurDividerConf.TopColor := clDefault;
if TopLvlColorBox.Selected <> clDefault then
TopLvlColorBox.Selected := clDefault;
end else begin
FCurDividerConf.TopColor := TopLvlColorBox.Tag;
if TopLvlColorBox.Selected <> TopLvlColorBox.Tag then
TopLvlColorBox.Selected := TopLvlColorBox.Tag;
end;
end;
function TEditorDividerDrawOptionsFrame.GetHighlighter(SynType: TLazSyntaxHighlighter;
CreateIfNotExists: Boolean): TSrcIDEHighlighter;
var
SynClass: TCustomSynClass;
begin
Result := FHighlighters[SynType];
if (Result <> nil) or not(CreateIfNotExists) then exit;
SynClass := LazSyntaxHighlighterClasses[SynType];
Result := SynClass.Create(nil);
FHighlighters[SynType] := Result;
EditorOpts.ReadHighlighterDivDrawSettings(Result);
end;
procedure TEditorDividerDrawOptionsFrame.ClearHighlighters;
var
i: TLazSyntaxHighlighter;
begin
for i := low(TLazSyntaxHighlighter) to high(TLazSyntaxHighlighter) do
FreeAndNil(FHighlighters[i]);
end;
destructor TEditorDividerDrawOptionsFrame.Destroy;
begin
ClearHighlighters;
inherited Destroy;
end;
function TEditorDividerDrawOptionsFrame.GetTitle: String;
begin
Result := dlgUseDividerDraw;
end;
procedure TEditorDividerDrawOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
LanguageLabel.Caption := dlgLang;
DividerSpinEdit.Hint := lis0No1DrawDividerLinesOnlyForTopLevel2DrawLinesForFi;
DividerSpinLabel.Caption := dlgDividerDrawDepth;
TopLvlColorLabel.Caption := dlgDividerTopColor;
TopLvlColorCheckBox.Caption := dlgDividerColorDefault;
NestLvlColorLabel.Caption := dlgDividerNestColor;
NestLvlColorCheckBox.Caption := dlgDividerColorDefault;
end;
procedure TEditorDividerDrawOptionsFrame.ReadSettings(
AOptions: TAbstractIDEOptions);
var
i: Integer;
rd: TEditorOptionsDividerRecord;
begin
with AOptions as TEditorOptions do
begin
with LanguageComboBox.Items do begin
BeginUpdate;
for i := 0 to EditorOpts.HighlighterList.Count - 1 do begin
rd := EditorOptionsDividerDefaults[HighlighterList[i].TheType];
if (rd.Count > 0) then
Add(HighlighterList[i].SynClass.GetLanguageName);
end;
EndUpdate;
end;
LanguageComboBox.ItemIndex := 0;
LanguageComboBoxExit(LanguageComboBox);
end;
end;
procedure TEditorDividerDrawOptionsFrame.WriteSettings(
AOptions: TAbstractIDEOptions);
var
i: TLazSyntaxHighlighter;
begin
with AOptions as TEditorOptions do
begin
for i := low(TLazSyntaxHighlighter) to high(TLazSyntaxHighlighter) do begin
if assigned(FHighlighters[i]) then
WriteHighlighterDivDrawSettings(FHighlighters[i]);
end;
end;
end;
class function TEditorDividerDrawOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := TEditorOptions;
end;
initialization
RegisterIDEOptionsEditor(GroupEditor, TEditorDividerDrawOptionsFrame,
EdtOptionsDrawDivider);
end.
|