Пример #1
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoString))
     {
         ItemsControlElement itemsControlElement = this.TargetElement as ItemsControlElement;
         if (itemsControlElement != null)
         {
             ITypeId              itemType       = this.ItemType;
             StyleAsset           asset          = this.Asset;
             IProperty            targetProperty = this.SceneViewModel.ProjectContext.ResolveProperty(ItemsControlElement.ItemsProperty);
             ISceneInsertionPoint insertionPoint = (ISceneInsertionPoint) new PropertySceneInsertionPoint((SceneElement)itemsControlElement, targetProperty);
             if (asset != null && asset.CanCreateInstance(insertionPoint))
             {
                 IExpandable expandable = this.TargetElement as IExpandable;
                 if (expandable != null)
                 {
                     using (this.SceneViewModel.ForceBaseValue())
                         this.TargetElement.SetValue(expandable.ExpansionProperty, (object)true);
                 }
                 asset.CreateInstance(this.DesignerContext.LicenseManager, insertionPoint, Rect.Empty, (OnCreateInstanceAction)null);
             }
             else
             {
                 this.TypeInstantiator.CreateInstance(itemType, insertionPoint, Rect.Empty, (OnCreateInstanceAction)null);
             }
         }
         editTransaction.Commit();
     }
 }
Пример #2
0
        public override void OnInspectorGUI()
        {
            StyleAsset styleAsset = target as StyleAsset;

            bool noContext = ImGui.GetCurrentContext() == System.IntPtr.Zero;

            if (noContext)
            {
                EditorGUILayout.HelpBox("Can't save or apply Style.\n"
                                        + "No active ImGui context.", MessageType.Warning, true);
            }

            // apply and save buttons only when a context is active
            if (!noContext)
            {
                ImGuiStylePtr style = ImGui.GetStyle();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Apply"))
                {
                    styleAsset.ApplyTo(style);
                }

                if (GUILayout.Button("Save") &&
                    EditorUtility.DisplayDialog("Save Style", "Do you want to save the current style to this asset?", "Ok", "Cancel"))
                {
                    styleAsset.SetFrom(style);
                    EditorUtility.SetDirty(target);
                }
                GUILayout.EndHorizontal();
            }

            // default
            DrawDefaultInspector();

            // colors
            bool changed = false;

            _showColors = EditorGUILayout.Foldout(_showColors, "Colors", true);
            if (_showColors)
            {
                for (int i = 0; i < (int)ImGuiCol.COUNT; ++i)
                {
                    Color indexColor = styleAsset.Colors[i];
                    Color newColor   = EditorGUILayout.ColorField(ImGui.GetStyleColorName((ImGuiCol)i), indexColor);
                    changed |= (newColor != indexColor);
                    styleAsset.Colors[i] = newColor;
                }
            }

            if (changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Пример #3
0
 internal virtual void ApplyBeforeInsertionDefaultsToElements(IList <SceneNode> nodes, SceneNode rootNode, DefaultTypeInstantiator.SceneElementNamingCallback callback)
 {
     foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes)
     {
         if (ProjectNeutralTypes.DockPanel.IsAssignableFrom((ITypeId)sceneNode.Type))
         {
             sceneNode.SetValue(DockPanelElement.LastChildFillProperty, (object)false);
         }
         SceneElement sceneElement = sceneNode as SceneElement;
         if (sceneElement != null)
         {
             sceneElement.Name = callback(sceneElement);
         }
     }
     foreach (SceneNode node in (IEnumerable <SceneNode>)nodes)
     {
         StyleAsset relatedUserThemeAsset = this.GetRelatedUserThemeAsset(node, rootNode);
         if (relatedUserThemeAsset != null)
         {
             relatedUserThemeAsset.ApplyStyle(node);
         }
     }
 }
Пример #4
0
 internal void ApplyAfterInsertionDefaultsToElements(IList <SceneNode> nodes, SceneNode rootNode)
 {
     foreach (SceneNode node in (IEnumerable <SceneNode>)nodes)
     {
         SceneElement element = node as SceneElement;
         if (element != null)
         {
             string name = element.Name;
             if (name == null)
             {
                 StyleAsset relatedUserThemeAsset = this.GetRelatedUserThemeAsset(node, rootNode);
                 if (relatedUserThemeAsset != null)
                 {
                     DocumentCompositeNode documentCompositeNode = relatedUserThemeAsset.ResourceModel.ValueNode as DocumentCompositeNode;
                     if (documentCompositeNode != null)
                     {
                         name = documentCompositeNode.GetValue <string>(DesignTimeProperties.StyleDefaultContentProperty);
                         double num1 = documentCompositeNode.GetValue <double>(DesignTimeProperties.ExplicitWidthProperty);
                         if (num1 > 0.0)
                         {
                             DefaultTypeInstantiator.SetIfUnset(node, BaseFrameworkElement.WidthProperty, (object)num1);
                         }
                         double num2 = documentCompositeNode.GetValue <double>(DesignTimeProperties.ExplicitHeightProperty);
                         if (num2 > 0.0)
                         {
                             DefaultTypeInstantiator.SetIfUnset(node, BaseFrameworkElement.HeightProperty, (object)num2);
                         }
                     }
                 }
             }
             if (name == null)
             {
                 name = element.TargetType.Name;
             }
             if (element.Name == null && this.ViewModel.DesignerContext.ProjectManager.OptionsModel.NameInteractiveElementsByDefault && Enumerable.FirstOrDefault <ITypeId>((IEnumerable <ITypeId>)DefaultTypeInstantiator.InteractiveElementTypes, (Func <ITypeId, bool>)(i =>
             {
                 IType type = this.ViewModel.ProjectContext.ResolveType(i);
                 if (type != null)
                 {
                     return(type.IsAssignableFrom((ITypeId)element.Type));
                 }
                 return(false);
             })) != null)
             {
                 element.EnsureNamed();
             }
             if (ProjectNeutralTypes.HeaderedContentControl.IsAssignableFrom((ITypeId)node.Type))
             {
                 DefaultTypeInstantiator.SetIfUnset(node, HeaderedControlProperties.HeaderedContentHeaderProperty, (object)name);
             }
             else if (ProjectNeutralTypes.HeaderedItemsControl.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.ToolBar.IsAssignableFrom((ITypeId)node.Type))
             {
                 DefaultTypeInstantiator.SetIfUnset(node, HeaderedControlProperties.HeaderedItemsHeaderProperty, (object)name);
             }
             else if (PlatformTypes.ContentControl.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.ScrollViewer.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.UserControl.IsAssignableFrom((ITypeId)node.Type))
             {
                 if (ProjectNeutralTypes.TabItem.IsAssignableFrom((ITypeId)node.Type) && this.ViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.UseHeaderOnTabItem))
                 {
                     IPropertyId property = (IPropertyId)ProjectNeutralTypes.TabItem.GetMember(MemberType.LocalProperty, "Header", MemberAccessTypes.Public);
                     DefaultTypeInstantiator.SetIfUnset(node, property, (object)name);
                 }
                 else
                 {
                     DefaultTypeInstantiator.SetIfUnset(node, ContentControlElement.ContentProperty, (object)name);
                 }
             }
             else
             {
                 BaseTextElement baseTextElement;
                 if ((baseTextElement = node as BaseTextElement) != null)
                 {
                     if (string.IsNullOrEmpty(baseTextElement.Text.Trim()))
                     {
                         baseTextElement.Text = name;
                     }
                     if (PlatformTypes.TextBox.IsAssignableFrom((ITypeId)node.Type))
                     {
                         DefaultTypeInstantiator.SetAsWpfIfUnset(node, TextBoxElement.TextWrappingProperty, (object)TextWrapping.Wrap);
                     }
                     if (!node.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)node.Type))
                     {
                         DefaultTypeInstantiator.SetAsWpfIfUnset(node, RichTextBoxElement.TextWrappingProperty, (object)TextWrapping.Wrap);
                     }
                 }
                 else if (PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type))
                 {
                     DefaultTypeInstantiator.SetIfUnset(node, TextBlockElement.TextProperty, (object)name);
                     DefaultTypeInstantiator.SetAsWpfIfUnset(node, TextBlockElement.TextWrappingProperty, (object)TextWrapping.Wrap);
                 }
                 else if (PlatformTypes.ListView.IsAssignableFrom((ITypeId)node.Type))
                 {
                     GridViewElement gridViewElement = (GridViewElement)node.ViewModel.CreateSceneNode(PlatformTypes.GridView);
                     SceneNode       sceneNode       = node.ViewModel.CreateSceneNode(PlatformTypes.GridViewColumn);
                     gridViewElement.Columns.Add(sceneNode);
                     node.SetValueAsSceneNode(DefaultTypeInstantiator.ListViewViewProperty, (SceneNode)gridViewElement);
                 }
                 else if (PlatformTypes.Border.IsAssignableFrom((ITypeId)node.Type))
                 {
                     DefaultTypeInstantiator.SetAsWpfIfUnset(node, BorderElement.BorderBrushProperty, (object)Brushes.Black);
                     DefaultTypeInstantiator.SetAsWpfIfUnset(node, BorderElement.BorderThicknessProperty, (object)new Thickness(1.0));
                 }
                 else if (typeof(FlowDocumentScrollViewer).IsAssignableFrom(node.TargetType))
                 {
                     DefaultTypeInstantiator.SetIfUnset(node, FlowDocumentScrollViewerElement.DocumentProperty, (object)new FlowDocument((Block) new Paragraph((Inline) new Run(name))));
                 }
                 else if (typeof(Glyphs).IsAssignableFrom(node.TargetType))
                 {
                     DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsUnicodeStringProperty, (object)name);
                     DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsFillProperty, (object)Brushes.Black);
                     DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsFontRenderingSizeEmProperty, (object)12.0);
                 }
                 else if (typeof(Viewport3D).IsAssignableFrom(node.TargetType))
                 {
                     Viewport3DElement viewport3Delement = node as Viewport3DElement;
                     if (viewport3Delement != null)
                     {
                         Camera camera1 = (Camera)Viewport3D.CameraProperty.DefaultMetadata.DefaultValue;
                         Camera camera2 = (Camera)viewport3Delement.GetComputedValue(Viewport3DElement.CameraProperty);
                         if (camera2 == null || PropertyUtilities.Compare((object)camera1, (object)camera2, this.sceneView))
                         {
                             Camera perspectiveCamera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, 1.0, new Rect3D(-1.0, -1.0, -1.0, 2.0, 2.0, 2.0), 1.0);
                             DefaultTypeInstantiator.SetIfUnset((SceneNode)viewport3Delement, Viewport3DElement.CameraProperty, (object)perspectiveCamera);
                         }
                     }
                 }
             }
         }
     }
 }