2
0

fpide.pas 41 KB

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