/Source/HydroModeler 2.0/ConfigurationEditor/MainTab.cs

# · C# · 1862 lines · 1108 code · 293 blank · 461 comment · 90 complexity · 4ea1ca4846bba96739acf5586604bc44 MD5 · raw file

Large files are truncated click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using DotSpatial.Controls;
  10. using Oatc.OpenMI.Gui.Core;
  11. using System.Threading;
  12. using System.IO;
  13. using System.Diagnostics;
  14. using Microsoft.Win32;
  15. using System.Reflection;
  16. using System.Collections;
  17. namespace Oatc.OpenMI.Gui.ConfigurationEditor
  18. {
  19. public partial class MainTab : UserControl
  20. {
  21. #region Window controls
  22. private HScrollBar compositionHScrollBar;
  23. private PictureBox compositionBox;
  24. //private VScrollBar compositionVScrollBar;
  25. private MainMenu mainMenu1;
  26. private ToolStripMenuItem menuItem15;
  27. private ToolStripMenuItem menuItem17;
  28. private ToolStripMenuItem menuItem18;
  29. private ToolStripMenuItem menuFileNew;
  30. private ToolStripMenuItem menuFileOpen;
  31. private ToolStripMenuItem menuFileSave;
  32. private ToolStripMenuItem menuFileSaveAs;
  33. private ToolStripMenuItem menuFileExit;
  34. private ToolStripMenuItem menuEditModelAdd;
  35. private ToolStripMenuItem menuModelAttachTrigger;
  36. private ToolStripMenuItem menuHelpAbout;
  37. private ToolStripMenuItem menuFileReload;
  38. private ToolStripMenuItem menuViewModelProperties;
  39. private ToolStripMenuItem menuEditConnectionLinks;
  40. private ToolStripMenuItem menuFile;
  41. private ToolStripMenuItem menuEditRunProperties;
  42. private ToolStripMenuItem menuHelp;
  43. private ImageList imageList;
  44. private ToolStripMenuItem menuCompositionSpacer;
  45. private ToolStripMenuItem menuComposition;
  46. private System.Windows.Forms.ContextMenu contextMenu;
  47. private System.Windows.Forms.MenuItem contextConnectionEditLinks;
  48. private System.Windows.Forms.MenuItem contextModelAttachTrigger;
  49. private System.Windows.Forms.MenuItem contextRun;
  50. private System.Windows.Forms.MenuItem contextConnectionAdd;
  51. private System.Windows.Forms.MenuItem contextModelProperties;
  52. private System.Windows.Forms.MenuItem contextConnectionProperties;
  53. private System.Windows.Forms.MenuItem contextModelRemove;
  54. private System.Windows.Forms.MenuItem contextConnectionRemove;
  55. private System.Windows.Forms.MenuItem contextModelAdd;
  56. #endregion
  57. #region Member variables
  58. readonly Cursor _sourceCursor;
  59. readonly Cursor _targetCursor;
  60. bool _isAddingConnection = false;
  61. UIModel _sourceModel = null;
  62. bool _isMovingModel = false;
  63. Point _prevMouse;
  64. object _contextSelectedObject;
  65. readonly CompositionManager _composition;
  66. Point _compositionBoxPositionInArea;
  67. Rectangle _compositionArea;
  68. const string ApplicationTitle = "OATC OpenMI Editor 2.0";
  69. private ToolStripMenuItem menuHelpContents;
  70. private ToolStripMenuItem menuItem3;
  71. private ToolStripMenuItem menuOptions;
  72. private ToolStripMenuItem menuRegisterExtensions;
  73. private ToolStripMenuItem menuItem2;
  74. private ToolStripMenuItem menuEditConnectionAdd;
  75. private ToolStripMenuItem menuItem1;
  76. private ToolStripMenuItem menuItem4;
  77. private ToolStripMenuItem menuExamples;
  78. private ToolStripMenuItem menuExample1;
  79. private ToolStripMenuItem menuExample2;
  80. private ToolStripMenuItem menuExample3;
  81. private ToolStripMenuItem menuExample4;
  82. private ToolStripMenuItem menuItem5;
  83. private ToolStripMenuItem popup;
  84. // pre-created dialogs
  85. ModelDialog _modelDialog;
  86. ConnectionDialog _connectionDialog;
  87. AboutBox _aboutBox;
  88. RunProperties _runProperties;
  89. RunBox _runBox;
  90. //a toolbar button added by the plugin
  91. private ToolStripButton btnHydroModelerPlugin = null;
  92. //a menu item added by the plugin
  93. private ToolStripMenuItem mnuHydroModelerPlugin = null;
  94. //reference to the main application and it's UI items
  95. private IMapPluginArgs _mapArgs;
  96. // record the culture that the application starts in
  97. readonly System.Globalization.CultureInfo _cultureInfo = Application.CurrentCulture;
  98. #endregion
  99. /// <summary>
  100. /// Creates a new instance of <see cref="MainForm">MainForm</see> window.
  101. /// </summary>
  102. public MainTab(IMapPluginArgs args)
  103. {
  104. //
  105. // Required for Windows Form Designer support
  106. //
  107. _mapArgs = args;
  108. _prevMouse = new Point(0, 0);
  109. // create dialogs
  110. _modelDialog = new ModelDialog();
  111. //_connectionDialog = new ConnectionDialog();
  112. _aboutBox = new AboutBox();
  113. _runProperties = new RunProperties();
  114. _runBox = new RunBox();
  115. _compositionBoxPositionInArea = new Point(0, 0);
  116. InitializeComponent();
  117. _composition = new CompositionManager();
  118. _prevMouse = new Point(0, 0);
  119. //_sourceCursor = new Cursor(GetType(), "Source.cur");
  120. //_targetCursor = new Cursor(GetType(), "Target.cur");
  121. menuRegisterExtensions.Checked = Utils.AreFileExtensionsRegistered(Application.ExecutablePath);
  122. }
  123. #region Methods and properties
  124. /// <summary>
  125. /// Method is used to start application.
  126. /// </summary>
  127. /// <param name="args">Command-line arguments.</param>
  128. /// <remarks>Method proceeds all command-line args ("/opr %", "/reg", ...)
  129. /// and perform requested actions.</remarks>
  130. private static void ProcessCommandLineArgs( string[] args )
  131. {
  132. // read commad-line args
  133. string oprFilename = null;
  134. string omiFilename = null;
  135. bool mta = false;
  136. for( int i=0; i<args.Length; i++ )
  137. switch( args[i].ToLower() )
  138. {
  139. case "/opr":
  140. case "-opr":
  141. if( oprFilename!=null )
  142. throw( new Exception("-opr can be used only once.") );
  143. if( omiFilename!=null )
  144. throw( new Exception("-opr cannot be used together with -omi option.") );
  145. if( args.Length <= i+1 )
  146. throw( new Exception("-opr option must be followed by filename.") );
  147. oprFilename = args[i+1];
  148. i++;
  149. break;
  150. case "/omi":
  151. case "-omi":
  152. if( omiFilename!=null )
  153. throw( new Exception("-omi can be used only once.") );
  154. if( oprFilename!=null )
  155. throw( new Exception("-omi cannot be used together with -opr option.") );
  156. if( args.Length <= i+1 )
  157. throw( new Exception("-omi option must be followed by filename.") );
  158. omiFilename = args[i+1];
  159. i++;
  160. break;
  161. case "/reg":
  162. case "-reg":
  163. Utils.RegisterFileExtensions( Application.ExecutablePath );
  164. return;
  165. case "/unreg":
  166. case "-unreg":
  167. Utils.UnregisterFileExtensions();
  168. return;
  169. case "-mta":
  170. case "/mta":
  171. mta = true;
  172. break;
  173. case "-help":
  174. case "/help":
  175. case "-?":
  176. case "/?":
  177. case "--help":
  178. case "-h":
  179. case "/h":
  180. string help =
  181. "OmiEd command-line options:\n\n" +
  182. "Syntax: OmiEd.exe [-opr OPRFILE | -omi OMIFILE | -reg | -unreg | -help] [-mta]\n\n" +
  183. "Options:\n" +
  184. "-opr OPRFILE\tOpens OmiEd project from specific OPRFILE\n" +
  185. "-omi OMIFILE\tCreates a new composition and adds model from OMIFILE into it.\n" +
  186. "-reg\t\tRegisters OPR and OMI file extensions in Windows registry to be opened with this OmiEd executable.\n" +
  187. "-unreg\t\tDiscards all OPR and OMI file extension registrations from Windows registry.\n" +
  188. "-help\t\tShows this help.\n" +
  189. "-mta\t\tApplication creates and enters a multi-threaded apartment COM model at start.\n";
  190. MessageBox.Show( help, "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
  191. return;
  192. default:
  193. throw( new Exception("Unknown command-line option: "+args[i]) );
  194. }
  195. // do actions...
  196. // VS2005 fix
  197. // In VS2005 the main thread uses MTA by default, so we have to create new thread,
  198. // which will run the message loop, and set it's appartment state before it's started
  199. Thread thread = new Thread( new ParameterizedThreadStart( StartApplication) );
  200. thread.IsBackground = false;
  201. if( mta )
  202. {
  203. thread.SetApartmentState( ApartmentState.MTA );
  204. // NOTE: when using MTA, the OpenFileDialog (and maybe other things)
  205. // throws ThreadStateException ("Current thread must be set to single thread
  206. // apartment (STA) mode before OLE calls can be made. Ensure that your Main
  207. // function has STAThreadAttribute marked on it. This exception is only raised
  208. // if a debugger is attached to the process.")
  209. //
  210. // MTA is used only if really needed (we provide it as feature),
  211. // thus this statement is perfectly correct
  212. CheckForIllegalCrossThreadCalls = false;
  213. }
  214. else
  215. {
  216. thread.SetApartmentState( ApartmentState.STA );
  217. }
  218. thread.Start( new string[] { oprFilename, omiFilename } );
  219. }
  220. private static void StartApplication( object data )
  221. {
  222. try
  223. {
  224. string oprFilename = ( (string[]) data )[0];
  225. string omiFilename = ( (string[]) data )[1];
  226. if( oprFilename!=null )
  227. {
  228. // Open OPR project from file
  229. MainForm mainForm = new MainForm();
  230. FileInfo oprFile = new FileInfo( oprFilename );
  231. mainForm.OpenComposition(oprFile);
  232. Application.Run( mainForm );
  233. }
  234. else if( omiFilename!=null )
  235. {
  236. // Create new project with one OMI model
  237. MainForm mainForm = new MainForm();
  238. FileInfo fileInfo = new FileInfo( omiFilename );
  239. mainForm.AddModel( fileInfo );
  240. Application.Run( mainForm );
  241. }
  242. else
  243. Application.Run( new MainForm() );
  244. }
  245. catch (Exception ex)
  246. {
  247. Trace.TraceError("Start Application: " + ex.Message);
  248. }
  249. }
  250. /// <summary>
  251. /// Opens composition from OPR file.
  252. /// </summary>
  253. /// <param name="fullPath">Full path to OPR file.</param>
  254. private void OpenComposition(FileInfo oprFile)
  255. {
  256. try
  257. {
  258. _composition.Open(oprFile);
  259. UpdateTitle();
  260. CompositionUpdateArea();
  261. CompositionCenterView();
  262. }
  263. catch( Exception ex )
  264. {
  265. FinalCatchAndDisplay("Open Composition", ex);
  266. }
  267. }
  268. /// <summary>
  269. /// Adds one model to composition.
  270. /// </summary>
  271. /// <param name="fullPath">Full path to OMI file.</param>
  272. private void AddModel(FileInfo omiFile)
  273. {
  274. try
  275. {
  276. UIModel model = new UIModel();
  277. model.OmiDeserializeAndInitialize(omiFile);
  278. _composition.ModelAdd(model);
  279. if (_composition.Models.Count == 1)
  280. _composition.Models[0].IsTrigger = true;
  281. }
  282. catch( Exception ex )
  283. {
  284. FinalCatchAndDisplay("Cannot add " + omiFile.FullName, ex);
  285. }
  286. // Reset the culture every time a new model is added.
  287. // The new model may be of a different culture, we want to retain the original culture of the application,
  288. // which will be that of the User's computer.
  289. Application.CurrentCulture = _cultureInfo;
  290. CompositionUpdateArea();
  291. UpdateTitle();
  292. Invalidate();
  293. }
  294. /// <summary>
  295. /// Method calculates size of composition area and it's scroll-bars according to
  296. /// position of models' rectangles and size of the window.
  297. /// </summary>
  298. /// <remarks>
  299. /// This method is called if some model has moved, main window has resized or if new file was opened.
  300. /// </remarks>
  301. private void CompositionUpdateArea()
  302. {
  303. Point topLeft = new Point( 0, 0 ),
  304. bottomRight = new Point( 0, 0 );
  305. foreach( UIModel model in _composition.Models )
  306. {
  307. topLeft.X = Math.Min( topLeft.X, model.Rect.X );
  308. topLeft.Y = Math.Min( topLeft.Y, model.Rect.Y );
  309. bottomRight.X = Math.Max( bottomRight.X, model.Rect.X + model.Rect.Width );
  310. bottomRight.Y = Math.Max( bottomRight.Y, model.Rect.Y + model.Rect.Height );
  311. }
  312. // increase size of area
  313. topLeft.X -= compositionBox.Width / 2;
  314. topLeft.Y -= compositionBox.Height / 2;
  315. bottomRight.X += compositionBox.Width - compositionBox.Width / 2;
  316. bottomRight.Y += compositionBox.Height - compositionBox.Height / 2;
  317. _compositionArea = new Rectangle( topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y );
  318. // update scrollbars
  319. compositionHScrollBar.Minimum = _compositionArea.X;
  320. compositionHScrollBar.Maximum = _compositionArea.X + _compositionArea.Width;
  321. compositionHScrollBar.LargeChange = compositionBox.Width;
  322. //compositionHScrollBar.Value = compositionHScrollBar.Value; // don't change Value, but call ValueChange event
  323. compositionVScrollBar.Minimum = _compositionArea.Y;
  324. compositionVScrollBar.Maximum = _compositionArea.Y + _compositionArea.Height;
  325. compositionVScrollBar.LargeChange = compositionBox.Height;
  326. //compositionVScrollBar.Value = compositionVScrollBar.Value; // todo
  327. compositionScrollBar_ValueChanged(null, null);
  328. compositionBox.Invalidate();
  329. }
  330. /// <summary>
  331. /// Sets composition box to center.
  332. /// </summary>
  333. private void CompositionCenterView()
  334. {
  335. // todo...
  336. }
  337. private Point CompositionWindowPointToAreaPoint( Point point )
  338. {
  339. return( new Point(_compositionBoxPositionInArea.X+point.X, _compositionBoxPositionInArea.Y+point.Y) );
  340. }
  341. private Point CompositionAreaPointToWindowPoint( Point point )
  342. {
  343. return( new Point(point.X - _compositionBoxPositionInArea.X, point.Y - _compositionBoxPositionInArea.Y) );
  344. }
  345. private void UpdateTitle()
  346. {
  347. string path = "?.opr";
  348. string readOnly = string.Empty;
  349. if (_composition != null && _composition.FileOpr != null)
  350. {
  351. if (_composition.FileOpr.FullName.Length < 40)
  352. path = _composition.FileOpr.FullName;
  353. else
  354. path = _composition.FileOpr.FullName.Substring(
  355. _composition.FileOpr.FullName.LastIndexOf(Path.DirectorySeparatorChar) + 1);
  356. if (_composition.FileOpr.IsReadOnly)
  357. readOnly = ", READ ONLY";
  358. }
  359. Text = string.Format("{0}: {1}{2}{3}",
  360. ApplicationTitle, path,
  361. _composition.ShouldBeSaved ? " *" : "",
  362. readOnly);
  363. }
  364. /// <summary>
  365. /// If composition should be saved, this method shows message box, where the user can do it, can
  366. /// ignore it or can cancel current operation.
  367. /// </summary>
  368. /// <returns>Returns <c>true</c> if current operation can continue, or <c>false</c>
  369. /// if user pressed cancel button.</returns>
  370. private bool CheckIfSaved()
  371. {
  372. if( _composition.ShouldBeSaved )
  373. {
  374. switch( MessageBox.Show("The composition has been changed.\n\nDo you want to save the changes?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) )
  375. {
  376. case DialogResult.Yes:
  377. OnSave(null, null);
  378. return( !_composition.ShouldBeSaved );
  379. case DialogResult.No:
  380. return( true );
  381. default:
  382. return( false );
  383. }
  384. }
  385. return( true );
  386. }
  387. private void ShowLinkDialog( UIConnection link )
  388. {
  389. ConnectionDialog dlg = new ConnectionDialog(_composition.Models);
  390. dlg.PopulateDialog(link);
  391. if (dlg.ShowDialog(this) == DialogResult.OK)
  392. _composition.ShouldBeSaved = true;
  393. UpdateTitle();
  394. }
  395. private UIModel GetModel( int x, int y )
  396. {
  397. Point areaPoint = CompositionWindowPointToAreaPoint( new Point(x,y) );
  398. // search from last model to first for case some models are overlapping
  399. for( int i=_composition.Models.Count-1; i>=0; i-- )
  400. {
  401. UIModel model = (UIModel)_composition.Models[i];
  402. if( model.IsPointInside(areaPoint) )
  403. return( model );
  404. }
  405. return( null );
  406. }
  407. private UIConnection GetConnection( int x, int y )
  408. {
  409. Point areaPoint = CompositionWindowPointToAreaPoint( new Point(x,y) );
  410. for( int i=_composition.Connections.Count-1; i>=0; i-- )
  411. {
  412. UIConnection connection = (UIConnection)_composition.Connections[i];
  413. if( connection.IsOnConnectionLine(areaPoint) )
  414. return( connection );
  415. }
  416. return( null );
  417. }
  418. private void StopAddingConnection()
  419. {
  420. _isAddingConnection = false;
  421. compositionBox.Cursor = Cursors.Default;
  422. _sourceModel = null;
  423. }
  424. private void StopMovingModel()
  425. {
  426. _isMovingModel = false;
  427. foreach( UIModel model in _composition.Models )
  428. model.IsMoving = false;
  429. compositionBox.Invalidate();
  430. }
  431. private void StopAllActions()
  432. {
  433. StopAddingConnection();
  434. StopMovingModel();
  435. }
  436. #endregion
  437. #region MainForm event handlers
  438. private void MainForm_Load(object sender, EventArgs e)
  439. {
  440. MainForm_SizeChanged(sender, e);
  441. UpdateTitle();
  442. CompositionUpdateArea();
  443. }
  444. private void MainForm_DragDrop(object sender, DragEventArgs e)
  445. {
  446. MessageBox.Show("form1, dragDrop");
  447. }
  448. private void MainForm_SizeChanged(object sender, EventArgs e)
  449. {
  450. /*// resize all elements so they fit to window
  451. const int border = 5;
  452. const int scrollBarWidth = 16;
  453. // listBoxOutput
  454. listBoxOutput.Height = (ClientRectangle.Height * 3) / 10; // 30%
  455. listBoxOutput.Width = ClientRectangle.Width - 2*border;
  456. listBoxOutput.Top = ClientRectangle.Height - (listBoxOutput.Height+border);
  457. listBoxOutput.Left = border;
  458. //compositionBox.BackColor = Color.Brown; // todo
  459. // compositionBox
  460. compositionBox.Top = border;
  461. compositionBox.Left = border;
  462. compositionBox.Width = listBoxOutput.Width - scrollBarWidth;
  463. compositionBox.Height = ClientRectangle.Height - listBoxOutput.Height - scrollBarWidth - 3*border;
  464. // compositionVScrollBar
  465. compositionVScrollBar.Width = scrollBarWidth;
  466. compositionVScrollBar.Height = compositionBox.Height;
  467. compositionVScrollBar.Top = compositionBox.Top;
  468. compositionVScrollBar.Left = border + compositionBox.Width;
  469. // compositionHScrollBar
  470. compositionHScrollBar.Width = compositionBox.Width;
  471. compositionHScrollBar.Height = scrollBarWidth;
  472. compositionHScrollBar.Top = border + compositionBox.Height;
  473. compositionHScrollBar.Left = border;*/
  474. CompositionUpdateArea();
  475. }
  476. private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  477. {
  478. // if composition isn't saved, show message box, and maybe stop the closing
  479. e.Cancel = !CheckIfSaved();
  480. }
  481. private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
  482. {
  483. // ESC cancels adding connection
  484. if( _isAddingConnection && e.KeyChar == 27 )
  485. {
  486. StopAddingConnection();
  487. e.Handled = true;
  488. Invalidate();
  489. }
  490. }
  491. #endregion
  492. #region Main menu event handlers
  493. private void OnAddModels(object sender, EventArgs e)
  494. {
  495. try
  496. {
  497. StopAllActions();
  498. OpenFileDialog dlg = new OpenFileDialog();
  499. dlg.CheckFileExists = true;
  500. dlg.CheckPathExists = true;
  501. dlg.Title = "Add model(s)...";
  502. dlg.Filter = "OpenMI models (*.omi)|*.omi|All files|*.*";
  503. dlg.Multiselect = true;
  504. if (dlg.ShowDialog(this) != DialogResult.OK)
  505. return;
  506. string[] files = new string[dlg.FileNames.Length];
  507. dlg.FileNames.CopyTo(files, 0);
  508. dlg.Dispose();
  509. try
  510. {
  511. Cursor.Current = Cursors.WaitCursor;
  512. Refresh();
  513. foreach (string filename in files)
  514. AddModel(new FileInfo(filename));
  515. }
  516. finally
  517. {
  518. Cursor.Current = Cursors.Default;
  519. }
  520. }
  521. catch( Exception ex )
  522. {
  523. FinalCatchAndDisplay("AddModels", ex);
  524. }
  525. }
  526. private void OnAttachTrigger(object sender, EventArgs e)
  527. {
  528. try
  529. {
  530. StopAllActions();
  531. if (_contextSelectedObject != null
  532. && _contextSelectedObject is UIModel)
  533. {
  534. foreach (UIModel model in _composition.Models)
  535. model.IsTrigger = false;
  536. ((UIModel)_contextSelectedObject).IsTrigger = true;
  537. }
  538. CompositionUpdateArea();
  539. }
  540. catch (Exception ex)
  541. {
  542. FinalCatchAndDisplay("Attach Trigger", ex);
  543. }
  544. }
  545. private void OnRun(object sender, EventArgs e)
  546. {
  547. try
  548. {
  549. StopAllActions();
  550. if (_composition.ShouldBeSaved)
  551. _composition.Save();
  552. Run run = new Run();
  553. run.Initialise(_composition.FileOpr.FullName);
  554. run.ShowDialog();
  555. }
  556. catch( Exception ex )
  557. {
  558. FinalCatchAndDisplay("Run", ex);
  559. }
  560. }
  561. private void OnNew(object sender, EventArgs e)
  562. {
  563. try
  564. {
  565. StopAllActions();
  566. if( !CheckIfSaved() )
  567. return;
  568. _composition.Initialize();
  569. UpdateTitle();
  570. CompositionUpdateArea();
  571. }
  572. catch (Exception ex)
  573. {
  574. FinalCatchAndDisplay("New", ex);
  575. }
  576. }
  577. private void OnOpen(object sender, EventArgs e)
  578. {
  579. try
  580. {
  581. StopAllActions();
  582. if( !CheckIfSaved() )
  583. return;
  584. OpenFileDialog dlg = new OpenFileDialog();
  585. dlg.Filter = "OmiEd projects (*.opr)|*.opr|All files|*.*";
  586. dlg.Multiselect = false;
  587. dlg.CheckFileExists = true;
  588. dlg.CheckPathExists = true;
  589. dlg.Title = "Open project...";
  590. if (dlg.ShowDialog(this) != DialogResult.OK)
  591. return;
  592. FileInfo oprFile = new FileInfo(dlg.FileName);
  593. dlg.Dispose();
  594. try
  595. {
  596. Cursor.Current = Cursors.WaitCursor;
  597. Refresh();
  598. OpenComposition(oprFile);
  599. UpdateTitle();
  600. CompositionUpdateArea();
  601. }
  602. finally
  603. {
  604. Cursor.Current = Cursors.Default;
  605. }
  606. }
  607. catch (Exception ex)
  608. {
  609. FinalCatchAndDisplay("Open", ex);
  610. }
  611. }
  612. private void OnSave(object sender, EventArgs e)
  613. {
  614. if (_composition.FileOpr == null
  615. || _composition.FileOpr.IsReadOnly)
  616. {
  617. OnSaveAs(sender, e);
  618. return;
  619. }
  620. try
  621. {
  622. StopAllActions();
  623. _composition.Save();
  624. UpdateTitle();
  625. }
  626. catch (Exception ex)
  627. {
  628. FinalCatchAndDisplay("Save", ex);
  629. }
  630. }
  631. private void OnSaveAs(object sender, EventArgs e)
  632. {
  633. try
  634. {
  635. SaveFileDialog dlg = new SaveFileDialog();
  636. dlg.Filter = "Compositions (*.opr)|*.opr|All files|*.*";
  637. dlg.ValidateNames = true;
  638. dlg.Title = "Save As ...";
  639. dlg.AddExtension = true;
  640. dlg.OverwritePrompt = true;
  641. dlg.FileName = _composition.FileOpr != null
  642. ? _composition.FileOpr.FullName : "";
  643. if( dlg.ShowDialog( this ) != DialogResult.OK )
  644. return;
  645. FileInfo fi = new FileInfo(dlg.FileName);
  646. dlg.Dispose();
  647. StopAllActions();
  648. _composition.SaveAs(fi);
  649. UpdateTitle();
  650. }
  651. catch (Exception ex)
  652. {
  653. FinalCatchAndDisplay("SaveAs", ex);
  654. }
  655. }
  656. private void OnReOpen(object sender, EventArgs e)
  657. {
  658. try
  659. {
  660. StopAllActions();
  661. if (!CheckIfSaved())
  662. return;
  663. _composition.ReOpen();
  664. UpdateTitle();
  665. }
  666. catch (Exception ex)
  667. {
  668. FinalCatchAndDisplay("ReOpen", ex);
  669. }
  670. }
  671. void FinalCatchAndDisplay(string task, Exception e)
  672. {
  673. string s = string.Format("Task:\n\n{0}\n\nReason:\n\n{1}",
  674. task, Utils.ToString(e));
  675. Trace.TraceError(s);
  676. MessageBox.Show(s, "Operation Failed",
  677. MessageBoxButtons.OK, MessageBoxIcon.Error);
  678. if (_composition != null)
  679. _composition.Initialize();
  680. }
  681. private void menuFileExit_Click(object sender, EventArgs e)
  682. {
  683. StopAllActions();
  684. //Close();
  685. }
  686. private void OnMenuConnectionAdd(object sender, EventArgs e)
  687. {
  688. try
  689. {
  690. StopAllActions();
  691. _isAddingConnection = true;
  692. compositionBox.Cursor = _sourceCursor;
  693. }
  694. catch (Exception ex)
  695. {
  696. FinalCatchAndDisplay("View Model Properties", ex);
  697. }
  698. }
  699. private void OnViewModelProperties(object sender, EventArgs e)
  700. {
  701. try
  702. {
  703. StopAllActions();
  704. ModelDialog modelDialog = new ModelDialog();
  705. modelDialog.PopulateDialog( _composition.Models );
  706. modelDialog.ShowDialog( this );
  707. }
  708. catch (Exception ex)
  709. {
  710. FinalCatchAndDisplay("View Model Properties", ex);
  711. }
  712. }
  713. private void menuRegisterExtensions_Click(object sender, EventArgs e)
  714. {
  715. if( menuRegisterExtensions.Checked )
  716. {
  717. Utils.UnregisterFileExtensions();
  718. menuRegisterExtensions.Checked = false;
  719. }
  720. else
  721. {
  722. Utils.RegisterFileExtensions( Application.ExecutablePath );
  723. menuRegisterExtensions.Checked = true;
  724. }
  725. }
  726. private void OnHelpAbout(object sender, EventArgs e)
  727. {
  728. try
  729. {
  730. StopAllActions();
  731. AboutBox aboutBox = new AboutBox();
  732. aboutBox.ShowDialog(this);
  733. }
  734. catch (Exception ex)
  735. {
  736. FinalCatchAndDisplay("Help About", ex);
  737. }
  738. }
  739. private void OnHelp(object sender, EventArgs e)
  740. {
  741. try
  742. {
  743. ShopHelp(HelpFormat.pdf);
  744. }
  745. catch (Exception ex)
  746. {
  747. FinalCatchAndDisplay("Help", ex);
  748. }
  749. }
  750. enum HelpFormat { chm = 0, pdf, };
  751. void ShopHelp(HelpFormat fmt)
  752. {
  753. FileInfo file = new FileInfo(Path.Combine(Application.StartupPath,
  754. @"OpenMIEditorHelp_2_0." + fmt.ToString()));
  755. if (file.Exists)
  756. Help.ShowHelp(this, file.FullName, HelpNavigator.TableOfContents);
  757. }
  758. void ShopUri(Uri uri)
  759. {
  760. StopAllActions();
  761. Help.ShowHelp(this, uri.AbsoluteUri, HelpNavigator.TableOfContents);
  762. }
  763. #endregion
  764. #region Context menu event handlers
  765. private void OnMenuCompositionOpen(object sender, EventArgs e)
  766. {
  767. menuEditModelAdd.Enabled = true;
  768. if (_composition != null)
  769. {
  770. if (_contextSelectedObject != null
  771. && _contextSelectedObject is UIModel)
  772. {
  773. menuModelAttachTrigger.Enabled = true;
  774. menuViewModelProperties.Enabled = true;
  775. }
  776. else
  777. {
  778. menuModelAttachTrigger.Enabled = false;
  779. menuViewModelProperties.Enabled = false;
  780. }
  781. menuEditConnectionAdd.Enabled
  782. = _composition.Models.Count > 1;
  783. menuEditConnectionLinks.Enabled
  784. = _contextSelectedObject != null
  785. && _contextSelectedObject is UIConnection;
  786. menuEditRunProperties.Enabled
  787. = !_composition.ShouldBeSaved
  788. && _composition.Models.Count > 0;
  789. }
  790. else
  791. {
  792. menuCompositionSpacer.Enabled = false;
  793. menuViewModelProperties.Enabled = false;
  794. menuEditConnectionAdd.Enabled = false;
  795. menuEditConnectionLinks.Enabled = false;
  796. menuEditRunProperties.Enabled = false;
  797. }
  798. }
  799. private void OnContextMenu(object sender, EventArgs e)
  800. {
  801. try
  802. {
  803. StopAllActions();
  804. contextModelAdd.Visible = false;
  805. contextModelRemove.Visible = false;
  806. contextModelProperties.Visible = false;
  807. contextModelAttachTrigger.Visible = false;
  808. contextConnectionAdd.Visible = false;
  809. contextConnectionRemove.Visible = false;
  810. contextConnectionEditLinks.Visible = false;
  811. contextRun.Visible = false;
  812. if( _contextSelectedObject == null )
  813. {
  814. contextModelAdd.Visible = true;
  815. contextRun.Visible = true;
  816. contextConnectionAdd.Visible = true;
  817. contextModelAdd.Enabled = true;
  818. if (_composition != null)
  819. {
  820. contextRun.Enabled
  821. = !_composition.ShouldBeSaved
  822. && _composition.Models.Count > 0;
  823. contextConnectionAdd.Enabled
  824. = _composition.Models.Count > 1;
  825. }
  826. }
  827. else if( _contextSelectedObject is UIConnection )
  828. {
  829. contextConnectionRemove.Visible = true;
  830. contextConnectionEditLinks.Visible = true;
  831. contextConnectionRemove.Enabled = true;
  832. contextConnectionEditLinks.Enabled = true;
  833. }
  834. else if( _contextSelectedObject is UIModel )
  835. {
  836. contextModelRemove.Visible = true;
  837. contextModelProperties.Visible = true;
  838. contextModelAttachTrigger.Visible = true;
  839. contextModelRemove.Enabled = true;
  840. contextModelProperties.Enabled = true;
  841. contextModelAttachTrigger.Enabled
  842. = !((UIModel)_contextSelectedObject).IsTrigger;
  843. }
  844. else
  845. Debug.Assert( false );
  846. }
  847. catch (Exception ex)
  848. {
  849. FinalCatchAndDisplay("Context Menu", ex);
  850. }
  851. }
  852. private void contextConnectionAdd_Click(object sender, EventArgs e)
  853. {
  854. OnMenuConnectionAdd(sender, e);
  855. CompositionUpdateArea();
  856. UpdateTitle();
  857. }
  858. private void contextConnectionRemove_Click(object sender, EventArgs e)
  859. {
  860. _composition.RemoveConnection( (UIConnection)_contextSelectedObject );
  861. CompositionUpdateArea();
  862. UpdateTitle();
  863. }
  864. private void contextConnectionProperties_Click(object sender, EventArgs e)
  865. {
  866. ShowSelectedObjectProperties();
  867. }
  868. private void contextModelAdd_Click(object sender, EventArgs e)
  869. {
  870. OnAddModels( sender, e );
  871. }
  872. private void contextModelRemove_Click(object sender, EventArgs e)
  873. {
  874. _composition.ModelRemove( (UIModel)_contextSelectedObject );
  875. CompositionUpdateArea();
  876. UpdateTitle();
  877. }
  878. private void contextModelProperties_Click(object sender, EventArgs e)
  879. {
  880. ShowSelectedObjectProperties();
  881. }
  882. private void contextRun_Click(object sender, EventArgs e)
  883. {
  884. OnRun(sender, e);
  885. }
  886. private void contextIsTrigger_Click(object sender, EventArgs e)
  887. {
  888. OnAttachTrigger( sender, e );
  889. }
  890. #endregion
  891. #region Composition box event handlers
  892. private void compositionScrollBar_ValueChanged(object sender, EventArgs e)
  893. {
  894. _compositionBoxPositionInArea.X = compositionHScrollBar.Value;
  895. _compositionBoxPositionInArea.Y = compositionVScrollBar.Value;
  896. compositionBox.Invalidate();
  897. }
  898. private void OnCanvasPaint(object sender, PaintEventArgs e)
  899. {
  900. try
  901. {
  902. // draw OpenMI logo
  903. e.Graphics.DrawImage(imageList.Images[0], 0, 0);
  904. //foreach (UIConnection link in _composition.Connections)
  905. // link.Draw(true,_compositionBoxPositionInArea, e.Graphics);
  906. //foreach (UIModel model in _composition.Models)
  907. // model.Draw(true,_compositionBoxPositionInArea, e.Graphics);
  908. foreach (UIConnection connection in _composition.Connections)
  909. connection.Draw(_contextSelectedObject == connection,
  910. _compositionBoxPositionInArea, e.Graphics);
  911. foreach (UIModel model in _composition.Models)
  912. model.Draw(_contextSelectedObject == model,
  913. _compositionBoxPositionInArea, e.Graphics);
  914. }
  915. catch (Exception ex)
  916. {
  917. FinalCatchAndDisplay("Canvas Paint", ex);
  918. }
  919. }
  920. private void compositionBox_MouseDown(object sender, MouseEventArgs e)
  921. {
  922. StopMovingModel();
  923. compositionBox.Invalidate();
  924. bool actionFoundOut = false;
  925. // Left mouse button
  926. if( e.Button == MouseButtons.Left )
  927. {
  928. // if adding a connection
  929. if( _isAddingConnection )
  930. {
  931. UIModel model = GetModel( e.X, e.Y );
  932. // if some model selected
  933. if( model!=null )
  934. {
  935. // if source model selected
  936. if( _sourceModel == null )
  937. {
  938. _sourceModel = model;
  939. compositionBox.Cursor = _targetCursor;
  940. }
  941. else
  942. {
  943. // target model selected => add connection to composition
  944. if( _sourceModel != model )
  945. _composition.AddConnection(
  946. new UIConnection(_sourceModel, model));
  947. StopAddingConnection();
  948. }
  949. }
  950. else
  951. {
  952. // no model selected
  953. StopAddingConnection();
  954. }
  955. actionFoundOut = true;
  956. }
  957. // move model ?
  958. if( !actionFoundOut )
  959. {
  960. UIModel model = GetModel( e.X, e.Y );
  961. if( model != null )
  962. {
  963. _prevMouse.X = e.X;
  964. _prevMouse.Y = e.Y;
  965. _isMovingModel = true;
  966. model.IsMoving = true;
  967. actionFoundOut = true;
  968. }
  969. }
  970. }
  971. else if( e.Button == MouseButtons.Right )
  972. {
  973. // right button => show context menu
  974. // stop other actions
  975. StopAddingConnection();
  976. StopMovingModel();
  977. // get model under cursor
  978. _contextSelectedObject = GetModel(e.X,e.Y);
  979. if( _contextSelectedObject == null )
  980. _contextSelectedObject = GetConnection(e.X,e.Y);
  981. //contextMenu.Show(popup, new Point(e.X, e.Y));
  982. contextMenu.Show( compositionBox, new Point(e.X,e.Y) );
  983. }
  984. }
  985. private void compositionBox_MouseMove(object sender, MouseEventArgs e)
  986. {
  987. // moving model ?
  988. if( _isMovingModel )
  989. {
  990. foreach( UIModel model in _composition.Models )
  991. if( model.IsMoving )
  992. {
  993. model.Rect.X += e.X -_prevMouse.X;
  994. model.Rect.Y += e.Y -_prevMouse.Y;
  995. _prevMouse.X = e.X;
  996. _prevMouse.Y = e.Y;
  997. _composition.ShouldBeSaved = true;
  998. CompositionUpdateArea();
  999. UpdateTitle();
  1000. compositionBox.Invalidate();
  1001. }
  1002. }
  1003. }
  1004. private void compositionBox_MouseUp(object sender, MouseEventArgs e)
  1005. {
  1006. StopMovingModel();
  1007. }
  1008. #endregion
  1009. #region .NET generated members
  1010. private System.ComponentModel.IContainer components;
  1011. /// <summary>
  1012. /// Clean up any resources being used.
  1013. /// </summary>
  1014. protected override void Dispose( bool disposing )
  1015. {
  1016. if( disposing )
  1017. {
  1018. if (components != null)
  1019. {
  1020. components.Dispose();
  1021. }
  1022. }
  1023. base.Dispose( disposing );
  1024. }
  1025. /// <summary>
  1026. /// The main entry point for the application.
  1027. /// </summary>
  1028. static void Main(string[] args)
  1029. {
  1030. try
  1031. {
  1032. ProcessCommandLineArgs(args);
  1033. }
  1034. catch (Exception e)
  1035. {
  1036. MessageBox.Show(e.ToString(), "Error occured while starting the application", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1037. }
  1038. }
  1039. #region Windows Form Designer generated code
  1040. /// <summary>
  1041. /// Required method for Designer support - do not modify
  1042. /// the contents of this method with the code editor.
  1043. /// </summary>
  1044. private void InitializeComponent()
  1045. {
  1046. this.components = new System.ComponentModel.Container();
  1047. ////InitializeMyMenu();
  1048. //InitializeOldMenu();
  1049. //InitializeContext();
  1050. //InitializeComposition();
  1051. //
  1052. // mainTab
  1053. //
  1054. this.components = new System.ComponentModel.Container();
  1055. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
  1056. this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
  1057. this.menuFile = new System.Windows.Forms.ToolStripMenuItem();
  1058. this.menuFileNew = new System.Windows.Forms.ToolStripMenuItem();
  1059. this.menuItem17 = new System.Windows.Forms.ToolStripMenuItem();
  1060. this.menuFileReload = new System.Windows.Forms.ToolStripMenuItem();
  1061. this.menuItem18 = new System.Windows.Forms.ToolStripMenuItem();
  1062. this.menuFileOpen = new System.Windows.Forms.ToolStripMenuItem();
  1063. this.menuFileSave = new System.Windows.Forms.ToolStripMenuItem();
  1064. this.menuFileSaveAs = new System.Windows.Forms.ToolStripMenuItem();
  1065. this.menuItem15 = new System.Windows.Forms.ToolStripMenuItem();
  1066. this.menuFileExit = new System.Windows.Forms.ToolStripMenuItem();
  1067. this.menuComposition = new System.Windows.Forms.ToolStripMenuItem();
  1068. this.menuEditModelAdd = new System.Windows.Forms.ToolStripMenuItem();
  1069. this.menuItem4 = new System.Windows.Forms.ToolStripMenuItem();
  1070. this.menuViewModelProperties = new System.Windows.Forms.ToolStripMenuItem();
  1071. this.menuModelAttachTrigger = new System.Windows.Forms.ToolStripMenuItem();
  1072. this.menuCompositionSpacer = new System.Windows.Forms.ToolStripMenuItem();
  1073. this.menuEditConnectionAdd = new System.Windows.Forms.ToolStripMenuItem();
  1074. this.menuEditConnectionLinks = new System.Windows.Forms.ToolStripMenuItem();
  1075. this.menuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  1076. this.menuEditRunProperties = new System.Windows.Forms.ToolStripMenuItem();
  1077. this.menuOptions = new System.Windows.Forms.ToolStripMenuItem();
  1078. this.menuItem5 = new System.Windows.Forms.ToolStripMenuItem();
  1079. this.menuRegisterExtensions = new System.Windows.Forms.ToolStripMenuItem();
  1080. this.menuHelp = new System.Windows.Forms.ToolStripMenuItem();
  1081. this.menuHelpContents = new System.Windows.Forms.ToolStripMenuItem();
  1082. this.menuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  1083. this.menuExamples = new System.Windows.Forms.ToolStripMenuItem();
  1084. this.menuExample1 = new System.Windows.Forms.ToolStripMenuItem();
  1085. this.menuExample2 = new System.Windows.Forms.ToolStripMenuItem();
  1086. this.menuExample3 = new System.Windows.Forms.ToolStripMenuItem();
  1087. this.menuExample4 = new System.Windows.Forms.ToolStripMenuItem();
  1088. this.menuItem3 = new System.Windows.Forms.ToolStripMenuItem();
  1089. this.menuHelpAbout = new System.Windows.Forms.ToolStripMenuItem();
  1090. this.compositionHScrollBar = new System.Windows.Forms.HScrollBar();
  1091. this.compositionBox = new System.Windows.Forms.PictureBox();
  1092. this.compositionVScrollBar = new System.Windows.Forms.VScrollBar();
  1093. this.contextMenu = new System.Windows.Forms.ContextMenu();
  1094. this.contextModelAdd = new System.Windows.Forms.MenuItem();
  1095. this.contextModelRemove = new System.Windows.Forms.MenuItem();
  1096. this.contextModelProperties = new System.Windows.Forms.MenuItem();
  1097. this.contextModelAttachTrigger = new System.Windows.Forms.MenuItem();
  1098. this.contextConnectionAdd = new System.Windows.Forms.MenuItem();
  1099. this.contextConnectionRemove = new System.Windows.Forms.MenuItem();
  1100. this.contextConnectionEditLinks = new System.Windows.Forms.MenuItem();
  1101. this.contextRun = new System.Windows.Forms.MenuItem();
  1102. this.imageList = new System.Windows.Forms.ImageList(this.components);
  1103. ((System.ComponentModel.ISupportInitialize)(this.compositionBox)).BeginInit();
  1104. this.SuspendLayout();
  1105. ////
  1106. //// mainMenu1
  1107. ////
  1108. //this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  1109. //this.menuFile,
  1110. //this.menuComposition,
  1111. //this.menuOptions,
  1112. //this.menuHelp});
  1113. //
  1114. this.menuFile = new ToolStripMenuItem();
  1115. this.menuFile.Text = "HydroModeler 2.0";
  1116. this.menuFile.Name = "hydroModelerMenuItem";
  1117. _mapArgs.MainMenu.Items.Add(this.menuFile);
  1118. // menuFile
  1119. //
  1120. //this.menuFile.Index = 0;
  1121. //this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItemCollection {
  1122. //this.menuFileNew,
  1123. //this.menuItem17,
  1124. //this.menuFileReload,
  1125. //this.menuItem18,
  1126. //this.menuFileOpen,
  1127. //this.menuFileSave,
  1128. //this.menuFileSaveAs,
  1129. //this.menuItem15,
  1130. //this.menuFileExit});
  1131. //
  1132. // menuFileNew
  1133. //
  1134. this.menuFileNew.Text = "&New";
  1135. this.menuFileNew.Click += new System.EventHandler(this.OnNew);
  1136. this.menuFile.DropDownItems.Add(this.menuFileNew);
  1137. //
  1138. // menuItem17
  1139. //
  1140. //this.menuItem17.Text = "-";
  1141. //this.menuFile.DropDownItems.Add(this.menuItem17);
  1142. //
  1143. // menuFileReload
  1144. //
  1145. this.menuFileReload.Text = "&Reload";
  1146. this.menuFileReload.Click += new System.EventHandler(this.OnReOpen);
  1147. this.menuFile.DropDownItems.Add(this.menuFileReload);
  1148. //
  1149. // menuItem18
  1150. //
  1151. //this.menuItem18.Text = "-";
  1152. //this.menuFile.DropDownItems.Add(this.menuItem18);
  1153. //
  1154. // menuFileOpen
  1155. //
  1156. this.menuFileOpen.Text = "&Open...";
  1157. this.menuFileOpen.Click += new System.EventHandler(this.OnOpen);
  1158. this.menuFile.DropDownItems.Add(this.menuFileOpen);
  1159. //
  1160. // menuFileSave
  1161. //
  1162. this.menuFileSave.Text = "&Save";
  1163. this.menuFileSave.Click += new System.EventHandler(this.OnSave);
  1164. this.menuFile.DropDownItems.Add(this.menuFileSave);
  1165. //
  1166. // menuFileSaveAs
  1167. //
  1168. this.menuFileSaveAs.Text = "Save &As...";
  1169. this.menuFileSaveAs.Click += new System.EventHandler(this.OnSaveAs);
  1170. this.menuFile.DropDownItems.Add(this.menuFileSaveAs);
  1171. //
  1172. // menuItem15
  1173. //
  1174. //this.menuItem15.Text = "-";
  1175. //this.menuFile.DropDownItems.Add(this.menuItem15);
  1176. //
  1177. // menuFileExit
  1178. //
  1179. this.menuFileExit.Text = "E&xit";
  1180. this.menuFileExit.Click += new System.EventHandler(this.menuFileExit_Click);
  1181. this.menuFile.DropDownItems.Add(this.menuFileExit);
  1182. this.menuFile.DropDownItems.Add(new ToolStripSeparator());
  1183. //
  1184. // menuComposition
  1185. //
  1186. //this.menuComposition.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  1187. //this.menuEditModelAdd,
  1188. //this.menuItem4,
  1189. //this.menuViewModelProperties,
  1190. //this.menuModelAttachTrigger,
  1191. //this.menuCompositionSpacer,
  1192. //this.menuEditConnectionAdd,
  1193. //this.menuEditConnectionLinks,
  1194. //this.menuItem1,
  1195. //this.menuEditRunProperties});
  1196. //this.menuComposition.Text = "&Composition";
  1197. //this.menuComposition.Popup += new System.EventHandler(this.OnMenuCompositionOpen);
  1198. //
  1199. // menuEditModelAdd
  1200. //
  1201. this.menuEditModelAdd.Text = "Add &Model(s) ...";
  1202. this.menuEditModelAdd.Click += new System.EventHandler(this.OnAddModels);
  1203. this.menuFile.DropDownItems.Add(this.menuEditModelAdd);
  1204. //
  1205. // menuItem4
  1206. //
  1207. //this.menuItem4.Index = 1;
  1208. //this.menuItem4.Text = "-";
  1209. //
  1210. // menuViewModelProperties
  1211. //
  1212. //this.menuViewModelProperties.Index = 2;
  1213. this.menuViewModelProperties.Text = "Model &Properties...";
  1214. this.menuViewModelProperties.Click += new System.EventHandler(this.OnViewModelProperties);
  1215. this.menuFile.DropDownItems.Add(this.menuViewModelProperties);
  1216. //
  1217. // menuModelAttachTrigger
  1218. //
  1219. //this.menuModelAttachTrigger.Index = 3;
  1220. this.menuModelAttachTrigger.Text = "Model Attach &Trigger";
  1221. this.menuModelAttachTrigger.Click += new System.EventHandler(this.OnAttachTrigger);
  1222. this.menuFile.DropDownItems.Add(this.menuModelAttachTrigger);
  1223. //
  1224. // menuCompositionSpacer
  1225. //
  1226. //this.menuCompositionSpacer.Index = 4;
  1227. //this.menuCompositionSpacer.Text = "-";
  1228. //this.menuFile.DropDownItems.Add(this.
  1229. //
  1230. // menuEditConnectionAdd
  1231. //
  1232. this.menuEditConnectionAdd.Enabled = false;
  1233. //this.menuEditConnectionAdd.Index = 5;
  1234. this.menuEditConnectionAdd.Text = "Add &Connection";
  1235. this.menuEditConnectionAdd.Click += new System.EventHandler(this.OnMenuConnectionAdd);
  1236. this.menuFile.DropDownItems.Add(this.menuEditConnectionAdd);
  1237. //
  1238. // menuEditConnectionLinks
  1239. //
  1240. this.menuEditConnectionLinks.Enabled = false;
  1241. //this.menuEditConnectionLinks.Index = 6;
  1242. this.menuEditConnectionLinks.Text = "Edit Connection &Links...";
  1243. this.menuFile.DropDownItems.Add(this.menuEditConnectionLinks);
  1244. //
  1245. // menuItem1
  1246. //
  1247. //this.menuItem1.Index = 7;
  1248. //this.menuItem1.Text = "-";
  1249. //
  1250. // menuEditRunProperties
  1251. //
  1252. //this.menuEditRunProperties.Index = 8;
  1253. //this.menuEditRunProperties.Shortcut = System.Windows.Forms.Shortcut.F5;
  1254. this.menuEditRunProperties.Text = "&Run...";
  1255. this.menuEditRunProperties.Click += new System.EventHandler(this.OnRun);
  1256. this.menuFile.DropDownItems.Add(this.menuEditRunProperties);
  1257. //
  1258. // menuOptions
  1259. //
  1260. //this.menuOptions.Index = 2;
  1261. //this.menuOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  1262. //this.menuItem5,
  1263. //this.menuRegisterExtensions});
  1264. //this.menuOptions.Text = "&Options";
  1265. this.menuFile.DropDownItems.Add(new ToolStripSeparator());
  1266. //
  1267. // menuItem5
  1268. //
  1269. //this.menuItem5.Index = 0;
  1270. this.menuItem5.Text = "View Exception details";
  1271. this.menuItem5.Click += new System.EventHandler(this.OnViewExceptionDetails);
  1272. this.menuFile.DropDownItems.Add(this.menuItem5);
  1273. //
  1274. // menuRegisterExtensions
  1275. //
  1276. this.menuRegisterExtensions.Checked = true;
  1277. //this.menuRegisterExtensions.Index = 1;
  1278. this.menuRegisterExtensions.Text = "&Register file extensions";
  1279. this.menuRegisterExtensions.Click += new System.EventHandler(this.menuRegisterExtensions_Click);
  1280. this.menuFile.DropDownItems.Add(this.menuRegisterExtensions);
  1281. //
  1282. // menuHelp
  1283. //
  1284. //this.menuHelp.Index = 3;
  1285. //this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  1286. //this.menuHelpContents,
  1287. //this.menuItem2,
  1288. //this.menuExamples,
  1289. //this.menuItem3,
  1290. //this.menuHelpAbout});
  1291. //this.menuHelp.Text = "&Help";
  1292. //this.menuHelp.Popup += new System.EventHandler(this.OnMenuHelpOpen);
  1293. //
  1294. // menuHelpContents
  1295. //
  1296. //this.menuHelpContents.Index = 0;
  1297. //this.menuHelpContents.Shortcut = System.Windows.Forms.Shortcut.F1;
  1298. this.menuHelpContents.Text = "&Help ...";
  1299. this.menuHelpContents.Click += new System.EventHandler(this.OnHelp);
  1300. this.menuFile.DropDownItems.Add(this.menuHelpContents);
  1301. //
  1302. // menuItem2
  1303. //
  1304. //this.menuItem2.Inde…