fpide.pas 43 KB

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