fpdesk.pas 25 KB

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