PageRenderTime 31ms CodeModel.GetById 22ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/ide/frames/editor_general_options.pas

http://github.com/graemeg/lazarus
Pascal | 432 lines | 341 code | 54 blank | 37 comment | 22 complexity | 5d5fa1b3ba2d9cb1fea6ce53d52a8c95 MD5 | raw file
  1{
  2 ***************************************************************************
  3 *                                                                         *
  4 *   This source is free software; you can redistribute it and/or modify   *
  5 *   it under the terms of the GNU General Public License as published by  *
  6 *   the Free Software Foundation; either version 2 of the License, or     *
  7 *   (at your option) any later version.                                   *
  8 *                                                                         *
  9 *   This code is distributed in the hope that it will be useful, but      *
 10 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 12 *   General Public License for more details.                              *
 13 *                                                                         *
 14 *   A copy of the GNU General Public License is available on the World    *
 15 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 16 *   obtain it by writing to the Free Software Foundation,                 *
 17 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 18 *                                                                         *
 19 ***************************************************************************
 20}
 21unit editor_general_options;
 22
 23{$mode objfpc}{$H+}
 24
 25interface
 26
 27uses
 28  Classes, SysUtils, LCLProc, LCLType, StdCtrls, Controls, ExtCtrls, Graphics,
 29  EditorOptions, LazarusIDEStrConsts, IDEProcs, IDEOptionsIntf,
 30  IDEUtils, SynEdit, SynHighlighterPas, SynPluginMultiCaret, DividerBevel;
 31
 32type
 33  TPreviewEditor = TSynEdit;
 34  { TEditorGeneralOptionsFrame }
 35
 36  TEditorGeneralOptionsFrame = class(TAbstractIDEOptionsEditor)
 37    chkMultiCaretColumnMode: TCheckBox;
 38    chkMultiCaretMode: TCheckBox;
 39    MultiCaretOnColumnSelection: TCheckBox;
 40    CursorSkipsTabCheckBox: TCheckBox;
 41    CaretGroupDivider: TDividerBevel;
 42    BlockGroupDivider: TDividerBevel;
 43    ScrollGroupDivider: TDividerBevel;
 44    UndoGroupDivider: TDividerBevel;
 45    EndKeyJumpsToNearestStartCheckBox: TCheckBox;
 46    KeepCursorXCheckBox: TCheckBox;
 47    CenterLabel:TLabel;
 48    OverwriteBlockCheckBox: TCheckBox;
 49    PersistentCursorCheckBox: TCheckBox;
 50    AlwaysVisibleCursorCheckBox: TCheckBox;
 51    CursorSkipsSelectionCheckBox: TCheckBox;
 52    HomeKeyJumpsToNearestStartCheckBox: TCheckBox;
 53    PersistentBlockCheckBox: TCheckBox;
 54    HalfPageScrollCheckBox: TCheckBox;
 55    ScrollPastEndFileCheckBox: TCheckBox;
 56    ScrollPastEndLineCheckBox: TCheckBox;
 57    ScrollByOneLessCheckBox: TCheckBox;
 58    UndoAfterSaveCheckBox: TCheckBox;
 59    GroupUndoCheckBox: TCheckBox;
 60    UndoLimitComboBox: TComboBox;
 61    UndoLimitLabel: TLabel;
 62    chkScrollHint: TCheckBox;
 63    procedure AlwaysVisibleCursorCheckBoxChange(Sender: TObject);
 64    procedure CursorSkipsSelectionCheckBoxChange(Sender: TObject);
 65    procedure CursorSkipsTabCheckBoxChange(Sender: TObject);
 66    procedure EndKeyJumpsToNearestStartCheckBoxChange(Sender: TObject);
 67    procedure GroupUndoCheckBoxChange(Sender: TObject);
 68    procedure HalfPageScrollCheckBoxChange(Sender: TObject);
 69    procedure HomeKeyJumpsToNearestStartCheckBoxChange(Sender: TObject);
 70    procedure KeepCursorXCheckBoxChange(Sender: TObject);
 71    procedure OverwriteBlockCheckBoxChange(Sender: TObject);
 72    procedure PersistentBlockCheckBoxChange(Sender: TObject);
 73    procedure PersistentCursorCheckBoxChange(Sender: TObject);
 74    procedure ScrollByOneLessCheckBoxChange(Sender: TObject);
 75    procedure ScrollPastEndFileCheckBoxChange(Sender: TObject);
 76    procedure ScrollPastEndLineCheckBoxChange(Sender: TObject);
 77  private
 78    FDefaultBookmarkImages: TImageList;
 79    FDialog: TAbstractOptionsEditorDialog;
 80    FPasExtendedKeywordsMode: Boolean;
 81    FPasStringKeywordMode: TSynPasStringMode;
 82    function DefaultBookmarkImages: TImageList;
 83    procedure SetExtendedKeywordsMode(const AValue: Boolean);
 84    procedure SetStringKeywordMode(const AValue: TSynPasStringMode);
 85  public
 86    PreviewEdits: array of TPreviewEditor;
 87    procedure AddPreviewEdit(AEditor: TPreviewEditor);
 88    procedure SetPreviewOption(AValue: Boolean; AnOption: TSynEditorOption); overload;
 89    procedure SetPreviewOption(AValue: Boolean; AnOption: TSynEditorOption2); overload;
 90    procedure UpdatePrevieEdits;
 91
 92    constructor Create(AOwner: TComponent); override;
 93    function GetTitle: String; override;
 94    procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
 95    procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
 96    procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
 97    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
 98    // current previewmode
 99    property PasExtendedKeywordsMode: Boolean
100             read FPasExtendedKeywordsMode write SetExtendedKeywordsMode default False;
101    property PasStringKeywordMode: TSynPasStringMode
102             read FPasStringKeywordMode write SetStringKeywordMode default spsmDefault;
103  end;
104
105implementation
106
107{$R *.lfm}
108
109{ TEditorGeneralOptionsFrame }
110
111function TEditorGeneralOptionsFrame.GetTitle: String;
112begin
113  Result := lisGeneral;
114end;
115
116procedure TEditorGeneralOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
117begin
118  FDialog := ADialog;
119
120  // undo
121  UndoGroupDivider.Caption := dlgUndoGroupOptions;
122  UndoAfterSaveCheckBox.Caption := dlgUndoAfterSave;
123  GroupUndoCheckBox.Caption := dlgGroupUndo;
124  UndoLimitLabel.Caption := dlgUndoLimit;
125
126  // scroll
127  ScrollGroupDivider.Caption := dlgScrollGroupOptions;
128  HalfPageScrollCheckBox.Caption := dlgHalfPageScroll;
129  ScrollByOneLessCheckBox.Caption := dlgScrollByOneLess;
130  ScrollPastEndFileCheckBox.Caption := dlgScrollPastEndFile;
131  ScrollPastEndLineCheckBox.Caption := dlgScrollPastEndLine;
132  chkScrollHint.Caption := dlgScrollHint;
133
134
135  // caret + key navigation
136  CaretGroupDivider.Caption := dlgCursorGroupOptions;
137  KeepCursorXCheckBox.Caption := dlgKeepCursorX;
138  PersistentCursorCheckBox.Caption := dlgPersistentCursor;
139  AlwaysVisibleCursorCheckBox.Caption := dlgAlwaysVisibleCursor;
140  CursorSkipsSelectionCheckBox.Caption := dlgCursorSkipsSelection;
141  CursorSkipsTabCheckBox.Caption := dlgCursorSkipsTab;
142  HomeKeyJumpsToNearestStartCheckBox.Caption := dlgHomeKeyJumpsToNearestStart;
143  EndKeyJumpsToNearestStartCheckBox.Caption := dlgEndKeyJumpsToNearestStart;
144  MultiCaretOnColumnSelection.Caption := dlgMultiCaretOnColumnSelection;
145  chkMultiCaretColumnMode.Caption := dlgMultiCaretColumnMode;
146  chkMultiCaretMode.Caption := dlgMultiCaretMode;
147
148  // Block
149  BlockGroupDivider.Caption := dlgBlockGroupOptions;
150  PersistentBlockCheckBox.Caption := dlgPersistentBlock;
151  OverwriteBlockCheckBox.Caption := dlgOverwriteBlock;
152end;
153
154procedure TEditorGeneralOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
155var
156  i: integer;
157begin
158  with AOptions as TEditorOptions do
159  begin
160    // undo
161    UndoAfterSaveCheckBox.Checked := UndoAfterSave;
162    GroupUndoCheckBox.Checked := eoGroupUndo in SynEditOptions;
163    SetComboBoxText(UndoLimitComboBox, IntToStr(UndoLimit), cstCaseInsensitive);
164
165    // scroll
166    HalfPageScrollCheckBox.Checked := eoHalfPageScroll in SynEditOptions;
167    ScrollByOneLessCheckBox.Checked := eoScrollByOneLess in SynEditOptions;
168    ScrollPastEndFileCheckBox.Checked := eoScrollPastEoF in SynEditOptions;
169    ScrollPastEndLineCheckBox.Checked := eoScrollPastEoL in SynEditOptions;
170    chkScrollHint.Checked := eoShowScrollHint in SynEditOptions;
171
172    // cursor
173    KeepCursorXCheckBox.Checked := eoKeepCaretX in SynEditOptions;
174    PersistentCursorCheckBox.Checked := eoPersistentCaret in SynEditOptions;
175    AlwaysVisibleCursorCheckBox.Checked := eoAlwaysVisibleCaret in SynEditOptions2;
176    CursorSkipsSelectionCheckBox.Checked := eoCaretSkipsSelection in SynEditOptions2;
177    CursorSkipsTabCheckBox.Checked := eoCaretSkipTab in SynEditOptions2;
178    HomeKeyJumpsToNearestStartCheckBox.Checked := eoEnhanceHomeKey in SynEditOptions;
179    EndKeyJumpsToNearestStartCheckBox.Checked := eoEnhanceEndKey in SynEditOptions2;
180    MultiCaretOnColumnSelection.Checked := MultiCaretOnColumnSelect;
181    chkMultiCaretColumnMode.Checked := MultiCaretDefaultColumnSelectMode = mcmMoveAllCarets;
182    chkMultiCaretMode.Checked := MultiCaretDefaultMode = mcmMoveAllCarets;
183
184    // block
185    PersistentBlockCheckBox.Checked := eoPersistentBlock in SynEditOptions2;
186    OverwriteBlockCheckBox.Checked := eoOverwriteBlock in SynEditOptions2;
187
188    for i := Low(PreviewEdits) to High(PreviewEdits) do
189      if PreviewEdits[i] <> nil then
190        GetSynEditPreviewSettings(PreviewEdits[i]);
191  end;
192end;
193
194procedure TEditorGeneralOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
195
196  procedure UpdateOptionFromBool(AValue: Boolean; AnOption: TSynEditorOption); overload;
197  begin
198    if AValue then
199      TEditorOptions(AOptions).SynEditOptions := TEditorOptions(AOptions).SynEditOptions + [AnOption]
200    else
201      TEditorOptions(AOptions).SynEditOptions := TEditorOptions(AOptions).SynEditOptions - [AnOption];
202  end;
203
204  procedure UpdateOptionFromBool(AValue: Boolean; AnOption: TSynEditorOption2); overload;
205  begin
206    if AValue then
207      TEditorOptions(AOptions).SynEditOptions2 := TEditorOptions(AOptions).SynEditOptions2 + [AnOption]
208    else
209      TEditorOptions(AOptions).SynEditOptions2 := TEditorOptions(AOptions).SynEditOptions2 - [AnOption];
210  end;
211
212var
213  i: integer;
214begin
215  with AOptions as TEditorOptions do
216  begin
217    // undo
218    UndoAfterSave := UndoAfterSaveCheckBox.Checked;
219    UpdateOptionFromBool(GroupUndoCheckBox.Checked, eoGroupUndo);
220    i := StrToIntDef(UndoLimitComboBox.Text, 32767);
221    if i < 1 then
222      i := 1;
223    if i > 32767 then
224      i := 32767;
225    UndoLimit := i;
226
227    // scroll
228    UpdateOptionFromBool(HalfPageScrollCheckBox.Checked, eoHalfPageScroll);
229    UpdateOptionFromBool(ScrollByOneLessCheckBox.Checked, eoScrollByOneLess);
230    UpdateOptionFromBool(ScrollPastEndFileCheckBox.Checked, eoScrollPastEoF);
231    UpdateOptionFromBool(ScrollPastEndLineCheckBox.Checked, eoScrollPastEoL);
232    UpdateOptionFromBool(chkScrollHint.Checked, eoShowScrollHint);
233
234    // cursor
235    UpdateOptionFromBool(KeepCursorXCheckBox.Checked, eoKeepCaretX);
236    UpdateOptionFromBool(PersistentCursorCheckBox.Checked, eoPersistentCaret);
237    UpdateOptionFromBool(AlwaysVisibleCursorCheckBox.Checked, eoAlwaysVisibleCaret);
238    UpdateOptionFromBool(CursorSkipsSelectionCheckBox.Checked, eoCaretSkipsSelection);
239    UpdateOptionFromBool(CursorSkipsTabCheckBox.Checked, eoCaretSkipTab);
240    UpdateOptionFromBool(HomeKeyJumpsToNearestStartCheckBox.Checked, eoEnhanceHomeKey);
241    UpdateOptionFromBool(EndKeyJumpsToNearestStartCheckBox.Checked, eoEnhanceEndKey);
242    MultiCaretOnColumnSelect := MultiCaretOnColumnSelection.Checked;
243    if chkMultiCaretColumnMode.Checked then
244      MultiCaretDefaultColumnSelectMode := mcmMoveAllCarets
245    else
246      MultiCaretDefaultColumnSelectMode := mcmCancelOnCaretMove;
247    if chkMultiCaretMode.Checked then
248      MultiCaretDefaultMode := mcmMoveAllCarets
249    else
250      MultiCaretDefaultMode := mcmCancelOnCaretMove;
251
252
253    // block
254    UpdateOptionFromBool(PersistentBlockCheckBox.Checked, eoPersistentBlock);
255    UpdateOptionFromBool(OverwriteBlockCheckBox.Checked, eoOverwriteBlock);
256  end;
257end;
258
259class function TEditorGeneralOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
260begin
261  Result := TEditorOptions;
262end;
263
264procedure TEditorGeneralOptionsFrame.SetPreviewOption(AValue: Boolean; AnOption: TSynEditorOption);
265var
266  a: Integer;
267begin
268  for a := Low(PreviewEdits) to High(PreviewEdits) do
269  begin
270    if PreviewEdits[a] <> nil then
271      if AValue then
272        PreviewEdits[a].Options := PreviewEdits[a].Options + [AnOption]
273      else
274        PreviewEdits[a].Options := PreviewEdits[a].Options - [AnOption];
275  end;
276end;
277
278procedure TEditorGeneralOptionsFrame.SetPreviewOption(AValue: Boolean; AnOption: TSynEditorOption2);
279var
280  a: Integer;
281begin
282  for a := Low(PreviewEdits) to High(PreviewEdits) do
283  begin
284    if PreviewEdits[a] <> nil then
285      if AValue then
286        PreviewEdits[a].Options2 := PreviewEdits[a].Options2 + [AnOption]
287      else
288        PreviewEdits[a].Options2 := PreviewEdits[a].Options2 - [AnOption];
289  end;
290end;
291
292procedure TEditorGeneralOptionsFrame.UpdatePrevieEdits;
293var
294  a: Integer;
295begin
296  for a := Low(PreviewEdits) to High(PreviewEdits) do
297    if PreviewEdits[a].Highlighter is TSynPasSyn then begin
298      TSynPasSyn(PreviewEdits[a].Highlighter).ExtendedKeywordsMode := PasExtendedKeywordsMode;
299      TSynPasSyn(PreviewEdits[a].Highlighter).StringKeywordMode := PasStringKeywordMode;
300    end;
301end;
302
303procedure TEditorGeneralOptionsFrame.AlwaysVisibleCursorCheckBoxChange(
304  Sender: TObject);
305begin
306  SetPreviewOption(AlwaysVisibleCursorCheckBox.Checked, eoAlwaysVisibleCaret);
307end;
308
309procedure TEditorGeneralOptionsFrame.CursorSkipsSelectionCheckBoxChange(
310  Sender: TObject);
311begin
312  SetPreviewOption(CursorSkipsSelectionCheckBox.Checked, eoCaretSkipsSelection);
313end;
314
315procedure TEditorGeneralOptionsFrame.CursorSkipsTabCheckBoxChange(Sender: TObject);
316begin
317  SetPreviewOption(CursorSkipsTabCheckBox.Checked, eoCaretSkipTab);
318end;
319
320procedure TEditorGeneralOptionsFrame.EndKeyJumpsToNearestStartCheckBoxChange(
321  Sender: TObject);
322begin
323  SetPreviewOption(EndKeyJumpsToNearestStartCheckBox.Checked, eoEnhanceEndKey);
324end;
325
326procedure TEditorGeneralOptionsFrame.GroupUndoCheckBoxChange(Sender: TObject);
327begin
328  SetPreviewOption(GroupUndoCheckBox.Checked, eoGroupUndo);
329end;
330
331procedure TEditorGeneralOptionsFrame.HalfPageScrollCheckBoxChange(
332  Sender: TObject);
333begin
334  SetPreviewOption(HalfPageScrollCheckBox.Checked, eoHalfPageScroll);
335end;
336
337procedure TEditorGeneralOptionsFrame.HomeKeyJumpsToNearestStartCheckBoxChange(
338  Sender: TObject);
339begin
340  SetPreviewOption(HomeKeyJumpsToNearestStartCheckBox.Checked, eoEnhanceHomeKey);
341end;
342
343procedure TEditorGeneralOptionsFrame.KeepCursorXCheckBoxChange(Sender: TObject);
344begin
345  SetPreviewOption(KeepCursorXCheckBox.Checked, eoKeepCaretX);
346end;
347
348procedure TEditorGeneralOptionsFrame.OverwriteBlockCheckBoxChange(Sender: TObject);
349begin
350  SetPreviewOption(KeepCursorXCheckBox.Checked, eoOverwriteBlock);
351end;
352
353procedure TEditorGeneralOptionsFrame.PersistentBlockCheckBoxChange(Sender: TObject);
354begin
355  SetPreviewOption(PersistentBlockCheckBox.Checked, eoPersistentBlock);
356end;
357
358procedure TEditorGeneralOptionsFrame.PersistentCursorCheckBoxChange(
359  Sender: TObject);
360begin
361  SetPreviewOption(PersistentCursorCheckBox.Checked, eoPersistentCaret);
362end;
363
364procedure TEditorGeneralOptionsFrame.ScrollByOneLessCheckBoxChange(
365  Sender: TObject);
366begin
367  SetPreviewOption(ScrollByOneLessCheckBox.Checked, eoScrollByOneLess);
368end;
369
370procedure TEditorGeneralOptionsFrame.ScrollPastEndFileCheckBoxChange(
371  Sender: TObject);
372begin
373  SetPreviewOption(ScrollPastEndFileCheckBox.Checked, eoScrollPastEoF);
374end;
375
376procedure TEditorGeneralOptionsFrame.ScrollPastEndLineCheckBoxChange(
377  Sender: TObject);
378begin
379  SetPreviewOption(ScrollPastEndLineCheckBox.Checked, eoScrollPastEoL);
380end;
381
382function TEditorGeneralOptionsFrame.DefaultBookmarkImages: TImageList;
383var
384  i: integer;
385begin
386  if FDefaultBookmarkImages = nil then
387  begin
388    FDefaultBookmarkImages := TImageList.Create(Self);
389    FDefaultBookmarkImages.Width := 11;
390    FDefaultBookmarkImages.Height := 11;
391    for i := 0 to 9 do
392      FDefaultBookmarkImages.AddResourceName(HInstance, 'bookmark' + IntToStr(i));
393  end;
394  Result := FDefaultBookmarkImages;
395end;
396
397procedure TEditorGeneralOptionsFrame.SetExtendedKeywordsMode(const AValue: Boolean);
398begin
399  if FPasExtendedKeywordsMode = AValue then exit;
400  FPasExtendedKeywordsMode := AValue;
401  UpdatePrevieEdits;
402end;
403
404procedure TEditorGeneralOptionsFrame.SetStringKeywordMode(const AValue: TSynPasStringMode);
405begin
406  if FPasStringKeywordMode = AValue then exit;
407  FPasStringKeywordMode := AValue;
408  UpdatePrevieEdits;
409end;
410
411procedure TEditorGeneralOptionsFrame.AddPreviewEdit(AEditor: TPreviewEditor);
412begin
413  SetLength(PreviewEdits, Length(PreviewEdits) + 1);
414  PreviewEdits[Length(PreviewEdits)-1] := AEditor;
415  if AEditor.BookMarkOptions.BookmarkImages = nil then
416    AEditor.BookMarkOptions.BookmarkImages := DefaultBookmarkImages;
417end;
418
419constructor TEditorGeneralOptionsFrame.Create(AOwner: TComponent);
420begin
421  inherited Create(AOwner);
422  PreviewEdits := nil;
423  if EditorOpts <> nil then begin
424    FPasExtendedKeywordsMode := EditorOpts.PasExtendedKeywordsMode;
425    FPasStringKeywordMode := EditorOpts.PasStringKeywordMode;
426  end;
427end;
428
429initialization
430  RegisterIDEOptionsEditor(GroupEditor, TEditorGeneralOptionsFrame, EdtOptionsGeneral);
431end.
432