fpide.pas 42 KB

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