fpdesk.pas 26 KB

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