fpide.pas 42 KB

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