fpdesk.pas 26 KB

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