fpdesk.pas 28 KB

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