Exemplo n.º 1
0
 private void DefaultsButton_Click(object sender, EventArgs e)
 {
     ConfirmationDialog dialog =
         new ConfirmationDialog(
             "Reset All Preferences".Localize("Reset all preferences to their default values?"),
             "Reset all preferences to their default values?".Localize());
     DialogResult result = dialog.ShowDialog(m_dialogOwner);
     if (result == DialogResult.Yes)
     {
         m_settingsService.SetDefaults();
         m_propertyGrid.Refresh();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Confirms that file should be closed</summary>
 /// <param name="message">Confirmation message</param>
 /// <returns>Dialog result</returns>
 public DialogResult ConfirmFileClose(string message)
 {
     ConfirmationDialog dialog = new ConfirmationDialog("Close".Localize("Close file"), message);
     dialog.YesButtonText = "&Save".Localize("The '&' is optional and means that Alt+S is the keyboard shortcut on this button");
     dialog.NoButtonText = "&Discard".Localize("The '&' is optional and means that Alt+D is the keyboard shortcut on this button");
     DialogResult result = dialog.ShowDialog(GetDialogOwner());
     return result;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Promotes objects to template library.
        /// Items can be promoted when the active context is CircuitEditingContext and all the items are selected modules.</summary>
        /// <param name="items">Items to promote</param>
        public override void PromoteToTemplateLibrary(IEnumerable<object> items)
        {
            var itemsArray = items.ToArray();
          
 
            // cache the external connections
            var externalConnectionsDict = new Dictionary<Element, List<Wire>>();
            var circuitEditingContext = ContextRegistry.GetActiveContext<CircuitEditingContext>();
            var graphContainer = circuitEditingContext.CircuitContainer;

            foreach (var item in itemsArray)
            {
                var modules = new HashSet<Element>();
                var internalConnections = new List<Wire>();
                var externalConnections = new List<Wire>();
                CircuitUtil.GetSubGraph(graphContainer, new[] { item }, modules, internalConnections, externalConnections, externalConnections);
                externalConnectionsDict.Add(item.Cast<Element>(), externalConnections);
            }

            // check source guid for templates to be replaced
            var templatingItems = new List<object>();
            var replacingItems = new List<object>();
            foreach (var item in itemsArray)
            {
                if (item.Is<Module>())
                {
                    var module = item.Cast<Module>();
                    if (module.SourceGuid != Guid.Empty)
                    {
                        var existingTemplate = TemplatingContext.SearchForTemplateByGuid(TemplatingContext.RootFolder,  module.SourceGuid);
                        if (existingTemplate != null)
                        {
                            string message = string.Format(
                                "Overwrite the existing \"{0}\"  Template with \"{1}\", or Add new one?\n".Localize(),
                                    existingTemplate.Name, module.Name);

                            var dialog = new ConfirmationDialog("Overwrite / Add".Localize(), message);
                            dialog.YesButtonText = "Overwrite".Localize();
                            dialog.NoButtonText = "Add".Localize();
                            dialog.Size = new System.Drawing.Size(300, 100);
                            DialogResult result = dialog.ShowDialog();
                            if (result == DialogResult.Yes)
                            {
                                TemplatingContext.ReplaceTemplateModel(existingTemplate, module.Cast<DomNode>());
                                replacingItems.Add(item);
                            }
                            else if (result == DialogResult.No)
                                templatingItems.Add(item);
                            //otherwise the item is skipped
                        }
                    }
                    else 
                        templatingItems.Add(item);
                }
            }

            // pack objects in IDataObject format 
            var dataObject = new DataObject();
            dataObject.SetData(typeof(object[]), templatingItems.ToArray());

            // Insert() expects IDataObject
            TemplatingContext.Insert(dataObject);

            // replace the original items with the template instances 
            foreach (var originalItem in templatingItems.Concat(replacingItems))
            {
                var template = TemplatingContext.LastPromoted(originalItem);
                var instance = TemplatingContext.CreateReference(template);

                var originalModule = originalItem.Cast<Element>();
                var replacedModule = instance.Cast<Element>();
                replacedModule.Bounds = originalModule.Bounds;
                replacedModule.Position = originalModule.Position;
 
                // reroute external connections from original modules to replaced template instances.
                var externalConnections = externalConnectionsDict[originalModule];
                foreach (var connection in externalConnections)
                {
                    if (connection.InputElement.DomNode == originalModule.DomNode)
                    {
                        // input pin, i.e. pin on element that receives connection as input
                        int pinIndex = connection.InputPin.Index;
                        connection.InputPin = replacedModule.Type.GetInputPin(pinIndex);
                        connection.InputElement = replacedModule;
                        connection.InputPinTarget = null; // reset
                    }
                    else if (connection.OutputElement.DomNode == originalModule.DomNode)//output pin, i.e., pin on element that receives connection as output
                    {
                        connection.OutputPin = replacedModule.Type.GetOutputPin(connection.OutputPin.Index);
                        connection.OutputElement = replacedModule;
                        connection.OutputPinTarget = null; 
                   
                    }
                    else
                         Debug.Assert(false);
                    
                 
                }
                circuitEditingContext.CircuitContainer.Elements.Remove(originalItem.Cast<Element>());
                circuitEditingContext.CircuitContainer.Elements.Add(replacedModule);
            }
        }