fpdesk.pas 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. Move(XData[XDataOfs],B,Size);
  344. Inc(XDataOfs,Size);
  345. end;
  346. procedure ProcessWindowInfo;
  347. var W: PWindow;
  348. SW: PSourceWindow absolute W;
  349. St: string;
  350. Ch: char;
  351. TP,TP2: TPoint;
  352. L: longint;
  353. R: TRect;
  354. ZZ: byte;
  355. Z: TRect;
  356. begin
  357. XDataOfs:=0;
  358. Desktop^.Lock;
  359. W:=SearchWindow(Title);
  360. case WI.HelpCtx of
  361. hcSourceWindow :
  362. begin
  363. GetData(St[0],1);
  364. GetData(St[1],ord(St[0]));
  365. W:=ITryToOpenFile(@WI.Bounds,St,0,0,false,false,true);
  366. if Assigned(W)=false then
  367. begin
  368. ClearFormatParams;
  369. AddFormatParamStr(St);
  370. Desktop^.Unlock;
  371. ErrorBox(msg_cantopenfile,@FormatParams);
  372. Desktop^.Lock;
  373. end
  374. else
  375. begin
  376. GetData(L,sizeof(L));
  377. If DeskUseSyntaxHighlight(SW^.Editor) Then
  378. L:=L or efSyntaxHighlight
  379. else
  380. L:=L and not efSyntaxHighlight;
  381. SW^.Editor^.SetFlags(L);
  382. GetData(TP,sizeof(TP)); GetData(TP2,sizeof(TP2));
  383. SW^.Editor^.SetSelection(TP,TP2);
  384. GetData(TP,sizeof(TP)); SW^.Editor^.SetCurPtr(TP.X,TP.Y);
  385. GetData(TP,sizeof(TP)); SW^.Editor^.ScrollTo(TP.X,TP.Y);
  386. end;
  387. end;
  388. hcClipboardWindow:
  389. W:=ClipboardWindow;
  390. hcCalcWindow:
  391. W:=CalcWindow;
  392. hcMessagesWindow:
  393. begin
  394. if MessagesWindow=nil then
  395. Desktop^.Insert(New(PMessagesWindow, Init));
  396. W:=MessagesWindow;
  397. end;
  398. hcCompilerMessagesWindow:
  399. W:=CompilerMessageWindow;
  400. {$ifndef NODEBUG}
  401. hcGDBWindow:
  402. begin
  403. InitGDBWindow;
  404. W:=GDBWindow;
  405. end;
  406. hcDisassemblyWindow:
  407. begin
  408. InitDisassemblyWindow;
  409. W:=DisassemblyWindow;
  410. end;
  411. hcWatchesWindow:
  412. begin
  413. if WatchesWindow=nil then
  414. begin
  415. New(WatchesWindow,Init);
  416. Desktop^.Insert(WatchesWindow);
  417. end;
  418. W:=WatchesWindow;
  419. end;
  420. hcStackWindow:
  421. begin
  422. if StackWindow=nil then
  423. begin
  424. New(StackWindow,Init);
  425. Desktop^.Insert(StackWindow);
  426. end;
  427. W:=StackWindow;
  428. end;
  429. hcFPURegisters:
  430. begin
  431. if FPUWindow=nil then
  432. begin
  433. New(FPUWindow,Init);
  434. Desktop^.Insert(FPUWindow);
  435. end;
  436. W:=FPUWindow;
  437. end;
  438. hcVectorRegisters:
  439. begin
  440. if VectorWindow=nil then
  441. begin
  442. New(VectorWindow,Init);
  443. Desktop^.Insert(VectorWindow);
  444. end;
  445. W:=VectorWindow;
  446. end;
  447. hcRegistersWindow:
  448. begin
  449. if RegistersWindow=nil then
  450. begin
  451. New(RegistersWindow,Init);
  452. Desktop^.Insert(RegistersWindow);
  453. end;
  454. W:=RegistersWindow;
  455. end;
  456. hcBreakpointListWindow:
  457. begin
  458. if BreakpointsWindow=nil then
  459. begin
  460. New(BreakpointsWindow,Init);
  461. Desktop^.Insert(BreakpointsWindow);
  462. end;
  463. W:=BreakpointsWindow;
  464. end;
  465. {$endif NODEBUG}
  466. hcASCIITableWindow:
  467. begin
  468. if ASCIIChart=nil then
  469. begin
  470. New(ASCIIChart, Init);
  471. Desktop^.Insert(ASCIIChart);
  472. end;
  473. W:=ASCIIChart;
  474. if DV>=$A then
  475. begin
  476. GetData(ch,sizeof(char));
  477. AsciiChart^.Report^.AsciiChar:=ord(ch);
  478. AsciiChart^.Table^.SetCursor(
  479. ord(ch) mod AsciiChart^.Table^.Size.X,
  480. ord(ch) div AsciiChart^.Table^.Size.X);
  481. end;
  482. end;
  483. end;
  484. if W=nil then
  485. begin
  486. Desktop^.Unlock;
  487. Exit;
  488. end;
  489. W^.GetBounds(R);
  490. if (R.A.X<>WI.Bounds.A.X) or (R.A.Y<>WI.Bounds.A.Y) then
  491. R.Move(WI.Bounds.A.X-R.A.X,WI.Bounds.A.Y-R.A.Y);
  492. if (W^.Flags and wfGrow)<>0 then
  493. begin
  494. R.B.X:=R.A.X+(WI.Bounds.B.X-WI.Bounds.A.X);
  495. R.B.Y:=R.A.Y+(WI.Bounds.B.Y-WI.Bounds.A.Y);
  496. end;
  497. W^.Locate(R);
  498. if W^.GetState(sfVisible)<>WI.Visible then
  499. if WI.Visible then
  500. begin
  501. W^.Show;
  502. W^.MakeFirst;
  503. end
  504. else
  505. W^.Hide;
  506. ZZ:=0;
  507. Desktop^.GetExtent(Z);
  508. if R.A.Y>Z.B.Y-7 then
  509. begin
  510. R.A.Y:=Z.B.Y-7;
  511. ZZ:=1;
  512. end;
  513. if R.A.X>Z.B.X-4 then
  514. begin
  515. R.A.X:=Z.B.X-4;
  516. ZZ:=1;
  517. end;
  518. if R.A.Y<0 then
  519. begin
  520. R.A.Y:=0;
  521. ZZ:=1;
  522. end;
  523. if R.A.X<0 then
  524. begin
  525. R.A.X:=0;
  526. ZZ:=1;
  527. end;
  528. if ZZ<>0 then W^.MoveTo(R.A.X,R.A.Y);
  529. W^.Number:=WI.WinNb;
  530. Desktop^.Unlock;
  531. end;
  532. begin
  533. PushStatus(msg_readingdesktopcontents);
  534. New(S, Init(32*1024,4096));
  535. OK:=F^.ReadResourceEntryToStream(resDesktop,langDefault,S^);
  536. S^.Seek(0);
  537. if OK then
  538. begin
  539. S^.Read(DV,SizeOf(DV));
  540. OK:=(DV=DesktopVersion) or (DV>=MinDesktopVersion);
  541. if OK=false then
  542. ErrorBox(msg_invaliddesktopversionlayoutlost,nil);
  543. end;
  544. if OK then
  545. begin
  546. XDataOfs:=0;
  547. repeat
  548. S^.Read(WI,sizeof(WI));
  549. if S^.Status=stOK then
  550. begin
  551. Title[0]:=chr(WI.TitleLen);
  552. S^.Read(Title[1],WI.TitleLen);
  553. if WI.ExtraDataSize>0 then
  554. S^.Read(XData,WI.ExtraDataSize);
  555. ProcessWindowInfo;
  556. end;
  557. until (S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  558. (* TempDesk:=PFPDesktop(S^.Get);
  559. OK:=Assigned(TempDesk);
  560. if OK then
  561. begin
  562. Dispose(Desktop, Done);
  563. Desktop:=TempDesk;
  564. with Desktop^ do
  565. begin
  566. GetSubViewPtr(S^,CompilerMessageWindow);
  567. GetSubViewPtr(S^,CompilerStatusDialog);
  568. GetSubViewPtr(S^,ClipboardWindow);
  569. if Assigned(ClipboardWindow) then Clipboard:=ClipboardWindow^.Editor;
  570. GetSubViewPtr(S^,CalcWindow);
  571. GetSubViewPtr(S^,GDBWindow);
  572. GetSubViewPtr(S^,BreakpointsWindow);
  573. GetSubViewPtr(S^,WatchesWindow);
  574. GetSubViewPtr(S^,UserScreenWindow);
  575. GetSubViewPtr(S^,ASCIIChart);
  576. GetSubViewPtr(S^,MessagesWindow); LastToolMessageFocused:=nil;
  577. end;
  578. Application^.GetExtent(R);
  579. Inc(R.A.Y);Dec(R.B.Y);
  580. DeskTop^.Locate(R);
  581. Application^.Insert(Desktop);
  582. Desktop^.ReDraw;
  583. Message(Application,evBroadcast,cmUpdate,nil);
  584. end;*)
  585. if OK=false then
  586. ErrorBox(msg_errorloadingdesktop,nil);
  587. end;
  588. Dispose(S, Done);
  589. PopStatus;
  590. ReadOpenWindows:=OK;
  591. end;
  592. function WriteOpenWindows(F: PResourceFile): boolean;
  593. var S: PMemoryStream;
  594. procedure CollectInfo(P: PView);
  595. var W: PWindow;
  596. SW: PSourceWindow absolute W;
  597. WI: TWindowInfo;
  598. Title: string;
  599. XDataOfs: word;
  600. XData: array[0..1024] of byte;
  601. St: string;
  602. Ch: char;
  603. TP: TPoint;
  604. L: longint;
  605. procedure AddData(const B; Size: word);
  606. begin
  607. Move(B,XData[XDataOfs],Size);
  608. Inc(XDataOfs,Size);
  609. end;
  610. begin
  611. XDataOfs:=0;
  612. W:=nil;
  613. if (P^.HelpCtx=hcSourceWindow) or
  614. (P^.HelpCtx=hcHelpWindow) or
  615. (P^.HelpCtx=hcClipboardWindow) or
  616. (P^.HelpCtx=hcCalcWindow) or
  617. (P^.HelpCtx=hcInfoWindow) or
  618. (P^.HelpCtx=hcBrowserWindow) or
  619. (P^.HelpCtx=hcMessagesWindow) or
  620. (P^.HelpCtx=hcCompilerMessagesWindow) or
  621. (P^.HelpCtx=hcGDBWindow) or
  622. (P^.HelpCtx=hcDisassemblyWindow) or
  623. (P^.HelpCtx=hcStackWindow) or
  624. (P^.HelpCtx=hcRegistersWindow) or
  625. (P^.HelpCtx=hcFPURegisters) or
  626. (P^.HelpCtx=hcVectorRegisters) or
  627. (P^.HelpCtx=hcWatchesWindow) or
  628. (P^.HelpCtx=hcBreakpointListWindow) or
  629. (P^.HelpCtx=hcASCIITableWindow)
  630. then
  631. W:=PWindow(P);
  632. if Assigned(W) and (P^.HelpCtx=hcSourceWindow) then
  633. if SW^.Editor^.FileName='' then
  634. W:=nil;
  635. if W=nil then Exit;
  636. FillChar(WI,sizeof(WI),0);
  637. Title:=W^.GetTitle(255);
  638. WI.HelpCtx:=W^.HelpCtx;
  639. W^.GetBounds(WI.Bounds);
  640. WI.Visible:=W^.GetState(sfVisible);
  641. WI.WinNb:=W^.Number;
  642. case WI.HelpCtx of
  643. hcSourceWindow :
  644. begin
  645. St:=SW^.Editor^.FileName; AddData(St,length(St)+1);
  646. L:=SW^.Editor^.GetFlags; AddData(L,sizeof(L));
  647. TP:=SW^.Editor^.SelStart; AddData(TP,sizeof(TP));
  648. TP:=SW^.Editor^.SelEnd; AddData(TP,sizeof(TP));
  649. TP:=SW^.Editor^.CurPos; AddData(TP,sizeof(TP));
  650. TP:=SW^.Editor^.Delta; AddData(TP,sizeof(TP));
  651. end;
  652. hcAsciiTableWindow :
  653. begin
  654. ch:=chr(PFPAsciiChart(P)^.Report^.AsciiChar);
  655. AddData(ch,sizeof(char));
  656. end;
  657. end;
  658. WI.TitleLen:=length(Title);
  659. WI.ExtraDataSize:=XDataOfs;
  660. S^.Write(WI,sizeof(WI));
  661. S^.Write(Title[1],WI.TitleLen);
  662. if WI.ExtraDataSize>0 then
  663. S^.Write(XData,WI.ExtraDataSize);
  664. end;
  665. var W: word;
  666. OK: boolean;
  667. PV: PView;
  668. begin
  669. PushStatus(msg_storingdesktopcontents);
  670. New(S, Init(30*1024,4096));
  671. OK:=Assigned(S);
  672. if OK then
  673. begin
  674. W:=DesktopVersion;
  675. S^.Write(W,SizeOf(W));
  676. { S^.Put(Desktop);
  677. with Desktop^ do
  678. begin
  679. PutSubViewPtr(S^,CompilerMessageWindow);
  680. PutSubViewPtr(S^,CompilerStatusDialog);
  681. PutSubViewPtr(S^,ClipboardWindow);
  682. PutSubViewPtr(S^,CalcWindow);
  683. PutSubViewPtr(S^,GDBWindow);
  684. PutSubViewPtr(S^,BreakpointsWindow);
  685. PutSubViewPtr(S^,WatchesWindow);
  686. PutSubViewPtr(S^,UserScreenWindow);
  687. PutSubViewPtr(S^,ASCIIChart);
  688. PutSubViewPtr(S^,MessagesWindow);
  689. end;}
  690. { PV:=Application^.Last;
  691. while PV<>nil do
  692. begin
  693. CollectInfo(PV);
  694. PV:=PV^.PrevView;
  695. end;}
  696. PV:=Desktop^.Last;
  697. while PV<>nil do
  698. begin
  699. CollectInfo(PV);
  700. PV:=PV^.PrevView;
  701. end;
  702. OK:=(S^.Status=stOK);
  703. if OK then
  704. begin
  705. S^.Seek(0);
  706. OK:=F^.CreateResource(resDesktop,rcBinary,0);
  707. OK:=OK and F^.AddResourceEntryFromStream(resDesktop,langDefault,0,S^,S^.GetSize);
  708. end;
  709. Dispose(S, Done);
  710. end;
  711. if OK=false then
  712. ErrorBox(msg_errorstoringdesktop,nil);
  713. PopStatus;
  714. WriteOpenWindows:=OK;
  715. end;
  716. function WriteFlags(F: PResourceFile): boolean;
  717. var
  718. OK: boolean;
  719. begin
  720. F^.CreateResource(resDesktopFlags,rcBinary,0);
  721. OK:=F^.AddResourceEntry(resDesktopFlags,langDefault,0,DesktopFileFlags,
  722. SizeOf(DesktopFileFlags));
  723. if OK=false then
  724. ErrorBox(msg_errorwritingflags,nil);
  725. WriteFlags:=OK;
  726. end;
  727. function ReadCodeComplete(F: PResourceFile): boolean;
  728. var S: PMemoryStream;
  729. OK: boolean;
  730. begin
  731. PushStatus(msg_readingcodecompletewordlist);
  732. New(S, Init(1024,1024));
  733. OK:=F^.ReadResourceEntryToStream(resCodeComplete,langDefault,S^);
  734. S^.Seek(0);
  735. if OK then
  736. OK:=LoadCodeComplete(S^);
  737. Dispose(S, Done);
  738. if OK=false then
  739. ErrorBox(msg_errorloadingcodecompletewordlist,nil);
  740. PopStatus;
  741. ReadCodeComplete:=OK;
  742. end;
  743. function WriteCodeComplete(F: PResourceFile): boolean;
  744. var OK: boolean;
  745. S: PMemoryStream;
  746. begin
  747. PushStatus(msg_storingcodecompletewordlist);
  748. New(S, Init(1024,1024));
  749. OK:=StoreCodeComplete(S^);
  750. if OK then
  751. begin
  752. S^.Seek(0);
  753. F^.CreateResource(resCodeComplete,rcBinary,0);
  754. OK:=F^.AddResourceEntryFromStream(resCodeComplete,langDefault,0,S^,S^.GetSize);
  755. end;
  756. Dispose(S, Done);
  757. if OK=false then
  758. ErrorBox(msg_errorstoringcodecompletewordlist,nil);
  759. PopStatus;
  760. WriteCodeComplete:=OK;
  761. end;
  762. function ReadCodeTemplates(F: PResourceFile): boolean;
  763. var S: PMemoryStream;
  764. OK: boolean;
  765. begin
  766. PushStatus(msg_readingcodetemplates);
  767. New(S, Init(1024,4096));
  768. OK:=F^.ReadResourceEntryToStream(resCodeTemplates,langDefault,S^);
  769. S^.Seek(0);
  770. if OK then
  771. OK:=LoadCodeTemplates(S^);
  772. Dispose(S, Done);
  773. if OK=false then
  774. ErrorBox(msg_errorloadingcodetemplates,nil);
  775. PopStatus;
  776. ReadCodeTemplates:=OK;
  777. end;
  778. function WriteCodeTemplates(F: PResourceFile): boolean;
  779. var OK: boolean;
  780. S: PMemoryStream;
  781. begin
  782. PushStatus(msg_storingcodetemplates);
  783. New(S, Init(1024,4096));
  784. OK:=StoreCodeTemplates(S^);
  785. if OK then
  786. begin
  787. S^.Seek(0);
  788. F^.CreateResource(resCodeTemplates,rcBinary,0);
  789. OK:=F^.AddResourceEntryFromStream(resCodeTemplates,langDefault,0,S^,S^.GetSize);
  790. end;
  791. Dispose(S, Done);
  792. if OK=false then
  793. ErrorBox(msg_errorstoringcodetemplates,nil);
  794. PopStatus;
  795. WriteCodeTemplates:=OK;
  796. end;
  797. function ReadFlags(F: PResourceFile): boolean;
  798. var
  799. OK: boolean;
  800. begin
  801. OK:=F^.ReadResourceEntry(resDesktopFlags,langDefault,DesktopFileFlags,
  802. sizeof(DesktopFileFlags));
  803. if OK=false then
  804. ErrorBox(msg_errorreadingflags,nil);
  805. ReadFlags:=OK;
  806. end;
  807. function WriteVideoMode(F: PResourceFile): boolean;
  808. var
  809. OK: boolean;
  810. begin
  811. F^.CreateResource(resVideo,rcBinary,0);
  812. OK:=F^.AddResourceEntry(resVideo,langDefault,0,ScreenMode,
  813. SizeOf(TVideoMode));
  814. if OK=false then
  815. ErrorBox(msg_errorstoringvideomode,nil);
  816. WriteVideoMode:=OK;
  817. end;
  818. function ReadVideoMode(F: PResourceFile;var NewScreenMode : TVideoMode): boolean;
  819. var
  820. OK,test : boolean;
  821. begin
  822. test:=F^.ReadResourceEntry(resVideo,langDefault,NewScreenMode,
  823. sizeof(NewScreenMode));
  824. if not test then
  825. NewScreenMode:=ScreenMode;
  826. OK:=test;
  827. if OK=false then
  828. ErrorBox(msg_errorreadingvideomode,nil);
  829. ReadVideoMode:=OK;
  830. end;
  831. function ReadSymbols(F: PResourceFile): boolean;
  832. var S: PMemoryStream;
  833. OK: boolean;
  834. R: PResource;
  835. begin
  836. ReadSymbols:=false; { if no symbols stored ... no problems }
  837. R:=F^.FindResource(resSymbols);
  838. if not Assigned(R) then
  839. exit;
  840. PushStatus(msg_readingsymbolinformation);
  841. New(S, Init(32*1024,4096));
  842. OK:=F^.ReadResourceEntryToStream(resSymbols,langDefault,S^);
  843. S^.Seek(0);
  844. if OK then
  845. OK:=LoadBrowserCol(S);
  846. Dispose(S, Done);
  847. if OK=false then
  848. ErrorBox(msg_errorloadingsymbolinformation,nil);
  849. PopStatus;
  850. ReadSymbols:=OK;
  851. end;
  852. function WriteSymbols(F: PResourceFile): boolean;
  853. var S: PMemoryStream;
  854. OK: boolean;
  855. begin
  856. OK:=Assigned(Modules);
  857. if OK then
  858. begin
  859. PushStatus(msg_storingsymbolinformation);
  860. New(S, Init(200*1024,4096));
  861. OK:=Assigned(S);
  862. if OK then
  863. OK:=StoreBrowserCol(S);
  864. if OK then
  865. begin
  866. S^.Seek(0);
  867. F^.CreateResource(resSymbols,rcBinary,0);
  868. OK:=F^.AddResourceEntryFromStream(resSymbols,langDefault,0,S^,S^.GetSize);
  869. end;
  870. Dispose(S, Done);
  871. if OK=false then
  872. ErrorBox(msg_errorstoringsymbolinformation,nil);
  873. PopStatus;
  874. end;
  875. WriteSymbols:=OK;
  876. end;
  877. function LoadDesktop: boolean;
  878. var OK,VOK: boolean;
  879. F: PResourceFile;
  880. VM : TVideoMode;
  881. begin
  882. PushStatus(msg_readingdesktopfile);
  883. New(F, LoadFile(DesktopPath));
  884. OK:=false;
  885. if Assigned(F) then
  886. begin
  887. OK:=ReadFlags(F);
  888. VOK:=ReadVideoMode(F,VM);
  889. if VOK and ((VM.Col<>ScreenMode.Col) or
  890. (VM.Row<>ScreenMode.Row) or (VM.Color<>ScreenMode.Color)) then
  891. begin
  892. if Assigned(Application) then
  893. Application^.SetScreenVideoMode(VM);
  894. end;
  895. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  896. OK:=ReadHistory(F) and OK;
  897. if ((DesktopFileFlags and dfWatches)<>0) then
  898. OK:=ReadWatches(F) and OK;
  899. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  900. OK:=ReadBreakpoints(F) and OK;
  901. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  902. OK:=ReadOpenWindows(F) and OK;
  903. { no errors if no browser info available PM }
  904. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  905. OK:=ReadSymbols(F) and OK;
  906. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  907. OK:=ReadCodeComplete(F) and OK;
  908. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  909. OK:=ReadCodeTemplates(F) and OK;
  910. {$ifdef Unix}
  911. OK:=ReadKeys(F) and OK;
  912. {$endif Unix}
  913. Dispose(F, Done);
  914. end;
  915. PopStatus;
  916. LoadDesktop:=OK;
  917. end;
  918. function SaveDesktop: boolean;
  919. var OK: boolean;
  920. F: PResourceFile;
  921. TempPath: string;
  922. begin
  923. TempPath:=DirOf(DesktopPath)+DesktopTempName;
  924. PushStatus(msg_writingdesktopfile);
  925. New(F, CreateFile(TempPath));
  926. if Assigned(Clipboard) then
  927. if (DesktopFileFlags and dfClipboardContent)<>0 then
  928. Clipboard^.SetFlags(Clipboard^.GetFlags or efStoreContent)
  929. else
  930. Clipboard^.SetFlags(Clipboard^.GetFlags and not efStoreContent);
  931. OK:=false;
  932. if Assigned(F) then
  933. begin
  934. OK:=WriteFlags(F);
  935. OK:=OK and WriteVideoMode(F);
  936. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  937. OK:=OK and WriteHistory(F);
  938. if ((DesktopFileFlags and dfWatches)<>0) then
  939. OK:=OK and WriteWatches(F);
  940. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  941. OK:=OK and WriteBreakpoints(F);
  942. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  943. OK:=OK and WriteOpenWindows(F);
  944. { no errors if no browser info available PM }
  945. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  946. OK:=OK and (WriteSymbols(F) or not Assigned(Modules));
  947. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  948. OK:=OK and WriteCodeComplete(F);
  949. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  950. OK:=OK and WriteCodeTemplates(F);
  951. {$ifdef Unix}
  952. OK:=OK and WriteKeys(F);
  953. {$endif Unix}
  954. Dispose(F, Done);
  955. end;
  956. if OK then
  957. begin
  958. if ExistsFile(DesktopPath) then
  959. OK:=EraseFile(DesktopPath);
  960. OK:=OK and RenameFile(TempPath,DesktopPath);
  961. if OK=false then
  962. ErrorBox(msg_failedtoreplacedesktopfile,nil);
  963. end;
  964. PopStatus;
  965. SaveDesktop:=OK;
  966. end;
  967. function WriteSymbolsFile(const filename : string): boolean;
  968. var OK: boolean;
  969. F: PResourceFile;
  970. begin
  971. WriteSymbolsFile:=false;
  972. If not assigned(Modules) then
  973. exit;
  974. New(F, CreateFile(FileName));
  975. OK:=Assigned(F);
  976. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  977. OK:=OK and WriteSymbols(F);
  978. if assigned(F) then
  979. Dispose(F,Done);
  980. WriteSymbolsFile:=OK;
  981. end;
  982. function ReadSymbolsFile(const FileName : string): boolean;
  983. var OK: boolean;
  984. F: PResourceFile;
  985. begin
  986. ReadSymbolsFile:=false;
  987. { Don't read again !! }
  988. If assigned(Modules) then
  989. exit;
  990. New(F, LoadFile(FileName));
  991. OK:=Assigned(F);
  992. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  993. OK:=OK and ReadSymbols(F);
  994. if assigned(F) then
  995. Dispose(F,Done);
  996. ReadSymbolsFile:=OK;
  997. end;
  998. END.