fpide.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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 Windows}
  269. // WindowsShowMouse;
  270. {$endif Windows}
  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. end;
  580. procedure TIDEApp.GetEvent(var Event: TEvent);
  581. var P: PView;
  582. begin
  583. { first of all dispatch queued targeted events }
  584. while GetTargetedEvent(P,Event) do
  585. P^.HandleEvent(Event);
  586. { Handle System events directly }
  587. Drivers.GetSystemEvent(Event); { Load system event }
  588. If (Event.What <> evNothing) Then
  589. HandleEvent(Event);
  590. inherited GetEvent(Event);
  591. {$ifdef DEBUG}
  592. if (Event.What=evKeyDown) and (Event.KeyCode=kbAltF11) then
  593. begin
  594. {$ifdef HasSignal}
  595. Generate_SIGSEGV;
  596. {$else}
  597. Halt(1);
  598. {$endif}
  599. end;
  600. if (Event.What=evKeyDown) and (Event.KeyCode=kbCtrlF11) then
  601. begin
  602. RunError(250);
  603. end;
  604. {$endif DEBUG}
  605. if (Event.What=evKeyDown) and (Event.KeyCode=kbAltF12) then
  606. begin
  607. CreateAnsiFile;
  608. ClearEvent(Event);
  609. end;
  610. if Event.What<>evNothing then
  611. LastEvent:=GetDosTicks
  612. else
  613. begin
  614. if abs(GetDosTicks-LastEvent)>SleepTimeOut then
  615. GiveUpTimeSlice;
  616. end;
  617. end;
  618. procedure TIDEApp.HandleEvent(var Event: TEvent);
  619. var DontClear: boolean;
  620. TempS: string;
  621. ForceDlg: boolean;
  622. W : PSourceWindow;
  623. DS : DirStr;
  624. NS : NameStr;
  625. ES : ExtStr;
  626. {$ifdef HasSignal}
  627. CtrlCCatched : boolean;
  628. {$endif HasSignal}
  629. begin
  630. {$ifdef HasSignal}
  631. if (Event.What=evKeyDown) and (Event.keyCode=kbCtrlC) and
  632. (CtrlCPressed) then
  633. begin
  634. CtrlCCatched:=true;
  635. {$ifdef DEBUG}
  636. Writeln(stderr,'One Ctrl-C caught');
  637. {$endif DEBUG}
  638. end
  639. else
  640. CtrlCCatched:=false;
  641. {$endif HasSignal}
  642. case Event.What of
  643. evKeyDown :
  644. begin
  645. DontClear:=true;
  646. { just for debugging purposes }
  647. end;
  648. evCommand :
  649. begin
  650. DontClear:=false;
  651. case Event.Command of
  652. cmUpdate : Message(Application,evBroadcast,cmUpdate,nil);
  653. { -- File menu -- }
  654. cmNew : NewEditor;
  655. cmNewFromTemplate: NewFromTemplate;
  656. cmOpen : begin
  657. ForceDlg:=false;
  658. if (OpenFileName<>'') and
  659. ((DirOf(OpenFileName)='') or (Pos(ListSeparator,OpenFileName)<>0)) then
  660. begin
  661. TempS:=LocateSourceFile(OpenFileName,false);
  662. if TempS='' then
  663. ForceDlg:=true
  664. else
  665. OpenFileName:=TempS;
  666. end;
  667. if ForceDlg then
  668. OpenSearch(OpenFileName)
  669. else
  670. begin
  671. W:=LastSourceEditor;
  672. if assigned(W) then
  673. FSplit(W^.Editor^.FileName,DS,NS,ES)
  674. else
  675. DS:='';
  676. Open(OpenFileName,DS);
  677. end;
  678. OpenFileName:='';
  679. end;
  680. cmPrint : Print;
  681. cmPrinterSetup : PrinterSetup;
  682. cmSaveAll : SaveAll;
  683. cmChangeDir : ChangeDir;
  684. cmDOSShell : DOSShell;
  685. cmRecentFileBase..
  686. cmRecentFileBase+10
  687. : OpenRecentFile(Event.Command-cmRecentFileBase);
  688. { -- Edit menu -- }
  689. cmShowClipboard : ShowClipboard;
  690. { -- Search menu -- }
  691. cmFindProcedure : FindProcedure;
  692. cmObjects : Objects;
  693. cmModules : Modules;
  694. cmGlobals : Globals;
  695. cmSymbol : SearchSymbol;
  696. { -- Run menu -- }
  697. cmRunDir : RunDir;
  698. cmParameters : Parameters;
  699. cmStepOver : DoStepOver;
  700. cmTraceInto : DoTraceInto;
  701. cmRun : DoRun;
  702. cmResetDebugger : DoResetDebugger;
  703. cmContToCursor : DoContToCursor;
  704. cmUntilReturn : DoContUntilReturn;
  705. { -- Compile menu -- }
  706. cmCompile : DoCompile(cCompile);
  707. cmBuild : DoCompile(cBuild);
  708. cmMake : DoCompile(cMake);
  709. cmTarget : Target;
  710. cmPrimaryFile : DoPrimaryFile;
  711. cmClearPrimary : DoClearPrimary;
  712. cmCompilerMessages : DoCompilerMessages;
  713. { -- Debug menu -- }
  714. cmUserScreen : DoUserScreen;
  715. cmToggleBreakpoint : DoToggleBreak;
  716. cmStack : DoShowCallStack;
  717. cmDisassemble : DoShowDisassembly;
  718. cmBreakpointList : DoShowBreakpointList;
  719. cmWatches : DoShowWatches;
  720. cmAddWatch : DoAddWatch;
  721. cmOpenGDBWindow : DoOpenGDBWindow;
  722. cmRegisters : DoShowRegisters;
  723. cmFPURegisters : DoShowFPU;
  724. cmVectorRegisters : DoShowVector;
  725. { -- Options menu -- }
  726. cmSwitchesMode : SetSwitchesMode;
  727. cmCompiler : DoCompilerSwitch;
  728. cmMemorySizes : MemorySizes;
  729. cmLinker : DoLinkerSwitch;
  730. cmDebugger : DoDebuggerSwitch;
  731. {$ifdef SUPPORT_REMOTE}
  732. cmRemoteDialog : DoRemote;
  733. cmTransferRemote: TransferRemote;
  734. {$endif SUPPORT_REMOTE}
  735. cmDirectories : Directories;
  736. cmTools : Tools;
  737. cmPreferences : Preferences;
  738. cmEditor : EditorOptions(nil);
  739. cmEditorOptions : EditorOptions(Event.InfoPtr);
  740. cmCodeTemplateOptions: CodeTemplates;
  741. cmCodeCompleteOptions: CodeComplete;
  742. cmBrowser : BrowserOptions(nil);
  743. cmBrowserOptions : BrowserOptions(Event.InfoPtr);
  744. cmMouse : Mouse;
  745. cmStartup : StartUp;
  746. cmDesktopOptions: DesktopOptions;
  747. cmColors : Colors;
  748. {$ifdef Unix}
  749. cmKeys : LearnKeysDialog;
  750. {$endif Unix}
  751. cmOpenINI : OpenINI;
  752. cmSaveINI : SaveINI;
  753. cmSaveAsINI : SaveAsINI;
  754. { -- Tools menu -- }
  755. cmToolsMessages : Messages;
  756. cmCalculator : Calculator;
  757. cmAsciiTable : DoAsciiTable;
  758. cmGrep : DoGrep;
  759. cmToolsBase+1..
  760. cmToolsBase+MaxToolCount
  761. : ExecuteTool(Event.Command-cmToolsBase);
  762. { -- Window menu -- }
  763. cmCloseAll : CloseAll;
  764. cmWindowList : WindowList;
  765. cmUserScreenWindow: DoUserScreenWindow;
  766. { -- Help menu -- }
  767. cmHelp,
  768. cmHelpContents : HelpContents;
  769. cmHelpIndex : HelpHelpIndex;
  770. { cmHelpTopicSearch: HelpTopicSearch;}
  771. cmHelpPrevTopic : HelpPrevTopic;
  772. cmHelpUsingHelp : HelpUsingHelp;
  773. cmHelpFiles : HelpFiles;
  774. cmAbout : About;
  775. cmShowReadme : ShowReadme;
  776. cmResizeApp : ResizeApplication(Event.Id, Event.InfoWord);
  777. cmQuitApp : Message(@Self, evCommand, cmQuit, nil);
  778. else DontClear:=true;
  779. end;
  780. if DontClear=false then ClearEvent(Event);
  781. end;
  782. evBroadcast :
  783. case Event.Command of
  784. cmSaveCancelled :
  785. SaveCancelled:=true;
  786. cmUpdateTools :
  787. UpdateTools;
  788. cmCommandSetChanged :
  789. UpdateMenu(MenuBar^.Menu);
  790. cmUpdate :
  791. Update;
  792. cmSourceWndClosing :
  793. begin
  794. with PSourceWindow(Event.InfoPtr)^ do
  795. if Editor^.FileName<>'' then
  796. AddRecentFile(Editor^.FileName,Editor^.CurPos.X,Editor^.CurPos.Y);
  797. {$ifndef NODEBUG}
  798. if assigned(Debugger) and (PView(Event.InfoPtr)=Debugger^.LastSource) then
  799. Debugger^.LastSource:=nil;
  800. {$endif}
  801. end;
  802. end;
  803. end;
  804. inherited HandleEvent(Event);
  805. {$ifdef HasSignal}
  806. { Reset flag if CrtlC was handled }
  807. if CtrlCCatched and (Event.What=evNothing) then
  808. begin
  809. CtrlCPressed:=false;
  810. {$ifdef DEBUG}
  811. Writeln(stderr,'One CtrlC handled');
  812. {$endif DEBUG}
  813. end;
  814. {$endif HasSignal}
  815. end;
  816. procedure TIDEApp.GetTileRect(var R: TRect);
  817. begin
  818. Desktop^.GetExtent(R);
  819. { Leave the compiler messages window in the bottom }
  820. if assigned(CompilerMessageWindow) and (CompilerMessageWindow^.GetState(sfVisible)) then
  821. R.B.Y:=Min(CompilerMessageWindow^.Origin.Y,R.B.Y);
  822. { Leave the messages window in the bottom }
  823. if assigned(MessagesWindow) and (MessagesWindow^.GetState(sfVisible)) then
  824. R.B.Y:=Min(MessagesWindow^.Origin.Y,R.B.Y);
  825. {$ifndef NODEBUG}
  826. { Leave the watch window in the bottom }
  827. if assigned(WatchesWindow) and (WatchesWindow^.GetState(sfVisible)) then
  828. R.B.Y:=Min(WatchesWindow^.Origin.Y,R.B.Y);
  829. {$endif NODEBUG}
  830. end;
  831. {****************************************************************************
  832. Switch Screens
  833. ****************************************************************************}
  834. procedure TIDEApp.ShowUserScreen;
  835. begin
  836. if Assigned(UserScreen) then
  837. UserScreen^.SaveIDEScreen;
  838. DoneSysError;
  839. DoneEvents;
  840. { DoneKeyboard should be called last to
  841. restore the keyboard correctly PM }
  842. {$ifndef go32v2}
  843. DoneScreen;
  844. {$endif ndef go32v2}
  845. DoneKeyboard;
  846. If UseMouse then
  847. DoneMouse
  848. else
  849. ButtonCount:=0;
  850. { DoneDosMem;}
  851. if Assigned(UserScreen) then
  852. UserScreen^.SwitchToConsoleScreen;
  853. end;
  854. procedure TIDEApp.ShowIDEScreen;
  855. begin
  856. if Assigned(UserScreen) then
  857. UserScreen^.SaveConsoleScreen;
  858. { InitDosMem;}
  859. InitKeyboard;
  860. If UseMouse then
  861. InitMouse
  862. else
  863. ButtonCount:=0;
  864. {$ifndef go32v2}
  865. InitScreen;
  866. {$endif ndef go32v2}
  867. {$ifdef Windows}
  868. { write the empty screen to dummy console handle }
  869. UpdateScreen(true);
  870. {$endif ndef Windows}
  871. InitEvents;
  872. InitSysError;
  873. CurDirChanged;
  874. {$ifndef Windows}
  875. Message(Application,evBroadcast,cmUpdate,nil);
  876. {$endif Windows}
  877. {$ifdef Windows}
  878. // WindowsShowMouse;
  879. {$endif Windows}
  880. if Assigned(UserScreen) then
  881. UserScreen^.SwitchBackToIDEScreen;
  882. {$ifdef Windows}
  883. { This message was sent when the VideoBuffer was smaller
  884. than was the IdeApp thought => writes to random memory and random crashes... PM }
  885. Message(Application,evBroadcast,cmUpdate,nil);
  886. {$endif Windows}
  887. {$ifdef Unix}
  888. SetKnownKeys;
  889. {$endif Unix}
  890. {$ifndef Windows}
  891. {$ifndef go32v2}
  892. UpdateScreen(true);
  893. {$endif go32v2}
  894. {$endif Windows}
  895. end;
  896. function TIDEApp.AutoSave: boolean;
  897. var IOK,SOK,DOK: boolean;
  898. begin
  899. IOK:=true; SOK:=true; DOK:=true;
  900. if (AutoSaveOptions and asEnvironment)<>0 then
  901. begin
  902. IOK:=WriteINIFile(false);
  903. if IOK=false then
  904. ErrorBox(error_saving_cfg_file,nil);
  905. end;
  906. if (AutoSaveOptions and asEditorFiles)<>0 then { was a typo here ("=0") - Gabor }
  907. SOK:=SaveAll;
  908. if (AutoSaveOptions and asDesktop)<>0 then
  909. begin
  910. { destory all help & browser windows - we don't want to store them }
  911. { UserScreenWindow is also not registered PM }
  912. DoCloseUserScreenWindow;
  913. {$IFNDEF NODEBUG}
  914. DoneDisassemblyWindow;
  915. {$ENDIF}
  916. CloseHelpWindows;
  917. CloseAllBrowsers;
  918. DOK:=SaveDesktop;
  919. if DOK=false then
  920. ErrorBox(error_saving_dsk_file,nil);
  921. end;
  922. AutoSave:=IOK and SOK and DOK;
  923. end;
  924. function TIDEApp.DoExecute(ProgramPath, Params, InFile,OutFile,ErrFile: string; ExecType: TExecType): boolean;
  925. var CanRun: boolean;
  926. ConsoleMode : TConsoleMode;
  927. {$ifndef Unix}
  928. PosExe: sw_integer;
  929. {$endif Unix}
  930. begin
  931. SaveCancelled:=false;
  932. CanRun:=AutoSave;
  933. if (CanRun=false) and (SaveCancelled=false) then
  934. CanRun:=true; { do not care about .DSK or .INI saving problems - just like TP }
  935. if CanRun then
  936. begin
  937. if UserScreen=nil then
  938. begin
  939. ErrorBox(error_user_screen_not_avail,nil);
  940. Exit;
  941. end;
  942. if ExecType<>exNoSwap then
  943. ShowUserScreen;
  944. SaveConsoleMode(ConsoleMode);
  945. if ExecType=exDosShell then
  946. WriteShellMsg
  947. else if ExecType<>exNoSwap then
  948. Writeln('Running "'+ProgramPath+' '+Params+'"');
  949. { DO NOT use COMSPEC for exe files as the
  950. ExitCode is lost in those cases PM }
  951. {$ifndef Unix}
  952. posexe:=Pos('.EXE',UpCaseStr(ProgramPath));
  953. { if programpath was three char long => bug }
  954. if (posexe>0) and (posexe=Length(ProgramPath)-3) then
  955. begin
  956. {$endif Unix}
  957. if (InFile='') and (OutFile='') and (ErrFile='') then
  958. DosExecute(ProgramPath,Params)
  959. else
  960. begin
  961. if ErrFile='' then
  962. ErrFile:='stderr';
  963. ExecuteRedir(ProgramPath,Params,InFile,OutFile,ErrFile);
  964. end;
  965. {$ifndef Unix}
  966. end
  967. else if (InFile='') and (OutFile='') and (ErrFile='') then
  968. DosExecute(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params)
  969. else
  970. begin
  971. if ErrFile='' then
  972. ErrFile:='stderr';
  973. ExecuteRedir(GetEnv('COMSPEC'),'/C '+ProgramPath+' '+Params,
  974. InFile,OutFile,ErrFile);
  975. end;
  976. {$endif Unix}
  977. {$ifdef Unix}
  978. if (DebuggeeTTY='') and (OutFile='') and (ExecType<>exDosShell) then
  979. begin
  980. Write(' Press any key to return to IDE');
  981. InitKeyBoard;
  982. Keyboard.GetKeyEvent;
  983. while (Keyboard.PollKeyEvent<>0) do
  984. Keyboard.GetKeyEvent;
  985. DoneKeyboard;
  986. end;
  987. {$endif}
  988. RestoreConsoleMode(ConsoleMode);
  989. if ExecType<>exNoSwap then
  990. ShowIDEScreen;
  991. end;
  992. DoExecute:=CanRun;
  993. end;
  994. procedure TIDEApp.Update;
  995. begin
  996. SetCmdState([cmSaveAll],IsThereAnyEditor);
  997. SetCmdState([cmCloseAll,cmWindowList],IsThereAnyWindow);
  998. SetCmdState([cmTile,cmCascade],IsThereAnyVisibleWindow);
  999. SetCmdState([cmFindProcedure,cmObjects,cmModules,cmGlobals,cmSymbol],IsSymbolInfoAvailable);
  1000. {$ifndef NODEBUG}
  1001. SetCmdState([cmResetDebugger,cmUntilReturn],assigned(debugger) and debugger^.debuggee_started);
  1002. {$endif}
  1003. SetCmdState([cmToolsMsgNext,cmToolsMsgPrev],MessagesWindow<>nil);
  1004. UpdateTools;
  1005. UpdateRecentFileList;
  1006. UpdatePrimaryFile;
  1007. UpdateINIFile;
  1008. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  1009. end;
  1010. procedure TIDEApp.SourceWindowClosed;
  1011. begin
  1012. if not IsClosing then
  1013. Update;
  1014. end;
  1015. procedure TIDEApp.CurDirChanged;
  1016. begin
  1017. Message(Application,evBroadcast,cmUpdateTitle,nil);
  1018. UpdatePrimaryFile;
  1019. UpdateINIFile;
  1020. UpdateMenu(MenuBar^.Menu);
  1021. end;
  1022. procedure TIDEApp.UpdatePrimaryFile;
  1023. begin
  1024. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmPrimaryFile),SmartPath(PrimaryFile));
  1025. SetCmdState([cmClearPrimary],PrimaryFile<>'');
  1026. if PrimaryFile<>'' then
  1027. SetCmdState(CompileCmds,true);
  1028. UpdateMenu(MenuBar^.Menu);
  1029. end;
  1030. procedure TIDEApp.UpdateINIFile;
  1031. begin
  1032. SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmSaveINI),SmartPath(IniFileName));
  1033. end;
  1034. procedure TIDEApp.UpdateRecentFileList;
  1035. var P: PMenuItem;
  1036. {ID,}I: word;
  1037. FileMenu: PMenuItem;
  1038. begin
  1039. { ID:=cmRecentFileBase;}
  1040. FileMenu:=SearchSubMenu(MenuBar^.Menu,menuFile);
  1041. repeat
  1042. { Inc(ID);
  1043. P:=SearchMenuItem(FileMenu^.SubMenu,ID);
  1044. if FileMenu^.SubMenu^.Default=P then
  1045. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  1046. if P<>nil then RemoveMenuItem(FileMenu^.SubMenu,P);}
  1047. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  1048. if (P<>nil) then
  1049. begin
  1050. if (cmRecentFileBase<P^.Command) and (P^.Command<=cmRecentFileBase+MaxRecentFileCount) then
  1051. begin
  1052. RemoveMenuItem(FileMenu^.SubMenu,P);
  1053. if FileMenu^.SubMenu^.Default=P then
  1054. FileMenu^.SubMenu^.Default:=FileMenu^.SubMenu^.Items;
  1055. end
  1056. else
  1057. P:=nil;
  1058. end;
  1059. until P=nil;
  1060. P:=GetMenuItemBefore(FileMenu^.SubMenu,nil);
  1061. if (P<>nil) and IsSeparator(P) then
  1062. RemoveMenuItem(FileMenu^.SubMenu,P);
  1063. if RecentFileCount>0 then
  1064. AppendMenuItem(FileMenu^.SubMenu,NewLine(nil));
  1065. for I:=1 to RecentFileCount do
  1066. begin
  1067. P:=NewItem('~'+IntToStr(I)+'~ '+ShrinkPath(SmartPath(RecentFiles[I].FileName),27),' ',
  1068. kbNoKey,cmRecentFileBase+I,hcRecentFileBase+I,nil);
  1069. AppendMenuItem(FileMenu^.SubMenu,P);
  1070. end;
  1071. end;
  1072. procedure TIDEApp.UpdateTools;
  1073. var P: PMenuItem;
  1074. { ID,}I: word;
  1075. ToolsMenu: PMenuItem;
  1076. S1,S2,S3: string;
  1077. W: word;
  1078. begin
  1079. { ID:=cmToolsBase;}
  1080. ToolsMenu:=SearchSubMenu(MenuBar^.Menu,menuTools);
  1081. repeat
  1082. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1083. if (P<>nil) then
  1084. begin
  1085. if (cmToolsBase<P^.Command) and (P^.Command<=cmToolsBase+MaxToolCount) then
  1086. begin
  1087. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1088. if ToolsMenu^.SubMenu^.Default=P then
  1089. ToolsMenu^.SubMenu^.Default:=ToolsMenu^.SubMenu^.Items;
  1090. end
  1091. else
  1092. P:=nil;
  1093. end;
  1094. until P=nil;
  1095. P:=GetMenuItemBefore(ToolsMenu^.SubMenu,nil);
  1096. if (P<>nil) and IsSeparator(P) then
  1097. RemoveMenuItem(ToolsMenu^.SubMenu,P);
  1098. if GetToolCount>0 then
  1099. AppendMenuItem(ToolsMenu^.SubMenu,NewLine(nil));
  1100. for I:=1 to GetToolCount do
  1101. begin
  1102. GetToolParams(I-1,S1,S2,S3,W);
  1103. P:=NewItem(S1,KillTilde(GetHotKeyName(W)),W,cmToolsBase+I,hcToolsBase+I,nil);
  1104. AppendMenuItem(ToolsMenu^.SubMenu,P);
  1105. end;
  1106. end;
  1107. procedure TIDEApp.DosShell;
  1108. var
  1109. s : string;
  1110. begin
  1111. {$ifdef Unix}
  1112. s:=GetEnv('SHELL');
  1113. if s='' then
  1114. if ExistsFile('/bin/sh') then
  1115. s:='/bin/sh';
  1116. {$else}
  1117. s:=GetEnv('COMSPEC');
  1118. if s='' then
  1119. if ExistsFile('c:\command.com') then
  1120. s:='c:\command.com'
  1121. else
  1122. begin
  1123. s:='command.com';
  1124. if Not LocateExeFile(s) then
  1125. s:='';
  1126. end;
  1127. {$endif}
  1128. if s='' then
  1129. ErrorBox(msg_errorexecutingshell,nil)
  1130. else
  1131. DoExecute(s, '', '', '', '', exDosShell);
  1132. { In case we have something that the compiler touched }
  1133. AskToReloadAllModifiedFiles;
  1134. end;
  1135. procedure TIDEApp.ShowReadme;
  1136. var R,R2: TRect;
  1137. D: PCenterDialog;
  1138. M: PFPMemo;
  1139. VSB: PScrollBar;
  1140. S: PFastBufStream;
  1141. begin
  1142. New(S, Init(ReadmeName, stOpenRead, 4096));
  1143. if S^.Status=stOK then
  1144. begin
  1145. R.Assign(0,0,63,18);
  1146. New(D, Init(R, 'Free Pascal IDE'));
  1147. with D^ do
  1148. begin
  1149. GetExtent(R);
  1150. R.Grow(-2,-2); Inc(R.B.Y);
  1151. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1152. New(VSB, Init(R2)); VSB^.GrowMode:=0; Insert(VSB);
  1153. New(M, Init(R,nil,VSB,nil));
  1154. M^.LoadFromStream(S);
  1155. M^.ReadOnly:=true;
  1156. Insert(M);
  1157. end;
  1158. InsertOK(D);
  1159. ExecuteDialog(D,nil);
  1160. end;
  1161. Dispose(S, Done);
  1162. end;
  1163. {$I FPMFILE.INC}
  1164. {$I FPMEDIT.INC}
  1165. {$I FPMSRCH.INC}
  1166. {$I FPMRUN.INC}
  1167. {$I FPMCOMP.INC}
  1168. {$I FPMDEBUG.INC}
  1169. {$I FPMTOOLS.INC}
  1170. {$I FPMOPTS.INC}
  1171. {$I FPMWND.INC}
  1172. {$I FPMHELP.INC}
  1173. {$I fpmansi.inc}
  1174. procedure TIDEApp.AddRecentFile(AFileName: string; CurX, CurY: sw_integer);
  1175. begin
  1176. if SearchRecentFile(AFileName)<>-1 then Exit;
  1177. if RecentFileCount>0 then
  1178. Move(RecentFiles[1],RecentFiles[2],SizeOf(RecentFiles[1])*Min(RecentFileCount,High(RecentFiles)-1));
  1179. if RecentFileCount<High(RecentFiles) then Inc(RecentFileCount);
  1180. with RecentFiles[1] do
  1181. begin
  1182. FileName:=AFileName;
  1183. LastPos.X:=CurX; LastPos.Y:=CurY;
  1184. end;
  1185. UpdateRecentFileList;
  1186. end;
  1187. function TIDEApp.SearchRecentFile(AFileName: string): integer;
  1188. var Idx,I: integer;
  1189. begin
  1190. Idx:=-1;
  1191. for I:=1 to RecentFileCount do
  1192. if UpcaseStr(AFileName)=UpcaseStr(RecentFiles[I].FileName) then
  1193. begin Idx:=I; Break; end;
  1194. SearchRecentFile:=Idx;
  1195. end;
  1196. procedure TIDEApp.RemoveRecentFile(Index: integer);
  1197. begin
  1198. if Index<RecentFileCount then
  1199. Move(RecentFiles[Index+1],RecentFiles[Index],SizeOf(RecentFiles[1])*(RecentFileCount-Index));
  1200. Dec(RecentFileCount);
  1201. UpdateRecentFileList;
  1202. end;
  1203. function TIDEApp.GetPalette: PPalette;
  1204. begin
  1205. GetPalette:=@AppPalette;
  1206. end;
  1207. function TIDEApp.IsClosing: Boolean;
  1208. begin
  1209. IsClosing:=InsideDone;
  1210. end;
  1211. destructor TIDEApp.Done;
  1212. begin
  1213. InsideDone:=true;
  1214. IsRunning:=false;
  1215. inherited Done;
  1216. Desktop:=nil;
  1217. RemoveBrowsersCollection;
  1218. DoneHelpSystem;
  1219. end;
  1220. end.