fpdesk.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Desktop loading/saving routines
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit FPDesk;
  13. interface
  14. const
  15. MinDesktopVersion = $0009;
  16. DesktopVersion = $000A; { <- if you change any Load&Store methods,
  17. default object properties (Options,State)
  18. then you should also change this }
  19. ResDesktopFlags = 'FLAGS';
  20. ResVideo = 'VIDEOMODE';
  21. ResHistory = 'HISTORY';
  22. ResClipboard = 'CLIPBOARD';
  23. ResWatches = 'WATCHES';
  24. ResBreakpoints = 'BREAKPOINTS';
  25. ResDesktop = 'DESKTOP';
  26. ResSymbols = 'SYMBOLS';
  27. ResCodeComplete = 'CODECOMPLETE';
  28. ResCodeTemplates = 'CODETEMPLATES';
  29. ResKeys = 'KEYS';
  30. procedure InitDesktopFile;
  31. function LoadDesktop: boolean;
  32. function SaveDesktop: boolean;
  33. procedure DoneDesktopFile;
  34. function WriteSymbolsFile(const filename : string): boolean;
  35. function ReadSymbolsFile(const filename : string): boolean;
  36. implementation
  37. uses Dos,
  38. Objects,Drivers,
  39. {$ifndef FVISION}
  40. Video,
  41. {$else FVISION}
  42. {$ifndef GRAPH_API}
  43. Video,
  44. {$endif GRAPH_API}
  45. {$endif FVISION}
  46. Views,App,HistList,BrowCol,
  47. WUtils,WResourc,WViews,WEditor,
  48. {$ifndef NODEBUG}
  49. fpdebug,
  50. {$endif ndef NODEBUG}
  51. {$ifdef Unix}
  52. FPKeys,
  53. {$endif Unix}
  54. FPConst,FPVars,FPString,FPTools,FPUtils,FPViews,FPHelp,
  55. FPCompil,FPCodCmp,FPCodTmp;
  56. type
  57. TWindowInfo = packed record
  58. HelpCtx : word;
  59. Bounds : TRect;
  60. Visible : boolean;
  61. WinNb : byte;
  62. ExtraDataSize : word;
  63. TitleLen : word;
  64. Title : packed record end;
  65. end;
  66. procedure InitDesktopFile;
  67. begin
  68. if DesktopLocation=dlCurrentDir then
  69. DesktopPath:=FExpand(DesktopName)
  70. else
  71. DesktopPath:=FExpand(DirOf(IniFileName)+DesktopName);
  72. end;
  73. procedure DoneDesktopFile;
  74. begin
  75. end;
  76. function ReadHistory(F: PResourceFile): boolean;
  77. var S: PMemoryStream;
  78. OK: boolean;
  79. begin
  80. PushStatus(msg_readinghistory);
  81. New(S, Init(32*1024,4096));
  82. OK:=F^.ReadResourceEntryToStream(resHistory,langDefault,S^);
  83. S^.Seek(0);
  84. if OK then
  85. LoadHistory(S^);
  86. Dispose(S, Done);
  87. if OK=false then
  88. ErrorBox(msg_errorloadinghistory,nil);
  89. PopStatus;
  90. ReadHistory:=OK;
  91. end;
  92. function WriteHistory(F: PResourceFile): boolean;
  93. var S: PMemoryStream;
  94. OK: boolean;
  95. begin
  96. PushStatus(msg_storinghistory);
  97. New(S, Init(10*1024,4096));
  98. StoreHistory(S^);
  99. S^.Seek(0);
  100. F^.CreateResource(resHistory,rcBinary,0);
  101. OK:=F^.AddResourceEntryFromStream(resHistory,langDefault,0,S^,S^.GetSize);
  102. Dispose(S, Done);
  103. if OK=false then
  104. ErrorBox(msg_errorstoringhistory,nil);
  105. PopStatus;
  106. WriteHistory:=OK;
  107. end;
  108. {$ifdef Unix}
  109. function ReadKeys(F: PResourceFile): boolean;
  110. var S: PMemoryStream;
  111. OK: boolean;
  112. begin
  113. New(S, Init(32*1024,4096));
  114. OK:=F^.ReadResourceEntryToStream(resKeys,langDefault,S^);
  115. S^.Seek(0);
  116. if OK then
  117. LoadKeys(S^);
  118. Dispose(S, Done);
  119. if OK=false then
  120. ErrorBox(msg_errorloadingkeys,nil);
  121. ReadKeys:=OK;
  122. end;
  123. function WriteKeys(F: PResourceFile): boolean;
  124. var S: PMemoryStream;
  125. OK: boolean;
  126. begin
  127. New(S, Init(10*1024,4096));
  128. StoreKeys(S^);
  129. S^.Seek(0);
  130. F^.CreateResource(resKeys,rcBinary,0);
  131. OK:=F^.AddResourceEntryFromStream(resKeys,langDefault,0,S^,S^.GetSize);
  132. Dispose(S, Done);
  133. if OK=false then
  134. ErrorBox(msg_errorstoringkeys,nil);
  135. WriteKeys:=OK;
  136. end;
  137. {$endif Unix}
  138. (*function ReadClipboard(F: PResourceFile): boolean;
  139. begin
  140. ReadClipboard:=true;
  141. end;
  142. function WriteClipboard(F: PResourceFile): boolean;
  143. var S: PMemoryStream;
  144. begin
  145. if Assigned(Clipboard) then
  146. begin
  147. PushStatus('Storing clipboard content...');
  148. New(S, Init(10*1024,4096));
  149. Clipboard^.SaveToStream(S^);
  150. S^.Seek(0);
  151. F^.CreateResource(resClipboard,rcBinary,0);
  152. F^.AddResourceEntryFromStream(resClipboard,langDefault,0,S^,S^.GetSize);
  153. Dispose(S, Done);
  154. PopStatus;
  155. end;
  156. WriteClipboard:=true;
  157. end;*)
  158. function ReadWatches(F: PResourceFile): boolean;
  159. {$ifndef NODEBUG}
  160. var S: PMemoryStream;
  161. OK: boolean;
  162. OWC : PWatchesCollection;
  163. {$endif}
  164. begin
  165. {$ifndef NODEBUG}
  166. PushStatus(msg_readingwatches);
  167. New(S, Init(32*1024,4096));
  168. OK:=F^.ReadResourceEntryToStream(resWatches,langDefault,S^);
  169. S^.Seek(0);
  170. if OK then
  171. begin
  172. OWC:=WatchesCollection;
  173. WatchesCollection:=PWatchesCollection(S^.Get);
  174. OK:=(S^.Status=stOK);
  175. if OK and assigned(OWC) and assigned(WatchesCollection) then
  176. Dispose(OWC,Done)
  177. else if assigned(OWC) then
  178. WatchesCollection:=OWC;
  179. end;
  180. if OK=false then
  181. ErrorBox(msg_errorloadingwatches,nil);
  182. ReadWatches:=OK;
  183. Dispose(S, Done);
  184. PopStatus;
  185. {$else NODEBUG}
  186. ReadWatches:=true;
  187. {$endif NODEBUG}
  188. end;
  189. function WriteWatches(F: PResourceFile): boolean;
  190. var
  191. S : PMemoryStream;
  192. OK : boolean;
  193. begin
  194. {$ifndef NODEBUG}
  195. if not assigned(WatchesCollection) then
  196. {$endif NODEBUG}
  197. WriteWatches:=true
  198. {$ifndef NODEBUG}
  199. else
  200. begin
  201. PushStatus(msg_storingwatches);
  202. New(S, Init(30*1024,4096));
  203. S^.Put(WatchesCollection);
  204. S^.Seek(0);
  205. F^.CreateResource(resWatches,rcBinary,0);
  206. OK:=F^.AddResourceEntryFromStream(resWatches,langDefault,0,S^,S^.GetSize);
  207. Dispose(S, Done);
  208. if OK=false then
  209. ErrorBox(msg_errorstoringwatches,nil);
  210. PopStatus;
  211. WriteWatches:=OK;
  212. end;
  213. {$endif NODEBUG}
  214. end;
  215. function ReadBreakpoints(F: PResourceFile): boolean;
  216. {$ifndef NODEBUG}
  217. var S: PMemoryStream;
  218. OK: boolean;
  219. OBC : PBreakpointCollection;
  220. {$endif}
  221. begin
  222. {$ifndef NODEBUG}
  223. PushStatus(msg_readingbreakpoints);
  224. New(S, Init(32*1024,4096));
  225. OK:=F^.ReadResourceEntryToStream(resBreakpoints,langDefault,S^);
  226. S^.Seek(0);
  227. if OK then
  228. begin
  229. OBC:=BreakpointsCollection;
  230. BreakpointsCollection:=PBreakpointCollection(S^.get);
  231. OK:=(S^.Status=stOK);
  232. If OK and assigned(OBC) and assigned(BreakpointsCollection) then
  233. Begin
  234. Dispose(OBC,Done);
  235. BreakpointsCollection^.ShowAllBreakpoints;
  236. end
  237. else if assigned(OBC) then
  238. BreakpointsCollection:=OBC;
  239. end;
  240. if OK=false then
  241. ErrorBox(msg_errorloadingbreakpoints,nil);
  242. ReadBreakpoints:=OK;
  243. Dispose(S, Done);
  244. PopStatus;
  245. {$else NODEBUG}
  246. ReadBreakpoints:=true;
  247. {$endif NODEBUG}
  248. end;
  249. function WriteBreakpoints(F: PResourceFile): boolean;
  250. var
  251. S : PMemoryStream;
  252. OK : boolean;
  253. begin
  254. {$ifndef NODEBUG}
  255. if not assigned(BreakpointsCollection) then
  256. {$endif NODEBUG}
  257. WriteBreakPoints:=true
  258. {$ifndef NODEBUG}
  259. else
  260. begin
  261. PushStatus(msg_storingbreakpoints);
  262. New(S, Init(30*1024,4096));
  263. BreakpointsCollection^.Store(S^);
  264. S^.Seek(0);
  265. F^.CreateResource(resBreakpoints,rcBinary,0);
  266. OK:=F^.AddResourceEntryFromStream(resBreakpoints,langDefault,0,S^,S^.GetSize);
  267. Dispose(S, Done);
  268. if OK=false then
  269. ErrorBox(msg_errorstoringbreakpoints,nil);
  270. WriteBreakPoints:=OK;
  271. PopStatus;
  272. end;
  273. {$endif NODEBUG}
  274. end;
  275. function ReadOpenWindows(F: PResourceFile): boolean;
  276. var S: PMemoryStream;
  277. OK: boolean;
  278. DV: word;
  279. WI: TWindowInfo;
  280. Title: string;
  281. XDataOfs: word;
  282. XData: array[0..1024] of byte;
  283. procedure GetData(var B; Size: word);
  284. begin
  285. Move(XData[XDataOfs],B,Size);
  286. Inc(XDataOfs,Size);
  287. end;
  288. procedure ProcessWindowInfo;
  289. var W: PWindow;
  290. SW: PSourceWindow absolute W;
  291. St: string;
  292. Ch: char;
  293. TP,TP2: TPoint;
  294. L: longint;
  295. R: TRect;
  296. begin
  297. XDataOfs:=0;
  298. Desktop^.Lock;
  299. W:=SearchWindow(Title);
  300. case WI.HelpCtx of
  301. hcSourceWindow :
  302. begin
  303. GetData(St[0],1);
  304. GetData(St[1],ord(St[0]));
  305. W:=ITryToOpenFile(@WI.Bounds,St,0,0,false,false,true);
  306. if Assigned(W)=false then
  307. begin
  308. ClearFormatParams;
  309. AddFormatParamStr(St);
  310. Desktop^.Unlock;
  311. ErrorBox(msg_cantopenfile,@FormatParams);
  312. Desktop^.Lock;
  313. end
  314. else
  315. begin
  316. GetData(L,sizeof(L)); SW^.Editor^.SetFlags(L);
  317. GetData(TP,sizeof(TP)); GetData(TP2,sizeof(TP2));
  318. SW^.Editor^.SetSelection(TP,TP2);
  319. GetData(TP,sizeof(TP)); SW^.Editor^.SetCurPtr(TP.X,TP.Y);
  320. GetData(TP,sizeof(TP)); SW^.Editor^.ScrollTo(TP.X,TP.Y);
  321. end;
  322. end;
  323. hcClipboardWindow:
  324. W:=ClipboardWindow;
  325. hcCalcWindow:
  326. W:=CalcWindow;
  327. hcMessagesWindow:
  328. begin
  329. if MessagesWindow=nil then
  330. Desktop^.Insert(New(PMessagesWindow, Init));
  331. W:=MessagesWindow;
  332. end;
  333. hcCompilerMessagesWindow:
  334. W:=CompilerMessageWindow;
  335. hcGDBWindow:
  336. begin
  337. InitGDBWindow;
  338. W:=GDBWindow;
  339. end;
  340. hcDisassemblyWindow:
  341. begin
  342. InitDisassemblyWindow;
  343. W:=DisassemblyWindow;
  344. end;
  345. hcInfoWindow:
  346. begin
  347. if ProgramInfoWindow=nil then
  348. begin
  349. New(ProgramInfoWindow, Init);
  350. Desktop^.Insert(ProgramInfoWindow);
  351. end;
  352. W:=ProgramInfoWindow;
  353. end;
  354. hcWatchesWindow:
  355. begin
  356. if WatchesWindow=nil then
  357. begin
  358. New(WatchesWindow,Init);
  359. Desktop^.Insert(WatchesWindow);
  360. end;
  361. W:=WatchesWindow;
  362. end;
  363. hcStackWindow:
  364. begin
  365. if StackWindow=nil then
  366. begin
  367. New(StackWindow,Init);
  368. Desktop^.Insert(StackWindow);
  369. end;
  370. W:=StackWindow;
  371. end;
  372. hcFPURegisters:
  373. begin
  374. if FPUWindow=nil then
  375. begin
  376. New(FPUWindow,Init);
  377. Desktop^.Insert(FPUWindow);
  378. end;
  379. W:=FPUWindow;
  380. end;
  381. hcRegistersWindow:
  382. begin
  383. if RegistersWindow=nil then
  384. begin
  385. New(RegistersWindow,Init);
  386. Desktop^.Insert(RegistersWindow);
  387. end;
  388. W:=RegistersWindow;
  389. end;
  390. hcBreakpointListWindow:
  391. begin
  392. if BreakpointsWindow=nil then
  393. begin
  394. New(BreakpointsWindow,Init);
  395. Desktop^.Insert(BreakpointsWindow);
  396. end;
  397. W:=BreakpointsWindow;
  398. end;
  399. hcASCIITableWindow:
  400. begin
  401. if ASCIIChart=nil then
  402. begin
  403. New(ASCIIChart, Init);
  404. Desktop^.Insert(ASCIIChart);
  405. end;
  406. W:=ASCIIChart;
  407. if DV>=$A then
  408. begin
  409. GetData(ch,sizeof(char));
  410. AsciiChart^.Report^.AsciiChar:=ord(ch);
  411. AsciiChart^.Table^.SetCursor(
  412. ord(ch) mod AsciiChart^.Table^.Size.X,
  413. ord(ch) div AsciiChart^.Table^.Size.X);
  414. end;
  415. end;
  416. end;
  417. if W=nil then
  418. begin
  419. Desktop^.Unlock;
  420. Exit;
  421. end;
  422. W^.GetBounds(R);
  423. if (R.A.X<>WI.Bounds.A.X) or (R.A.Y<>WI.Bounds.A.Y) then
  424. R.Move(WI.Bounds.A.X-R.A.X,WI.Bounds.A.Y-R.A.Y);
  425. if (W^.Flags and wfGrow)<>0 then
  426. begin
  427. R.B.X:=R.A.X+(WI.Bounds.B.X-WI.Bounds.A.X);
  428. R.B.Y:=R.A.Y+(WI.Bounds.B.Y-WI.Bounds.A.Y);
  429. end;
  430. W^.Locate(R);
  431. if W^.GetState(sfVisible)<>WI.Visible then
  432. if WI.Visible then
  433. begin
  434. W^.Show;
  435. W^.MakeFirst;
  436. end
  437. else
  438. W^.Hide;
  439. W^.Number:=WI.WinNb;
  440. Desktop^.Unlock;
  441. end;
  442. begin
  443. PushStatus(msg_readingdesktopcontents);
  444. New(S, Init(32*1024,4096));
  445. OK:=F^.ReadResourceEntryToStream(resDesktop,langDefault,S^);
  446. S^.Seek(0);
  447. if OK then
  448. begin
  449. S^.Read(DV,SizeOf(DV));
  450. OK:=(DV=DesktopVersion) or (DV>=MinDesktopVersion);
  451. if OK=false then
  452. ErrorBox(msg_invaliddesktopversionlayoutlost,nil);
  453. end;
  454. if OK then
  455. begin
  456. XDataOfs:=0;
  457. repeat
  458. S^.Read(WI,sizeof(WI));
  459. if S^.Status=stOK then
  460. begin
  461. Title[0]:=chr(WI.TitleLen);
  462. S^.Read(Title[1],WI.TitleLen);
  463. if WI.ExtraDataSize>0 then
  464. S^.Read(XData,WI.ExtraDataSize);
  465. ProcessWindowInfo;
  466. end;
  467. until (S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  468. (* TempDesk:=PFPDesktop(S^.Get);
  469. OK:=Assigned(TempDesk);
  470. if OK then
  471. begin
  472. Dispose(Desktop, Done);
  473. Desktop:=TempDesk;
  474. with Desktop^ do
  475. begin
  476. GetSubViewPtr(S^,CompilerMessageWindow);
  477. GetSubViewPtr(S^,CompilerStatusDialog);
  478. GetSubViewPtr(S^,ClipboardWindow);
  479. if Assigned(ClipboardWindow) then Clipboard:=ClipboardWindow^.Editor;
  480. GetSubViewPtr(S^,CalcWindow);
  481. GetSubViewPtr(S^,ProgramInfoWindow);
  482. GetSubViewPtr(S^,GDBWindow);
  483. GetSubViewPtr(S^,BreakpointsWindow);
  484. GetSubViewPtr(S^,WatchesWindow);
  485. GetSubViewPtr(S^,UserScreenWindow);
  486. GetSubViewPtr(S^,ASCIIChart);
  487. GetSubViewPtr(S^,MessagesWindow); LastToolMessageFocused:=nil;
  488. end;
  489. Application^.GetExtent(R);
  490. Inc(R.A.Y);Dec(R.B.Y);
  491. DeskTop^.Locate(R);
  492. Application^.Insert(Desktop);
  493. Desktop^.ReDraw;
  494. Message(Application,evBroadcast,cmUpdate,nil);
  495. end;*)
  496. if OK=false then
  497. ErrorBox(msg_errorloadingdesktop,nil);
  498. end;
  499. Dispose(S, Done);
  500. PopStatus;
  501. ReadOpenWindows:=OK;
  502. end;
  503. function WriteOpenWindows(F: PResourceFile): boolean;
  504. var S: PMemoryStream;
  505. procedure CollectInfo(P: PView); {$ifndef FPC}far;{$endif}
  506. var W: PWindow;
  507. SW: PSourceWindow absolute W;
  508. WI: TWindowInfo;
  509. Title: string;
  510. XDataOfs: word;
  511. XData: array[0..1024] of byte;
  512. St: string;
  513. Ch: char;
  514. TP: TPoint;
  515. L: longint;
  516. procedure AddData(const B; Size: word);
  517. begin
  518. Move(B,XData[XDataOfs],Size);
  519. Inc(XDataOfs,Size);
  520. end;
  521. begin
  522. XDataOfs:=0;
  523. W:=nil;
  524. if (P^.HelpCtx=hcSourceWindow) or
  525. (P^.HelpCtx=hcHelpWindow) or
  526. (P^.HelpCtx=hcClipboardWindow) or
  527. (P^.HelpCtx=hcCalcWindow) or
  528. (P^.HelpCtx=hcInfoWindow) or
  529. (P^.HelpCtx=hcBrowserWindow) or
  530. (P^.HelpCtx=hcMessagesWindow) or
  531. (P^.HelpCtx=hcCompilerMessagesWindow) or
  532. (P^.HelpCtx=hcGDBWindow) or
  533. (P^.HelpCtx=hcDisassemblyWindow) or
  534. (P^.HelpCtx=hcStackWindow) or
  535. (P^.HelpCtx=hcRegistersWindow) or
  536. (P^.HelpCtx=hcFPURegisters) or
  537. (P^.HelpCtx=hcWatchesWindow) or
  538. (P^.HelpCtx=hcBreakpointListWindow) or
  539. (P^.HelpCtx=hcASCIITableWindow)
  540. then
  541. W:=PWindow(P);
  542. if Assigned(W) and (P^.HelpCtx=hcSourceWindow) then
  543. if SW^.Editor^.FileName='' then
  544. W:=nil;
  545. if W=nil then Exit;
  546. FillChar(WI,sizeof(WI),0);
  547. Title:=W^.GetTitle(255);
  548. WI.HelpCtx:=W^.HelpCtx;
  549. W^.GetBounds(WI.Bounds);
  550. WI.Visible:=W^.GetState(sfVisible);
  551. WI.WinNb:=W^.Number;
  552. case WI.HelpCtx of
  553. hcSourceWindow :
  554. begin
  555. St:=SW^.Editor^.FileName; AddData(St,length(St)+1);
  556. L:=SW^.Editor^.GetFlags; AddData(L,sizeof(L));
  557. TP:=SW^.Editor^.SelStart; AddData(TP,sizeof(TP));
  558. TP:=SW^.Editor^.SelEnd; AddData(TP,sizeof(TP));
  559. TP:=SW^.Editor^.CurPos; AddData(TP,sizeof(TP));
  560. TP:=SW^.Editor^.Delta; AddData(TP,sizeof(TP));
  561. end;
  562. hcAsciiTableWindow :
  563. begin
  564. ch:=chr(PFPAsciiChart(P)^.Report^.AsciiChar);
  565. AddData(ch,sizeof(char));
  566. end;
  567. end;
  568. WI.TitleLen:=length(Title);
  569. WI.ExtraDataSize:=XDataOfs;
  570. S^.Write(WI,sizeof(WI));
  571. S^.Write(Title[1],WI.TitleLen);
  572. if WI.ExtraDataSize>0 then
  573. S^.Write(XData,WI.ExtraDataSize);
  574. end;
  575. var W: word;
  576. OK: boolean;
  577. PV: PView;
  578. begin
  579. PushStatus(msg_storingdesktopcontents);
  580. New(S, Init(30*1024,4096));
  581. OK:=Assigned(S);
  582. if OK then
  583. begin
  584. W:=DesktopVersion;
  585. S^.Write(W,SizeOf(W));
  586. { S^.Put(Desktop);
  587. with Desktop^ do
  588. begin
  589. PutSubViewPtr(S^,CompilerMessageWindow);
  590. PutSubViewPtr(S^,CompilerStatusDialog);
  591. PutSubViewPtr(S^,ClipboardWindow);
  592. PutSubViewPtr(S^,CalcWindow);
  593. PutSubViewPtr(S^,ProgramInfoWindow);
  594. PutSubViewPtr(S^,GDBWindow);
  595. PutSubViewPtr(S^,BreakpointsWindow);
  596. PutSubViewPtr(S^,WatchesWindow);
  597. PutSubViewPtr(S^,UserScreenWindow);
  598. PutSubViewPtr(S^,ASCIIChart);
  599. PutSubViewPtr(S^,MessagesWindow);
  600. end;}
  601. { PV:=Application^.Last;
  602. while PV<>nil do
  603. begin
  604. CollectInfo(PV);
  605. PV:=PV^.PrevView;
  606. end;}
  607. PV:=Desktop^.Last;
  608. while PV<>nil do
  609. begin
  610. CollectInfo(PV);
  611. PV:=PV^.PrevView;
  612. end;
  613. OK:=(S^.Status=stOK);
  614. if OK then
  615. begin
  616. S^.Seek(0);
  617. OK:=F^.CreateResource(resDesktop,rcBinary,0);
  618. OK:=OK and F^.AddResourceEntryFromStream(resDesktop,langDefault,0,S^,S^.GetSize);
  619. end;
  620. Dispose(S, Done);
  621. end;
  622. if OK=false then
  623. ErrorBox(msg_errorstoringdesktop,nil);
  624. PopStatus;
  625. WriteOpenWindows:=OK;
  626. end;
  627. function WriteFlags(F: PResourceFile): boolean;
  628. var
  629. OK: boolean;
  630. begin
  631. F^.CreateResource(resDesktopFlags,rcBinary,0);
  632. OK:=F^.AddResourceEntry(resDesktopFlags,langDefault,0,DesktopFileFlags,
  633. SizeOf(DesktopFileFlags));
  634. if OK=false then
  635. ErrorBox(msg_errorwritingflags,nil);
  636. WriteFlags:=OK;
  637. end;
  638. function ReadCodeComplete(F: PResourceFile): boolean;
  639. var S: PMemoryStream;
  640. OK: boolean;
  641. begin
  642. PushStatus(msg_readingcodecompletewordlist);
  643. New(S, Init(1024,1024));
  644. OK:=F^.ReadResourceEntryToStream(resCodeComplete,langDefault,S^);
  645. S^.Seek(0);
  646. if OK then
  647. OK:=LoadCodeComplete(S^);
  648. Dispose(S, Done);
  649. if OK=false then
  650. ErrorBox(msg_errorloadingcodecompletewordlist,nil);
  651. PopStatus;
  652. ReadCodeComplete:=OK;
  653. end;
  654. function WriteCodeComplete(F: PResourceFile): boolean;
  655. var OK: boolean;
  656. S: PMemoryStream;
  657. begin
  658. PushStatus(msg_storingcodecompletewordlist);
  659. New(S, Init(1024,1024));
  660. OK:=StoreCodeComplete(S^);
  661. if OK then
  662. begin
  663. S^.Seek(0);
  664. F^.CreateResource(resCodeComplete,rcBinary,0);
  665. OK:=F^.AddResourceEntryFromStream(resCodeComplete,langDefault,0,S^,S^.GetSize);
  666. end;
  667. Dispose(S, Done);
  668. if OK=false then
  669. ErrorBox(msg_errorstoringcodecompletewordlist,nil);
  670. PopStatus;
  671. WriteCodeComplete:=OK;
  672. end;
  673. function ReadCodeTemplates(F: PResourceFile): boolean;
  674. var S: PMemoryStream;
  675. OK: boolean;
  676. begin
  677. PushStatus(msg_readingcodetemplates);
  678. New(S, Init(1024,4096));
  679. OK:=F^.ReadResourceEntryToStream(resCodeTemplates,langDefault,S^);
  680. S^.Seek(0);
  681. if OK then
  682. OK:=LoadCodeTemplates(S^);
  683. Dispose(S, Done);
  684. if OK=false then
  685. ErrorBox(msg_errorloadingcodetemplates,nil);
  686. PopStatus;
  687. ReadCodeTemplates:=OK;
  688. end;
  689. function WriteCodeTemplates(F: PResourceFile): boolean;
  690. var OK: boolean;
  691. S: PMemoryStream;
  692. begin
  693. PushStatus(msg_storingcodetemplates);
  694. New(S, Init(1024,4096));
  695. OK:=StoreCodeTemplates(S^);
  696. if OK then
  697. begin
  698. S^.Seek(0);
  699. F^.CreateResource(resCodeTemplates,rcBinary,0);
  700. OK:=F^.AddResourceEntryFromStream(resCodeTemplates,langDefault,0,S^,S^.GetSize);
  701. end;
  702. Dispose(S, Done);
  703. if OK=false then
  704. ErrorBox(msg_errorstoringcodetemplates,nil);
  705. PopStatus;
  706. WriteCodeTemplates:=OK;
  707. end;
  708. function ReadFlags(F: PResourceFile): boolean;
  709. var
  710. size : sw_word;
  711. OK: boolean;
  712. begin
  713. OK:=F^.ReadResourceEntry(resDesktopFlags,langDefault,DesktopFileFlags,
  714. size);
  715. if OK=false then
  716. ErrorBox(msg_errorreadingflags,nil);
  717. ReadFlags:=OK;
  718. end;
  719. function WriteVideoMode(F: PResourceFile): boolean;
  720. var
  721. OK: boolean;
  722. begin
  723. F^.CreateResource(resVideo,rcBinary,0);
  724. OK:=F^.AddResourceEntry(resVideo,langDefault,0,ScreenMode,
  725. SizeOf(TVideoMode));
  726. if OK=false then
  727. ErrorBox(msg_errorstoringvideomode,nil);
  728. WriteVideoMode:=OK;
  729. end;
  730. function ReadVideoMode(F: PResourceFile;var NewScreenMode : TVideoMode): boolean;
  731. var
  732. size : sw_word;
  733. OK,test : boolean;
  734. begin
  735. size:=SizeOf(TVideoMode);
  736. test:=F^.ReadResourceEntry(resVideo,langDefault,NewScreenMode,
  737. size);
  738. if not test then
  739. NewScreenMode:=ScreenMode;
  740. OK:=test and (size = SizeOf(TVideoMode));
  741. if OK=false then
  742. ErrorBox(msg_errorreadingvideomode,nil);
  743. ReadVideoMode:=OK;
  744. end;
  745. function ReadSymbols(F: PResourceFile): boolean;
  746. var S: PMemoryStream;
  747. OK: boolean;
  748. R: PResource;
  749. begin
  750. { if no symbols stored ... no problems }
  751. R:=F^.FindResource(resSymbols);
  752. if not Assigned(R) then
  753. exit;
  754. PushStatus(msg_readingsymbolinformation);
  755. New(S, Init(32*1024,4096));
  756. OK:=F^.ReadResourceEntryToStream(resSymbols,langDefault,S^);
  757. S^.Seek(0);
  758. if OK then
  759. OK:=LoadBrowserCol(S);
  760. Dispose(S, Done);
  761. if OK=false then
  762. ErrorBox(msg_errorloadingsymbolinformation,nil);
  763. PopStatus;
  764. ReadSymbols:=OK;
  765. end;
  766. function WriteSymbols(F: PResourceFile): boolean;
  767. var S: PMemoryStream;
  768. OK: boolean;
  769. begin
  770. OK:=Assigned(Modules);
  771. if OK then
  772. begin
  773. PushStatus(msg_storingsymbolinformation);
  774. New(S, Init(200*1024,4096));
  775. OK:=Assigned(S);
  776. if OK then
  777. OK:=StoreBrowserCol(S);
  778. if OK then
  779. begin
  780. S^.Seek(0);
  781. F^.CreateResource(resSymbols,rcBinary,0);
  782. OK:=F^.AddResourceEntryFromStream(resSymbols,langDefault,0,S^,S^.GetSize);
  783. end;
  784. Dispose(S, Done);
  785. if OK=false then
  786. ErrorBox(msg_errorstoringsymbolinformation,nil);
  787. PopStatus;
  788. end;
  789. WriteSymbols:=OK;
  790. end;
  791. function LoadDesktop: boolean;
  792. var OK,VOK: boolean;
  793. F: PResourceFile;
  794. VM : TVideoMode;
  795. begin
  796. PushStatus(msg_readingdesktopfile);
  797. New(F, LoadFile(DesktopPath));
  798. OK:=false;
  799. if Assigned(F) then
  800. begin
  801. OK:=ReadFlags(F);
  802. VOK:=ReadVideoMode(F,VM);
  803. if VOK and ((VM.Col<>ScreenMode.Col) or
  804. (VM.Row<>ScreenMode.Row) or (VM.Color<>ScreenMode.Color)) then
  805. begin
  806. if Assigned(Application) then
  807. Application^.SetScreenVideoMode(VM);
  808. end;
  809. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  810. OK:=OK and ReadHistory(F);
  811. if ((DesktopFileFlags and dfWatches)<>0) then
  812. OK:=OK and ReadWatches(F);
  813. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  814. OK:=OK and ReadBreakpoints(F);
  815. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  816. OK:=OK and ReadOpenWindows(F);
  817. { no errors if no browser info available PM }
  818. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  819. OK:=OK and ReadSymbols(F);
  820. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  821. OK:=OK and ReadCodeComplete(F);
  822. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  823. OK:=OK and ReadCodeTemplates(F);
  824. {$ifdef Unix}
  825. OK:=OK and ReadKeys(F);
  826. {$endif Unix}
  827. Dispose(F, Done);
  828. end;
  829. PopStatus;
  830. LoadDesktop:=OK;
  831. end;
  832. function SaveDesktop: boolean;
  833. var OK: boolean;
  834. F: PResourceFile;
  835. TempPath: string;
  836. begin
  837. TempPath:=DirOf(DesktopPath)+DesktopTempName;
  838. PushStatus(msg_writingdesktopfile);
  839. New(F, CreateFile(TempPath));
  840. if Assigned(Clipboard) then
  841. if (DesktopFileFlags and dfClipboardContent)<>0 then
  842. Clipboard^.SetFlags(Clipboard^.GetFlags or efStoreContent)
  843. else
  844. Clipboard^.SetFlags(Clipboard^.GetFlags and not efStoreContent);
  845. OK:=false;
  846. if Assigned(F) then
  847. begin
  848. OK:=WriteFlags(F);
  849. OK:=OK and WriteVideoMode(F);
  850. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  851. OK:=OK and WriteHistory(F);
  852. if ((DesktopFileFlags and dfWatches)<>0) then
  853. OK:=OK and WriteWatches(F);
  854. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  855. OK:=OK and WriteBreakpoints(F);
  856. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  857. OK:=OK and WriteOpenWindows(F);
  858. { no errors if no browser info available PM }
  859. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  860. OK:=OK and (WriteSymbols(F) or not Assigned(Modules));
  861. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  862. OK:=OK and WriteCodeComplete(F);
  863. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  864. OK:=OK and WriteCodeTemplates(F);
  865. {$ifdef Unix}
  866. OK:=OK and WriteKeys(F);
  867. {$endif Unix}
  868. Dispose(F, Done);
  869. end;
  870. if OK then
  871. begin
  872. if ExistsFile(DesktopPath) then
  873. OK:=EraseFile(DesktopPath);
  874. OK:=OK and RenameFile(TempPath,DesktopPath);
  875. if OK=false then
  876. ErrorBox(msg_failedtoreplacedesktopfile,nil);
  877. end;
  878. PopStatus;
  879. SaveDesktop:=OK;
  880. end;
  881. function WriteSymbolsFile(const filename : string): boolean;
  882. var OK: boolean;
  883. F: PResourceFile;
  884. begin
  885. WriteSymbolsFile:=false;
  886. If not assigned(Modules) then
  887. exit;
  888. New(F, CreateFile(FileName));
  889. OK:=Assigned(F);
  890. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  891. OK:=OK and WriteSymbols(F);
  892. if assigned(F) then
  893. Dispose(F,Done);
  894. WriteSymbolsFile:=OK;
  895. end;
  896. function ReadSymbolsFile(const FileName : string): boolean;
  897. var OK: boolean;
  898. F: PResourceFile;
  899. begin
  900. ReadSymbolsFile:=false;
  901. { Don't read again !! }
  902. If assigned(Modules) then
  903. exit;
  904. New(F, LoadFile(FileName));
  905. OK:=Assigned(F);
  906. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  907. OK:=OK and ReadSymbols(F);
  908. if assigned(F) then
  909. Dispose(F,Done);
  910. ReadSymbolsFile:=OK;
  911. end;
  912. END.
  913. {
  914. $Log$
  915. Revision 1.4 2002-05-31 12:37:09 pierre
  916. + register asciitable char
  917. Revision 1.3 2001/10/11 11:38:22 pierre
  918. * small fvision specific changes
  919. Revision 1.2 2001/08/05 12:23:00 peter
  920. * Automatically support for fvision or old fv
  921. Revision 1.1 2001/08/04 11:30:23 peter
  922. * ide works now with both compiler versions
  923. Revision 1.1.2.8 2001/03/22 17:28:03 pierre
  924. * small fix to OpenWindows
  925. Revision 1.1.2.7 2001/03/12 17:34:55 pierre
  926. + Disassembly window started
  927. Revision 1.1.2.6 2000/12/12 16:51:50 pierre
  928. + keys loading/storing begin
  929. Revision 1.1.2.5 2000/11/29 11:25:59 pierre
  930. + TFPDlgWindow that handles cmSearchWindow
  931. Revision 1.1.2.4 2000/11/29 00:54:44 pierre
  932. + preserve window number and save special windows
  933. Revision 1.1.2.3 2000/10/18 21:53:26 pierre
  934. * several Gabor fixes
  935. Revision 1.1.2.2 2000/09/18 13:20:54 pierre
  936. New bunch of Gabor changes
  937. Revision 1.1.2.1 2000/07/20 11:02:15 michael
  938. + Fixes from gabor. See fixes.txt
  939. Revision 1.1 2000/07/13 09:48:34 michael
  940. + Initial import
  941. Revision 1.29 2000/06/22 09:07:12 pierre
  942. * Gabor changes: see fixes.txt
  943. Revision 1.28 2000/05/02 08:42:27 pierre
  944. * new set of Gabor changes: see fixes.txt
  945. Revision 1.27 2000/04/25 08:42:33 pierre
  946. * New Gabor changes : see fixes.txt
  947. Revision 1.26 2000/04/18 11:42:36 pierre
  948. lot of Gabor changes : see fixes.txt
  949. Revision 1.25 2000/03/21 23:32:05 pierre
  950. adapted to wcedit addition by Gabor
  951. Revision 1.24 2000/03/20 19:19:46 pierre
  952. * LFN support in streams
  953. Revision 1.23 2000/03/13 20:36:52 pierre
  954. * Breakpoints saved and loaded before sources
  955. Revision 1.22 2000/02/07 12:03:48 pierre
  956. Last commit is from Gabor's changes!
  957. Revision 1.21 2000/02/07 11:55:27 pierre
  958. + Code Complete and Template saving from Gabor
  959. Revision 1.20 2000/02/04 00:12:57 pierre
  960. * Breakpoint are marked in source at desktop loading
  961. Revision 1.19 2000/01/25 00:26:36 pierre
  962. + Browser info saving
  963. Revision 1.18 2000/01/03 11:38:33 michael
  964. Changes from Gabor
  965. Revision 1.17 1999/12/20 00:30:56 pierre
  966. * problem with VideoMode storing solved
  967. Revision 1.16 1999/12/10 13:02:05 pierre
  968. + VideoMode save/restore
  969. Revision 1.15 1999/11/26 17:09:51 pierre
  970. * Force Desktop into Screen
  971. Revision 1.14 1999/11/25 00:25:43 pierre
  972. * add Status when loading/saving files
  973. Revision 1.13 1999/09/20 15:37:59 pierre
  974. * ReadOpenWindows and ReadSymobls was missing, still does not work correctly :(
  975. Revision 1.12 1999/09/17 16:41:10 pierre
  976. * other stream error for Watches/Breakpoints corrected
  977. Revision 1.11 1999/09/17 16:28:58 pierre
  978. * ResWatches in WriteBreakpoints typo !
  979. Revision 1.10 1999/09/16 14:34:58 pierre
  980. + TBreakpoint and TWatch registering
  981. + WatchesCollection and BreakpointsCollection stored in desk file
  982. * Syntax highlighting was broken
  983. Revision 1.9 1999/09/07 09:23:00 pierre
  984. * no errors if no browser info available
  985. Revision 1.8 1999/08/16 18:25:16 peter
  986. * Adjusting the selection when the editor didn't contain any line.
  987. * Reserved word recognition redesigned, but this didn't affect the overall
  988. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  989. The syntax scanner loop is a bit slow but the main problem is the
  990. recognition of special symbols. Switching off symbol processing boosts
  991. the performance up to ca. 200%...
  992. * The editor didn't allow copying (for ex to clipboard) of a single character
  993. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  994. * Compiler Messages window (actually the whole desktop) did not act on any
  995. keypress when compilation failed and thus the window remained visible
  996. + Message windows are now closed upon pressing Esc
  997. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  998. only when neccessary
  999. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  1000. + LineSelect (Ctrl+K+L) implemented
  1001. * The IDE had problems closing help windows before saving the desktop
  1002. Revision 1.7 1999/08/03 20:22:30 peter
  1003. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  1004. + Desktop saving should work now
  1005. - History saved
  1006. - Clipboard content saved
  1007. - Desktop saved
  1008. - Symbol info saved
  1009. * syntax-highlight bug fixed, which compared special keywords case sensitive
  1010. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  1011. * with 'whole words only' set, the editor didn't found occourences of the
  1012. searched text, if the text appeared previously in the same line, but didn't
  1013. satisfied the 'whole-word' condition
  1014. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  1015. (ie. the beginning of the selection)
  1016. * when started typing in a new line, but not at the start (X=0) of it,
  1017. the editor inserted the text one character more to left as it should...
  1018. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  1019. * Shift shouldn't cause so much trouble in TCodeEditor now...
  1020. * Syntax highlight had problems recognizing a special symbol if it was
  1021. prefixed by another symbol character in the source text
  1022. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  1023. Revision 1.5 1999/06/30 23:58:13 pierre
  1024. + BreakpointsList Window implemented
  1025. with Edit/New/Delete functions
  1026. + Individual breakpoint dialog with support for all types
  1027. ignorecount and conditions
  1028. (commands are not yet implemented, don't know if this wolud be useful)
  1029. awatch and rwatch have problems because GDB does not annotate them
  1030. I fixed v4.16 for this
  1031. Revision 1.4 1999/04/15 08:58:05 peter
  1032. * syntax highlight fixes
  1033. * browser updates
  1034. Revision 1.3 1999/04/07 21:55:45 peter
  1035. + object support for browser
  1036. * html help fixes
  1037. * more desktop saving things
  1038. * NODEBUG directive to exclude debugger
  1039. Revision 1.2 1999/03/23 16:16:39 peter
  1040. * linux fixes
  1041. Revision 1.1 1999/03/23 15:11:28 peter
  1042. * desktop saving things
  1043. * vesa mode
  1044. * preferences dialog
  1045. }