fpdesk.pas 26 KB

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