fpide.pas 44 KB

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