fpdesk.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Desktop loading/saving routines
  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 FPDesk;
  13. interface
  14. const
  15. MinDesktopVersion = $000A;
  16. DesktopVersion = $000A; { <- if you change any Load&Store methods,
  17. default object properties (Options,State)
  18. then you should also change this }
  19. ResDesktopFlags = 'FLAGS';
  20. ResVideo = 'VIDEOMODE';
  21. ResHistory = 'HISTORY';
  22. ResClipboard = 'CLIPBOARD';
  23. ResWatches = 'WATCHES';
  24. ResBreakpoints = 'BREAKPOINTS';
  25. ResDesktop = 'DESKTOP';
  26. ResSymbols = 'SYMBOLS';
  27. ResCodeComplete = 'CODECOMPLETE';
  28. ResCodeTemplates = 'CODETEMPLATES';
  29. ResKeys = 'KEYS';
  30. procedure InitDesktopFile;
  31. function LoadDesktop: boolean;
  32. function SaveDesktop: boolean;
  33. procedure DoneDesktopFile;
  34. function WriteSymbolsFile(const filename : string): boolean;
  35. function ReadSymbolsFile(const filename : string): boolean;
  36. implementation
  37. uses Dos,
  38. Objects,Drivers,
  39. Video,
  40. Views,App,HistList,BrowCol,
  41. WUtils,WResourc,WViews,WEditor,
  42. {$ifndef NODEBUG}
  43. fpdebug,
  44. {$endif ndef NODEBUG}
  45. {$ifdef Unix}
  46. FPKeys,
  47. {$endif Unix}
  48. FPConst,FPVars,FPString,FPTools,FPUtils,FPViews,FPHelp,
  49. FPCompil,FPCodCmp,FPCodTmp;
  50. type
  51. TWindowInfo = packed record
  52. HelpCtx : word;
  53. Bounds : TRect;
  54. Visible : boolean;
  55. WinNb : byte;
  56. ExtraDataSize : word;
  57. TitleLen : word;
  58. Title : packed record end;
  59. end;
  60. procedure InitDesktopFile;
  61. begin
  62. if DesktopLocation=dlCurrentDir then
  63. DesktopPath:=FExpand(DesktopName)
  64. else
  65. DesktopPath:=FExpand(DirOf(IniFileName)+DesktopName);
  66. end;
  67. procedure DoneDesktopFile;
  68. begin
  69. end;
  70. function ReadHistory(F: PResourceFile): boolean;
  71. var S: PMemoryStream;
  72. OK: boolean;
  73. begin
  74. PushStatus(msg_readinghistory);
  75. New(S, Init(32*1024,4096));
  76. OK:=F^.ReadResourceEntryToStream(resHistory,langDefault,S^);
  77. S^.Seek(0);
  78. if OK then
  79. LoadHistory(S^);
  80. Dispose(S, Done);
  81. if OK=false then
  82. ErrorBox(msg_errorloadinghistory,nil);
  83. PopStatus;
  84. ReadHistory:=OK;
  85. end;
  86. function WriteHistory(F: PResourceFile): boolean;
  87. var S: PMemoryStream;
  88. OK: boolean;
  89. begin
  90. PushStatus(msg_storinghistory);
  91. New(S, Init(10*1024,4096));
  92. StoreHistory(S^);
  93. S^.Seek(0);
  94. F^.CreateResource(resHistory,rcBinary,0);
  95. OK:=F^.AddResourceEntryFromStream(resHistory,langDefault,0,S^,S^.GetSize);
  96. Dispose(S, Done);
  97. if OK=false then
  98. ErrorBox(msg_errorstoringhistory,nil);
  99. PopStatus;
  100. WriteHistory:=OK;
  101. end;
  102. {$ifdef Unix}
  103. function ReadKeys(F: PResourceFile): boolean;
  104. var S: PMemoryStream;
  105. OK: boolean;
  106. begin
  107. New(S, Init(32*1024,4096));
  108. OK:=F^.ReadResourceEntryToStream(resKeys,langDefault,S^);
  109. S^.Seek(0);
  110. if OK then
  111. LoadKeys(S^);
  112. Dispose(S, Done);
  113. if OK=false then
  114. ErrorBox(msg_errorloadingkeys,nil);
  115. ReadKeys:=OK;
  116. end;
  117. function WriteKeys(F: PResourceFile): boolean;
  118. var S: PMemoryStream;
  119. OK: boolean;
  120. begin
  121. New(S, Init(10*1024,4096));
  122. StoreKeys(S^);
  123. S^.Seek(0);
  124. F^.CreateResource(resKeys,rcBinary,0);
  125. OK:=F^.AddResourceEntryFromStream(resKeys,langDefault,0,S^,S^.GetSize);
  126. Dispose(S, Done);
  127. if OK=false then
  128. ErrorBox(msg_errorstoringkeys,nil);
  129. WriteKeys:=OK;
  130. end;
  131. {$endif Unix}
  132. (*function ReadClipboard(F: PResourceFile): boolean;
  133. begin
  134. ReadClipboard:=true;
  135. end;
  136. function WriteClipboard(F: PResourceFile): boolean;
  137. var S: PMemoryStream;
  138. begin
  139. if Assigned(Clipboard) then
  140. begin
  141. PushStatus('Storing clipboard content...');
  142. New(S, Init(10*1024,4096));
  143. Clipboard^.SaveToStream(S^);
  144. S^.Seek(0);
  145. F^.CreateResource(resClipboard,rcBinary,0);
  146. F^.AddResourceEntryFromStream(resClipboard,langDefault,0,S^,S^.GetSize);
  147. Dispose(S, Done);
  148. PopStatus;
  149. end;
  150. WriteClipboard:=true;
  151. end;*)
  152. function ReadWatches(F: PResourceFile): boolean;
  153. {$ifndef NODEBUG}
  154. var S: PMemoryStream;
  155. OK: boolean;
  156. OWC : PWatchesCollection;
  157. {$endif}
  158. begin
  159. {$ifndef NODEBUG}
  160. PushStatus(msg_readingwatches);
  161. New(S, Init(32*1024,4096));
  162. OK:=F^.ReadResourceEntryToStream(resWatches,langDefault,S^);
  163. S^.Seek(0);
  164. if OK then
  165. begin
  166. OWC:=WatchesCollection;
  167. WatchesCollection:=PWatchesCollection(S^.Get);
  168. OK:=(S^.Status=stOK);
  169. if OK and assigned(OWC) and assigned(WatchesCollection) then
  170. Dispose(OWC,Done)
  171. else if assigned(OWC) then
  172. WatchesCollection:=OWC;
  173. end;
  174. if OK=false then
  175. ErrorBox(msg_errorloadingwatches,nil);
  176. ReadWatches:=OK;
  177. Dispose(S, Done);
  178. PopStatus;
  179. {$else NODEBUG}
  180. ReadWatches:=true;
  181. {$endif NODEBUG}
  182. end;
  183. function WriteWatches(F: PResourceFile): boolean;
  184. var
  185. S : PMemoryStream;
  186. OK : boolean;
  187. begin
  188. {$ifndef NODEBUG}
  189. if not assigned(WatchesCollection) then
  190. {$endif NODEBUG}
  191. WriteWatches:=true
  192. {$ifndef NODEBUG}
  193. else
  194. begin
  195. PushStatus(msg_storingwatches);
  196. New(S, Init(30*1024,4096));
  197. S^.Put(WatchesCollection);
  198. S^.Seek(0);
  199. F^.CreateResource(resWatches,rcBinary,0);
  200. OK:=F^.AddResourceEntryFromStream(resWatches,langDefault,0,S^,S^.GetSize);
  201. Dispose(S, Done);
  202. if OK=false then
  203. ErrorBox(msg_errorstoringwatches,nil);
  204. PopStatus;
  205. WriteWatches:=OK;
  206. end;
  207. {$endif NODEBUG}
  208. end;
  209. function ReadBreakpoints(F: PResourceFile): boolean;
  210. {$ifndef NODEBUG}
  211. var S: PMemoryStream;
  212. OK: boolean;
  213. OBC : PBreakpointCollection;
  214. {$endif}
  215. begin
  216. {$ifndef NODEBUG}
  217. PushStatus(msg_readingbreakpoints);
  218. New(S, Init(32*1024,4096));
  219. OK:=F^.ReadResourceEntryToStream(resBreakpoints,langDefault,S^);
  220. S^.Seek(0);
  221. if OK then
  222. begin
  223. OBC:=BreakpointsCollection;
  224. BreakpointsCollection:=PBreakpointCollection(S^.get);
  225. OK:=(S^.Status=stOK);
  226. If OK and assigned(OBC) and assigned(BreakpointsCollection) then
  227. Begin
  228. Dispose(OBC,Done);
  229. BreakpointsCollection^.ShowAllBreakpoints;
  230. end
  231. else if assigned(OBC) then
  232. BreakpointsCollection:=OBC;
  233. end;
  234. if OK=false then
  235. ErrorBox(msg_errorloadingbreakpoints,nil);
  236. ReadBreakpoints:=OK;
  237. Dispose(S, Done);
  238. PopStatus;
  239. {$else NODEBUG}
  240. ReadBreakpoints:=true;
  241. {$endif NODEBUG}
  242. end;
  243. function WriteBreakpoints(F: PResourceFile): boolean;
  244. var
  245. S : PMemoryStream;
  246. OK : boolean;
  247. begin
  248. {$ifndef NODEBUG}
  249. if not assigned(BreakpointsCollection) then
  250. {$endif NODEBUG}
  251. WriteBreakPoints:=true
  252. {$ifndef NODEBUG}
  253. else
  254. begin
  255. PushStatus(msg_storingbreakpoints);
  256. New(S, Init(30*1024,4096));
  257. S^.Put(BreakpointsCollection);
  258. S^.Seek(0);
  259. F^.CreateResource(resBreakpoints,rcBinary,0);
  260. OK:=F^.AddResourceEntryFromStream(resBreakpoints,langDefault,0,S^,S^.GetSize);
  261. Dispose(S, Done);
  262. if OK=false then
  263. ErrorBox(msg_errorstoringbreakpoints,nil);
  264. WriteBreakPoints:=OK;
  265. PopStatus;
  266. end;
  267. {$endif NODEBUG}
  268. end;
  269. function ReadOpenWindows(F: PResourceFile): boolean;
  270. var S: PMemoryStream;
  271. OK: boolean;
  272. DV: word;
  273. WI: TWindowInfo;
  274. Title: string;
  275. XDataOfs: word;
  276. XData: array[0..1024] of byte;
  277. procedure GetData(var B; Size: word);
  278. begin
  279. Move(XData[XDataOfs],B,Size);
  280. Inc(XDataOfs,Size);
  281. end;
  282. procedure ProcessWindowInfo;
  283. var W: PWindow;
  284. SW: PSourceWindow absolute W;
  285. St: string;
  286. Ch: char;
  287. TP,TP2: TPoint;
  288. L: longint;
  289. R: TRect;
  290. begin
  291. XDataOfs:=0;
  292. Desktop^.Lock;
  293. W:=SearchWindow(Title);
  294. case WI.HelpCtx of
  295. hcSourceWindow :
  296. begin
  297. GetData(St[0],1);
  298. GetData(St[1],ord(St[0]));
  299. W:=ITryToOpenFile(@WI.Bounds,St,0,0,false,false,true);
  300. if Assigned(W)=false then
  301. begin
  302. ClearFormatParams;
  303. AddFormatParamStr(St);
  304. Desktop^.Unlock;
  305. ErrorBox(msg_cantopenfile,@FormatParams);
  306. Desktop^.Lock;
  307. end
  308. else
  309. begin
  310. GetData(L,sizeof(L)); SW^.Editor^.SetFlags(L);
  311. GetData(TP,sizeof(TP)); GetData(TP2,sizeof(TP2));
  312. SW^.Editor^.SetSelection(TP,TP2);
  313. GetData(TP,sizeof(TP)); SW^.Editor^.SetCurPtr(TP.X,TP.Y);
  314. GetData(TP,sizeof(TP)); SW^.Editor^.ScrollTo(TP.X,TP.Y);
  315. end;
  316. end;
  317. hcClipboardWindow:
  318. W:=ClipboardWindow;
  319. hcCalcWindow:
  320. W:=CalcWindow;
  321. hcMessagesWindow:
  322. begin
  323. if MessagesWindow=nil then
  324. Desktop^.Insert(New(PMessagesWindow, Init));
  325. W:=MessagesWindow;
  326. end;
  327. hcCompilerMessagesWindow:
  328. W:=CompilerMessageWindow;
  329. hcGDBWindow:
  330. begin
  331. InitGDBWindow;
  332. W:=GDBWindow;
  333. end;
  334. hcDisassemblyWindow:
  335. begin
  336. InitDisassemblyWindow;
  337. W:=DisassemblyWindow;
  338. end;
  339. hcWatchesWindow:
  340. begin
  341. if WatchesWindow=nil then
  342. begin
  343. New(WatchesWindow,Init);
  344. Desktop^.Insert(WatchesWindow);
  345. end;
  346. W:=WatchesWindow;
  347. end;
  348. hcStackWindow:
  349. begin
  350. if StackWindow=nil then
  351. begin
  352. New(StackWindow,Init);
  353. Desktop^.Insert(StackWindow);
  354. end;
  355. W:=StackWindow;
  356. end;
  357. hcFPURegisters:
  358. begin
  359. if FPUWindow=nil then
  360. begin
  361. New(FPUWindow,Init);
  362. Desktop^.Insert(FPUWindow);
  363. end;
  364. W:=FPUWindow;
  365. end;
  366. hcRegistersWindow:
  367. begin
  368. if RegistersWindow=nil then
  369. begin
  370. New(RegistersWindow,Init);
  371. Desktop^.Insert(RegistersWindow);
  372. end;
  373. W:=RegistersWindow;
  374. end;
  375. hcBreakpointListWindow:
  376. begin
  377. if BreakpointsWindow=nil then
  378. begin
  379. New(BreakpointsWindow,Init);
  380. Desktop^.Insert(BreakpointsWindow);
  381. end;
  382. W:=BreakpointsWindow;
  383. end;
  384. hcASCIITableWindow:
  385. begin
  386. if ASCIIChart=nil then
  387. begin
  388. New(ASCIIChart, Init);
  389. Desktop^.Insert(ASCIIChart);
  390. end;
  391. W:=ASCIIChart;
  392. if DV>=$A then
  393. begin
  394. GetData(ch,sizeof(char));
  395. AsciiChart^.Report^.AsciiChar:=ord(ch);
  396. AsciiChart^.Table^.SetCursor(
  397. ord(ch) mod AsciiChart^.Table^.Size.X,
  398. ord(ch) div AsciiChart^.Table^.Size.X);
  399. end;
  400. end;
  401. end;
  402. if W=nil then
  403. begin
  404. Desktop^.Unlock;
  405. Exit;
  406. end;
  407. W^.GetBounds(R);
  408. if (R.A.X<>WI.Bounds.A.X) or (R.A.Y<>WI.Bounds.A.Y) then
  409. R.Move(WI.Bounds.A.X-R.A.X,WI.Bounds.A.Y-R.A.Y);
  410. if (W^.Flags and wfGrow)<>0 then
  411. begin
  412. R.B.X:=R.A.X+(WI.Bounds.B.X-WI.Bounds.A.X);
  413. R.B.Y:=R.A.Y+(WI.Bounds.B.Y-WI.Bounds.A.Y);
  414. end;
  415. W^.Locate(R);
  416. if W^.GetState(sfVisible)<>WI.Visible then
  417. if WI.Visible then
  418. begin
  419. W^.Show;
  420. W^.MakeFirst;
  421. end
  422. else
  423. W^.Hide;
  424. W^.Number:=WI.WinNb;
  425. Desktop^.Unlock;
  426. end;
  427. begin
  428. PushStatus(msg_readingdesktopcontents);
  429. New(S, Init(32*1024,4096));
  430. OK:=F^.ReadResourceEntryToStream(resDesktop,langDefault,S^);
  431. S^.Seek(0);
  432. if OK then
  433. begin
  434. S^.Read(DV,SizeOf(DV));
  435. OK:=(DV=DesktopVersion) or (DV>=MinDesktopVersion);
  436. if OK=false then
  437. ErrorBox(msg_invaliddesktopversionlayoutlost,nil);
  438. end;
  439. if OK then
  440. begin
  441. XDataOfs:=0;
  442. repeat
  443. S^.Read(WI,sizeof(WI));
  444. if S^.Status=stOK then
  445. begin
  446. Title[0]:=chr(WI.TitleLen);
  447. S^.Read(Title[1],WI.TitleLen);
  448. if WI.ExtraDataSize>0 then
  449. S^.Read(XData,WI.ExtraDataSize);
  450. ProcessWindowInfo;
  451. end;
  452. until (S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  453. (* TempDesk:=PFPDesktop(S^.Get);
  454. OK:=Assigned(TempDesk);
  455. if OK then
  456. begin
  457. Dispose(Desktop, Done);
  458. Desktop:=TempDesk;
  459. with Desktop^ do
  460. begin
  461. GetSubViewPtr(S^,CompilerMessageWindow);
  462. GetSubViewPtr(S^,CompilerStatusDialog);
  463. GetSubViewPtr(S^,ClipboardWindow);
  464. if Assigned(ClipboardWindow) then Clipboard:=ClipboardWindow^.Editor;
  465. GetSubViewPtr(S^,CalcWindow);
  466. GetSubViewPtr(S^,GDBWindow);
  467. GetSubViewPtr(S^,BreakpointsWindow);
  468. GetSubViewPtr(S^,WatchesWindow);
  469. GetSubViewPtr(S^,UserScreenWindow);
  470. GetSubViewPtr(S^,ASCIIChart);
  471. GetSubViewPtr(S^,MessagesWindow); LastToolMessageFocused:=nil;
  472. end;
  473. Application^.GetExtent(R);
  474. Inc(R.A.Y);Dec(R.B.Y);
  475. DeskTop^.Locate(R);
  476. Application^.Insert(Desktop);
  477. Desktop^.ReDraw;
  478. Message(Application,evBroadcast,cmUpdate,nil);
  479. end;*)
  480. if OK=false then
  481. ErrorBox(msg_errorloadingdesktop,nil);
  482. end;
  483. Dispose(S, Done);
  484. PopStatus;
  485. ReadOpenWindows:=OK;
  486. end;
  487. function WriteOpenWindows(F: PResourceFile): boolean;
  488. var S: PMemoryStream;
  489. procedure CollectInfo(P: PView); {$ifndef FPC}far;{$endif}
  490. var W: PWindow;
  491. SW: PSourceWindow absolute W;
  492. WI: TWindowInfo;
  493. Title: string;
  494. XDataOfs: word;
  495. XData: array[0..1024] of byte;
  496. St: string;
  497. Ch: char;
  498. TP: TPoint;
  499. L: longint;
  500. procedure AddData(const B; Size: word);
  501. begin
  502. Move(B,XData[XDataOfs],Size);
  503. Inc(XDataOfs,Size);
  504. end;
  505. begin
  506. XDataOfs:=0;
  507. W:=nil;
  508. if (P^.HelpCtx=hcSourceWindow) or
  509. (P^.HelpCtx=hcHelpWindow) or
  510. (P^.HelpCtx=hcClipboardWindow) or
  511. (P^.HelpCtx=hcCalcWindow) or
  512. (P^.HelpCtx=hcInfoWindow) or
  513. (P^.HelpCtx=hcBrowserWindow) or
  514. (P^.HelpCtx=hcMessagesWindow) or
  515. (P^.HelpCtx=hcCompilerMessagesWindow) or
  516. (P^.HelpCtx=hcGDBWindow) or
  517. (P^.HelpCtx=hcDisassemblyWindow) or
  518. (P^.HelpCtx=hcStackWindow) or
  519. (P^.HelpCtx=hcRegistersWindow) or
  520. (P^.HelpCtx=hcFPURegisters) or
  521. (P^.HelpCtx=hcWatchesWindow) or
  522. (P^.HelpCtx=hcBreakpointListWindow) or
  523. (P^.HelpCtx=hcASCIITableWindow)
  524. then
  525. W:=PWindow(P);
  526. if Assigned(W) and (P^.HelpCtx=hcSourceWindow) then
  527. if SW^.Editor^.FileName='' then
  528. W:=nil;
  529. if W=nil then Exit;
  530. FillChar(WI,sizeof(WI),0);
  531. Title:=W^.GetTitle(255);
  532. WI.HelpCtx:=W^.HelpCtx;
  533. W^.GetBounds(WI.Bounds);
  534. WI.Visible:=W^.GetState(sfVisible);
  535. WI.WinNb:=W^.Number;
  536. case WI.HelpCtx of
  537. hcSourceWindow :
  538. begin
  539. St:=SW^.Editor^.FileName; AddData(St,length(St)+1);
  540. L:=SW^.Editor^.GetFlags; AddData(L,sizeof(L));
  541. TP:=SW^.Editor^.SelStart; AddData(TP,sizeof(TP));
  542. TP:=SW^.Editor^.SelEnd; AddData(TP,sizeof(TP));
  543. TP:=SW^.Editor^.CurPos; AddData(TP,sizeof(TP));
  544. TP:=SW^.Editor^.Delta; AddData(TP,sizeof(TP));
  545. end;
  546. hcAsciiTableWindow :
  547. begin
  548. ch:=chr(PFPAsciiChart(P)^.Report^.AsciiChar);
  549. AddData(ch,sizeof(char));
  550. end;
  551. end;
  552. WI.TitleLen:=length(Title);
  553. WI.ExtraDataSize:=XDataOfs;
  554. S^.Write(WI,sizeof(WI));
  555. S^.Write(Title[1],WI.TitleLen);
  556. if WI.ExtraDataSize>0 then
  557. S^.Write(XData,WI.ExtraDataSize);
  558. end;
  559. var W: word;
  560. OK: boolean;
  561. PV: PView;
  562. begin
  563. PushStatus(msg_storingdesktopcontents);
  564. New(S, Init(30*1024,4096));
  565. OK:=Assigned(S);
  566. if OK then
  567. begin
  568. W:=DesktopVersion;
  569. S^.Write(W,SizeOf(W));
  570. { S^.Put(Desktop);
  571. with Desktop^ do
  572. begin
  573. PutSubViewPtr(S^,CompilerMessageWindow);
  574. PutSubViewPtr(S^,CompilerStatusDialog);
  575. PutSubViewPtr(S^,ClipboardWindow);
  576. PutSubViewPtr(S^,CalcWindow);
  577. PutSubViewPtr(S^,GDBWindow);
  578. PutSubViewPtr(S^,BreakpointsWindow);
  579. PutSubViewPtr(S^,WatchesWindow);
  580. PutSubViewPtr(S^,UserScreenWindow);
  581. PutSubViewPtr(S^,ASCIIChart);
  582. PutSubViewPtr(S^,MessagesWindow);
  583. end;}
  584. { PV:=Application^.Last;
  585. while PV<>nil do
  586. begin
  587. CollectInfo(PV);
  588. PV:=PV^.PrevView;
  589. end;}
  590. PV:=Desktop^.Last;
  591. while PV<>nil do
  592. begin
  593. CollectInfo(PV);
  594. PV:=PV^.PrevView;
  595. end;
  596. OK:=(S^.Status=stOK);
  597. if OK then
  598. begin
  599. S^.Seek(0);
  600. OK:=F^.CreateResource(resDesktop,rcBinary,0);
  601. OK:=OK and F^.AddResourceEntryFromStream(resDesktop,langDefault,0,S^,S^.GetSize);
  602. end;
  603. Dispose(S, Done);
  604. end;
  605. if OK=false then
  606. ErrorBox(msg_errorstoringdesktop,nil);
  607. PopStatus;
  608. WriteOpenWindows:=OK;
  609. end;
  610. function WriteFlags(F: PResourceFile): boolean;
  611. var
  612. OK: boolean;
  613. begin
  614. F^.CreateResource(resDesktopFlags,rcBinary,0);
  615. OK:=F^.AddResourceEntry(resDesktopFlags,langDefault,0,DesktopFileFlags,
  616. SizeOf(DesktopFileFlags));
  617. if OK=false then
  618. ErrorBox(msg_errorwritingflags,nil);
  619. WriteFlags:=OK;
  620. end;
  621. function ReadCodeComplete(F: PResourceFile): boolean;
  622. var S: PMemoryStream;
  623. OK: boolean;
  624. begin
  625. PushStatus(msg_readingcodecompletewordlist);
  626. New(S, Init(1024,1024));
  627. OK:=F^.ReadResourceEntryToStream(resCodeComplete,langDefault,S^);
  628. S^.Seek(0);
  629. if OK then
  630. OK:=LoadCodeComplete(S^);
  631. Dispose(S, Done);
  632. if OK=false then
  633. ErrorBox(msg_errorloadingcodecompletewordlist,nil);
  634. PopStatus;
  635. ReadCodeComplete:=OK;
  636. end;
  637. function WriteCodeComplete(F: PResourceFile): boolean;
  638. var OK: boolean;
  639. S: PMemoryStream;
  640. begin
  641. PushStatus(msg_storingcodecompletewordlist);
  642. New(S, Init(1024,1024));
  643. OK:=StoreCodeComplete(S^);
  644. if OK then
  645. begin
  646. S^.Seek(0);
  647. F^.CreateResource(resCodeComplete,rcBinary,0);
  648. OK:=F^.AddResourceEntryFromStream(resCodeComplete,langDefault,0,S^,S^.GetSize);
  649. end;
  650. Dispose(S, Done);
  651. if OK=false then
  652. ErrorBox(msg_errorstoringcodecompletewordlist,nil);
  653. PopStatus;
  654. WriteCodeComplete:=OK;
  655. end;
  656. function ReadCodeTemplates(F: PResourceFile): boolean;
  657. var S: PMemoryStream;
  658. OK: boolean;
  659. begin
  660. PushStatus(msg_readingcodetemplates);
  661. New(S, Init(1024,4096));
  662. OK:=F^.ReadResourceEntryToStream(resCodeTemplates,langDefault,S^);
  663. S^.Seek(0);
  664. if OK then
  665. OK:=LoadCodeTemplates(S^);
  666. Dispose(S, Done);
  667. if OK=false then
  668. ErrorBox(msg_errorloadingcodetemplates,nil);
  669. PopStatus;
  670. ReadCodeTemplates:=OK;
  671. end;
  672. function WriteCodeTemplates(F: PResourceFile): boolean;
  673. var OK: boolean;
  674. S: PMemoryStream;
  675. begin
  676. PushStatus(msg_storingcodetemplates);
  677. New(S, Init(1024,4096));
  678. OK:=StoreCodeTemplates(S^);
  679. if OK then
  680. begin
  681. S^.Seek(0);
  682. F^.CreateResource(resCodeTemplates,rcBinary,0);
  683. OK:=F^.AddResourceEntryFromStream(resCodeTemplates,langDefault,0,S^,S^.GetSize);
  684. end;
  685. Dispose(S, Done);
  686. if OK=false then
  687. ErrorBox(msg_errorstoringcodetemplates,nil);
  688. PopStatus;
  689. WriteCodeTemplates:=OK;
  690. end;
  691. function ReadFlags(F: PResourceFile): boolean;
  692. var
  693. OK: boolean;
  694. begin
  695. OK:=F^.ReadResourceEntry(resDesktopFlags,langDefault,DesktopFileFlags,
  696. sizeof(DesktopFileFlags));
  697. if OK=false then
  698. ErrorBox(msg_errorreadingflags,nil);
  699. ReadFlags:=OK;
  700. end;
  701. function WriteVideoMode(F: PResourceFile): boolean;
  702. var
  703. OK: boolean;
  704. begin
  705. F^.CreateResource(resVideo,rcBinary,0);
  706. OK:=F^.AddResourceEntry(resVideo,langDefault,0,ScreenMode,
  707. SizeOf(TVideoMode));
  708. if OK=false then
  709. ErrorBox(msg_errorstoringvideomode,nil);
  710. WriteVideoMode:=OK;
  711. end;
  712. function ReadVideoMode(F: PResourceFile;var NewScreenMode : TVideoMode): boolean;
  713. var
  714. OK,test : boolean;
  715. begin
  716. test:=F^.ReadResourceEntry(resVideo,langDefault,NewScreenMode,
  717. sizeof(NewScreenMode));
  718. if not test then
  719. NewScreenMode:=ScreenMode;
  720. OK:=test;
  721. if OK=false then
  722. ErrorBox(msg_errorreadingvideomode,nil);
  723. ReadVideoMode:=OK;
  724. end;
  725. function ReadSymbols(F: PResourceFile): boolean;
  726. var S: PMemoryStream;
  727. OK: boolean;
  728. R: PResource;
  729. begin
  730. ReadSymbols:=false; { if no symbols stored ... no problems }
  731. R:=F^.FindResource(resSymbols);
  732. if not Assigned(R) then
  733. exit;
  734. PushStatus(msg_readingsymbolinformation);
  735. New(S, Init(32*1024,4096));
  736. OK:=F^.ReadResourceEntryToStream(resSymbols,langDefault,S^);
  737. S^.Seek(0);
  738. if OK then
  739. OK:=LoadBrowserCol(S);
  740. Dispose(S, Done);
  741. if OK=false then
  742. ErrorBox(msg_errorloadingsymbolinformation,nil);
  743. PopStatus;
  744. ReadSymbols:=OK;
  745. end;
  746. function WriteSymbols(F: PResourceFile): boolean;
  747. var S: PMemoryStream;
  748. OK: boolean;
  749. begin
  750. OK:=Assigned(Modules);
  751. if OK then
  752. begin
  753. PushStatus(msg_storingsymbolinformation);
  754. New(S, Init(200*1024,4096));
  755. OK:=Assigned(S);
  756. if OK then
  757. OK:=StoreBrowserCol(S);
  758. if OK then
  759. begin
  760. S^.Seek(0);
  761. F^.CreateResource(resSymbols,rcBinary,0);
  762. OK:=F^.AddResourceEntryFromStream(resSymbols,langDefault,0,S^,S^.GetSize);
  763. end;
  764. Dispose(S, Done);
  765. if OK=false then
  766. ErrorBox(msg_errorstoringsymbolinformation,nil);
  767. PopStatus;
  768. end;
  769. WriteSymbols:=OK;
  770. end;
  771. function LoadDesktop: boolean;
  772. var OK,VOK: boolean;
  773. F: PResourceFile;
  774. VM : TVideoMode;
  775. begin
  776. PushStatus(msg_readingdesktopfile);
  777. New(F, LoadFile(DesktopPath));
  778. OK:=false;
  779. if Assigned(F) then
  780. begin
  781. OK:=ReadFlags(F);
  782. VOK:=ReadVideoMode(F,VM);
  783. if VOK and ((VM.Col<>ScreenMode.Col) or
  784. (VM.Row<>ScreenMode.Row) or (VM.Color<>ScreenMode.Color)) then
  785. begin
  786. if Assigned(Application) then
  787. Application^.SetScreenVideoMode(VM);
  788. end;
  789. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  790. OK:=ReadHistory(F) and OK;
  791. if ((DesktopFileFlags and dfWatches)<>0) then
  792. OK:=ReadWatches(F) and OK;
  793. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  794. OK:=ReadBreakpoints(F) and OK;
  795. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  796. OK:=ReadOpenWindows(F) and OK;
  797. { no errors if no browser info available PM }
  798. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  799. OK:=ReadSymbols(F) and OK;
  800. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  801. OK:=ReadCodeComplete(F) and OK;
  802. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  803. OK:=ReadCodeTemplates(F) and OK;
  804. {$ifdef Unix}
  805. OK:=ReadKeys(F) and OK;
  806. {$endif Unix}
  807. Dispose(F, Done);
  808. end;
  809. PopStatus;
  810. LoadDesktop:=OK;
  811. end;
  812. function SaveDesktop: boolean;
  813. var OK: boolean;
  814. F: PResourceFile;
  815. TempPath: string;
  816. begin
  817. TempPath:=DirOf(DesktopPath)+DesktopTempName;
  818. PushStatus(msg_writingdesktopfile);
  819. New(F, CreateFile(TempPath));
  820. if Assigned(Clipboard) then
  821. if (DesktopFileFlags and dfClipboardContent)<>0 then
  822. Clipboard^.SetFlags(Clipboard^.GetFlags or efStoreContent)
  823. else
  824. Clipboard^.SetFlags(Clipboard^.GetFlags and not efStoreContent);
  825. OK:=false;
  826. if Assigned(F) then
  827. begin
  828. OK:=WriteFlags(F);
  829. OK:=OK and WriteVideoMode(F);
  830. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  831. OK:=OK and WriteHistory(F);
  832. if ((DesktopFileFlags and dfWatches)<>0) then
  833. OK:=OK and WriteWatches(F);
  834. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  835. OK:=OK and WriteBreakpoints(F);
  836. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  837. OK:=OK and WriteOpenWindows(F);
  838. { no errors if no browser info available PM }
  839. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  840. OK:=OK and (WriteSymbols(F) or not Assigned(Modules));
  841. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  842. OK:=OK and WriteCodeComplete(F);
  843. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  844. OK:=OK and WriteCodeTemplates(F);
  845. {$ifdef Unix}
  846. OK:=OK and WriteKeys(F);
  847. {$endif Unix}
  848. Dispose(F, Done);
  849. end;
  850. if OK then
  851. begin
  852. if ExistsFile(DesktopPath) then
  853. OK:=EraseFile(DesktopPath);
  854. OK:=OK and RenameFile(TempPath,DesktopPath);
  855. if OK=false then
  856. ErrorBox(msg_failedtoreplacedesktopfile,nil);
  857. end;
  858. PopStatus;
  859. SaveDesktop:=OK;
  860. end;
  861. function WriteSymbolsFile(const filename : string): boolean;
  862. var OK: boolean;
  863. F: PResourceFile;
  864. begin
  865. WriteSymbolsFile:=false;
  866. If not assigned(Modules) then
  867. exit;
  868. New(F, CreateFile(FileName));
  869. OK:=Assigned(F);
  870. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  871. OK:=OK and WriteSymbols(F);
  872. if assigned(F) then
  873. Dispose(F,Done);
  874. WriteSymbolsFile:=OK;
  875. end;
  876. function ReadSymbolsFile(const FileName : string): boolean;
  877. var OK: boolean;
  878. F: PResourceFile;
  879. begin
  880. ReadSymbolsFile:=false;
  881. { Don't read again !! }
  882. If assigned(Modules) then
  883. exit;
  884. New(F, LoadFile(FileName));
  885. OK:=Assigned(F);
  886. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  887. OK:=OK and ReadSymbols(F);
  888. if assigned(F) then
  889. Dispose(F,Done);
  890. ReadSymbolsFile:=OK;
  891. end;
  892. END.
  893. {
  894. $Log$
  895. Revision 1.10 2004-11-08 20:28:26 peter
  896. * Breakpoints are now deleted when removed from source, disabling is
  897. still possible from the breakpoint list
  898. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  899. FV and 1.9.x compilers
  900. * Run directory added to Run menu
  901. * Useless programinfo window removed
  902. Revision 1.9 2004/11/05 16:39:37 peter
  903. * uninitialized var
  904. Revision 1.8 2004/11/02 23:53:19 peter
  905. * fixed crashes with ide and 1.9.x
  906. Revision 1.7 2002/02/09 00:32:27 pierre
  907. * fix error when loading breakpoints, try to load other items even after an error
  908. Revision 1.6 2002/09/07 15:40:42 peter
  909. * old logs removed and tabs fixed
  910. Revision 1.5 2002/09/04 14:03:52 pierre
  911. * MinDesktopVersion increased because of CodeComplete changes
  912. Revision 1.4 2002/05/31 12:37:09 pierre
  913. + register asciitable char
  914. }