fpide.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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,timeddlg,
  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. {$ifndef NODEBUG}
  774. { Leave the watch window in the bottom }
  775. if assigned(WatchesWindow) and (WatchesWindow^.GetState(sfVisible)) then
  776. R.B.Y:=Min(WatchesWindow^.Origin.Y,R.B.Y);
  777. {$endif NODEBUG}
  778. end;
  779. {****************************************************************************
  780. Switch Screens
  781. ****************************************************************************}
  782. procedure TIDEApp.ShowUserScreen;
  783. begin
  784. if Assigned(UserScreen) then
  785. UserScreen^.SaveIDEScreen;
  786. DoneSysError;
  787. DoneEvents;
  788. { DoneKeyboard should be called last to
  789. restore the keyboard correctly PM }
  790. {$ifndef go32v2}
  791. DoneScreen;
  792. {$endif ndef go32v2}
  793. DoneKeyboard;
  794. If UseMouse then
  795. DoneMouse
  796. else
  797. ButtonCount:=0;
  798. DoneDosMem;
  799. if Assigned(UserScreen) then
  800. UserScreen^.SwitchToConsoleScreen;
  801. end;
  802. procedure TIDEApp.ShowIDEScreen;
  803. begin
  804. if Assigned(UserScreen) then
  805. UserScreen^.SaveConsoleScreen;
  806. InitDosMem;
  807. InitKeyboard;
  808. If UseMouse then
  809. InitMouse
  810. else
  811. ButtonCount:=0;
  812. {$ifndef go32v2}
  813. InitScreen;
  814. {$endif ndef go32v2}
  815. {$ifdef win32}
  816. { write the empty screen to dummy console handle }
  817. UpdateScreen(true);
  818. {$endif ndef win32}
  819. InitEvents;
  820. InitSysError;
  821. CurDirChanged;
  822. {$ifndef win32}
  823. Message(Application,evBroadcast,cmUpdate,nil);
  824. {$endif win32}
  825. {$ifdef win32}
  826. // Win32ShowMouse;
  827. {$endif win32}
  828. if Assigned(UserScreen) then
  829. UserScreen^.SwitchBackToIDEScreen;
  830. {$ifdef win32}
  831. { This message was sent when the VideoBuffer was smaller
  832. than was the IdeApp thought => writes to random memory and random crashes... PM }
  833. Message(Application,evBroadcast,cmUpdate,nil);
  834. {$endif win32}
  835. {$ifdef Unix}
  836. SetKnownKeys;
  837. {$endif Unix}
  838. {$ifndef win32}
  839. {$ifndef go32v2}
  840. UpdateScreen(true);
  841. {$endif go32v2}
  842. {$endif win32}
  843. end;
  844. function TIDEApp.AutoSave: boolean;
  845. var IOK,SOK,DOK: boolean;
  846. begin
  847. IOK:=true; SOK:=true; DOK:=true;
  848. if (AutoSaveOptions and asEnvironment)<>0 then
  849. begin
  850. IOK:=WriteINIFile(false);
  851. if IOK=false then
  852. ErrorBox(error_saving_cfg_file,nil);
  853. end;
  854. if (AutoSaveOptions and asEditorFiles)<>0 then { was a typo here ("=0") - Gabor }
  855. SOK:=SaveAll;
  856. if (AutoSaveOptions and asDesktop)<>0 then
  857. begin
  858. { destory all help & browser windows - we don't want to store them }
  859. { UserScreenWindow is also not registered PM }
  860. DoCloseUserScreenWindow;
  861. {$IFNDEF NODEBUG}
  862. DoneDisassemblyWindow;
  863. {$ENDIF}
  864. CloseHelpWindows;
  865. CloseAllBrowsers;
  866. DOK:=SaveDesktop;
  867. if DOK=false then
  868. ErrorBox(error_saving_dsk_file,nil);
  869. end;
  870. AutoSave:=IOK and SOK and DOK;
  871. end;
  872. function TIDEApp.DoExecute(ProgramPath, Params, InFile,OutFile,ErrFile: string; ExecType: TExecType): boolean;
  873. var CanRun: boolean;
  874. ConsoleMode : TConsoleMode;
  875. {$ifndef Unix}
  876. PosExe: sw_integer;
  877. {$endif Unix}
  878. begin
  879. SaveCancelled:=false;
  880. CanRun:=AutoSave;
  881. if (CanRun=false) and (SaveCancelled=false) then
  882. CanRun:=true; { do not care about .DSK or .INI saving problems - just like TP }
  883. if CanRun then
  884. begin
  885. if UserScreen=nil then
  886. begin
  887. ErrorBox(error_user_screen_not_avail,nil);
  888. Exit;
  889. end;
  890. if ExecType<>exNoSwap then
  891. ShowUserScreen;
  892. SaveConsoleMode(ConsoleMode);
  893. if ExecType=exDosShell then
  894. WriteShellMsg
  895. else if ExecType<>exNoSwap then
  896. Writeln('Running "'+ProgramPath+' '+Params+'"');
  897. { DO NOT use COMSPEC for exe files as the
  898. ExitCode is lost in those cases PM }
  899. {$ifndef Unix}
  900. posexe:=Pos('.EXE',UpCaseStr(ProgramPath));
  901. { if programpath was three char long => bug }
  902. if (posexe>0) and (posexe=Length(ProgramPath)-3) then
  903. begin
  904. {$endif Unix}
  905. if (InFile='') and (OutFile='') and (ErrFile='') then
  906. DosExecute(ProgramPath,Params)
  907. else
  908. begin
  909. if ErrFile='' then
  910. ErrFile:='stderr';
  911. ExecuteRedir(ProgramPath,Params,InFile,OutFile,ErrFile);
  912. end;
  913. {$ifndef Unix}
  914. end
  915. else if (InFile='') and (OutFile='') and (ErrFile='') then
  916. DosExecute(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params)
  917. else
  918. begin
  919. if ErrFile='' then
  920. ErrFile:='stderr';
  921. ExecuteRedir(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params,
  922. InFile,OutFile,ErrFile);
  923. end;
  924. {$endif Unix}
  925. {$ifdef Unix}
  926. if (DebuggeeTTY='') and (OutFile='') and (ExecType<>exDosShell) then
  927. begin
  928. Write(' Press any key to return to IDE');
  929. InitKeyBoard;
  930. Keyboard.GetKeyEvent;
  931. while (Keyboard.PollKeyEvent<>0) do
  932. Keyboard.GetKeyEvent;
  933. DoneKeyboard;
  934. end;
  935. {$endif}
  936. RestoreConsoleMode(ConsoleMode);
  937. if ExecType<>exNoSwap then
  938. ShowIDEScreen;
  939. end;
  940. DoExecute:=CanRun;
  941. end;
  942. procedure TIDEApp.Update;
  943. begin
  944. SetCmdState([cmSaveAll],IsThereAnyEditor);
  945. SetCmdState([cmCloseAll,cmWindowList],IsThereAnyWindow);
  946. SetCmdState([cmTile,cmCascade],IsThereAnyVisibleWindow);
  947. SetCmdState([cmFindProcedure,cmObjects,cmModules,cmGlobals,cmSymbol],IsSymbolInfoAvailable);
  948. {$ifndef NODEBUG}
  949. SetCmdState([cmResetDebugger,cmUntilReturn],assigned(debugger) and debugger^.debuggee_started);
  950. {$endif}
  951. SetCmdState([cmToolsMsgNext,cmToolsMsgPrev],MessagesWindow<>nil);
  952. UpdateTools;
  953. UpdateRecentFileList;
  954. UpdatePrimaryFile;
  955. UpdateINIFile;
  956. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  957. end;
  958. procedure TIDEApp.SourceWindowClosed;
  959. begin
  960. if not IsClosing then
  961. Update;
  962. end;
  963. procedure TIDEApp.CurDirChanged;
  964. begin
  965. Message(Application,evBroadcast,cmUpdateTitle,nil);
  966. UpdatePrimaryFile;
  967. UpdateINIFile;
  968. UpdateMenu(MenuBar^.Menu);
  969. end;
  970. procedure TIDEApp.UpdatePrimaryFile;
  971. begin
  972. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmPrimaryFile),SmartPath(PrimaryFile));
  973. SetCmdState([cmClearPrimary],PrimaryFile<>'');
  974. if PrimaryFile<>'' then
  975. SetCmdState(CompileCmds,true);
  976. UpdateMenu(MenuBar^.Menu);
  977. end;
  978. procedure TIDEApp.UpdateINIFile;
  979. begin
  980. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmSaveINI),SmartPath(IniFileName));
  981. end;
  982. procedure TIDEApp.UpdateRecentFileList;
  983. var P: PMenuItem;
  984. {ID,}I: word;
  985. FileMenu: PMenuItem;
  986. begin
  987. { ID:=cmRecentFileBase;}
  988. FileMenu:=SearchSubMenu(MenuBar^.Menu,menuFile);
  989. repeat
  990. { Inc(ID);
  991. P:=SearchMenuItem(FileMenu^.SubMenu,ID);
  992. if FileMenu^.SubMenu^.Default=P then
  993. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  994. if P<>nil then RemoveMenuItem(FileMenu^.SubMenu,P);}
  995. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  996. if (P<>nil) then
  997. begin
  998. if (cmRecentFileBase<P^.Command) and (P^.Command<=cmRecentFileBase+MaxRecentFileCount) then
  999. begin
  1000. RemoveMenuItem(FileMenu^.SubMenu,P);
  1001. if FileMenu^.SubMenu^.Default=P then
  1002. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  1003. end
  1004. else
  1005. P:=nil;
  1006. end;
  1007. until P=nil;
  1008. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  1009. if (P<>nil) and IsSeparator(P) then
  1010. RemoveMenuItem(FileMenu^.SubMenu,P);
  1011. if RecentFileCount>0 then
  1012. AppendMenuItem(FileMenu^.SubMenu,NewLine(nil));
  1013. for I:=1 to RecentFileCount do
  1014. begin
  1015. P:=NewItem('~'+IntToStr(I)+'~ '+ShrinkPath(SmartPath(RecentFiles[I].FileName),27),' ',
  1016. kbNoKey,cmRecentFileBase+I,hcRecentFileBase+I,nil);
  1017. AppendMenuItem(FileMenu^.SubMenu,P);
  1018. end;
  1019. end;
  1020. procedure TIDEApp.UpdateTools;
  1021. var P: PMenuItem;
  1022. { ID,}I: word;
  1023. ToolsMenu: PMenuItem;
  1024. S1,S2,S3: string;
  1025. W: word;
  1026. begin
  1027. { ID:=cmToolsBase;}
  1028. ToolsMenu:=SearchSubMenu(MenuBar^.Menu,menuTools);
  1029. repeat
  1030. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1031. if (P<>nil) then
  1032. begin
  1033. if (cmToolsBase<P^.Command) and (P^.Command<=cmToolsBase+MaxToolCount) then
  1034. begin
  1035. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1036. if ToolsMenu^.SubMenu^.Default=P then
  1037. ToolsMenu^.SubMenu^.Default:=ToolsMenu^.SubMenu^.Items;
  1038. end
  1039. else
  1040. P:=nil;
  1041. end;
  1042. until P=nil;
  1043. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1044. if (P<>nil) and IsSeparator(P) then
  1045. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1046. if GetToolCount>0 then
  1047. AppendMenuItem(ToolsMenu^.SubMenu,NewLine(nil));
  1048. for I:=1 to GetToolCount do
  1049. begin
  1050. GetToolParams(I-1,S1,S2,S3,W);
  1051. P:=NewItem(S1,KillTilde(GetHotKeyName(W)),W,cmToolsBase+I,hcToolsBase+I,nil);
  1052. AppendMenuItem(ToolsMenu^.SubMenu,P);
  1053. end;
  1054. end;
  1055. procedure TIDEApp.DosShell;
  1056. var
  1057. s : string;
  1058. begin
  1059. {$ifdef Unix}
  1060. s:=GetEnv('SHELL');
  1061. if s='' then
  1062. if ExistsFile('/bin/sh') then
  1063. s:='/bin/sh';
  1064. {$else}
  1065. s:=GetEnv('COMSPEC');
  1066. if s='' then
  1067. if ExistsFile('c:\command.com') then
  1068. s:='c:\command.com'
  1069. else
  1070. begin
  1071. s:='command.com';
  1072. if Not LocateExeFile(s) then
  1073. s:='';
  1074. end;
  1075. {$endif}
  1076. if s='' then
  1077. ErrorBox(msg_errorexecutingshell,nil)
  1078. else
  1079. DoExecute(s, '', '', '', '', exDosShell);
  1080. { In case we have something that the compiler touched }
  1081. AskToReloadAllModifiedFiles;
  1082. end;
  1083. procedure TIDEApp.ShowReadme;
  1084. var R,R2: TRect;
  1085. D: PCenterDialog;
  1086. M: PFPMemo;
  1087. VSB: PScrollBar;
  1088. S: PFastBufStream;
  1089. begin
  1090. New(S, Init(ReadmeName, stOpenRead, 4096));
  1091. if S^.Status=stOK then
  1092. begin
  1093. R.Assign(0,0,63,18);
  1094. New(D, Init(R, 'Free Pascal IDE'));
  1095. with D^ do
  1096. begin
  1097. GetExtent(R);
  1098. R.Grow(-2,-2); Inc(R.B.Y);
  1099. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1100. New(VSB, Init(R2)); VSB^.GrowMode:=0; Insert(VSB);
  1101. New(M, Init(R,nil,VSB,nil));
  1102. M^.LoadFromStream(S);
  1103. M^.ReadOnly:=true;
  1104. Insert(M);
  1105. end;
  1106. InsertOK(D);
  1107. ExecuteDialog(D,nil);
  1108. end;
  1109. Dispose(S, Done);
  1110. end;
  1111. {$I FPMFILE.INC}
  1112. {$I FPMEDIT.INC}
  1113. {$I FPMSRCH.INC}
  1114. {$I FPMRUN.INC}
  1115. {$I FPMCOMP.INC}
  1116. {$I FPMDEBUG.INC}
  1117. {$I FPMTOOLS.INC}
  1118. {$I FPMOPTS.INC}
  1119. {$I FPMWND.INC}
  1120. {$I FPMHELP.INC}
  1121. {$I fpmansi.inc}
  1122. procedure TIDEApp.AddRecentFile(AFileName: string; CurX, CurY: sw_integer);
  1123. begin
  1124. if SearchRecentFile(AFileName)<>-1 then Exit;
  1125. if RecentFileCount>0 then
  1126. Move(RecentFiles[1],RecentFiles[2],SizeOf(RecentFiles[1])*Min(RecentFileCount,High(RecentFiles)-1));
  1127. if RecentFileCount<High(RecentFiles) then Inc(RecentFileCount);
  1128. with RecentFiles[1] do
  1129. begin
  1130. FileName:=AFileName;
  1131. LastPos.X:=CurX; LastPos.Y:=CurY;
  1132. end;
  1133. UpdateRecentFileList;
  1134. end;
  1135. function TIDEApp.SearchRecentFile(AFileName: string): integer;
  1136. var Idx,I: integer;
  1137. begin
  1138. Idx:=-1;
  1139. for I:=1 to RecentFileCount do
  1140. if UpcaseStr(AFileName)=UpcaseStr(RecentFiles[I].FileName) then
  1141. begin Idx:=I; Break; end;
  1142. SearchRecentFile:=Idx;
  1143. end;
  1144. procedure TIDEApp.RemoveRecentFile(Index: integer);
  1145. begin
  1146. if Index<RecentFileCount then
  1147. Move(RecentFiles[Index+1],RecentFiles[Index],SizeOf(RecentFiles[1])*(RecentFileCount-Index));
  1148. Dec(RecentFileCount);
  1149. UpdateRecentFileList;
  1150. end;
  1151. function TIDEApp.GetPalette: PPalette;
  1152. begin
  1153. GetPalette:=@AppPalette;
  1154. end;
  1155. function TIDEApp.IsClosing: Boolean;
  1156. begin
  1157. IsClosing:=InsideDone;
  1158. end;
  1159. destructor TIDEApp.Done;
  1160. begin
  1161. InsideDone:=true;
  1162. IsRunning:=false;
  1163. inherited Done;
  1164. Desktop:=nil;
  1165. RemoveBrowsersCollection;
  1166. DoneHelpSystem;
  1167. end;
  1168. END.
  1169. {
  1170. $Log$
  1171. Revision 1.35 2004-12-22 15:24:07 peter
  1172. * fixed NODEBUG
  1173. * set default target to the default target of the compiler
  1174. Revision 1.34 2004/12/19 20:38:35 hajny
  1175. + confirmation box after video mode switch (bug 2933)
  1176. Revision 1.33 2004/11/20 14:21:19 florian
  1177. * implemented reload menu item
  1178. * increased file history to 9 files
  1179. Revision 1.32 2004/11/14 21:45:28 florian
  1180. * fixed non working mouse after tools call
  1181. * better handling of source/target info
  1182. * more info in about dialog
  1183. * better info in compiler status dialiog
  1184. Revision 1.31 2004/11/08 21:55:09 peter
  1185. * fixed run directory
  1186. * Open dialog starts in dir of last editted file
  1187. Revision 1.30 2004/11/08 20:28:26 peter
  1188. * Breakpoints are now deleted when removed from source, disabling is
  1189. still possible from the breakpoint list
  1190. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  1191. FV and 1.9.x compilers
  1192. * Run directory added to Run menu
  1193. * Useless programinfo window removed
  1194. Revision 1.29 2004/11/06 22:02:49 peter
  1195. * fixed resize helptext
  1196. Revision 1.28 2004/11/04 20:57:59 peter
  1197. sysmsgs is always available
  1198. Revision 1.27 2004/11/02 23:53:19 peter
  1199. * fixed crashes with ide and 1.9.x
  1200. Revision 1.26 2003/09/29 14:36:59 peter
  1201. * win32 fixed
  1202. Revision 1.25 2003/01/31 11:01:00 pierre
  1203. * fix a bug in cmQuitApp handling
  1204. Revision 1.24 2002/12/12 00:06:41 pierre
  1205. Use fpregs unit
  1206. Revision 1.23 2002/11/28 12:58:15 pierre
  1207. + remote support additions
  1208. Revision 1.22 2002/10/12 19:43:07 hajny
  1209. * missing HasSignal conditionals added (needed for FPC/2)
  1210. Revision 1.21 2002/09/13 07:16:56 pierre
  1211. * avoid RTE 201 if closing file with position outside integer bounds
  1212. Revision 1.20 2002/09/09 06:58:51 pierre
  1213. + adapted to FastBufStream.readline method
  1214. Revision 1.19 2002/09/07 15:40:43 peter
  1215. * old logs removed and tabs fixed
  1216. Revision 1.18 2002/09/03 13:58:05 pierre
  1217. * fix bug about Recent file list not updated correctly when opening a file from the list
  1218. Revision 1.17 2002/08/26 13:02:15 pierre
  1219. * avoid a crash with fvision
  1220. Revision 1.16 2002/08/13 08:59:12 pierre
  1221. + Run menu changes depending on wether the debuggee is running or not
  1222. Revision 1.15 2002/07/12 14:17:39 pierre
  1223. * try to avoid memory corruption if UserScreen is smaller than IDE screen on win32
  1224. Revision 1.14 2002/06/10 08:12:17 pierre
  1225. * System messages must be handled by the application directly
  1226. Revision 1.13 2002/05/30 15:03:23 pierre
  1227. + ResizeApplication pethod for fvision
  1228. Revision 1.12 2002/05/29 22:38:13 pierre
  1229. Asciitab now in fvision
  1230. Revision 1.11 2002/04/25 13:34:17 pierre
  1231. * fix the disappearing desktop for win32
  1232. Revision 1.10 2002/04/12 08:58:22 pierre
  1233. + add RTE(250) for Ctrl+F11 in DEBUG mode
  1234. Revision 1.9 2002/03/20 14:52:01 pierre
  1235. + deliberatly generate a SIGSEGV if Alt+F11 is pressed (DEBUG code)
  1236. Revision 1.8 2002/01/24 09:21:42 pierre
  1237. * only disable Alt-X in Options|Compiler dialog
  1238. }