PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/debugger/frames/debugger_language_exceptions_options.pas

http://github.com/graemeg/lazarus
Pascal | 205 lines | 156 code | 25 blank | 24 comment | 14 complexity | edbb091a287bd44a60b5ef7e0e28d62f 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 debugger_language_exceptions_options;
 22
 23{$mode objfpc}{$H+}
 24
 25interface
 26
 27uses
 28  Classes, SysUtils, FileUtil, Forms, Controls, StdCtrls, CheckLst,
 29  Buttons, Dialogs,
 30  LazarusIDEStrConsts, IDEOptionsIntf, Debugger, BaseDebugManager;
 31
 32type
 33
 34  { TDebuggerLanguageExceptionsOptions }
 35
 36  TDebuggerLanguageExceptionsOptions = class(TAbstractIDEOptionsEditor)
 37    bgIgnoreExceptions: TGroupBox;
 38    chkNotifyOnException: TCheckBox;
 39    clbExceptions: TCheckListBox;
 40    cmdExceptionAdd: TBitBtn;
 41    cmdExceptionRemove: TBitBtn;
 42    DbgLangExceptHint: TLabel;
 43    procedure clbExceptionsClick(Sender: TObject);
 44    procedure cmdExceptionAddClick(Sender: TObject);
 45    procedure cmdExceptionRemoveClick(Sender: TObject);
 46  private
 47    FExceptionDeleteList: TStringList;
 48    procedure AddExceptionLine(const AException: TIDEException; AName: String);
 49  public
 50    constructor Create(AOwner: TComponent); override;
 51    destructor Destroy; override;
 52    function GetTitle: String; override;
 53    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
 54    procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
 55    procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
 56    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
 57  end;
 58
 59implementation
 60
 61{$R *.lfm}
 62
 63{ TDebuggerLanguageExceptionsOptions }
 64
 65procedure TDebuggerLanguageExceptionsOptions.cmdExceptionAddClick(
 66  Sender: TObject);
 67var
 68  idx: Integer;
 69  S: String;
 70begin
 71  S:='';
 72  if not InputQuery(lisDebugOptionsFrmAddException, lisDebugOptionsFrmEnterExceptionName, S)
 73  then Exit;
 74
 75  if clbExceptions.Items.IndexOf(S) = -1
 76  then begin
 77    idx := FExceptionDeleteList.IndexOf(S);
 78    if idx = -1
 79    then begin
 80      AddExceptionLine(nil, S);
 81    end
 82    else begin
 83      AddExceptionLine(TIDEException(FExceptionDeleteList.Objects[idx]), S);
 84      FExceptionDeleteList.Delete(idx);
 85    end;
 86  end
 87  else begin
 88    MessageDlg(lisDebugOptionsFrmDuplicateExceptionName, mtError, [mbOK], 0);
 89  end;
 90end;
 91
 92procedure TDebuggerLanguageExceptionsOptions.clbExceptionsClick(Sender: TObject);
 93begin
 94  cmdExceptionRemove.Enabled :=  clbExceptions.ItemIndex <> -1;
 95end;
 96
 97procedure TDebuggerLanguageExceptionsOptions.cmdExceptionRemoveClick(
 98  Sender: TObject);
 99var
100  idx: Integer;
101  obj: TObject;
102begin
103  idx := clbExceptions.ItemIndex;
104  if idx <> -1
105  then begin
106    obj := clbExceptions.Items.Objects[idx];
107    if obj <> nil
108    then FExceptionDeleteList.AddObject(clbExceptions.Items[idx], obj);
109    clbExceptions.Items.Delete(idx);
110  end;
111  cmdExceptionRemove.Enabled :=  clbExceptions.ItemIndex <> -1;
112end;
113
114procedure TDebuggerLanguageExceptionsOptions.AddExceptionLine(
115  const AException: TIDEException; AName: String);
116var
117  idx: Integer;
118begin
119  if (AName = '') and (AException <> nil)
120  then AName := AException.Name;
121  if AName = '' then Exit;
122
123  idx := clbExceptions.Items.AddObject(AName, AException);
124  clbExceptions.Checked[idx] := (AException = nil) or AException.Enabled;
125end;
126
127constructor TDebuggerLanguageExceptionsOptions.Create(AOwner: TComponent);
128begin
129  inherited Create(AOwner);
130  FExceptionDeleteList := TStringList.Create;
131  FExceptionDeleteList.Sorted := True;
132end;
133
134destructor TDebuggerLanguageExceptionsOptions.Destroy;
135begin
136  FreeAndNil(FExceptionDeleteList);
137  inherited Destroy;
138end;
139
140function TDebuggerLanguageExceptionsOptions.GetTitle: String;
141begin
142  Result := lisDebugOptionsFrmLanguageExceptions;
143end;
144
145procedure TDebuggerLanguageExceptionsOptions.Setup(
146  ADialog: TAbstractOptionsEditorDialog);
147begin
148  bgIgnoreExceptions.Caption := lisDebugOptionsFrmIgnoreTheseExceptions;
149  DbgLangExceptHint.Caption := lisTheseSettingsAreStoredWithTheProject;
150  cmdExceptionRemove.Caption := lisRemove;
151  cmdExceptionAdd.Caption := lisAdd;
152  cmdExceptionRemove.LoadGlyphFromResourceName(HInstance, 'laz_delete');
153  cmdExceptionAdd.LoadGlyphFromResourceName(HInstance, 'laz_add');
154  chkNotifyOnException.Caption := lisDebugOptionsFrmNotifyOnLazarusExceptions;
155end;
156
157procedure TDebuggerLanguageExceptionsOptions.ReadSettings(
158  AOptions: TAbstractIDEOptions);
159var
160  n: integer;
161begin
162  chkNotifyOnException.Checked := not DebugBoss.Exceptions.IgnoreAll;
163  for n := 0 to DebugBoss.Exceptions.Count - 1 do
164    AddExceptionLine(DebugBoss.Exceptions[n], '');
165end;
166
167procedure TDebuggerLanguageExceptionsOptions.WriteSettings(
168  AOptions: TAbstractIDEOptions);
169var
170  n: integer;
171  ie: TIDEException;
172begin
173  for n := 0 to FExceptionDeleteList.Count - 1 do
174    FExceptionDeleteList.Objects[n].Free;
175
176  for n := 0 to clbExceptions.Items.Count - 1 do
177  begin
178    ie := TIDEException(clbExceptions.Items.Objects[n]);
179    if ie = nil
180    then begin
181      ie := DebugBoss.Exceptions.Add(clbExceptions.Items[n]);
182      ie.Enabled := clbExceptions.Checked[n];
183    end
184    else begin
185      ie.BeginUpdate;
186      try
187        ie.Name := clbExceptions.Items[n];
188        ie.Enabled := clbExceptions.Checked[n];
189      finally
190        ie.EndUpdate;
191      end;
192    end;
193  end;
194  DebugBoss.Exceptions.IgnoreAll := not chkNotifyOnException.Checked;
195end;
196
197class function TDebuggerLanguageExceptionsOptions.SupportedOptionsClass: TAbstractIDEOptionsClass;
198begin
199  Result := TDebuggerOptions;
200end;
201
202initialization
203  RegisterIDEOptionsEditor(GroupDebugger, TDebuggerLanguageExceptionsOptions, DbgOptionsLanguageExceptions);
204end.
205