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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
18 *                                                                         *
19 ***************************************************************************
20
21  Author: Michael Van Canneyt
22}
23unit LazDEOpts;
24
25{$mode objfpc}{$H+}
26
27Interface
28
29uses SysUtils, IniFiles, LazFileUtils, LazUTF8;
30
31Var
32  SkipEmptyNodes   : Boolean;
33  ConfirmDelete    : Boolean;
34  CreateBackup     : Boolean;
35  ShowHelpHints    : Boolean;
36  StartMaximized   : Boolean;
37  ReopenLast       : Boolean;
38  MaxRecentUsed    : Integer;
39  BackupExtension  : String;
40  DefaultExtension : String;
41  CmdMakeSkel      : String;
42  cmdFPDoc         : String;
43
44Const
45  ImgIndxNew        = 0;
46  ImgIndxEdited     = 1;
47
48Procedure LoadOptions;
49Procedure SaveOptions;
50Function  GetOptionFileName : String;
51
52Implementation
53uses gettext, translations;
54
55const
56  DefFilename         = 'fpde.ini';
57  SecPrefs            = 'Preferences';
58  KeySkipEmptyNodes   = 'SkipEmptyNodes';
59  KeyConfirmDelete    = 'ConfirmDelete';
60  KeyCreateBackup     = 'CreateBackup';
61  KeyBackupExtension  = 'BackupExtension';
62  KeyDefaultExtension = 'DefaultExtension';
63  //KeyMaxRecentUsed    = 'MaxMRUitems';
64  KeyCmdMakeSkel      = 'makeskel';
65  KeyCmdFpdoc         = 'fpdoc';
66  KeyShowHints        = 'ShowHints';
67
68{$ifndef MSWindows}
69Function GetOptionFileName : String;
70
71Const
72  fpdedir = '.fpde';
73
74Var
75  HomeDir : String;
76
77begin
78  HomeDir:=GetEnvironmentVariableUTF8('HOME');
79  If (HomeDir<>'') then
80    begin
81    HomeDir:=IncludeTrailingPathDelimiter(HomeDir)+fpdedir;
82    If not DirectoryExistsUTF8(HomeDir) then
83      If Not CreateDirUTF8(HomeDir) then
84        HomeDir:=''
85      else
86        HomeDir:=HomeDir;
87    end;
88  Result:=IncludeTrailingPathDelimiter(HomeDir)+DefFileName;
89end;
90
91{$else}
92
93Function GetOptionFileName : String;
94
95begin
96  Result:=ExtractFilePath(ParamStrUTF8(0))+DefFileName;
97end;
98{$endif}
99
100Procedure LoadOptions;
101
102begin
103  With TInifile.Create(UTF8ToSys(GetOptionFileName)) do
104    Try
105      SkipEmptyNodes:=ReadBool(SecPrefs,KeySkipEmptyNodes,SkipEmptyNodes);
106      ConfirmDelete:=ReadBool(SecPrefs,KeyConfirmDelete,ConfirmDelete);
107      CreateBackup:=ReadBool(SecPrefs,KeyCreateBackup,CreateBackup);
108      ShowHelpHints:=ReadBool(SecPrefs,KeyShowHints,ShowHelpHints);
109      StartMaximized := ReadBool(SecPrefs, 'StartMaximized', StartMaximized);
110      ReopenLast := ReadBool(SecPrefs, 'ReopenLast', ReopenLast);
111      BackupExtension:=ReadString(SecPrefs,KeyBackupExtension,BackupExtension);
112      DefaultExtension:=ReadString(SecPrefs,KeyDefaultExtension,DefaultExtension);
113      CmdMakeSkel:=ReadString(SecPrefs,KeyCmdMakeSkel,cmdMakeSkel);
114      Cmdfpdoc:=ReadString(SecPrefs,KeyCmdfpdoc,cmdfpdoc);
115    finally
116      Free;
117    end;
118end;
119
120Procedure SaveOptions;
121
122begin
123  With TInifile.Create(UTF8ToSys(GetOptionFileName)) do
124    Try
125      WriteBool(SecPrefs,KeySkipEmptyNodes,SkipEmptyNodes);
126      WriteBool(SecPrefs,KeyConfirmDelete,ConfirmDelete);
127      WriteBool(SecPrefs,KeyCreateBackup,CreateBackup);
128      WriteBool(SecPrefs,KeyShowHints,ShowHelpHints);
129      WriteBool(SecPrefs, 'StartMaximized', StartMaximized);
130      WriteBool(SecPrefs, 'ReopenLast', ReopenLast);
131      WriteString(SecPrefs,KeyBackupExtension,BackupExtension);
132      WriteString(SecPrefs,KeyDefaultExtension,DefaultExtension);
133      WriteString(SecPrefs,KeyCmdMakeSkel,cmdMakeSkel);
134      WriteString(SecPrefs,KeyCmdfpdoc,cmdfpdoc);
135      UpdateFile;
136    finally
137      Free;
138    end;
139end;
140
141procedure TranslateResStrings;
142var
143  Lang, FallbackLang, S: String;
144begin
145  FallbackLang:='';
146  Lang:='';
147  GetLanguageIDs(Lang,FallbackLang); // in unit gettext
148  S:=AppendPathDelim(AppendPathDelim(ExtractFileDir(ParamStr(0))) + 'languages');
149  TranslateUnitResourceStrings('LazDEMsg',S+'lazde.%s.po', Lang,FallbackLang);
150end;
151
152Initialization
153  SkipEmptyNodes   := True;
154  ConfirmDelete    := True;
155  CreateBackup     := True;
156  StartMaximized   := true;
157  ReopenLast       := true;
158  BackupExtension  := '.~xml';
159  DefaultExtension := '.xml';
160  MaxRecentUSed    := 10;
161  CmdMakeSkel      := 'makeskel';
162  cmdfpdoc         := 'fpdoc';
163  ShowHelpHints    := true;
164
165  TranslateResStrings;
166end.
167