fpide.pas 43 KB

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