fpide.pas 41 KB

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