fpide.pas 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Main IDEApp object
  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 fpide;
  13. interface
  14. {$i globdir.inc}
  15. uses
  16. Objects,Drivers,Views,App,Gadgets,MsgBox,
  17. {$ifdef EDITORS}Editors,{$else}WEditor,WCEdit,{$endif}
  18. Comphook,Browcol,
  19. WHTMLScn,
  20. FPViews,FPSymbol,fpstring;
  21. type
  22. TExecType = (exNormal,exNoSwap,exDosShell);
  23. TIDEApp = object(TApplication)
  24. IsRunning : boolean;
  25. constructor Init;
  26. procedure InitDesktop; virtual;
  27. procedure InitMenuBar; virtual;
  28. procedure InitStatusLine; virtual;
  29. procedure Open(FileName: string);
  30. function OpenSearch(FileName: string) : boolean;
  31. function AskSaveAll: boolean;
  32. function SaveAll: boolean;
  33. function AutoSave: boolean;
  34. procedure Idle; virtual;
  35. procedure Update;
  36. procedure UpdateMode;
  37. procedure UpdateRunMenu(DebuggeeRunning : boolean);
  38. procedure UpdateTarget;
  39. procedure GetEvent(var Event: TEvent); virtual;
  40. procedure HandleEvent(var Event: TEvent); virtual;
  41. procedure GetTileRect(var R: TRect); virtual;
  42. function GetPalette: PPalette; virtual;
  43. procedure DosShell; {virtual;}
  44. procedure ShowReadme;
  45. destructor Done; virtual;
  46. procedure ShowUserScreen;
  47. procedure ShowIDEScreen;
  48. function IsClosing : boolean;
  49. private
  50. procedure NewEditor;
  51. procedure NewFromTemplate;
  52. procedure OpenRecentFile(RecentIndex: integer);
  53. procedure ChangeDir;
  54. procedure ShowClipboard;
  55. procedure FindProcedure;
  56. procedure Objects;
  57. procedure Modules;
  58. procedure Globals;
  59. procedure SearchSymbol;
  60. procedure Parameters;
  61. procedure DoStepOver;
  62. procedure DoTraceInto;
  63. procedure DoRun;
  64. procedure DoResetDebugger;
  65. procedure DoContToCursor;
  66. procedure DoContUntilReturn;
  67. procedure Target;
  68. procedure DoCompilerMessages;
  69. procedure DoPrimaryFile;
  70. procedure DoClearPrimary;
  71. procedure DoUserScreenWindow;
  72. procedure DoCloseUserScreenWindow;
  73. procedure DoUserScreen;
  74. procedure DoOpenGDBWindow;
  75. procedure DoToggleBreak;
  76. procedure DoShowCallStack;
  77. procedure DoShowBreakpointList;
  78. procedure DoShowWatches;
  79. procedure DoAddWatch;
  80. procedure DoShowRegisters;
  81. procedure DoShowFPU;
  82. function AskRecompileIfModified:boolean;
  83. procedure DoInformation;
  84. procedure Messages;
  85. procedure Calculator;
  86. procedure DoAsciiTable;
  87. procedure ExecuteTool(Idx: integer);
  88. procedure SetSwitchesMode;
  89. procedure DoCompilerSwitch;
  90. procedure MemorySizes;
  91. procedure DoLinkerSwitch;
  92. procedure DoDebuggerSwitch;
  93. procedure Directories;
  94. procedure Tools;
  95. procedure DoGrep;
  96. procedure Preferences;
  97. procedure EditorOptions(Editor: PEditor);
  98. procedure CodeComplete;
  99. procedure CodeTemplates;
  100. procedure BrowserOptions(Browser: PBrowserWindow);
  101. procedure DesktopOptions;
  102. procedure ResizeApplication(x, y : longint);
  103. procedure Mouse;
  104. procedure StartUp;
  105. procedure Colors;
  106. procedure OpenINI;
  107. procedure SaveINI;
  108. procedure SaveAsINI;
  109. procedure CloseAll;
  110. procedure WindowList;
  111. procedure HelpContents;
  112. procedure HelpHelpIndex;
  113. procedure HelpTopicSearch;
  114. procedure HelpPrevTopic;
  115. procedure HelpUsingHelp;
  116. procedure HelpFiles;
  117. procedure About;
  118. procedure CreateAnsiFile;
  119. public
  120. procedure SourceWindowClosed;
  121. private
  122. SaveCancelled: boolean;
  123. InsideDone : boolean;
  124. LastEvent: longint;
  125. function DoExecute(ProgramPath, Params, InFile, OutFile, ErrFile: string; ExecType: TExecType): boolean;
  126. procedure AddRecentFile(AFileName: string; CurX, CurY: integer);
  127. function SearchRecentFile(AFileName: string): integer;
  128. procedure RemoveRecentFile(Index: integer);
  129. procedure CurDirChanged;
  130. procedure UpdatePrimaryFile;
  131. procedure UpdateINIFile;
  132. procedure UpdateRecentFileList;
  133. procedure UpdateTools;
  134. end;
  135. procedure PutEvent(TargetView: PView; E: TEvent);
  136. procedure PutCommand(TargetView: PView; What, Command: Word; InfoPtr: Pointer);
  137. var
  138. IDEApp: TIDEApp;
  139. implementation
  140. uses
  141. {$ifdef HasSignal}
  142. fpcatch,
  143. {$endif HasSignal}
  144. {$ifdef WinClipSupported}
  145. WinClip,
  146. {$endif WinClipSupported}
  147. {$ifdef Unix}
  148. fpKeys,
  149. {$endif Unix}
  150. FpDpAnsi,WConsts,
  151. Video,Mouse,Keyboard,
  152. Compiler,Version,
  153. {$ifdef FVISION}
  154. FVConsts,
  155. {$else}
  156. Commands,HelpCtx,
  157. {$endif}
  158. Dos,Memory,Menus,Dialogs,StdDlg,
  159. {$ifndef FVISION}
  160. ColorSel,
  161. {$endif FVISION}
  162. Systems,
  163. WUtils,WHlpView,WViews,WHTMLHlp,WHelp,WConsole,
  164. FPConst,FPVars,FPUtils,FPSwitch,FPIni,FPIntf,FPCompil,FPHelp,
  165. FPTemplt,FPCalc,FPUsrScr,FPTools,{$ifndef NODEBUG}FPDebug,{$endif}FPRedir,
  166. FPDesk,FPCodCmp,FPCodTmp;
  167. type
  168. TTargetedEvent = record
  169. Target: PView;
  170. Event: TEvent;
  171. end;
  172. const
  173. TargetedEventHead : integer = 0;
  174. TargetedEventTail : integer = 0;
  175. var
  176. TargetedEvents : array[0..10] of TTargetedEvent;
  177. function IncTargetedEventPtr(I: integer): integer;
  178. begin
  179. Inc(I);
  180. if I>High(TargetedEvents) then I:=Low(TargetedEvents);
  181. IncTargetedEventPtr:=I;
  182. end;
  183. procedure PutEvent(TargetView: PView; E: TEvent);
  184. begin
  185. if IncTargetedEventPtr(TargetedEventHead)=TargetedEventTail then Exit;
  186. with TargetedEvents[TargetedEventHead] do
  187. begin
  188. Target:=TargetView;
  189. Event:=E;
  190. end;
  191. TargetedEventHead:=IncTargetedEventPtr(TargetedEventHead);
  192. end;
  193. procedure PutCommand(TargetView: PView; What, Command: Word; InfoPtr: Pointer);
  194. var E: TEvent;
  195. begin
  196. FillChar(E,Sizeof(E),0);
  197. E.What:=What;
  198. E.Command:=Command;
  199. E.InfoPtr:=InfoPtr;
  200. PutEvent(TargetView,E);
  201. end;
  202. function GetTargetedEvent(var P: PView; var E: TEvent): boolean;
  203. var OK: boolean;
  204. begin
  205. OK:=TargetedEventHead<>TargetedEventTail;
  206. if OK then
  207. begin
  208. with TargetedEvents[TargetedEventTail] do
  209. begin
  210. P:=Target;
  211. E:=Event;
  212. end;
  213. TargetedEventTail:=IncTargetedEventPtr(TargetedEventTail);
  214. end;
  215. GetTargetedEvent:=OK;
  216. end;
  217. function IDEUseSyntaxHighlight(Editor: PFileEditor): boolean; {$ifndef FPC}far;{$endif}
  218. begin
  219. IDEUseSyntaxHighlight:=(Editor^.FileName='') or MatchesFileList(NameAndExtOf(Editor^.FileName),HighlightExts);
  220. end;
  221. function IDEUseTabsPattern(Editor: PFileEditor): boolean; {$ifndef FPC}far;{$endif}
  222. begin
  223. { the commented code lead all new files
  224. to become with TAB use enabled which is wrong in my opinion PM }
  225. IDEUseTabsPattern:={(Editor^.FileName='') or }MatchesFileList(NameAndExtOf(Editor^.FileName),TabsPattern);
  226. end;
  227. constructor TIDEApp.Init;
  228. var R: TRect;
  229. begin
  230. {$ifndef EDITORS}
  231. {$ifdef TP}
  232. UseSyntaxHighlight:=IDEUseSyntaxHighlight;
  233. UseTabsPattern:=IDEUseTabsPattern;
  234. {$else TP}
  235. UseSyntaxHighlight:=@IDEUseSyntaxHighlight;
  236. UseTabsPattern:=@IDEUseTabsPattern;
  237. {$endif TP}
  238. {$endif}
  239. inherited Init;
  240. InitAdvMsgBox;
  241. InsideDone:=false;
  242. IsRunning:=true;
  243. MenuBar^.GetBounds(R); R.A.X:=R.B.X-8;
  244. New(ClockView, Init(R));
  245. ClockView^.GrowMode:=gfGrowLoX+gfGrowHiX;
  246. Application^.Insert(ClockView);
  247. New(ClipboardWindow, Init);
  248. Desktop^.Insert(ClipboardWindow);
  249. New(CalcWindow, Init); CalcWindow^.Hide;
  250. Desktop^.Insert(CalcWindow);
  251. New(CompilerMessageWindow, Init);
  252. CompilerMessageWindow^.Hide;
  253. Desktop^.Insert(CompilerMessageWindow);
  254. Message(@Self,evBroadcast,cmUpdate,nil);
  255. CurDirChanged;
  256. { heap viewer }
  257. GetExtent(R); Dec(R.B.X); R.A.X:=R.B.X-9; R.A.Y:=R.B.Y-1;
  258. New(HeapView, InitKb(R));
  259. if (StartupOptions and soHeapMonitor)=0 then HeapView^.Hide;
  260. Insert(HeapView);
  261. Drivers.ShowMouse;
  262. {$ifdef win32}
  263. // Win32ShowMouse;
  264. {$endif win32}
  265. end;
  266. procedure TIDEApp.InitDesktop;
  267. var
  268. R: TRect;
  269. begin
  270. GetExtent(R);
  271. Inc(R.A.Y);
  272. Dec(R.B.Y);
  273. Desktop:=New(PFPDesktop, Init(R));
  274. end;
  275. procedure TIDEApp.InitMenuBar;
  276. var R: TRect;
  277. WinPMI : PMenuItem;
  278. begin
  279. GetExtent(R); R.B.Y:=R.A.Y+1;
  280. WinPMI:=nil;
  281. {$ifdef WinClipSupported}
  282. if WinClipboardSupported then
  283. WinPMI:=NewLine(
  284. NewItem(menu_edit_copywin,'', kbNoKey, cmCopyWin, hcCopyWin,
  285. NewItem(menu_edit_pastewin,'', kbNoKey, cmPasteWin, hcPasteWin,
  286. nil)));
  287. {$endif WinClipSupported}
  288. MenuBar:=New(PAdvancedMenuBar, Init(R, NewMenu(
  289. NewSubMenu(menu_file,hcFileMenu, NewMenu(
  290. NewItem(menu_file_new,'',kbNoKey,cmNew,hcNew,
  291. NewItem(menu_file_template,'',kbNoKey,cmNewFromTemplate,hcNewFromTemplate,
  292. NewItem(menu_file_open,menu_key_file_open,kbF3,cmOpen,hcOpen,
  293. NewItem(menu_file_save,menu_key_file_save,kbF2,cmSave,hcSave,
  294. NewItem(menu_file_saveas,'',kbNoKey,cmSaveAs,hcSaveAs,
  295. NewItem(menu_file_saveall,'',kbNoKey,cmSaveAll,hcSaveAll,
  296. NewLine(
  297. NewItem(menu_file_changedir,'',kbNoKey,cmChangeDir,hcChangeDir,
  298. NewItem(menu_file_dosshell,'',kbNoKey,cmDOSShell,hcDOSShell,
  299. NewItem(menu_file_exit,menu_key_file_exit,kbNoKey,cmQuit,hcQuit,
  300. nil))))))))))),
  301. NewSubMenu(menu_edit,hcEditMenu, NewMenu(
  302. NewItem(menu_edit_undo,menu_key_edit_undo, kbAltBack, cmUndo, hcUndo,
  303. NewItem(menu_edit_redo,'', kbNoKey, cmRedo, hcRedo,
  304. {$ifdef DebugUndo}
  305. NewItem('~D~ump Undo','', kbNoKey, cmDumpUndo, hcUndo,
  306. NewItem('U~n~do All','', kbNoKey, cmUndoAll, hcUndo,
  307. NewItem('R~e~do All','', kbNoKey, cmRedoAll, hcRedo,
  308. {$endif DebugUndo}
  309. NewLine(
  310. NewItem(menu_edit_cut,menu_key_edit_cut, kbShiftDel, cmCut, hcCut,
  311. NewItem(menu_edit_copy,menu_key_edit_copy, kbCtrlIns, cmCopy, hcCut,
  312. NewItem(menu_edit_paste,menu_key_edit_paste, kbShiftIns, cmPaste, hcPaste,
  313. NewItem(menu_edit_clear,menu_key_edit_clear, kbCtrlDel, cmClear, hcClear,
  314. NewLine(
  315. NewItem(menu_edit_showclipboard,'', kbNoKey, cmShowClipboard, hcShowClipboard,
  316. WinPMI))))))
  317. {$ifdef DebugUndo}))){$endif DebugUndo}
  318. )))),
  319. NewSubMenu(menu_search,hcSearchMenu, NewMenu(
  320. NewItem(menu_search_find,'', kbNoKey, cmFind, hcFind,
  321. NewItem(menu_search_replace,'', kbNoKey, cmReplace, hcReplace,
  322. NewItem(menu_search_searchagain,'', kbNoKey, cmSearchAgain, hcSearchAgain,
  323. NewLine(
  324. NewItem(menu_search_jumpline,'', kbNoKey, cmJumpLine, hcGotoLine,
  325. NewItem(menu_search_findproc,'', kbNoKey, cmFindProcedure, hcFindProcedure,
  326. NewLine(
  327. NewItem(menu_search_objects,'', kbNoKey, cmObjects, hcObjects,
  328. NewItem(menu_search_modules,'', kbNoKey, cmModules, hcModules,
  329. NewItem(menu_search_globals,'', kbNoKey, cmGlobals, hcGlobals,
  330. NewLine(
  331. NewItem(menu_search_symbol,'', kbNoKey, cmSymbol, hcSymbol,
  332. nil))))))))))))),
  333. NewSubMenu(menu_run,hcRunMenu, NewMenu(
  334. NewItem(menu_run_run,menu_key_run_run, kbCtrlF9, cmRun, hcRun,
  335. NewItem(menu_run_stepover,menu_key_run_stepover, kbF8, cmStepOver, hcRun,
  336. NewItem(menu_run_traceinto,menu_key_run_traceinto, kbF7, cmTraceInto, hcRun,
  337. NewItem(menu_run_conttocursor,menu_key_run_conttocursor, kbF4, cmContToCursor, hcContToCursor,
  338. NewItem(menu_run_untilreturn,'', kbNoKey,cmUntilReturn,hcUntilReturn,
  339. NewItem(menu_run_parameters,'', kbNoKey, cmParameters, hcParameters,
  340. NewItem(menu_run_resetdebugger,menu_key_run_resetdebugger, kbCtrlF2, cmResetDebugger, hcResetDebugger,
  341. nil)))))))),
  342. NewSubMenu(menu_compile,hcCompileMenu, NewMenu(
  343. NewItem(menu_compile_compile,menu_key_compile_compile, kbAltF9, cmCompile, hcCompile,
  344. NewItem(menu_compile_make,menu_key_compile_make, kbF9, cmMake, hcMake,
  345. NewItem(menu_compile_build,'', kbNoKey, cmBuild, hcBuild,
  346. NewLine(
  347. NewItem(menu_compile_target,'', kbNoKey, cmTarget, hcTarget,
  348. NewItem(menu_compile_primaryfile,'', kbNoKey, cmPrimaryFile, hcPrimaryFile,
  349. NewItem(menu_compile_clearprimaryfile,'', kbNoKey, cmClearPrimary, hcClearPrimary,
  350. NewLine(
  351. NewItem(menu_compile_information,'', kbNoKey, cmInformation, hcInformation,
  352. NewItem(menu_compile_compilermessages,menu_key_compile_compilermessages, kbF12, cmCompilerMessages, hcCompilerMessages,
  353. nil))))))))))),
  354. NewSubMenu(menu_debug, hcDebugMenu, NewMenu(
  355. NewItem(menu_debug_output,'', kbNoKey, cmUserScreenWindow, hcUserScreenWindow,
  356. NewItem(menu_debug_userscreen,menu_key_debug_userscreen, kbAltF5, cmUserScreen, hcUserScreen,
  357. NewLine(
  358. NewItem(menu_debug_registers,'', kbNoKey, cmRegisters, hcRegistersWindow,
  359. NewItem(menu_debug_fpu_registers,'', kbNoKey, cmFPURegisters, hcRegistersWindow,
  360. NewItem(menu_debug_addwatch,menu_key_debug_addwatch, kbCtrlF7, cmAddWatch, hcAddWatch,
  361. NewItem(menu_debug_watches,'', kbNoKey, cmWatches, hcWatchesWindow,
  362. NewItem(menu_debug_breakpoint,menu_key_debug_breakpoint, kbCtrlF8, cmToggleBreakpoint, hcToggleBreakpoint,
  363. NewItem(menu_debug_breakpointlist,'', kbNoKey, cmBreakpointList, hcBreakpointList,
  364. NewItem(menu_debug_callstack,menu_key_debug_callstack, kbCtrlF3, cmStack, hcStackWindow,
  365. NewLine(
  366. NewItem(menu_debug_gdbwindow,'', kbNoKey, cmOpenGDBWindow, hcOpenGDBWindow,
  367. nil))))))))))))),
  368. NewSubMenu(menu_tools, hcToolsMenu, NewMenu(
  369. NewItem(menu_tools_messages,menu_key_tools_messages, kbF11, cmToolsMessages, hcToolsMessages,
  370. NewItem(menu_tools_msgnext,menu_key_tools_msgnext, kbAltF8, cmToolsMsgNext, hcToolsMsgNext,
  371. NewItem(menu_tools_msgprev,menu_key_tools_msgprev, kbAltF7, cmToolsMsgPrev, hcToolsMsgPrev,
  372. NewLine(
  373. NewItem(menu_tools_grep,menu_key_tools_grep, kbShiftF2, cmGrep, hcGrep,
  374. NewItem(menu_tools_calculator, '', kbNoKey, cmCalculator, hcCalculator,
  375. NewItem(menu_tools_asciitable, '', kbNoKey, cmAsciiTable, hcAsciiTable,
  376. nil)))))))),
  377. NewSubMenu(menu_options, hcOptionsMenu, NewMenu(
  378. NewItem(menu_options_mode,'', kbNoKey, cmSwitchesMode, hcSwitchesMode,
  379. NewItem(menu_options_compiler,'', kbNoKey, cmCompiler, hcCompiler,
  380. NewItem(menu_options_memory,'', kbNoKey, cmMemorySizes, hcMemorySizes,
  381. NewItem(menu_options_linker,'', kbNoKey, cmLinker, hcLinker,
  382. NewItem(menu_options_debugger,'', kbNoKey, cmDebugger, hcDebugger,
  383. NewItem(menu_options_directories,'', kbNoKey, cmDirectories, hcDirectories,
  384. NewItem(menu_options_browser,'',kbNoKey, cmBrowser, hcBrowser,
  385. NewItem(menu_options_tools,'', kbNoKey, cmTools, hcTools,
  386. NewLine(
  387. NewSubMenu(menu_options_env, hcEnvironmentMenu, NewMenu(
  388. NewItem(menu_options_env_preferences,'', kbNoKey, cmPreferences, hcPreferences,
  389. NewItem(menu_options_env_editor,'', kbNoKey, cmEditor, hcEditor,
  390. NewItem(menu_options_env_codecomplete,'', kbNoKey, cmCodeCompleteOptions, hcCodeCompleteOptions,
  391. NewItem(menu_options_env_codetemplates,'', kbNoKey, cmCodeTemplateOptions, hcCodeTemplateOptions,
  392. NewItem(menu_options_env_desktop,'', kbNoKey, cmDesktopOptions, hcDesktopOptions,
  393. NewItem(menu_options_env_mouse,'', kbNoKey, cmMouse, hcMouse,
  394. NewItem(menu_options_env_startup,'', kbNoKey, cmStartup, hcStartup,
  395. NewItem(menu_options_env_colors,'', kbNoKey, cmColors, hcColors,
  396. {$ifdef Unix}
  397. NewItem(menu_options_learn_keys,'', kbNoKey, cmKeys, hcKeys,
  398. {$endif Unix}
  399. nil{$ifdef Unix}){$endif Unix}))))))))),
  400. NewLine(
  401. NewItem(menu_options_open,'', kbNoKey, cmOpenINI, hcOpenINI,
  402. NewItem(menu_options_save,'', kbNoKey, cmSaveINI, hcSaveINI,
  403. NewItem(menu_options_saveas,'', kbNoKey, cmSaveAsINI, hcSaveAsINI,
  404. nil))))))))))))))),
  405. NewSubMenu(menu_window, hcWindowMenu, NewMenu(
  406. NewItem(menu_window_tile,'', kbNoKey, cmTile, hcTile,
  407. NewItem(menu_window_cascade,'', kbNoKey, cmCascade, hcCascade,
  408. NewItem(menu_window_closeall,'', kbNoKey, cmCloseAll, hcCloseAll,
  409. NewLine(
  410. NewItem(menu_window_resize,menu_key_window_resize, kbCtrlF5, cmResize, hcResize,
  411. NewItem(menu_window_zoom,menu_key_window_zoom, kbF5, cmZoom, hcZoom,
  412. NewItem(menu_window_next,menu_key_window_next, kbF6, cmNext, hcNext,
  413. NewItem(menu_window_previous,menu_key_window_previous, kbShiftF6, cmPrev, hcPrev,
  414. NewItem(menu_window_hide,menu_key_window_hide, kbCtrlF6, cmHide, hcHide,
  415. NewItem(menu_window_close,menu_key_window_close, kbAltF3, cmClose, hcClose,
  416. NewLine(
  417. NewItem(menu_window_list,menu_key_window_list, kbAlt0, cmWindowList, hcWindowList,
  418. NewItem(menu_window_update,'', kbNoKey, cmUpdate, hcUpdate,
  419. nil)))))))))))))),
  420. NewSubMenu(menu_help, hcHelpMenu, NewMenu(
  421. NewItem(menu_help_contents,'', kbNoKey, cmHelpContents, hcHelpContents,
  422. NewItem(menu_help_index,menu_key_help_helpindex, kbShiftF1, cmHelpIndex, hcHelpIndex,
  423. NewItem(menu_help_topicsearch,menu_key_help_topicsearch, kbCtrlF1, cmHelpTopicSearch, hcHelpTopicSearch,
  424. NewItem(menu_help_prevtopic,menu_key_help_prevtopic, kbAltF1, cmHelpPrevTopic, hcHelpPrevTopic,
  425. NewItem(menu_help_using,'',kbNoKey, cmHelpUsingHelp, hcHelpUsingHelp,
  426. NewItem(menu_help_files,'',kbNoKey, cmHelpFiles, hcHelpFiles,
  427. NewLine(
  428. NewItem(menu_help_about,'',kbNoKey, cmAbout, hcAbout,
  429. nil))))))))),
  430. nil)))))))))))));
  431. DisableCommands(EditorCmds+SourceCmds+CompileCmds);
  432. // Update; Desktop is still nil at that point ...
  433. end;
  434. procedure TIDEApp.InitStatusLine;
  435. var
  436. R: TRect;
  437. begin
  438. GetExtent(R);
  439. R.A.Y := R.B.Y - 1;
  440. StatusLine:=New(PIDEStatusLine, Init(R,
  441. NewStatusDef(hcDragging, hcDragging,
  442. NewStatusKey(status_help, kbF1, cmHelp,
  443. StdStatusKeys(
  444. NewStatusKey('~'#24#25#26#27+'~ Move', kbNoKey, 65535,
  445. NewStatusKey('~Shift+'#24#25#26#27+'~ Size', kbNoKey, 65535,
  446. NewStatusKey('~'#17+'ÄÙ~ Done', kbNoKey, 65535,
  447. NewStatusKey('~Esc~ Cancel', kbNoKey, 65535,
  448. nil)))))),
  449. NewStatusDef(hcStackWindow, hcStackWindow,
  450. NewStatusKey(status_help, kbF1, cmHelp,
  451. NewStatusKey(status_disassemble, kbAltI, cmDisassemble,
  452. StdStatusKeys(
  453. nil))),
  454. NewStatusDef(hcFirstCommand, hcLastNormalCommand,
  455. NewStatusKey(status_help, kbF1, cmHelp,
  456. StdStatusKeys(
  457. nil)),
  458. NewStatusDef(hcFirstNoAltXCommand, hcLastCommand,
  459. NewStatusKey(status_help, kbF1, cmHelp,
  460. NewStatusKey('', kbF10, cmMenu,
  461. NewStatusKey('', kbAltF3, cmClose,
  462. NewStatusKey('', kbF5, cmZoom,
  463. NewStatusKey('', kbCtrlF5, cmResize,
  464. NewStatusKey('', kbF6, cmNext,
  465. NewStatusKey('', kbShiftF6, cmPrev,
  466. nil))))))),
  467. NewStatusDef(hcHelpWindow, hcHelpWindow,
  468. NewStatusKey(status_help_on_help, kbF1, cmHelpUsingHelp,
  469. NewStatusKey(status_help_previoustopic, kbAltF1, cmHelpPrevTopic,
  470. NewStatusKey(status_help_index, kbShiftF1, cmHelpIndex,
  471. NewStatusKey(status_help_close, kbEsc, cmClose,
  472. StdStatusKeys(
  473. nil))))),
  474. NewStatusDef(hcSourceWindow, hcSourceWindow,
  475. NewStatusKey(status_help, kbF1, cmHelp,
  476. NewStatusKey(status_save, kbF2, cmSave,
  477. NewStatusKey(status_open, kbF3, cmOpen,
  478. NewStatusKey(status_compile, kbAltF9, cmCompile,
  479. NewStatusKey(status_make, kbF9, cmMake,
  480. NewStatusKey(status_localmenu, kbAltF10, cmLocalMenu,
  481. StdStatusKeys
  482. (
  483. nil))))))),
  484. NewStatusDef(hcASCIITableWindow, hcASCIITableWindow,
  485. NewStatusKey(status_help, kbF1, cmHelp,
  486. NewStatusKey(status_transferchar, kbCtrlEnter, cmTransfer,
  487. StdStatusKeys(
  488. nil))),
  489. NewStatusDef(hcMessagesWindow, hcMessagesWindow,
  490. NewStatusKey(status_help, kbF1, cmHelp,
  491. NewStatusKey(status_msggotosource, kbEnter, cmMsgGotoSource,
  492. NewStatusKey(status_msgtracksource, kbNoKey, cmMsgTrackSource,
  493. NewStatusKey(status_localmenu, kbAltF10, cmLocalMenu,
  494. NewStatusKey('', kbEsc, cmClose,
  495. StdStatusKeys(
  496. nil)))))),
  497. NewStatusDef(hcCalcWindow, hcCalcWindow,
  498. NewStatusKey(status_help, kbF1, cmHelp,
  499. NewStatusKey(status_close, kbEsc, cmClose,
  500. NewStatusKey(status_calculatorpaste, kbCtrlEnter, cmCalculatorPaste,
  501. StdStatusKeys(
  502. nil)))),
  503. NewStatusDef(0, $FFFF,
  504. NewStatusKey(status_help, kbF1, cmHelp,
  505. NewStatusKey(status_open, kbF3, cmOpen,
  506. NewStatusKey(status_compile, kbAltF9, cmCompile,
  507. NewStatusKey(status_make, kbF9, cmMake,
  508. NewStatusKey(status_localmenu, kbAltF10, cmLocalMenu,
  509. StdStatusKeys(
  510. nil)))))),
  511. nil))))))))))));
  512. end;
  513. procedure TIDEApp.Idle;
  514. begin
  515. inherited Idle;
  516. Message(Application,evIdle,0,nil);
  517. GiveUpTimeSlice;
  518. end;
  519. procedure TIDEApp.GetEvent(var Event: TEvent);
  520. var P: PView;
  521. begin
  522. { first of all dispatch queued targeted events }
  523. while GetTargetedEvent(P,Event) do
  524. P^.HandleEvent(Event);
  525. {$ifdef FVISION}
  526. {$ifdef HasSysMsgUnit}
  527. { Handle System events directly }
  528. Drivers.GetSystemEvent(Event); { Load system event }
  529. If (Event.What <> evNothing) Then
  530. Begin
  531. HandleEvent(Event);
  532. End;
  533. {$endif HasSysMsgUnit}
  534. {$endif FVISION}
  535. inherited GetEvent(Event);
  536. {$ifdef DEBUG}
  537. if (Event.What=evKeyDown) and (Event.KeyCode=kbAltF11) then
  538. begin
  539. Generate_SIGSEGV;
  540. end;
  541. if (Event.What=evKeyDown) and (Event.KeyCode=kbCtrlF11) then
  542. begin
  543. RunError(250);
  544. end;
  545. {$endif DEBUG}
  546. if (Event.What=evKeyDown) and (Event.KeyCode=kbAltF12) then
  547. begin
  548. CreateAnsiFile;
  549. ClearEvent(Event);
  550. end;
  551. if Event.What<>evNothing then
  552. LastEvent:=GetDosTicks
  553. else
  554. begin
  555. if abs(GetDosTicks-LastEvent)>SleepTimeOut then
  556. GiveUpTimeSlice;
  557. end;
  558. end;
  559. procedure TIDEApp.HandleEvent(var Event: TEvent);
  560. var DontClear: boolean;
  561. TempS: string;
  562. ForceDlg: boolean;
  563. {$ifdef HasSignal}
  564. CtrlCCatched : boolean;
  565. {$endif HasSignal}
  566. begin
  567. {$ifdef HasSignal}
  568. if (Event.What=evKeyDown) and (Event.keyCode=kbCtrlC) and
  569. (CtrlCPressed) then
  570. begin
  571. CtrlCCatched:=true;
  572. {$ifdef DEBUG}
  573. Writeln(stderr,'One CtrlC caught');
  574. {$endif DEBUG}
  575. end
  576. else
  577. CtrlCCatched:=false;
  578. {$endif HasSignal}
  579. case Event.What of
  580. evKeyDown :
  581. begin
  582. DontClear:=true;
  583. { just for debugging purposes }
  584. end;
  585. evCommand :
  586. begin
  587. DontClear:=false;
  588. case Event.Command of
  589. cmUpdate : Message(Application,evBroadcast,cmUpdate,nil);
  590. { -- File menu -- }
  591. cmNew : NewEditor;
  592. cmNewFromTemplate: NewFromTemplate;
  593. cmOpen : begin
  594. ForceDlg:=false;
  595. if (OpenFileName<>'') and
  596. ((DirOf(OpenFileName)='') or (Pos(ListSeparator,OpenFileName)<>0)) then
  597. begin
  598. TempS:=LocateSourceFile(OpenFileName,false);
  599. if TempS='' then
  600. ForceDlg:=true
  601. else
  602. OpenFileName:=TempS;
  603. end;
  604. if ForceDlg then
  605. OpenSearch(OpenFileName)
  606. else
  607. Open(OpenFileName);
  608. OpenFileName:='';
  609. end;
  610. cmSaveAll : SaveAll;
  611. cmChangeDir : ChangeDir;
  612. cmDOSShell : DOSShell;
  613. cmRecentFileBase..
  614. cmRecentFileBase+10
  615. : OpenRecentFile(Event.Command-cmRecentFileBase);
  616. { -- Edit menu -- }
  617. cmShowClipboard : ShowClipboard;
  618. { -- Search menu -- }
  619. cmFindProcedure : FindProcedure;
  620. cmObjects : Objects;
  621. cmModules : Modules;
  622. cmGlobals : Globals;
  623. cmSymbol : SearchSymbol;
  624. { -- Run menu -- }
  625. cmParameters : Parameters;
  626. cmStepOver : DoStepOver;
  627. cmTraceInto : DoTraceInto;
  628. cmRun : DoRun;
  629. cmResetDebugger : DoResetDebugger;
  630. cmContToCursor : DoContToCursor;
  631. cmUntilReturn : DoContUntilReturn;
  632. { -- Compile menu -- }
  633. cmCompile : DoCompile(cCompile);
  634. cmBuild : DoCompile(cBuild);
  635. cmMake : DoCompile(cMake);
  636. cmTarget : Target;
  637. cmPrimaryFile : DoPrimaryFile;
  638. cmClearPrimary : DoClearPrimary;
  639. cmInformation : DoInformation;
  640. cmCompilerMessages : DoCompilerMessages;
  641. { -- Debug menu -- }
  642. cmUserScreen : DoUserScreen;
  643. cmToggleBreakpoint : DoToggleBreak;
  644. cmStack : DoShowCallStack;
  645. cmBreakpointList : DoShowBreakpointList;
  646. cmWatches : DoShowWatches;
  647. cmAddWatch : DoAddWatch;
  648. cmOpenGDBWindow : DoOpenGDBWindow;
  649. cmRegisters : DoShowRegisters;
  650. cmFPURegisters : DoShowFPU;
  651. { -- Options menu -- }
  652. cmSwitchesMode : SetSwitchesMode;
  653. cmCompiler : DoCompilerSwitch;
  654. cmMemorySizes : MemorySizes;
  655. cmLinker : DoLinkerSwitch;
  656. cmDebugger : DoDebuggerSwitch;
  657. cmDirectories : Directories;
  658. cmTools : Tools;
  659. cmPreferences : Preferences;
  660. cmEditor : EditorOptions(nil);
  661. cmEditorOptions : EditorOptions(Event.InfoPtr);
  662. cmCodeTemplateOptions: CodeTemplates;
  663. cmCodeCompleteOptions: CodeComplete;
  664. cmBrowser : BrowserOptions(nil);
  665. cmBrowserOptions : BrowserOptions(Event.InfoPtr);
  666. cmMouse : Mouse;
  667. cmStartup : StartUp;
  668. cmDesktopOptions: DesktopOptions;
  669. cmColors : Colors;
  670. {$ifdef Unix}
  671. cmKeys : LearnKeysDialog;
  672. {$endif Unix}
  673. cmOpenINI : OpenINI;
  674. cmSaveINI : SaveINI;
  675. cmSaveAsINI : SaveAsINI;
  676. { -- Tools menu -- }
  677. cmToolsMessages : Messages;
  678. cmCalculator : Calculator;
  679. cmAsciiTable : DoAsciiTable;
  680. cmGrep : DoGrep;
  681. cmToolsBase+1..
  682. cmToolsBase+MaxToolCount
  683. : ExecuteTool(Event.Command-cmToolsBase);
  684. { -- Window menu -- }
  685. cmCloseAll : CloseAll;
  686. cmWindowList : WindowList;
  687. cmUserScreenWindow: DoUserScreenWindow;
  688. { -- Help menu -- }
  689. cmHelp,
  690. cmHelpContents : HelpContents;
  691. cmHelpIndex : HelpHelpIndex;
  692. { cmHelpTopicSearch: HelpTopicSearch;}
  693. cmHelpPrevTopic : HelpPrevTopic;
  694. cmHelpUsingHelp : HelpUsingHelp;
  695. cmHelpFiles : HelpFiles;
  696. cmAbout : About;
  697. cmShowReadme : ShowReadme;
  698. {$ifdef FVISION}
  699. cmResizeApp : ResizeApplication(Event.Id, Event.InfoWord);
  700. cmQuitApp : Message(@Self, evCommand, cmQuitApp, nil);
  701. {$endif FVISION}
  702. else DontClear:=true;
  703. end;
  704. if DontClear=false then ClearEvent(Event);
  705. end;
  706. evBroadcast :
  707. case Event.Command of
  708. cmSaveCancelled :
  709. SaveCancelled:=true;
  710. cmUpdateTools :
  711. UpdateTools;
  712. cmCommandSetChanged :
  713. UpdateMenu(MenuBar^.Menu);
  714. cmUpdate :
  715. Update;
  716. cmSourceWndClosing :
  717. begin
  718. with PSourceWindow(Event.InfoPtr)^ do
  719. if Editor^.FileName<>'' then
  720. AddRecentFile(Editor^.FileName,Editor^.CurPos.X,Editor^.CurPos.Y);
  721. {$ifndef NODEBUG}
  722. if assigned(Debugger) and (PView(Event.InfoPtr)=Debugger^.LastSource) then
  723. Debugger^.LastSource:=nil;
  724. {$endif}
  725. end;
  726. end;
  727. end;
  728. inherited HandleEvent(Event);
  729. {$ifdef HasSignal}
  730. { Reset flag if CrtlC was handled }
  731. if CtrlCCatched and (Event.What=evNothing) then
  732. begin
  733. CtrlCPressed:=false;
  734. {$ifdef DEBUG}
  735. Writeln(stderr,'One CtrlC handled');
  736. {$endif DEBUG}
  737. end;
  738. {$endif HasSignal}
  739. end;
  740. procedure TIDEApp.GetTileRect(var R: TRect);
  741. begin
  742. Desktop^.GetExtent(R);
  743. { Leave the compiler messages window in the bottom }
  744. if assigned(CompilerMessageWindow) and (CompilerMessageWindow^.GetState(sfVisible)) then
  745. R.B.Y:=Min(CompilerMessageWindow^.Origin.Y,R.B.Y);
  746. { Leave the messages window in the bottom }
  747. if assigned(MessagesWindow) and (MessagesWindow^.GetState(sfVisible)) then
  748. R.B.Y:=Min(MessagesWindow^.Origin.Y,R.B.Y);
  749. { Leave the watch window in the bottom }
  750. if assigned(WatchesWindow) and (WatchesWindow^.GetState(sfVisible)) then
  751. R.B.Y:=Min(WatchesWindow^.Origin.Y,R.B.Y);
  752. end;
  753. {****************************************************************************
  754. Switch Screens
  755. ****************************************************************************}
  756. procedure TIDEApp.ShowUserScreen;
  757. begin
  758. if Assigned(UserScreen) then
  759. UserScreen^.SaveIDEScreen;
  760. DoneSysError;
  761. DoneEvents;
  762. { DoneKeyboard should be called last to
  763. restore the keyboard correctly PM }
  764. {$ifndef go32v2}
  765. DoneScreen;
  766. {$endif ndef go32v2}
  767. DoneKeyboard;
  768. If UseMouse then
  769. DoneMouse
  770. else
  771. ButtonCount:=0;
  772. DoneDosMem;
  773. if Assigned(UserScreen) then
  774. UserScreen^.SwitchToConsoleScreen;
  775. end;
  776. procedure TIDEApp.ShowIDEScreen;
  777. begin
  778. if Assigned(UserScreen) then
  779. UserScreen^.SaveConsoleScreen;
  780. InitDosMem;
  781. InitKeyboard;
  782. If UseMouse then
  783. InitMouse
  784. else
  785. ButtonCount:=0;
  786. {$ifndef go32v2}
  787. InitScreen;
  788. {$endif ndef go32v2}
  789. {$ifdef win32}
  790. { write the empty screen to dummy console handle }
  791. UpdateScreen(true);
  792. {$endif ndef win32}
  793. InitEvents;
  794. InitSysError;
  795. CurDirChanged;
  796. {$ifndef win32}
  797. Message(Application,evBroadcast,cmUpdate,nil);
  798. {$endif win32}
  799. {$ifdef win32}
  800. Win32ShowMouse;
  801. {$endif win32}
  802. if Assigned(UserScreen) then
  803. UserScreen^.SwitchBackToIDEScreen;
  804. {$ifdef win32}
  805. { This message was sent when the VideoBuffer was smaller
  806. than was the IdeApp thought => writes to random memory and random crashes... PM }
  807. Message(Application,evBroadcast,cmUpdate,nil);
  808. {$endif win32}
  809. {$ifdef Unix}
  810. SetKnownKeys;
  811. {$endif Unix}
  812. {$ifndef win32}
  813. {$ifndef go32v2}
  814. UpdateScreen(true);
  815. {$endif go32v2}
  816. {$endif win32}
  817. end;
  818. function TIDEApp.AutoSave: boolean;
  819. var IOK,SOK,DOK: boolean;
  820. begin
  821. IOK:=true; SOK:=true; DOK:=true;
  822. if (AutoSaveOptions and asEnvironment)<>0 then
  823. begin
  824. IOK:=WriteINIFile(false);
  825. if IOK=false then
  826. ErrorBox(error_saving_cfg_file,nil);
  827. end;
  828. if (AutoSaveOptions and asEditorFiles)<>0 then { was a typo here ("=0") - Gabor }
  829. SOK:=SaveAll;
  830. if (AutoSaveOptions and asDesktop)<>0 then
  831. begin
  832. { destory all help & browser windows - we don't want to store them }
  833. { UserScreenWindow is also not registered PM }
  834. DoCloseUserScreenWindow;
  835. DoneDisassemblyWindow;
  836. CloseHelpWindows;
  837. CloseAllBrowsers;
  838. DOK:=SaveDesktop;
  839. if DOK=false then
  840. ErrorBox(error_saving_dsk_file,nil);
  841. end;
  842. AutoSave:=IOK and SOK and DOK;
  843. end;
  844. function TIDEApp.DoExecute(ProgramPath, Params, InFile,OutFile,ErrFile: string; ExecType: TExecType): boolean;
  845. var CanRun: boolean;
  846. ConsoleMode : TConsoleMode;
  847. {$ifndef Unix}
  848. PosExe: sw_integer;
  849. {$endif Unix}
  850. begin
  851. SaveCancelled:=false;
  852. CanRun:=AutoSave;
  853. if (CanRun=false) and (SaveCancelled=false) then
  854. CanRun:=true; { do not care about .DSK or .INI saving problems - just like TP }
  855. if CanRun then
  856. begin
  857. if UserScreen=nil then
  858. begin
  859. ErrorBox(error_user_screen_not_avail,nil);
  860. Exit;
  861. end;
  862. if ExecType<>exNoSwap then
  863. ShowUserScreen;
  864. SaveConsoleMode(ConsoleMode);
  865. if ExecType=exDosShell then
  866. WriteShellMsg;
  867. { DO NOT use COMSPEC for exe files as the
  868. ExitCode is lost in those cases PM }
  869. {$ifndef Unix}
  870. posexe:=Pos('.EXE',UpCaseStr(ProgramPath));
  871. { if programpath was three char long => bug }
  872. if (posexe>0) and (posexe=Length(ProgramPath)-3) then
  873. begin
  874. {$endif Unix}
  875. if (InFile='') and (OutFile='') and (ErrFile='') then
  876. DosExecute(ProgramPath,Params)
  877. else
  878. begin
  879. if ErrFile='' then
  880. ErrFile:='stderr';
  881. ExecuteRedir(ProgramPath,Params,InFile,OutFile,ErrFile);
  882. end;
  883. {$ifndef Unix}
  884. end
  885. else if (InFile='') and (OutFile='') and (ErrFile='') then
  886. DosExecute(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params)
  887. else
  888. begin
  889. if ErrFile='' then
  890. ErrFile:='stderr';
  891. ExecuteRedir(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params,
  892. InFile,OutFile,ErrFile);
  893. end;
  894. {$endif Unix}
  895. {$ifdef Unix}
  896. if (DebuggeeTTY='') and (OutFile='') and (ExecType<>exDosShell) then
  897. begin
  898. Write(' Press any key to return to IDE');
  899. InitKeyBoard;
  900. Keyboard.GetKeyEvent;
  901. while (Keyboard.PollKeyEvent<>0) do
  902. Keyboard.GetKeyEvent;
  903. DoneKeyboard;
  904. end;
  905. {$endif}
  906. RestoreConsoleMode(ConsoleMode);
  907. if ExecType<>exNoSwap then
  908. ShowIDEScreen;
  909. end;
  910. DoExecute:=CanRun;
  911. end;
  912. procedure TIDEApp.Update;
  913. begin
  914. SetCmdState([cmSaveAll],IsThereAnyEditor);
  915. SetCmdState([cmCloseAll,cmWindowList],IsThereAnyWindow);
  916. SetCmdState([cmTile,cmCascade],IsThereAnyVisibleWindow);
  917. SetCmdState([cmFindProcedure,cmObjects,cmModules,cmGlobals,cmSymbol{,cmInformation}],IsSymbolInfoAvailable);
  918. {$ifndef NODEBUG}
  919. SetCmdState([cmResetDebugger,cmUntilReturn],assigned(debugger) and debugger^.debuggee_started);
  920. {$endif}
  921. SetCmdState([cmToolsMsgNext,cmToolsMsgPrev],MessagesWindow<>nil);
  922. UpdateTools;
  923. UpdateRecentFileList;
  924. UpdatePrimaryFile;
  925. UpdateINIFile;
  926. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  927. end;
  928. procedure TIDEApp.SourceWindowClosed;
  929. begin
  930. if not IsClosing then
  931. Update;
  932. end;
  933. procedure TIDEApp.CurDirChanged;
  934. begin
  935. Message(Application,evBroadcast,cmUpdateTitle,nil);
  936. UpdatePrimaryFile;
  937. UpdateINIFile;
  938. UpdateMenu(MenuBar^.Menu);
  939. end;
  940. procedure TIDEApp.UpdatePrimaryFile;
  941. begin
  942. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmPrimaryFile),SmartPath(PrimaryFile));
  943. SetCmdState([cmClearPrimary],PrimaryFile<>'');
  944. if PrimaryFile<>'' then
  945. SetCmdState(CompileCmds,true);
  946. UpdateMenu(MenuBar^.Menu);
  947. Message(ProgramInfoWindow,evBroadcast,cmUpdate,nil);
  948. end;
  949. procedure TIDEApp.UpdateINIFile;
  950. begin
  951. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmSaveINI),SmartPath(IniFileName));
  952. end;
  953. procedure TIDEApp.UpdateRecentFileList;
  954. var P: PMenuItem;
  955. {ID,}I: word;
  956. FileMenu: PMenuItem;
  957. begin
  958. { ID:=cmRecentFileBase;}
  959. FileMenu:=SearchSubMenu(MenuBar^.Menu,menuFile);
  960. repeat
  961. { Inc(ID);
  962. P:=SearchMenuItem(FileMenu^.SubMenu,ID);
  963. if FileMenu^.SubMenu^.Default=P then
  964. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  965. if P<>nil then RemoveMenuItem(FileMenu^.SubMenu,P);}
  966. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  967. if (P<>nil) then
  968. begin
  969. if (cmRecentFileBase<P^.Command) and (P^.Command<=cmRecentFileBase+MaxRecentFileCount) then
  970. begin
  971. RemoveMenuItem(FileMenu^.SubMenu,P);
  972. if FileMenu^.SubMenu^.Default=P then
  973. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  974. end
  975. else
  976. P:=nil;
  977. end;
  978. until P=nil;
  979. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  980. if (P<>nil) and IsSeparator(P) then
  981. RemoveMenuItem(FileMenu^.SubMenu,P);
  982. if RecentFileCount>0 then
  983. AppendMenuItem(FileMenu^.SubMenu,NewLine(nil));
  984. for I:=1 to RecentFileCount do
  985. begin
  986. P:=NewItem('~'+IntToStr(I)+'~ '+ShrinkPath(SmartPath(RecentFiles[I].FileName),27),' ',
  987. kbNoKey,cmRecentFileBase+I,hcRecentFileBase+I,nil);
  988. AppendMenuItem(FileMenu^.SubMenu,P);
  989. end;
  990. end;
  991. procedure TIDEApp.UpdateTools;
  992. var P: PMenuItem;
  993. { ID,}I: word;
  994. ToolsMenu: PMenuItem;
  995. S1,S2,S3: string;
  996. W: word;
  997. begin
  998. { ID:=cmToolsBase;}
  999. ToolsMenu:=SearchSubMenu(MenuBar^.Menu,menuTools);
  1000. repeat
  1001. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1002. if (P<>nil) then
  1003. begin
  1004. if (cmToolsBase<P^.Command) and (P^.Command<=cmToolsBase+MaxToolCount) then
  1005. begin
  1006. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1007. if ToolsMenu^.SubMenu^.Default=P then
  1008. ToolsMenu^.SubMenu^.Default:=ToolsMenu^.SubMenu^.Items;
  1009. end
  1010. else
  1011. P:=nil;
  1012. end;
  1013. until P=nil;
  1014. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1015. if (P<>nil) and IsSeparator(P) then
  1016. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1017. if GetToolCount>0 then
  1018. AppendMenuItem(ToolsMenu^.SubMenu,NewLine(nil));
  1019. for I:=1 to GetToolCount do
  1020. begin
  1021. GetToolParams(I-1,S1,S2,S3,W);
  1022. P:=NewItem(S1,KillTilde(GetHotKeyName(W)),W,cmToolsBase+I,hcToolsBase+I,nil);
  1023. AppendMenuItem(ToolsMenu^.SubMenu,P);
  1024. end;
  1025. end;
  1026. procedure TIDEApp.DosShell;
  1027. var
  1028. s : string;
  1029. begin
  1030. {$ifdef Unix}
  1031. s:=GetEnv('SHELL');
  1032. if s='' then
  1033. if ExistsFile('/bin/sh') then
  1034. s:='/bin/sh';
  1035. {$else}
  1036. s:=GetEnv('COMSPEC');
  1037. if s='' then
  1038. if ExistsFile('c:\command.com') then
  1039. s:='c:\command.com'
  1040. else
  1041. begin
  1042. s:='command.com';
  1043. if Not LocateExeFile(s) then
  1044. s:='';
  1045. end;
  1046. {$endif}
  1047. if s='' then
  1048. ErrorBox(msg_errorexecutingshell,nil)
  1049. else
  1050. DoExecute(s, '', '', '', '', exDosShell);
  1051. { In case we have something that the compiler touched }
  1052. AskToReloadAllModifiedFiles;
  1053. end;
  1054. procedure TIDEApp.ShowReadme;
  1055. var R,R2: TRect;
  1056. D: PCenterDialog;
  1057. M: PFPMemo;
  1058. VSB: PScrollBar;
  1059. S: PBufStream;
  1060. begin
  1061. New(S, Init(ReadmeName, stOpenRead, 4096));
  1062. if S^.Status=stOK then
  1063. begin
  1064. R.Assign(0,0,63,18);
  1065. New(D, Init(R, 'Free Pascal IDE'));
  1066. with D^ do
  1067. begin
  1068. GetExtent(R);
  1069. R.Grow(-2,-2); Inc(R.B.Y);
  1070. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1071. New(VSB, Init(R2)); VSB^.GrowMode:=0; Insert(VSB);
  1072. New(M, Init(R,nil,VSB,nil));
  1073. M^.LoadFromStream(S);
  1074. M^.ReadOnly:=true;
  1075. Insert(M);
  1076. end;
  1077. InsertOK(D);
  1078. ExecuteDialog(D,nil);
  1079. end;
  1080. Dispose(S, Done);
  1081. end;
  1082. {$I FPMFILE.INC}
  1083. {$I FPMEDIT.INC}
  1084. {$I FPMSRCH.INC}
  1085. {$I FPMRUN.INC}
  1086. {$I FPMCOMP.INC}
  1087. {$I FPMDEBUG.INC}
  1088. {$I FPMTOOLS.INC}
  1089. {$I FPMOPTS.INC}
  1090. {$I FPMWND.INC}
  1091. {$I FPMHELP.INC}
  1092. {$I fpmansi.inc}
  1093. procedure TIDEApp.AddRecentFile(AFileName: string; CurX, CurY: integer);
  1094. begin
  1095. if SearchRecentFile(AFileName)<>-1 then Exit;
  1096. if RecentFileCount>0 then
  1097. Move(RecentFiles[1],RecentFiles[2],SizeOf(RecentFiles[1])*Min(RecentFileCount,High(RecentFiles)-1));
  1098. if RecentFileCount<High(RecentFiles) then Inc(RecentFileCount);
  1099. with RecentFiles[1] do
  1100. begin
  1101. FileName:=AFileName;
  1102. LastPos.X:=CurX; LastPos.Y:=CurY;
  1103. end;
  1104. UpdateRecentFileList;
  1105. end;
  1106. function TIDEApp.SearchRecentFile(AFileName: string): integer;
  1107. var Idx,I: integer;
  1108. begin
  1109. Idx:=-1;
  1110. for I:=1 to RecentFileCount do
  1111. if UpcaseStr(AFileName)=UpcaseStr(RecentFiles[I].FileName) then
  1112. begin Idx:=I; Break; end;
  1113. SearchRecentFile:=Idx;
  1114. end;
  1115. procedure TIDEApp.RemoveRecentFile(Index: integer);
  1116. begin
  1117. if Index<RecentFileCount then
  1118. Move(RecentFiles[Index+1],RecentFiles[Index],SizeOf(RecentFiles[1])*(RecentFileCount-Index));
  1119. Dec(RecentFileCount);
  1120. UpdateRecentFileList;
  1121. end;
  1122. function TIDEApp.GetPalette: PPalette;
  1123. var P: string;
  1124. begin
  1125. P:=AppPalette;
  1126. GetPalette:=@P;
  1127. end;
  1128. function TIDEApp.IsClosing: Boolean;
  1129. begin
  1130. IsClosing:=InsideDone;
  1131. end;
  1132. destructor TIDEApp.Done;
  1133. begin
  1134. InsideDone:=true;
  1135. IsRunning:=false;
  1136. inherited Done;
  1137. Desktop:=nil;
  1138. RemoveBrowsersCollection;
  1139. DoneHelpSystem;
  1140. end;
  1141. END.
  1142. {
  1143. $Log$
  1144. Revision 1.19 2002-09-07 15:40:43 peter
  1145. * old logs removed and tabs fixed
  1146. Revision 1.18 2002/09/03 13:58:05 pierre
  1147. * fix bug about Recent file list not updated correctly when opening a file from the list
  1148. Revision 1.17 2002/08/26 13:02:15 pierre
  1149. * avoid a crash with fvision
  1150. Revision 1.16 2002/08/13 08:59:12 pierre
  1151. + Run menu changes depending on wether the debuggee is running or not
  1152. Revision 1.15 2002/07/12 14:17:39 pierre
  1153. * try to avoid memory corruption if UserScreen is smaller than IDE screen on win32
  1154. Revision 1.14 2002/06/10 08:12:17 pierre
  1155. * System messages must be handled by the application directly
  1156. Revision 1.13 2002/05/30 15:03:23 pierre
  1157. + ResizeApplication pethod for fvision
  1158. Revision 1.12 2002/05/29 22:38:13 pierre
  1159. Asciitab now in fvision
  1160. Revision 1.11 2002/04/25 13:34:17 pierre
  1161. * fix the disappearing desktop for win32
  1162. Revision 1.10 2002/04/12 08:58:22 pierre
  1163. + add RTE(250) for Ctrl+F11 in DEBUG mode
  1164. Revision 1.9 2002/03/20 14:52:01 pierre
  1165. + deliberatly generate a SIGSEGV if Alt+F11 is pressed (DEBUG code)
  1166. Revision 1.8 2002/01/24 09:21:42 pierre
  1167. * only disable Alt-X in Options|Compiler dialog
  1168. }