fpdesk.pas 30 KB

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