fpdesk.pas 28 KB

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