fpini.pas 22 KB

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