fpide.pas 43 KB

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