fpdesk.pas 26 KB

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