PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/ide/frames/desktop_options.pas

http://github.com/graemeg/lazarus
Pascal | 356 lines | 269 code | 37 blank | 50 comment | 14 complexity | 649cc3b89592c57b965f40e08f6940b0 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 desktop_options;
 22
 23{$mode objfpc}{$H+}
 24
 25interface
 26
 27uses
 28  Classes, SysUtils, FileUtil, Forms, StdCtrls, Dialogs, LCLProc, ExtCtrls,
 29  Buttons, EnvironmentOpts, LazarusIDEStrConsts, IDETranslations, InputHistory,
 30  IDEProcs, IDEOptionsIntf, IDEWindowIntf, IDEUtils, DividerBevel;
 31
 32type
 33
 34  { TDesktopOptionsFrame }
 35
 36  TDesktopOptionsFrame = class(TAbstractIDEOptionsEditor)
 37    AskSavingOnlySessionCheckBox: TCheckBox;
 38    AutoSaveEditorFilesCheckBox: TCheckBox;
 39    AutoSaveIntervalInSecsComboBox: TComboBox;
 40    AutoSaveIntervalInSecsLabel: TLabel;
 41    AutoSaveProjectCheckBox: TCheckBox;
 42    lblCheckAndAutoSave: TDividerBevel;
 43    lblImportExport: TDividerBevel;
 44    lblGlyphs: TDividerBevel;
 45    lblHints: TDividerBevel;
 46    lblLanguage: TDividerBevel;
 47    lblMouseAction: TDividerBevel;
 48    PreferDoubleClickCheckBox: TCheckBox;
 49    CheckDiskChangesWithLoadingCheckBox: TCheckBox;
 50    lblButtons: TLabel;
 51    lblCenter: TLabel;
 52    lblMenus: TLabel;
 53    LanguageComboBox: TComboBox;
 54    ImportDesktopButton: TButton;
 55    PanelGlyphsButtonsOptions: TPanel;
 56    PanelGlyphsMenusOptions: TPanel;
 57    rbMenuGlyphShowAlways: TRadioButton;
 58    rbMenuGlyphShowNever: TRadioButton;
 59    rbMenuGlyphShowSystem: TRadioButton;
 60    rbBtnGlyphShowAlways: TRadioButton;
 61    rbBtnGlyphShowNever: TRadioButton;
 62    rbBtnGlyphShowSystem: TRadioButton;
 63    ExportDesktopButton: TButton;
 64    ShowHintsForComponentPaletteCheckBox: TCheckBox;
 65    ShowHintsForMainSpeedButtonsCheckBox: TCheckBox;
 66    procedure ExportDesktopButtonClick(Sender: TObject);
 67    procedure ImportDesktopButtonClick(Sender: TObject);
 68  private
 69    function LangIDToCaption(const LangID: string): string;
 70    function CaptionToLangID(const ACaption: string): string;
 71
 72    procedure DoLoadSettings(AOptions: TAbstractIDEOptions);
 73    procedure DoSaveSettings(AOptions: TAbstractIDEOptions);
 74  public
 75    function GetTitle: String; override;
 76    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
 77    procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
 78    procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
 79    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
 80  end;
 81
 82implementation
 83
 84{$R *.lfm}
 85
 86{ TDesktopOptionsFrame }
 87
 88function TDesktopOptionsFrame.GetTitle: String;
 89begin
 90  Result := lisGeneral;
 91end;
 92
 93procedure TDesktopOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
 94var
 95  i: Integer;
 96  LangID: String;
 97  sl: TStringList;
 98begin
 99  // language
100  lblLanguage.Caption := dlgEnvLanguage;
101  LanguageComboBox.Hint := dlgEnvLanguageHint;
102
103  // languages: first the automatic, then sorted the rest
104  sl:=TStringList.Create;
105  for i:=0 to LazarusTranslations.Count-1 do
106  begin
107    LangID:=LazarusTranslations[i].ID;
108    if LangID<>'' then
109      sl.Add(LangIDToCaption(LangID));
110  end;
111  sl.Sort;
112  sl.Insert(0,GetLazarusLanguageLocalizedName(''));
113  LanguageComboBox.Items.Assign(sl);
114  sl.Free;
115
116  // mouse action
117  lblMouseAction.Caption := dlgMouseAction;
118  PreferDoubleClickCheckBox.Caption := dlgPreferDoubleClickOverSingleClick;
119  PreferDoubleClickCheckBox.Hint := dlgCurrentlyRespectedByMessagesWindow;
120
121  // hints
122  lblHints.Caption := dlgDesktopHints;
123  ShowHintsForMainSpeedButtonsCheckBox.Caption := dlgSpBHints;
124  ShowHintsForComponentPaletteCheckBox.Caption := dlgPalHints;
125
126  // button glyphs
127  lblGlyphs.Caption := lisShowGlyphsFor;
128  lblButtons.Caption := dlgDesktopButtons;
129  lblMenus.Caption := dlgDesktopMenus;
130  rbBtnGlyphShowAlways.Caption := lisAlways;
131  rbBtnGlyphShowNever.Caption := lisNever;
132  rbBtnGlyphShowSystem.Caption := lisDefault;
133  rbMenuGlyphShowAlways.Caption := lisAlways;
134  rbMenuGlyphShowNever.Caption := lisNever;
135  rbMenuGlyphShowSystem.Caption := lisDefault;
136
137  // check and auto save files
138  lblCheckAndAutoSave.Caption := dlgCheckAndAutoSaveFiles;
139  CheckDiskChangesWithLoadingCheckBox.Caption := lisCheckForDiskFileChangesViaContent;
140  CheckDiskChangesWithLoadingCheckBox.Hint := lisSlowerButMoreAccurate;
141  AskSavingOnlySessionCheckBox.Caption := lisAskBeforeSavingProjectSSession;
142  AskSavingOnlySessionCheckBox.Hint := lisIfOnlySessionInfoChangedThenAsk;
143  // The following 3 are now hidden.
144  AutoSaveEditorFilesCheckBox.Caption := dlgEdFiles;
145  AutoSaveProjectCheckBox.Caption := dlgProject;
146  AutoSaveIntervalInSecsLabel.Caption := dlgIntvInSec;
147
148  // desktop files
149  lblImportExport.Caption := lisExportImport;
150  ExportDesktopButton.Caption := lisExport;
151  ImportDesktopButton.Caption := lisImport;
152  ExportDesktopButton.Hint := lisExportEnvironmentOptions;
153  ImportDesktopButton.Hint := lisImportEnvironmentOptions;
154end;
155
156procedure TDesktopOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
157begin
158  with AOptions as TEnvironmentOptions do
159  begin
160    // language
161    LanguageComboBox.Text:=LangIDToCaption(LanguageID);
162    //debugln('TEnvironmentOptionsDialog.ReadSettings LanguageComboBox.ItemIndex=',dbgs(LanguageComboBox.ItemIndex),' LanguageID="',LanguageID,'" LanguageComboBox.Text="',LanguageComboBox.Text,'"');
163
164    // mouse action
165    PreferDoubleClickCheckBox.Checked := MsgViewDblClickJumps;
166
167    // hints
168    ShowHintsForMainSpeedButtonsCheckBox.Checked:=ShowHintsForMainSpeedButtons;
169    ShowHintsForComponentPaletteCheckBox.Checked:=ShowHintsForComponentPalette;
170
171    // glyphs
172    case ShowButtonGlyphs of
173      sbgAlways: rbBtnGlyphShowAlways.Checked := True;
174      sbgNever: rbBtnGlyphShowNever.Checked := True;
175      sbgSystem: rbBtnGlyphShowSystem.Checked := True;
176    end;
177    case ShowMenuGlyphs of
178      sbgAlways: rbMenuGlyphShowAlways.Checked := True;
179      sbgNever: rbMenuGlyphShowNever.Checked := True;
180      sbgSystem: rbMenuGlyphShowSystem.Checked := True;
181    end;
182
183    // check and auto save files
184    CheckDiskChangesWithLoadingCheckBox.Checked:=CheckDiskChangesWithLoading;
185    AskSavingOnlySessionCheckBox.Checked:=AskSaveSessionOnly;
186    AutoSaveEditorFilesCheckBox.Checked:=AutoSaveEditorFiles;
187    AutoSaveProjectCheckBox.Checked:=AutoSaveProject;
188    SetComboBoxText(AutoSaveIntervalInSecsComboBox
189       ,IntToStr(AutoSaveIntervalInSecs),cstCaseInsensitive);
190  end;
191end;
192
193procedure TDesktopOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
194begin
195  with AOptions as TEnvironmentOptions do
196  begin
197    // language
198    LanguageID:=CaptionToLangID(LanguageComboBox.Text);
199    //debugln('TEnvironmentOptionsDialog.WriteSettings A LanguageID="',LanguageID,'" LanguageComboBox.ItemIndex=',dbgs(LanguageComboBox.ItemIndex),' LanguageComboBox.Text=',LanguageComboBox.Text);
200
201    // mouse action
202    MsgViewDblClickJumps := PreferDoubleClickCheckBox.Checked;
203
204    // hints
205    ShowHintsForMainSpeedButtons:=ShowHintsForMainSpeedButtonsCheckBox.Checked;
206    ShowHintsForComponentPalette:=ShowHintsForComponentPaletteCheckBox.Checked;
207
208    // glyphs
209    if rbBtnGlyphShowAlways.Checked then
210      ShowButtonGlyphs := sbgAlways
211    else
212    if rbBtnGlyphShowNever.Checked then
213      ShowButtonGlyphs := sbgNever
214    else
215      ShowButtonGlyphs := sbgSystem;
216    if rbMenuGlyphShowAlways.Checked then
217      ShowMenuGlyphs := sbgAlways
218    else
219    if rbMenuGlyphShowNever.Checked then
220      ShowMenuGlyphs := sbgNever
221    else
222      ShowMenuGlyphs := sbgSystem;
223
224    // check and auto save files
225    CheckDiskChangesWithLoading:=CheckDiskChangesWithLoadingCheckBox.Checked;
226    AskSaveSessionOnly:=AskSavingOnlySessionCheckBox.Checked;
227    AutoSaveEditorFiles:=AutoSaveEditorFilesCheckBox.Checked;
228    AutoSaveProject:=AutoSaveProjectCheckBox.Checked;
229    AutoSaveIntervalInSecs:=StrToIntDef(
230      AutoSaveIntervalInSecsComboBox.Text,AutoSaveIntervalInSecs);
231  end;
232end;
233
234procedure TDesktopOptionsFrame.ExportDesktopButtonClick(Sender: TObject);
235var
236  AnEnvironmentOptions: TEnvironmentOptions;
237  SaveDialog: TSaveDialog;
238  AFilename: String;
239begin
240  //debugln('TDesktopOptionsFrame.ExportDesktopButtonClick A');
241  SaveDialog := TSaveDialog.Create(nil);
242  try
243    try
244      InputHistories.ApplyFileDialogSettings(SaveDialog);
245      SaveDialog.Filter:=dlgFilterLazarusDesktopSettings+' (*.lds)|*.lds'
246           //+'|'+dlgFilterXML+' (*.xml)|*.xml'
247           +'|'+dlgFilterAll+' ('+GetAllFilesMask+')|' + GetAllFilesMask;
248      if SaveDialog.Execute then
249      begin
250        AFilename:=SaveDialog.Filename;
251        if ExtractFileExt(AFilename)='' then
252          AFilename:=AFilename+'.lds';
253        AnEnvironmentOptions := TEnvironmentOptions.Create;
254        try
255          AnEnvironmentOptions.Filename := AFilename;
256          DoSaveSettings(AnEnvironmentOptions);
257          AnEnvironmentOptions.Save(true);
258          ShowMessageFmt(lisSuccessfullyExported, [SaveDialog.Filename]);
259        finally
260          AnEnvironmentOptions.Free;
261        end;
262      end;
263      InputHistories.StoreFileDialogSettings(SaveDialog);
264    except
265      on E: Exception do
266      begin
267        DebugLn('ERROR: [TDesktopOptionsFrame.ExportDesktopButtonClick] ', E.Message);
268      end;
269    end;
270  finally
271    SaveDialog.Free;
272  end;
273end;
274
275procedure TDesktopOptionsFrame.ImportDesktopButtonClick(Sender: TObject);
276var
277  AnEnvironmentOptions: TEnvironmentOptions;
278  OpenDialog: TOpenDialog;
279begin
280  //debugln('TDesktopOptionsFrame.ImportDesktopButtonClick A');
281  OpenDialog := TOpenDialog.Create(nil);
282  try
283    try
284      InputHistories.ApplyFileDialogSettings(OpenDialog);
285      OpenDialog.Filter:=dlgFilterLazarusDesktopSettings+' (*.lds)|*.lds'
286           //+'|'+dlgFilterXML+' (*.xml)|*.xml'
287           +'|'+dlgFilterAll+' ('+GetAllFilesMask+')|' + GetAllFilesMask;
288      if OpenDialog.Execute then
289      begin
290        AnEnvironmentOptions := TEnvironmentOptions.Create;
291        try
292          AnEnvironmentOptions.Filename := OpenDialog.Filename;
293          AnEnvironmentOptions.Load(true);
294          DoLoadSettings(AnEnvironmentOptions);
295          IDEWindowCreators.RestoreSimpleLayout;
296          ShowMessageFmt(lisSuccessfullyImported, [OpenDialog.Filename]);
297        finally
298          AnEnvironmentOptions.Free;
299        end;
300      end;
301      InputHistories.StoreFileDialogSettings(OpenDialog);
302    except
303      on E: Exception do
304      begin
305        // ToDo
306        DebugLn('ERROR: [TDesktopOptionsFrame.ImportDesktopButtonClick] ', E.Message);
307      end;
308    end;
309  finally
310    OpenDialog.Free;
311  end;
312end;
313
314function TDesktopOptionsFrame.LangIDToCaption(const LangID: string): string;
315begin
316  if LangID <> '' then
317    Result := GetLazarusLanguageLocalizedName(LangID)+' ['+LangID+']'
318  else
319    //No [] if automatic
320    Result := GetLazarusLanguageLocalizedName(LangID);
321end;
322
323function TDesktopOptionsFrame.CaptionToLangID(const ACaption: string): string;
324var
325  i: Integer;
326begin
327  for i := 0 to LazarusTranslations.Count-1 do 
328  begin
329    Result := LazarusTranslations[i].ID;
330    if ACaption = LangIDToCaption(Result) then 
331      Exit;
332  end;
333  Result := '';
334end;
335
336procedure TDesktopOptionsFrame.DoLoadSettings(AOptions: TAbstractIDEOptions);
337begin
338  if Assigned(OnLoadIDEOptions) then
339    OnLoadIDEOptions(Self, AOptions);
340end;
341
342procedure TDesktopOptionsFrame.DoSaveSettings(AOptions: TAbstractIDEOptions);
343begin
344  if Assigned(OnSaveIDEOptions) then
345    OnSaveIDEOptions(Self, AOptions);
346end;
347
348class function TDesktopOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
349begin
350  Result := TEnvironmentOptions;
351end;
352
353initialization
354  RegisterIDEOptionsEditor(GroupEnvironment, TDesktopOptionsFrame, EnvOptionsDesktop);
355end.
356