fpdesk.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 = $0003; { <- if you change any Load&Store methods,
  16. then you should also change this }
  17. ResDesktopFlags = 'FLAGS';
  18. ResHistory = 'HISTORY';
  19. ResClipboard = 'CLIPBOARD';
  20. ResWatches = 'WATCHES';
  21. ResBreakpoints = 'BREAKPOINTS';
  22. ResDesktop = 'DESKTOP';
  23. ResSymbols = 'SYMBOLS';
  24. procedure InitDesktopFile;
  25. function LoadDesktop: boolean;
  26. function SaveDesktop: boolean;
  27. procedure DoneDesktopFile;
  28. implementation
  29. uses Dos,
  30. Objects,Drivers,Views,App,HistList,BrowCol,
  31. WResource,WViews,WEditor,
  32. {$ifndef NODEBUG}
  33. fpdebug,
  34. {$endif ndef NODEBUG}
  35. FPConst,FPVars,FPUtils,FPViews,FPCompile,FPTools,FPHelp;
  36. procedure InitDesktopFile;
  37. begin
  38. if DesktopLocation=dlCurrentDir then
  39. DesktopPath:=FExpand(DesktopName)
  40. else
  41. DesktopPath:=FExpand(DirOf(INIPath)+DesktopName);
  42. end;
  43. procedure DoneDesktopFile;
  44. begin
  45. end;
  46. function ReadHistory(F: PResourceFile): boolean;
  47. var S: PMemoryStream;
  48. OK: boolean;
  49. begin
  50. PushStatus('Reading history...');
  51. New(S, Init(32*1024,4096));
  52. OK:=F^.ReadResourceEntryToStream(resHistory,langDefault,S^);
  53. S^.Seek(0);
  54. if OK then
  55. LoadHistory(S^);
  56. Dispose(S, Done);
  57. PopStatus;
  58. ReadHistory:=OK;
  59. end;
  60. function WriteHistory(F: PResourceFile): boolean;
  61. var S: PMemoryStream;
  62. begin
  63. PushStatus('Storing history...');
  64. New(S, Init(10*1024,4096));
  65. StoreHistory(S^);
  66. S^.Seek(0);
  67. F^.CreateResource(resHistory,rcBinary,0);
  68. F^.AddResourceEntryFromStream(resHistory,langDefault,0,S^,S^.GetSize);
  69. Dispose(S, Done);
  70. PopStatus;
  71. WriteHistory:=true;
  72. end;
  73. (*function ReadClipboard(F: PResourceFile): boolean;
  74. begin
  75. ReadClipboard:=true;
  76. end;
  77. function WriteClipboard(F: PResourceFile): boolean;
  78. var S: PMemoryStream;
  79. begin
  80. if Assigned(Clipboard) then
  81. begin
  82. PushStatus('Storing clipboard content...');
  83. New(S, Init(10*1024,4096));
  84. Clipboard^.SaveToStream(S^);
  85. S^.Seek(0);
  86. F^.CreateResource(resClipboard,rcBinary,0);
  87. F^.AddResourceEntryFromStream(resClipboard,langDefault,0,S^,S^.GetSize);
  88. Dispose(S, Done);
  89. PopStatus;
  90. end;
  91. WriteClipboard:=true;
  92. end;*)
  93. function ReadWatches(F: PResourceFile): boolean;
  94. var S: PMemoryStream;
  95. OK: boolean;
  96. OWC : PWatchesCollection;
  97. begin
  98. {$ifndef NODEBUG}
  99. PushStatus('Reading watches...');
  100. New(S, Init(32*1024,4096));
  101. OK:=F^.ReadResourceEntryToStream(resWatches,langDefault,S^);
  102. S^.Seek(0);
  103. if OK then
  104. begin
  105. OWC:=WatchesCollection;
  106. WatchesCollection:=PWatchesCollection(S^.Get);
  107. OK:=(S^.Status=stOK);
  108. if OK and assigned(OWC) then
  109. Dispose(OWC,Done);
  110. end;
  111. ReadWatches:=OK;
  112. Dispose(S, Done);
  113. PopStatus;
  114. {$else NODEBUG}
  115. ReadWatches:=true;
  116. {$endif NODEBUG}
  117. end;
  118. function WriteWatches(F: PResourceFile): boolean;
  119. var
  120. S : PMemoryStream;
  121. begin
  122. {$ifndef NODEBUG}
  123. if not assigned(WatchesCollection) then
  124. {$endif NODEBUG}
  125. WriteWatches:=true
  126. {$ifndef NODEBUG}
  127. else
  128. begin
  129. PushStatus('Storing watches...');
  130. New(S, Init(30*1024,4096));
  131. S^.Put(WatchesCollection);
  132. S^.Seek(0);
  133. F^.CreateResource(resWatches,rcBinary,0);
  134. WriteWatches:=F^.AddResourceEntryFromStream(resWatches,langDefault,0,S^,S^.GetSize);
  135. Dispose(S, Done);
  136. PopStatus;
  137. end;
  138. {$endif NODEBUG}
  139. end;
  140. function ReadBreakpoints(F: PResourceFile): boolean;
  141. var S: PMemoryStream;
  142. OK: boolean;
  143. OBC : PBreakpointCollection;
  144. begin
  145. {$ifndef NODEBUG}
  146. PushStatus('Reading breakpoints...');
  147. New(S, Init(32*1024,4096));
  148. OK:=F^.ReadResourceEntryToStream(resBreakpoints,langDefault,S^);
  149. S^.Seek(0);
  150. if OK then
  151. begin
  152. OBC:=BreakpointsCollection;
  153. BreakpointsCollection:=PBreakpointCollection(S^.get);
  154. OK:=(S^.Status=stOK);
  155. If OK and assigned(OBC) then
  156. Dispose(OBC,Done);
  157. end;
  158. ReadBreakpoints:=OK;
  159. Dispose(S, Done);
  160. PopStatus;
  161. {$else NODEBUG}
  162. ReadBreakpoints:=true;
  163. {$endif NODEBUG}
  164. end;
  165. function WriteBreakpoints(F: PResourceFile): boolean;
  166. var
  167. S : PMemoryStream;
  168. begin
  169. {$ifndef NODEBUG}
  170. if not assigned(BreakpointsCollection) then
  171. {$endif NODEBUG}
  172. WriteBreakPoints:=true
  173. {$ifndef NODEBUG}
  174. else
  175. begin
  176. PushStatus('Storing breakpoints...');
  177. New(S, Init(30*1024,4096));
  178. BreakpointsCollection^.Store(S^);
  179. S^.Seek(0);
  180. F^.CreateResource(resBreakpoints,rcBinary,0);
  181. WriteBreakPoints:=F^.AddResourceEntryFromStream(resBreakpoints,langDefault,0,S^,S^.GetSize);
  182. Dispose(S, Done);
  183. PopStatus;
  184. end;
  185. {$endif NODEBUG}
  186. end;
  187. function ReadOpenWindows(F: PResourceFile): boolean;
  188. var S: PMemoryStream;
  189. TempDesk: PFPDesktop;
  190. OK: boolean;
  191. W: word;
  192. begin
  193. PushStatus('Reading desktop contents...');
  194. New(S, Init(32*1024,4096));
  195. OK:=F^.ReadResourceEntryToStream(resDesktop,langDefault,S^);
  196. S^.Seek(0);
  197. if OK then
  198. begin
  199. S^.Read(W,SizeOf(W));
  200. OK:=(W=DesktopVersion);
  201. if OK=false then
  202. ErrorBox('Invalid desktop version. Desktop layout lost.',nil);
  203. end;
  204. if OK then
  205. begin
  206. TempDesk:=PFPDesktop(S^.Get);
  207. OK:=Assigned(TempDesk);
  208. if OK then
  209. begin
  210. Dispose(Desktop, Done);
  211. Desktop:=TempDesk;
  212. with Desktop^ do
  213. begin
  214. GetSubViewPtr(S^,CompilerMessageWindow);
  215. GetSubViewPtr(S^,CompilerStatusDialog);
  216. GetSubViewPtr(S^,ClipboardWindow);
  217. if Assigned(ClipboardWindow) then Clipboard:=ClipboardWindow^.Editor;
  218. GetSubViewPtr(S^,CalcWindow);
  219. GetSubViewPtr(S^,ProgramInfoWindow);
  220. GetSubViewPtr(S^,GDBWindow);
  221. GetSubViewPtr(S^,BreakpointsWindow);
  222. GetSubViewPtr(S^,WatchesWindow);
  223. GetSubViewPtr(S^,UserScreenWindow);
  224. GetSubViewPtr(S^,ASCIIChart);
  225. GetSubViewPtr(S^,MessagesWindow); LastToolMessageFocused:=nil;
  226. end;
  227. Application^.Insert(Desktop);
  228. Desktop^.ReDraw;
  229. Message(Application,evBroadcast,cmUpdate,nil);
  230. end;
  231. if OK=false then
  232. ErrorBox('Error loading desktop',nil);
  233. end;
  234. Dispose(S, Done);
  235. PopStatus;
  236. ReadOpenWindows:=OK;
  237. end;
  238. function WriteOpenWindows(F: PResourceFile): boolean;
  239. var S: PMemoryStream;
  240. W: word;
  241. begin
  242. PushStatus('Storing desktop contents...');
  243. New(S, Init(30*1024,4096));
  244. W:=DesktopVersion;
  245. S^.Write(W,SizeOf(W));
  246. S^.Put(Desktop);
  247. with Desktop^ do
  248. begin
  249. PutSubViewPtr(S^,CompilerMessageWindow);
  250. PutSubViewPtr(S^,CompilerStatusDialog);
  251. PutSubViewPtr(S^,ClipboardWindow);
  252. PutSubViewPtr(S^,CalcWindow);
  253. PutSubViewPtr(S^,ProgramInfoWindow);
  254. PutSubViewPtr(S^,GDBWindow);
  255. PutSubViewPtr(S^,BreakpointsWindow);
  256. PutSubViewPtr(S^,WatchesWindow);
  257. PutSubViewPtr(S^,UserScreenWindow);
  258. PutSubViewPtr(S^,ASCIIChart);
  259. PutSubViewPtr(S^,MessagesWindow);
  260. end;
  261. S^.Seek(0);
  262. F^.CreateResource(resDesktop,rcBinary,0);
  263. F^.AddResourceEntryFromStream(resDesktop,langDefault,0,S^,S^.GetSize);
  264. Dispose(S, Done);
  265. PopStatus;
  266. WriteOpenWindows:=true;
  267. end;
  268. function WriteFlags(F: PResourceFile): boolean;
  269. begin
  270. F^.CreateResource(resDesktopFlags,rcBinary,0);
  271. WriteFlags:=F^.AddResourceEntry(resDesktopFlags,langDefault,0,DesktopFileFlags,
  272. SizeOf(DesktopFileFlags));
  273. end;
  274. function ReadFlags(F: PResourceFile): boolean;
  275. var
  276. size : sw_word;
  277. begin
  278. ReadFlags:=F^.ReadResourceEntry(resDesktopFlags,langDefault,DesktopFileFlags,
  279. size);
  280. end;
  281. function ReadSymbols(F: PResourceFile): boolean;
  282. var S: PMemoryStream;
  283. OK: boolean;
  284. begin
  285. PushStatus('Reading symbol information...');
  286. New(S, Init(32*1024,4096));
  287. OK:=F^.ReadResourceEntryToStream(resSymbols,langDefault,S^);
  288. S^.Seek(0);
  289. if OK then
  290. LoadBrowserCol(S);
  291. Dispose(S, Done);
  292. PopStatus;
  293. ReadSymbols:=OK;
  294. end;
  295. function WriteSymbols(F: PResourceFile): boolean;
  296. var S: PMemoryStream;
  297. OK: boolean;
  298. begin
  299. OK:=Assigned(Modules);
  300. if OK then
  301. begin
  302. PushStatus('Storing symbol information...');
  303. New(S, Init(200*1024,4096));
  304. StoreBrowserCol(S);
  305. S^.Seek(0);
  306. F^.CreateResource(resSymbols,rcBinary,0);
  307. OK:=F^.AddResourceEntryFromStream(resSymbols,langDefault,0,S^,S^.GetSize);
  308. Dispose(S, Done);
  309. PopStatus;
  310. end;
  311. WriteSymbols:=OK;
  312. end;
  313. function LoadDesktop: boolean;
  314. var OK: boolean;
  315. F: PResourceFile;
  316. begin
  317. PushStatus('Reading desktop file...');
  318. New(F, LoadFile(DesktopPath));
  319. OK:=Assigned(F);
  320. if OK then
  321. begin
  322. OK:=ReadFlags(F);
  323. if OK and ((DesktopFileFlags and dfHistoryLists)<>0) then
  324. OK:=ReadHistory(F);
  325. if OK and ((DesktopFileFlags and dfWatches)<>0) then
  326. OK:=ReadWatches(F);
  327. if OK and ((DesktopFileFlags and dfBreakpoints)<>0) then
  328. OK:=ReadBreakpoints(F);
  329. end;
  330. PopStatus;
  331. LoadDesktop:=OK;
  332. end;
  333. function SaveDesktop: boolean;
  334. var OK: boolean;
  335. F: PResourceFile;
  336. begin
  337. PushStatus('Writing desktop file...');
  338. New(F, CreateFile(DesktopPath));
  339. if Assigned(Clipboard) then
  340. if (DesktopFileFlags and dfClipboardContent)<>0 then
  341. Clipboard^.Flags:=Clipboard^.Flags or efStoreContent
  342. else
  343. Clipboard^.Flags:=Clipboard^.Flags and not efStoreContent;
  344. OK:=Assigned(F);
  345. if OK then
  346. OK:=WriteFlags(F);
  347. if OK and ((DesktopFileFlags and dfHistoryLists)<>0) then
  348. OK:=WriteHistory(F);
  349. if OK and ((DesktopFileFlags and dfWatches)<>0) then
  350. OK:=WriteWatches(F);
  351. if OK and ((DesktopFileFlags and dfBreakpoints)<>0) then
  352. OK:=WriteBreakpoints(F);
  353. if OK and ((DesktopFileFlags and dfOpenWindows)<>0) then
  354. OK:=WriteOpenWindows(F);
  355. { no errors if no browser info available PM }
  356. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  357. OK:=WriteSymbols(F) or not Assigned(Modules);
  358. Dispose(F, Done);
  359. PopStatus;
  360. SaveDesktop:=OK;
  361. end;
  362. END.
  363. {
  364. $Log$
  365. Revision 1.12 1999-09-17 16:41:10 pierre
  366. * other stream error for Watches/Breakpoints corrected
  367. Revision 1.11 1999/09/17 16:28:58 pierre
  368. * ResWatches in WriteBreakpoints typo !
  369. Revision 1.10 1999/09/16 14:34:58 pierre
  370. + TBreakpoint and TWatch registering
  371. + WatchesCollection and BreakpointsCollection stored in desk file
  372. * Syntax highlighting was broken
  373. Revision 1.9 1999/09/07 09:23:00 pierre
  374. * no errors if no browser info available
  375. Revision 1.8 1999/08/16 18:25:16 peter
  376. * Adjusting the selection when the editor didn't contain any line.
  377. * Reserved word recognition redesigned, but this didn't affect the overall
  378. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  379. The syntax scanner loop is a bit slow but the main problem is the
  380. recognition of special symbols. Switching off symbol processing boosts
  381. the performance up to ca. 200%...
  382. * The editor didn't allow copying (for ex to clipboard) of a single character
  383. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  384. * Compiler Messages window (actually the whole desktop) did not act on any
  385. keypress when compilation failed and thus the window remained visible
  386. + Message windows are now closed upon pressing Esc
  387. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  388. only when neccessary
  389. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  390. + LineSelect (Ctrl+K+L) implemented
  391. * The IDE had problems closing help windows before saving the desktop
  392. Revision 1.7 1999/08/03 20:22:30 peter
  393. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  394. + Desktop saving should work now
  395. - History saved
  396. - Clipboard content saved
  397. - Desktop saved
  398. - Symbol info saved
  399. * syntax-highlight bug fixed, which compared special keywords case sensitive
  400. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  401. * with 'whole words only' set, the editor didn't found occourences of the
  402. searched text, if the text appeared previously in the same line, but didn't
  403. satisfied the 'whole-word' condition
  404. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  405. (ie. the beginning of the selection)
  406. * when started typing in a new line, but not at the start (X=0) of it,
  407. the editor inserted the text one character more to left as it should...
  408. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  409. * Shift shouldn't cause so much trouble in TCodeEditor now...
  410. * Syntax highlight had problems recognizing a special symbol if it was
  411. prefixed by another symbol character in the source text
  412. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  413. Revision 1.5 1999/06/30 23:58:13 pierre
  414. + BreakpointsList Window implemented
  415. with Edit/New/Delete functions
  416. + Individual breakpoint dialog with support for all types
  417. ignorecount and conditions
  418. (commands are not yet implemented, don't know if this wolud be useful)
  419. awatch and rwatch have problems because GDB does not annotate them
  420. I fixed v4.16 for this
  421. Revision 1.4 1999/04/15 08:58:05 peter
  422. * syntax highlight fixes
  423. * browser updates
  424. Revision 1.3 1999/04/07 21:55:45 peter
  425. + object support for browser
  426. * html help fixes
  427. * more desktop saving things
  428. * NODEBUG directive to exclude debugger
  429. Revision 1.2 1999/03/23 16:16:39 peter
  430. * linux fixes
  431. Revision 1.1 1999/03/23 15:11:28 peter
  432. * desktop saving things
  433. * vesa mode
  434. * preferences dialog
  435. }