Ejemplo n.º 1
0
        /// <summary>Add user documentation, based on the example.</summary>
        /// <param name="tags">The tags to add to.</param>
        /// <param name="modelName">Name of model to document.</param>
        private void AddUserDocumentation(List <AutoDocumentation.ITag> tags, string modelName)
        {
            // Look for some instructions on which models in the example file we should write.
            // Instructions will be in a memo in the validation .apsimx file

            IModel userDocumentation = Apsim.Get(explorerPresenter.ApsimXFile, ".Simulations.UserDocumentation") as IModel;
            string exampleFileName   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "Examples", modelName + ".apsimx");

            if (userDocumentation != null && userDocumentation.Children.Count > 0 && File.Exists(exampleFileName))
            {
                // Write heading.
                tags.Add(new AutoDocumentation.Heading("User documentation", 1));

                // Open the related example .apsimx file and get its presenter.
                ExplorerPresenter examplePresenter = explorerPresenter.MainPresenter.OpenApsimXFileInTab(exampleFileName, onLeftTabControl: true);

                Memo     instructionsMemo = userDocumentation.Children[0] as Memo;
                string[] instructions     = instructionsMemo.Text.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string instruction in instructions)
                {
                    IModel model = Apsim.Find(examplePresenter.ApsimXFile, instruction);
                    if (model != null)
                    {
                        examplePresenter.SelectNode(Apsim.FullPath(model));
                        while (Gtk.Application.EventsPending())
                        {
                            Gtk.Application.RunIteration();
                        }
                        if (model is Memo)
                        {
                            AutoDocumentation.DocumentModel(model, tags, 1, 0);
                        }
                        else
                        {
                            Image image = examplePresenter.GetScreenhotOfRightHandPanel();
                            if (image != null)
                            {
                                string name = "Example" + instruction;
                                tags.Add(new AutoDocumentation.Image()
                                {
                                    name = name, image = image
                                });
                            }
                        }
                    }
                }

                // Close the tab
                examplePresenter.MainPresenter.CloseTabContaining(examplePresenter.GetView().MainWidget);
                while (Gtk.Application.EventsPending())
                {
                    Gtk.Application.RunIteration();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a one-time initialisation of the Gtk components.
        /// </summary>
        private void Initialise()
        {
            tree                = new TreeView();
            data                = new ListStore(typeof(string), typeof(string), typeof(string));
            tree.Model          = data;
            tree.CanFocus       = true;
            tree.RulesHint      = true; // Allows for alternate-row colouring.
            tree.CursorChanged += OnSelectionChanged;
            tree.KeyPressEvent += OnKeyPress;

            // First column displays the path to the model.
            TreeViewColumn col = new TreeViewColumn();

            col.Title = "Model";
            CellRendererText cell = new CellRendererText();

            col.PackStart(cell, false);
            col.AddAttribute(cell, "text", 0);
            tree.AppendColumn(col);

            // Second column displays the name of the property or field which
            // references the model.
            col       = new TreeViewColumn();
            col.Title = "Property Name";
            cell      = new CellRendererText();
            col.PackStart(cell, false);
            col.AddAttribute(cell, "text", 1);
            tree.AppendColumn(col);

            window = new Window("Find All References")
            {
                SkipPagerHint   = true,
                SkipTaskbarHint = true,
                Parent          = explorerPresenter.GetView().MainWidget,
                WindowPosition  = WindowPosition.CenterAlways,
                TransientFor    = explorerPresenter.GetView().MainWidget.Toplevel as Window
            };
            window.DeleteEvent += OnClose;
            window.Destroyed   += OnClose;
            window.Add(tree);
            window.ShowAll();
        }
Ejemplo n.º 3
0
 /// <summary>Constructor.</summary>
 /// <param name="explorerView">The explorer view.</param>
 /// <param name="modelToReplace">The model to move.</param>
 /// <param name="modelToInsert">The new model to put in place of the old one</param>
 public ReplaceModelCommand(IModel modelToReplace, IModel modelToInsert, ExplorerPresenter presenter)
 {
     if (modelToReplace.ReadOnly)
     {
         throw new ApsimXException(modelToReplace, string.Format("Unable to replace {0} - it is read-only.", modelToReplace.Name));
     }
     this.modelToReplace = modelToReplace;
     this.modelToInsert  = modelToInsert;
     this.explorerView   = presenter.GetView() as IExplorerView;
     this.presenter      = presenter;
 }