private IPropertyEditingContext GetPropertyEditingContext()
        {
            IPropertyEditingContext edcontext = m_contextRef != null ?
                                                (IPropertyEditingContext)m_contextRef.Target : null;

            return(edcontext ?? (m_propertyEditor == null ? null
                : m_propertyEditor.PropertyGrid.PropertyGridView.EditingContext));
        }
        /// <summary>
        /// Gets tags for context menu (right click) commands</summary>
        /// <param name="context">Context containing target object</param>
        /// <param name="target">Right clicked object, or null if none</param>
        /// <returns>Enumeration of command tags for context menu</returns>
        public IEnumerable <object> GetCommands(object context, object target)
        {
            m_contextRef = new WeakReference(context.As <IPropertyEditingContext>());

            IPropertyEditingContext editingContext = GetPropertyEditingContext();

            m_descriptor = null;
            PropertyDescriptor descriptor = target as PropertyDescriptor;

            if (editingContext != null)
            {
                if (descriptor != null && editingContext.PropertyDescriptors.Contains(descriptor))
                {
                    m_descriptor = descriptor;
                    yield return(Command.CopyProperty);

                    yield return(Command.PasteProperty);

                    yield return(Command.ResetProperty);

                    yield return(Command.CopyAll);

                    yield return(Command.PasteAll);

                    yield return(Command.ResetAll);

                    yield return(Command.ViewInTextEditor);

                    if (!(context is IPropertyEditingContext))
                    {
                        yield return(Command.CreateNewPropertyEditor);
                    }
                }
                else if (editingContext.Items.LastOrDefault() != null)
                {
                    yield return(Command.CopyAll);

                    yield return(Command.PasteAll);

                    yield return(Command.ResetAll);

                    if (!(context is IPropertyEditingContext))
                    {
                        yield return(Command.CreateNewPropertyEditor);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private IPropertyEditingContext GetContext()
        {
            // first try to get a client-defined IPropertyEditingContext
            IPropertyEditingContext context = ContextRegistry.GetMostRecentContext <IPropertyEditingContext>();

            if (context != null)
            {
                m_defaultContext.SelectionContext = null;
            }
            else
            {
                // otherwise, try to get a client-defined ISelectionContext and adapt it
                ISelectionContext selectionContext = ContextRegistry.GetMostRecentContext <ISelectionContext>();
                m_defaultContext.SelectionContext = selectionContext;
                if (selectionContext != null)
                {
                    context = m_defaultContext;
                }
            }

            return(context);
        }
Ejemplo n.º 4
0
 public CustomPropertyEditingContext(IPropertyEditingContext context)
 {
     m_transactionContext = context.As <ITransactionContext>();
     m_items.AddRange(context.Items);
 }
Ejemplo n.º 5
0
        private void contextRegistry_ActiveContextChanged(object sender, EventArgs e)
        {
            IPropertyEditingContext context = GetContext();

            m_propertyGrid.Bind(context);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the PropertyDescriptor for the property under the client point, or null if none</summary>
 /// <param name="clientPoint">Client point, as from a mouse event. For points that
 /// are in screen coordinates, as from drag events, convert to client coordinates
 /// by using PointToClient().</param>
 /// <param name="editingContext">The IPropertyEditingContext to be used with the resulting PropertyDescriptor.</param>
 /// <returns>PropertyDescriptor for the property under the client point, or null if none</returns>
 public PropertyDescriptor GetDescriptorAt(Point clientPoint, out IPropertyEditingContext editingContext)
 {
     return m_propertyGridView.GetDescriptorAt(clientPoint, out editingContext);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Binds the control to a property editing context</summary>
 /// <param name="context">Context in which properties are edited</param>
 public void Bind(IPropertyEditingContext context)
 {
     m_propertyGridView.EditingContext = context;
     SkinService.ApplyActiveSkin(m_propertyGridView);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the PropertyDescriptor for the property under the client point, or null if none</summary>
 /// <param name="clientPoint">Client point, as from a mouse event. For points that
 /// are in screen coordinates, as from drag events, convert to client coordinates
 /// by using PointToClient().</param>
 /// <param name="editingContext">The IPropertyEditingContext to be used with the resulting PropertyDescriptor.</param>
 /// <returns>PropertyDescriptor for the property under the client point, or null if none</returns>
 public PropertyDescriptor GetDescriptorAt(Point clientPoint, out IPropertyEditingContext editingContext)
 {
     return(m_propertyGridView.GetDescriptorAt(clientPoint, out editingContext));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Binds the control to a property editing context</summary>
 /// <param name="context">Context in which properties are edited</param>
 public void Bind(IPropertyEditingContext context)
 {
     m_propertyGridView.EditingContext = context;
     SkinService.ApplyActiveSkin(m_propertyGridView);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Binds the control to a property editing context</summary>
 /// <param name="context">Context in which properties are edited</param>
 public void Bind(IPropertyEditingContext context)
 {
     m_gridView.EditingContext = context;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Handles the Reloaded event of the observableContext and updates the view's data context.</summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected override void observableContext_Reloaded(object sender, EventArgs e)
 {
     base.observableContext_Reloaded(sender, e);
     Context = EditingContext;
 }
Ejemplo n.º 12
0
 public CustomPropertyEditingContext(IPropertyEditingContext context)
 {
     m_transactionContext = context.As<ITransactionContext>();
     m_items.AddRange(context.Items);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Handles the Reloaded event of the observableContext and updates the view's data context.</summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected override void observableContext_Reloaded(object sender, EventArgs e)
 {
     base.observableContext_Reloaded(sender, e);
     Context = EditingContext;
 }
        /// <summary>
        /// Does the command</summary>
        /// <param name="commandTag">Command to be done</param>
        public virtual void DoCommand(object commandTag)
        {
            IPropertyEditingContext editingContext     = GetPropertyEditingContext();
            ITransactionContext     transactionContext = editingContext.As <ITransactionContext>();

            switch ((Command)commandTag)
            {
            case Command.CopyProperty:
            {
                if (!(m_descriptor is ChildPropertyDescriptor))
                {
                    var lastObject = editingContext.Items.LastOrDefault();
                    m_copyDescriptor = m_descriptor;
                    m_copyValue      = m_descriptor.GetValue(lastObject);
                }
            }
            break;

            case Command.PasteProperty:
            {
                transactionContext.DoTransaction(delegate
                    {
                        foreach (object item in editingContext.Items)
                        {
                            PropertyUtils.SetProperty(item, m_descriptor, m_copyValue);
                        }
                    },
                                                 string.Format("Paste: {0}".Localize("'Paste' is a verb and this is the name of a command"),
                                                               m_descriptor.DisplayName));
            }
            break;

            case Command.ResetProperty:
                transactionContext.DoTransaction(delegate
                {
                    PropertyUtils.ResetProperty(editingContext.Items, m_descriptor);
                },
                                                 string.Format("Reset: {0}".Localize("'Reset' is a verb and this is the name of a command"),
                                                               m_descriptor.DisplayName));
                break;

            case Command.CopyAll:
            {
                m_descriptorToValue.Clear();
                var lastObject = editingContext.Items.LastOrDefault();
                foreach (var descriptor in editingContext.PropertyDescriptors)
                {
                    if ((descriptor is ChildPropertyDescriptor))
                    {
                        continue;
                    }

                    AttributePropertyDescriptor attr = descriptor as AttributePropertyDescriptor;
                    if (attr != null && attr.AttributeInfo.IsIdAttribute)
                    {
                        continue;
                    }

                    m_descriptorToValue.Add(descriptor.GetPropertyDescriptorKey(),
                                            descriptor.GetValue(lastObject));
                }
            }
            break;

            case Command.PasteAll:
            {
                transactionContext.DoTransaction(delegate
                    {
                        foreach (var descriptor in editingContext.PropertyDescriptors)
                        {
                            if (descriptor.IsReadOnly)
                            {
                                continue;
                            }
                            ;
                            object value;
                            if (m_descriptorToValue.TryGetValue(descriptor.GetPropertyDescriptorKey(), out value))
                            {
                                foreach (object item in editingContext.Items)
                                {
                                    PropertyUtils.SetProperty(item,
                                                              descriptor,
                                                              value);
                                }
                            }
                        }
                    }, "Paste All".Localize("'Paste' is a verb and this is the name of a command"));
            }
            break;

            case Command.ResetAll:
                transactionContext.DoTransaction(delegate
                {
                    foreach (PropertyDescriptor descriptor in editingContext.PropertyDescriptors)
                    {
                        foreach (object item in editingContext.Items)
                        {
                            if (descriptor.CanResetValue(item))
                            {
                                descriptor.ResetValue(item);
                            }
                        }
                    }
                },
                                                 "Reset All Properties".Localize("'Reset' is a verb and this is the name of a command"));
                break;

            case Command.ViewInTextEditor:
            {
                var fileUriEditor = m_descriptor.GetEditor(typeof(UITypeEditor)) as FileUriEditor;
                var fileUri       = m_descriptor.GetValue(editingContext.Items.LastOrDefault()) as Uri;
                if (fileUri != null && File.Exists(fileUri.LocalPath))
                {
                    Process.Start(fileUriEditor.AssociatedTextEditor, fileUri.LocalPath);
                }
            }
            break;

            case Command.CreateNewPropertyEditor:
            {
                m_propertyEditor.Duplicate();
            }
            break;
            }
        }
        /// <summary>
        /// Checks whether the client can do the command if it handles it</summary>
        /// <param name="commandTag">Command to be done</param>
        /// <returns>True if client can do the command</returns>
        public virtual bool CanDoCommand(object commandTag)
        {
            IPropertyEditingContext editingContext = GetPropertyEditingContext();

            if (commandTag is Command && editingContext != null)
            {
                switch ((Command)commandTag)
                {
                case Command.CopyProperty:
                    return(m_descriptor != null &&
                           !(m_descriptor is ChildPropertyDescriptor) &&
                           !(m_descriptor is ChildAttributeCollectionPropertyDescriptor));

                case Command.PasteProperty:
                {
                    var lastObject = editingContext.Items.LastOrDefault();

                    return(m_descriptor != null && CanPaste(m_copyValue, m_copyDescriptor, m_descriptor,
                                                            m_descriptor.GetValue(lastObject)));
                }

                case Command.ResetProperty:
                    return(CanResetValue(editingContext.Items, m_descriptor));

                case Command.CopyAll:
                {
                    foreach (var descriptor in editingContext.PropertyDescriptors)
                    {
                        if ((descriptor is ChildPropertyDescriptor) ||
                            (descriptor is ChildAttributeCollectionPropertyDescriptor))
                        {
                            continue;
                        }
                        AttributePropertyDescriptor attr = descriptor as AttributePropertyDescriptor;
                        if (attr != null && attr.AttributeInfo.IsIdAttribute)
                        {
                            continue;
                        }
                        return(true);
                    }
                    break;
                }

                case Command.PasteAll:
                    return(m_descriptorToValue.Count > 0);

                case Command.ResetAll:
                    foreach (PropertyDescriptor descriptor in editingContext.PropertyDescriptors)
                    {
                        if (CanResetValue(editingContext.Items, descriptor))
                        {
                            return(true);
                        }
                    }
                    break;

                case Command.ViewInTextEditor:
                    if (m_descriptor != null && m_descriptor.GetEditor(typeof(UITypeEditor)) is FileUriEditor)
                    {
                        return(true);
                    }
                    break;

                case Command.CreateNewPropertyEditor:
                    return(editingContext == m_propertyEditor.PropertyGrid.PropertyGridView.EditingContext);
                }
            }

            return(false);
        }