fpini.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Write/Read Options to INI File
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPIni;
  12. interface
  13. {$i globdir.inc}
  14. uses
  15. FPUtils;
  16. procedure InitDirs;
  17. procedure InitINIFile;
  18. procedure CheckINIFile;
  19. function ReadINIFile: boolean;
  20. function WriteINIFile(FromSaveAs : boolean) : boolean;
  21. function GetPrinterDevice: string;
  22. procedure SetPrinterDevice(const Device: string);
  23. implementation
  24. uses
  25. Dos,Objects,Drivers,
  26. FVConsts,
  27. Version,
  28. {$ifdef USE_EXTERNAL_COMPILER}
  29. fpintf, { superseeds version_string of version unit }
  30. {$endif USE_EXTERNAL_COMPILER}
  31. WConsts,WUtils,WINI,WViews,WEditor,WCEdit,
  32. {$ifndef NODEBUG}FPDebug,{$endif}FPConst,FPVars,
  33. FPIntf,FPTools,FPSwitch,FPString,fpccrc;
  34. const
  35. PrinterDevice : string = 'prn';
  36. function GetPrinterDevice: string;
  37. begin
  38. GetPrinterDevice:=PrinterDevice;
  39. end;
  40. procedure SetPrinterDevice(const Device: string);
  41. begin
  42. PrinterDevice:=Device;
  43. end;
  44. const
  45. { INI file sections }
  46. secFiles = 'Files';
  47. secRun = 'Run';
  48. secCompile = 'Compile';
  49. secColors = 'Colors';
  50. secHelp = 'Help';
  51. secEditor = 'Editor';
  52. secBreakpoint = 'Breakpoints';
  53. secWatches = 'Watches';
  54. secHighlight = 'Highlight';
  55. secKeyboard = 'Keyboard';
  56. secMouse = 'Mouse';
  57. secSearch = 'Search';
  58. secTools = 'Tools';
  59. secSourcePath = 'SourcePath';
  60. secPreferences = 'Preferences';
  61. secMisc = 'Misc';
  62. { INI file tags }
  63. ieRecentFile = 'RecentFile';
  64. iePrinterDevice = 'PrinterDevice';
  65. (* ieOpenFile = 'OpenFile';
  66. ieOpenFileCount = 'OpenFileCount'; *)
  67. ieRunDir = 'RunDirectory';
  68. ieRunParameters = 'Parameters';
  69. ieDebuggeeRedir = 'DebugRedirection';
  70. ieRemoteMachine = 'RemoteMachine';
  71. ieRemotePort = 'RemotePort';
  72. ieRemoteSendCommand = 'RemoteSendCommand';
  73. ieRemoteConfig = 'RemoteSendConfig';
  74. ieRemoteIdent = 'RemoteSendIdent';
  75. ieRemoteDirectory = 'RemoteDirectory';
  76. iePrimaryFile = 'PrimaryFile';
  77. ieCompileMode = 'CompileMode';
  78. iePalette = 'Palette';
  79. ieHelpFiles = 'Files';
  80. ieDefaultTabSize = 'DefaultTabSize';
  81. ieDefaultIndentSize = 'DefaultIndentSize';
  82. ieDefaultEditorFlags='DefaultFlags';
  83. ieDefaultSaveExt = 'DefaultSaveExt';
  84. ieOpenExts = 'OpenExts';
  85. ieHighlightExts = 'Exts';
  86. ieTabsPattern = 'NeedsTabs';
  87. ieDoubleClickDelay = 'DoubleDelay';
  88. ieReverseButtons = 'ReverseButtons';
  89. ieAltClickAction = 'AltClickAction';
  90. ieCtrlClickAction = 'CtrlClickAction';
  91. ieFindFlags = 'FindFlags';
  92. ieToolName = 'Title';
  93. ieToolProgram = 'Program';
  94. ieToolParams = 'Params';
  95. ieToolHotKey = 'HotKey';
  96. ieBreakpointTyp = 'Type';
  97. ieBreakpointCount = 'Count';
  98. ieBreakpointState = 'State';
  99. ieBreakpointName = 'Name';
  100. ieBreakpointFile = 'FileName';
  101. ieBreakpointLine = 'LineNumber';
  102. ieBreakpointCond = 'Condition';
  103. ieWatchCount = 'Count';
  104. ieWatchName = 'Watch';
  105. ieSourceList = 'SourceList';
  106. { ieVideoMode = 'VideoMode';}
  107. ieAutoSave = 'AutoSaveFlags';
  108. ieMiscOptions = 'MiscOptions';
  109. ieDesktopLocation = 'DesktopLocation';
  110. ieDesktopFlags = 'DesktopFileFlags';
  111. ieCenterDebuggerRow= 'CenterCurrentLineWhileDebugging';
  112. ieShowReadme = 'ShowReadme';
  113. ieEditKeys = 'EditKeys';
  114. Procedure InitDirs;
  115. begin
  116. StartupDir:=CompleteDir(FExpand('.'));
  117. {$ifndef unix}
  118. IDEDir:=CompleteDir(DirOf(system.Paramstr(0)));
  119. {$else}
  120. SystemIDEDir:='/usr/lib/fpc/'+version_string+'/ide/text';
  121. IDEdir:=CompleteDir(FExpand('~/.fp'));
  122. If Not ExistsDir(IDEdir) Then
  123. begin
  124. IDEDir:=SystemIDEDir;
  125. if Not ExistsDir(IDEDir) then
  126. begin
  127. if DirOf(system.paramstr(0))<>'' then
  128. IDEDir:=CompleteDir(DirOf(system.ParamStr(0)))
  129. else
  130. IDEDir:=StartupDir;
  131. end;
  132. end;
  133. {$endif}
  134. end;
  135. procedure InitINIFile;
  136. var S: string;
  137. begin
  138. S:=LocateFile(INIFileName);
  139. if S<>'' then
  140. IniFileName:=S;
  141. IniFileName:=FExpand(IniFileName);
  142. end;
  143. procedure CheckINIFile;
  144. var IniDir,CurDir: DirStr;
  145. INI: PINIFile;
  146. const Btns : array[1..2] of string = (btn_config_copyexisting,btn_config_createnew);
  147. begin
  148. IniDir:=DirOf(IniFileName); CurDir:=GetCurDir;
  149. if CompareText(IniDir,CurDir)<>0 then
  150. if not ExistsFile(CurDir+DirInfoName) then
  151. if ConfirmBox(FormatStrStr(msg_doyouwanttocreatelocalconfigfile,IniDir),nil,false)=cmYes then
  152. begin
  153. if (not ExistsFile(IniFileName)) or
  154. (ChoiceBox(msg_configcopyexistingorcreatenew,nil,
  155. Btns,false)=cmUserBtn2) then
  156. begin
  157. { create new config here }
  158. IniFileName:=CurDir+IniName;
  159. SwitchesPath:=CurDir+SwitchesName;
  160. end
  161. else
  162. begin
  163. { copy config here }
  164. if CopyFile(IniFileName,CurDir+IniName)=false then
  165. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+IniName),nil)
  166. else
  167. IniFileName:=CurDir+IniName;
  168. if CopyFile(SwitchesPath,CurDir+SwitchesName)=false then
  169. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+SwitchesName),nil)
  170. else
  171. SwitchesPath:=CurDir+SwitchesName;
  172. end;
  173. end
  174. else
  175. begin
  176. New(INI, Init(CurDir+DirInfoName));
  177. INI^.SetEntry(MainSectionName,'Comment','Do NOT delete this file!!!');
  178. if INI^.Update=false then
  179. ErrorBox(FormatStrStr(msg_errorwritingfile,INI^.GetFileName),nil);
  180. Dispose(INI, Done);
  181. end;
  182. end;
  183. function PaletteToStr(S: string): string;
  184. var C: string;
  185. I: integer;
  186. begin
  187. C:='';
  188. for I:=1 to length(S) do
  189. Insert('#$'+hexstr(ord(S[I]),2),C,Length(C)+1);
  190. PaletteToStr:=C;
  191. end;
  192. function strtopalette(S: string): string;
  193. {Converts a string in palette string format, i.e #$41#$42#$43 or
  194. #65#66#67 to an actual format.}
  195. var i,p,x,len:byte;
  196. code:integer;
  197. begin
  198. i:=1;
  199. len:=0;
  200. while (i<=length(S)) and (s[i]='#') do
  201. begin
  202. s[i]:=#0;
  203. inc(i);
  204. p:=pos('#',s);
  205. if p=0 then
  206. p:=length(s)
  207. else
  208. p:=p-i;
  209. val(copy(s,i,p),x,code); {Val supports hexadecimal.}
  210. if code<>0 then
  211. break;
  212. inc(len);
  213. strtopalette[len]:=char(X);
  214. inc(i,p);
  215. end;
  216. strtopalette[0]:=char(len);
  217. end;
  218. {$ifndef NODEBUG}
  219. procedure WriteOneWatchEntry(I : Longint;INIFile : PINIFile);
  220. var
  221. PW : PWatch;
  222. S : String;
  223. begin
  224. Str(I,S);
  225. PW:=WatchesCollection^.At(I);
  226. With PW^ do
  227. begin
  228. INIFile^.SetEntry(secWatches,ieWatchName+S,GetStr(expr));
  229. end;
  230. end;
  231. procedure WriteOneBreakPointEntry(I : longint;INIFile : PINIFile);
  232. var PB : PBreakpoint;
  233. S : String;
  234. begin
  235. Str(I,S);
  236. PB:=BreakpointsCollection^.At(I);
  237. If assigned(PB) then
  238. With PB^ do
  239. Begin
  240. INIFile^.SetEntry(secBreakpoint,ieBreakpointTyp+S,BreakpointTypeStr[typ]);
  241. INIFile^.SetEntry(secBreakpoint,ieBreakpointState+S,BreakpointStateStr[state]);
  242. if typ=bt_file_line then
  243. begin
  244. INIFile^.SetEntry(secBreakpoint,ieBreakpointFile+S,FileName^);
  245. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointLine+S,Line);
  246. end
  247. else
  248. INIFile^.SetEntry(secBreakpoint,ieBreakpointName+S,Name^);
  249. if assigned(Conditions) then
  250. INIFile^.SetEntry(secBreakpoint,ieBreakpointCond+S,Conditions^)
  251. else
  252. INIFile^.SetEntry(secBreakpoint,ieBreakpointCond+S,'');
  253. end;
  254. end;
  255. procedure ReadOneWatchEntry(I : Longint;INIFile : PINIFile);
  256. var
  257. PW : PWatch;
  258. S : String;
  259. begin
  260. Str(I,S);
  261. PW:=new(PWatch,Init(INIFile^.GetEntry(secWatches,ieWatchName+S,'')));
  262. WatchesCollection^.Insert(PW);
  263. end;
  264. procedure ReadOneBreakPointEntry(i : longint;INIFile : PINIFile);
  265. var PB : PBreakpoint;
  266. S,S2,SC : string;
  267. Line : longint;
  268. typ : BreakpointType;
  269. state : BreakpointState;
  270. begin
  271. Str(I,S2);
  272. typ:=bt_invalid;
  273. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointTyp+S2,BreakpointTypeStr[typ]);
  274. for typ:=low(BreakpointType) to high(BreakpointType) do
  275. If pos(BreakpointTypeStr[typ],S)>0 then break;
  276. state:=bs_deleted;
  277. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointState+S2,BreakpointStateStr[state]);
  278. for state:=low(BreakpointState) to high(BreakpointState) do
  279. If pos(BreakpointStateStr[state],S)>0 then break;
  280. case typ of
  281. bt_invalid :;
  282. bt_file_line :
  283. begin
  284. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointFile+S2,'');
  285. Line:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointLine+S2,0);
  286. end;
  287. else
  288. begin
  289. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointName+S2,'');
  290. end;
  291. end;
  292. SC:=INIFile^.GetEntry(secBreakpoint,ieBreakpointCond+S2,'');
  293. if (typ=bt_function) and (S<>'') then
  294. new(PB,init_function(S))
  295. else if (typ=bt_file_line) and (S<>'') then
  296. new(PB,init_file_line(S,Line))
  297. else
  298. new(PB,init_type(typ,S));
  299. If assigned(PB) then
  300. begin
  301. PB^.state:=state;
  302. If SC<>'' then
  303. PB^.conditions:=NewStr(SC);
  304. BreakpointsCollection^.Insert(PB);
  305. end;
  306. end;
  307. {$endif NODEBUG}
  308. function ReadINIFile: boolean;
  309. var INIFile: PINIFile;
  310. S,PS,S1,S2,S3: string;
  311. I,P: integer;
  312. BreakPointCount,WatchesCount:longint;
  313. OK: boolean;
  314. ts : TSwitchMode;
  315. W: word;
  316. begin
  317. OK:=ExistsFile(IniFileName);
  318. if OK then
  319. begin
  320. New(INIFile, Init(IniFileName));
  321. { Files }
  322. OpenExts:=INIFile^.GetEntry(secFiles,ieOpenExts,OpenExts);
  323. RecentFileCount:=High(RecentFiles);
  324. for I:=Low(RecentFiles) to High(RecentFiles) do
  325. begin
  326. S:=INIFile^.GetEntry(secFiles,ieRecentFile+IntToStr(I),'');
  327. if (S='') and (RecentFileCount>I-1) then RecentFileCount:=I-1;
  328. with RecentFiles[I] do
  329. begin
  330. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  331. FileName:=copy(S,1,P-1); Delete(S,1,P);
  332. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  333. LastPos.X:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  334. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  335. LastPos.Y:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  336. end;
  337. end;
  338. { Run }
  339. SetRunDir(INIFile^.GetEntry(secRun,ieRunDir,GetRunDir));
  340. SetRunParameters(INIFile^.GetEntry(secRun,ieRunParameters,GetRunParameters));
  341. SetPrinterDevice(INIFile^.GetEntry(secFiles,iePrinterDevice,GetPrinterDevice));
  342. { First read the primary file, which can also set the parameters which can
  343. be overruled with the parameter loading }
  344. SetPrimaryFile(INIFile^.GetEntry(secCompile,iePrimaryFile,PrimaryFile));
  345. DebuggeeTTY := INIFile^.GetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  346. {$ifdef SUPPORT_REMOTE}
  347. RemoteMachine :=INIFile^.GetEntry(secRun,ieRemoteMachine,RemoteMachine);
  348. RemotePort :=INIFile^.GetEntry(secRun,ieRemotePort,RemotePort);
  349. RemoteSendCommand :=INIFile^.GetEntry(secRun,ieRemoteSendCommand,RemoteSendCommand);
  350. RemoteConfig :=INIFile^.GetEntry(secRun,ieRemoteConfig,RemoteConfig);
  351. RemoteIdent :=INIFile^.GetEntry(secRun,ieRemoteIdent,RemoteIdent);
  352. RemoteDir :=INIFile^.GetEntry(secRun,ieRemoteDirectory,RemoteDir);
  353. {$endif SUPPORT_REMOTE}
  354. { Compile }
  355. S:=INIFile^.GetEntry(secCompile,ieCompileMode,'');
  356. for ts:=low(TSwitchMode) to high(TSwitchMode) do
  357. begin
  358. if SwitchesModeStr[ts]=S then
  359. SwitchesMode:=ts;
  360. end;
  361. { Help }
  362. S:=INIFile^.GetEntry(secHelp,ieHelpFiles,'');
  363. repeat
  364. P:=Pos(';',S); if P=0 then P:=length(S)+1;
  365. PS:=copy(S,1,P-1);
  366. if PS<>'' then HelpFiles^.Insert(NewStr(PS));
  367. Delete(S,1,P);
  368. until S='';
  369. { Editor }
  370. DefaultTabSize:=INIFile^.GetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  371. DefaultIndentSize:=INIFile^.GetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  372. DefaultCodeEditorFlags:=INIFile^.GetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  373. DefaultSaveExt:=INIFile^.GetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  374. { Highlight }
  375. HighlightExts:=INIFile^.GetEntry(secHighlight,ieHighlightExts,HighlightExts);
  376. TabsPattern:=INIFile^.GetEntry(secHighlight,ieTabsPattern,TabsPattern);
  377. { SourcePath }
  378. SourceDirs:=INIFile^.GetEntry(secSourcePath,ieSourceList,SourceDirs);
  379. { Mouse }
  380. DoubleDelay:=INIFile^.GetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  381. MouseReverse:=boolean(INIFile^.GetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse)));
  382. AltMouseAction:=INIFile^.GetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  383. CtrlMouseAction:=INIFile^.GetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  384. {Keyboard}
  385. case crc32(upcase(INIFile^.GetEntry(secKeyboard,ieEditKeys,''))) of
  386. $86a4c898: {crc32 for 'MICROSOFT'}
  387. EditKeys:=ekm_microsoft;
  388. $b20b87b3: {crc32 for 'BORLAND'}
  389. EditKeys:=ekm_borland;
  390. else
  391. EditKeys:=ekm_default;
  392. end;
  393. { Search }
  394. FindFlags:=INIFile^.GetIntEntry(secSearch,ieFindFlags,FindFlags);
  395. { Breakpoints }
  396. {$ifndef NODEBUG}
  397. BreakpointCount:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointCount,0);
  398. for i:=1 to BreakpointCount do
  399. ReadOneBreakPointEntry(i-1,INIFile);
  400. WatchesCount:=INIFile^.GetIntEntry(secWatches,ieWatchCount,0);
  401. for i:=1 to WatchesCount do
  402. ReadOneWatchEntry(i-1,INIFile);
  403. {$endif}
  404. { Tools }
  405. for I:=1 to MaxToolCount do
  406. begin
  407. S:=IntToStr(I);
  408. S1:=INIFile^.GetEntry(secTools,ieToolName+S,'');
  409. if S1='' then Break; { !!! }
  410. S2:=INIFile^.GetEntry(secTools,ieToolProgram+S,'');
  411. S3:=INIFile^.GetEntry(secTools,ieToolParams+S,'');
  412. W:=Max(0,Min(65535,INIFile^.GetIntEntry(secTools,ieToolHotKey+S,0)));
  413. AddTool(S1,S2,S3,W);
  414. end;
  415. { Colors }
  416. S:=AppPalette;
  417. PS:=StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40))));
  418. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40))));
  419. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40))));
  420. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40))));
  421. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
  422. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
  423. if length(PS)<length(CIDEAppColor) then
  424. PS:=PS+copy(CIDEAppColor,length(PS)+1,255);
  425. AppPalette:=PS;
  426. (* { Open files }
  427. for I:=INIFile^.GetIntEntry(secFiles,ieOpenFileCount,0) downto 1 do
  428. begin
  429. S:=INIFile^.GetEntry(secFiles,ieOpenFile+IntToStr(I),'');
  430. if (S='') then
  431. break;
  432. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  433. S1:=copy(S,1,P-1);
  434. Delete(S,1,P);
  435. P:=Pos(',',S);
  436. if P=0 then P:=length(S)+1;
  437. X:=Max(0,StrToInt(copy(S,1,P-1)));
  438. Delete(S,1,P);
  439. P:=Pos(',',S);
  440. if P=0 then P:=length(S)+1;
  441. Y:=Max(0,StrToInt(copy(S,1,P-1)));
  442. Delete(S,1,P);
  443. P:=Pos(',',S);
  444. if P=0 then P:=length(S)+1;
  445. R.A.X:=Max(0,StrToInt(copy(S,1,P-1)));
  446. Delete(S,1,P);
  447. P:=Pos(',',S);
  448. if P=0 then P:=length(S)+1;
  449. R.A.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  450. Delete(S,1,P);
  451. P:=Pos(',',S);
  452. if P=0 then P:=length(S)+1;
  453. R.B.X:=Max(0,StrToInt(copy(S,1,P-1)));
  454. Delete(S,1,P);
  455. P:=Pos(',',S);
  456. if P=0 then P:=length(S)+1;
  457. R.B.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  458. if (R.A.X<R.B.X) and (R.A.Y<R.B.Y) then
  459. TryToOpenFile(@R,S1,X,Y,false)
  460. else
  461. TryToOpenFile(nil,S1,X,Y,false);
  462. { remove it because otherwise we allways keep old files }
  463. INIFile^.DeleteEntry(secFiles,ieOpenFile+IntToStr(I));
  464. end;
  465. *)
  466. { Desktop }
  467. DesktopFileFlags:=INIFile^.GetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  468. { Debugger }
  469. IniCenterDebuggerRow:=tcentre(INIFile^.GetIntEntry(secPreferences,ieCenterDebuggerRow,1));
  470. { Preferences }
  471. AutoSaveOptions:=INIFile^.GetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  472. MiscOptions:=INIFile^.GetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  473. DesktopLocation:=INIFile^.GetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  474. { Misc }
  475. ShowReadme:=INIFile^.GetIntEntry(secMisc,ieShowReadme,{integer(ShowReadme)}1)<>0;
  476. Dispose(INIFile, Done);
  477. end;
  478. ReadINIFile:=OK;
  479. end;
  480. function WriteINIFile (FromSaveAs : boolean): boolean;
  481. var INIFile: PINIFile;
  482. S: string;
  483. S1,S2,S3: string;
  484. W: word;
  485. BreakPointCount,WatchesCount:longint;
  486. I(*,OpenFileCount*): integer;
  487. OK: boolean;
  488. procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
  489. begin
  490. if (S<>'') then S:=S+';';
  491. S:=S+P^;
  492. end;
  493. begin
  494. {$ifdef Unix}
  495. if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) then
  496. begin
  497. IniFileName:=FExpand('~/.fp/'+IniName);
  498. If not ExistsDir(DirOf(IniFileName)) then
  499. MkDir(FExpand('~/.fp'));
  500. end;
  501. {$endif Unix}
  502. New(INIFile, Init(IniFileName));
  503. { Files }
  504. { avoid keeping old files }
  505. INIFile^.DeleteSection(secFiles);
  506. INIFile^.SetEntry(secFiles,ieOpenExts,'"'+OpenExts+'"');
  507. for I:=1 to High(RecentFiles) do
  508. begin
  509. if I<=RecentFileCount then
  510. with RecentFiles[I] do S:=FileName+','+IntToStr(LastPos.X)+','+IntToStr(LastPos.Y)
  511. else
  512. S:='';
  513. INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
  514. end;
  515. (*
  516. PW:=FirstEditorWindow;
  517. PPW:=PW;
  518. I:=1;
  519. while assigned(PW) do
  520. begin
  521. If PW^.HelpCtx=hcSourceWindow then
  522. begin
  523. With PW^.editor^ do
  524. S:=FileName+','+IntToStr(CurPos.X)+','+IntToStr(CurPos.Y);
  525. PW^.GetBounds(R);
  526. S:=S+','+IntToStr(R.A.X)+','+IntToStr(R.A.Y)+','+
  527. IntToStr(R.B.X)+','+IntToStr(R.B.Y);
  528. INIFile^.SetEntry(secFiles,ieOpenFile+IntToStr(I),S);
  529. Inc(I);
  530. OpenFileCount:=I-1;
  531. end;
  532. PW:=PSourceWindow(PW^.next);
  533. While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
  534. PW:=PSourceWindow(PW^.next);
  535. If PW=PPW then
  536. break;
  537. end;
  538. INIFile^.SetIntEntry(secFiles,ieOpenFileCount,OpenFileCount);
  539. *)
  540. { Run }
  541. INIFile^.SetEntry(secRun,ieRunDir,GetRunDir);
  542. INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
  543. INIFile^.SetEntry(secFiles,iePrinterDevice,GetPrinterDevice);
  544. { If DebuggeeTTY<>'' then }
  545. INIFile^.SetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  546. {$ifdef SUPPORT_REMOTE}
  547. INIFile^.SetEntry(secRun,ieRemoteMachine,RemoteMachine);
  548. INIFile^.SetEntry(secRun,ieRemotePort,RemotePort);
  549. INIFile^.SetEntry(secRun,ieRemoteSendCommand,RemoteSendCommand);
  550. INIFile^.SetEntry(secRun,ieRemoteConfig,RemoteConfig);
  551. INIFile^.SetEntry(secRun,ieRemoteIdent,RemoteIdent);
  552. INIFile^.SetEntry(secRun,ieRemoteDirectory,RemoteDir);
  553. {$endif SUPPORT_REMOTE}
  554. { Compile }
  555. INIFile^.SetEntry(secCompile,iePrimaryFile,PrimaryFile);
  556. INIFile^.SetEntry(secCompile,ieCompileMode,SwitchesModeStr[SwitchesMode]);
  557. { Help }
  558. S:='';
  559. HelpFiles^.ForEach(@ConcatName);
  560. INIFile^.SetEntry(secHelp,ieHelpFiles,'"'+S+'"');
  561. { Editor }
  562. INIFile^.SetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  563. INIFile^.SetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  564. INIFile^.SetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  565. INIFile^.SetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  566. { Highlight }
  567. INIFile^.SetEntry(secHighlight,ieHighlightExts,'"'+HighlightExts+'"');
  568. INIFile^.SetEntry(secHighlight,ieTabsPattern,'"'+TabsPattern+'"');
  569. { SourcePath }
  570. INIFile^.SetEntry(secSourcePath,ieSourceList,'"'+SourceDirs+'"');
  571. { Mouse }
  572. INIFile^.SetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  573. INIFile^.SetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse));
  574. INIFile^.SetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  575. INIFile^.SetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  576. { Keyboard }
  577. if EditKeys=ekm_microsoft then
  578. INIFile^.SetEntry(secKeyboard,ieEditKeys,'microsoft')
  579. else
  580. INIFile^.SetEntry(secKeyboard,ieEditKeys,'borland');
  581. { Search }
  582. INIFile^.SetIntEntry(secSearch,ieFindFlags,FindFlags);
  583. { Breakpoints }
  584. {$ifndef NODEBUG}
  585. BreakPointCount:=BreakpointsCollection^.Count;
  586. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointCount,BreakpointCount);
  587. for i:=1 to BreakpointCount do
  588. WriteOneBreakPointEntry(I-1,INIFile);
  589. WatchesCount:=WatchesCollection^.Count;
  590. INIFile^.SetIntEntry(secWatches,ieWatchCount,WatchesCount);
  591. for i:=1 to WatchesCount do
  592. WriteOneWatchEntry(I-1,INIFile);
  593. {$endif}
  594. { Tools }
  595. INIFile^.DeleteSection(secTools);
  596. for I:=1 to GetToolCount do
  597. begin
  598. S:=IntToStr(I);
  599. GetToolParams(I-1,S1,S2,S3,W);
  600. if S1<>'' then S1:='"'+S1+'"';
  601. if S2<>'' then S2:='"'+S2+'"';
  602. if S3<>'' then S3:='"'+S3+'"';
  603. INIFile^.SetEntry(secTools,ieToolName+S,S1);
  604. INIFile^.SetEntry(secTools,ieToolProgram+S,S2);
  605. INIFile^.SetEntry(secTools,ieToolParams+S,S3);
  606. INIFile^.SetIntEntry(secTools,ieToolHotKey+S,W);
  607. end;
  608. { Colors }
  609. if AppPalette<>CIDEAppColor then
  610. begin
  611. { this has a bug. if a different palette has been read on startup, and
  612. then changed back to match the default, this will not update it in the
  613. ini file, eg. the original (non-default) will be left unmodified... }
  614. S:=AppPalette;
  615. INIFile^.SetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40)));
  616. INIFile^.SetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40)));
  617. INIFile^.SetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40)));
  618. INIFile^.SetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40)));
  619. INIFile^.SetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40)));
  620. INIFile^.SetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40)));
  621. end;
  622. { Desktop }
  623. INIFile^.SetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  624. INIFile^.SetIntEntry(secPreferences,ieCenterDebuggerRow,byte(IniCenterDebuggerRow));
  625. { Preferences }
  626. INIFile^.SetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  627. INIFile^.SetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  628. INIFile^.SetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  629. { Misc }
  630. INIFile^.SetIntEntry(secMisc,ieShowReadme,integer(ShowReadme));
  631. OK:=INIFile^.Update;
  632. Dispose(INIFile, Done);
  633. WriteINIFile:=OK;
  634. end;
  635. end.