fpide.pas 41 KB

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