fpdesk.pas 25 KB

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