2
0

fpdesk.pas 29 KB

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