fpdesk.pas 28 KB

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