fpdesk.pas 30 KB

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