fpini.pas 22 KB

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