fpide.pas 41 KB

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