/// <param name="configuration"></param>
        /// <param name="requestingType">Type of the class for which to create the field</param>
        /// <param name="fieldType">FieldType of the field to construct</param>
        /// <param name="preferredDefaultValue"></param>
        /// <returns>a new Field of the given fieldType, with the scope of it's value being restricted to the Type scope</returns>
        public static IField CreateField(this IEditorConfiguration configuration, Type requestingType, IFieldType fieldType, object preferredDefaultValue)
        {
            var requestingTypeName = requestingType.Name;
            var requestedField     = requestingTypeName + "." + fieldType.Name;
            var fieldValue         = preferredDefaultValue;

            // Check if the configuration exists
            if (configuration.LastUsedFieldValues == null)
            {
                configuration.LastUsedFieldValues = new Dictionary <string, object>();
            }

            // Check if settings for the requesting type exist, if not create!
            if (configuration.LastUsedFieldValues.ContainsKey(requestedField))
            {
                // Check if a value is set (not null)!
                if (configuration.LastUsedFieldValues[requestedField] != null)
                {
                    fieldValue = configuration.LastUsedFieldValues[requestedField];
                }
                else
                {
                    // Overwrite null value
                    configuration.LastUsedFieldValues[requestedField] = fieldValue;
                }
            }
            else
            {
                configuration.LastUsedFieldValues.Add(requestedField, fieldValue);
            }
            return(new Field(fieldType, requestingType)
            {
                Value = fieldValue
            });
        }
Exemplo n.º 2
0
        static EditorConfigurator()
        {
            Type[] lowestPriorityTypes = { typeof(DefaultEditorConfiguration) };
            Type[] definitions         = ReflectionUtils.GetFinalImplementationsOf <IEditorConfiguration>(lowestPriorityTypes).ToArray();

            if (definitions.Except(lowestPriorityTypes).Count() > 1)
            {
                string listOfDefinitions = string.Join("', '", definitions.Select(definition => definition.FullName).ToArray());
                Debug.LogErrorFormat(
                    "There is more than one final implementation of training editor configurations in this Unity project: '{0}'."
                    + " Remove all editor configurations except for '{1}' and the one you want to use."
                    + " '{2}' was selected as current editor configuration.",
                    listOfDefinitions,
                    typeof(DefaultEditorConfiguration).FullName,
                    definitions.First().FullName
                    );
            }

            IEditorConfiguration config = (IEditorConfiguration)ReflectionUtils.CreateInstanceOfType(definitions.First());

            if (config is DefaultEditorConfiguration configuration)
            {
                editorConfiguration = configuration;
            }
            else
            {
                editorConfiguration = new EditorConfigWrapper(config);
            }

            LoadAllowedMenuItems();
        }
Exemplo n.º 3
0
 public EditorConfigViewModel(
     IEditorConfiguration editorConfiguration,
     IEditorLanguage editorLanguage)
 {
     EditorConfiguration = editorConfiguration;
     EditorLanguage      = editorLanguage;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Store the WindowPlacement for the editor
 /// </summary>
 /// <param name="editorConfiguration">IEditorConfiguration</param>
 /// <param name="placement">WindowPlacement</param>
 public static void SetEditorPlacement(this IEditorConfiguration editorConfiguration, WindowPlacement placement)
 {
     editorConfiguration.WindowNormalPosition = placement.NormalPosition;
     editorConfiguration.WindowMaxPosition    = placement.MaxPosition;
     editorConfiguration.WindowMinPosition    = placement.MinPosition;
     editorConfiguration.ShowWindowCommand    = placement.ShowCmd;
     editorConfiguration.WindowPlacementFlags = placement.Flags;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Reset the WindowPlacement for the editor
 /// </summary>
 /// <param name="editorConfiguration">IEditorConfiguration</param>
 public static void ResetEditorPlacement(this IEditorConfiguration editorConfiguration)
 {
     editorConfiguration.WindowNormalPosition = new NativeRect(100, 100, 400, 400);
     editorConfiguration.WindowMaxPosition    = new NativePoint(-1, -1);
     editorConfiguration.WindowMinPosition    = new NativePoint(-1, -1);
     editorConfiguration.WindowPlacementFlags = 0;
     editorConfiguration.ShowWindowCommand    = ShowWindowCommands.Normal;
 }
Exemplo n.º 6
0
 public ToolStripColorButton(
     IEditorConfiguration editorConfiguration,
     IGreenshotLanguage greenshotLanguage)
 {
     _editorConfiguration = editorConfiguration;
     _greenshotLanguage   = greenshotLanguage;
     Click += ColorButtonClick;
 }
Exemplo n.º 7
0
 public EditorFactory(
     IEditorConfiguration editorConfiguration,
     ExportFactory <ImageEditorForm> imageEditorExportFactory,
     ExportFactory <ISurface> surfaceExportFactory)
 {
     _editorConfiguration      = editorConfiguration;
     _imageEditorExportFactory = imageEditorExportFactory;
     // Factory for surface objects
     ImageOutput.SurfaceFactory = surfaceExportFactory;
 }
Exemplo n.º 8
0
 public ColorDialog(
     IEditorConfiguration editorConfiguration,
     IGreenshotLanguage greenshotLanguage) : base(greenshotLanguage)
 {
     _editorConfiguration = editorConfiguration;
     SuspendLayout();
     InitializeComponent();
     ResumeLayout();
     Load += (sender, args) => DrawButtons();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Retrieve the WindowPlacement from the configuration
        /// </summary>
        /// <param name="editorConfiguration">IEditorConfiguration</param>
        /// <returns>WindowPlacement</returns>
        public static WindowPlacement GetEditorPlacement(this IEditorConfiguration editorConfiguration)
        {
            var placement = WindowPlacement.Create();

            placement.NormalPosition = editorConfiguration.WindowNormalPosition;
            placement.MaxPosition    = editorConfiguration.WindowMaxPosition;
            placement.MinPosition    = editorConfiguration.WindowMinPosition;
            placement.ShowCmd        = editorConfiguration.ShowWindowCommand;
            placement.Flags          = editorConfiguration.WindowPlacementFlags;
            return(placement);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Update the last field value in the configuration
        /// </summary>
        /// <param name="editorConfiguration">IEditorConfiguration</param>
        /// <param name="field">IField</param>
        public static void UpdateLastFieldValue(this IEditorConfiguration editorConfiguration, IField field)
        {
            var requestedField = field.Scope + "." + field.FieldType.Name;

            // Check if the configuration exists
            if (editorConfiguration.LastUsedFieldValues == null)
            {
                editorConfiguration.LastUsedFieldValues = new Dictionary <string, object>();
            }
            // check if settings for the requesting type exist, if not create!
            if (field.Value is Color color)
            {
                editorConfiguration.LastUsedFieldValues[requestedField] = color.ToArgb().ToString();
            }
            else
            {
                editorConfiguration.LastUsedFieldValues[requestedField] = field.Value.ToString();
            }
        }
        public static void UpdateLastFieldValue(this IEditorConfiguration configuration, IField field)
        {
            var requestedField = field.Scope + "." + field.FieldType.Name;

            // Check if the configuration exists
            if (configuration.LastUsedFieldValues == null)
            {
                configuration.LastUsedFieldValues = new Dictionary <string, object>();
            }
            // check if settings for the requesting type exist, if not create!
            if (configuration.LastUsedFieldValues.ContainsKey(requestedField))
            {
                configuration.LastUsedFieldValues[requestedField] = field.Value;
            }
            else
            {
                configuration.LastUsedFieldValues.Add(requestedField, field.Value);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// This is a factory method for IField which considers the defaults from the configuration
        /// </summary>
        /// <param name="editorConfiguration"></param>
        /// <param name="requestingType">Type of the class for which to create the field</param>
        /// <param name="fieldType">FieldType of the field to construct</param>
        /// <param name="preferredDefaultValue"></param>
        /// <returns>a new Field of the given fieldType, with the scope of it's value being restricted to the Type scope</returns>
        public static IField CreateField(this IEditorConfiguration editorConfiguration, Type requestingType, IFieldType fieldType, object preferredDefaultValue)
        {
            var requestingTypeName = requestingType.Name;
            var requestedField     = requestingTypeName + "." + fieldType.Name;
            var fieldValue         = preferredDefaultValue;

            // Check if the configuration exists
            if (editorConfiguration.LastUsedFieldValues == null)
            {
                editorConfiguration.LastUsedFieldValues = new Dictionary <string, object>();
            }

            // Check if settings for the requesting type exist, if not create!
            if (editorConfiguration.LastUsedFieldValues.ContainsKey(requestedField))
            {
                // Check if a value is set (not null)!
                if (editorConfiguration.LastUsedFieldValues[requestedField] != null)
                {
                    var preferredValue = editorConfiguration.LastUsedFieldValues[requestedField];
                    if (preferredValue is string preferredStringValue)
                    {
                        switch (fieldType.ValueType)
                        {
                        case var intType when fieldType.ValueType == typeof(int):
                            fieldValue = Convert.ToInt32(preferredValue);
                            break;

                        case var boolType when fieldType.ValueType == typeof(bool):
                            fieldValue = Convert.ToBoolean(preferredValue);
                            break;

                        case var colorType when fieldType.ValueType == typeof(Color):
                            var color = Color.FromName(preferredStringValue);
                            fieldValue = color;
                            if (Color.Empty == color)
                            {
                                fieldValue = Color.FromArgb(Convert.ToInt32(preferredValue));
                            }
                            break;

                        case var allignType when fieldType.ValueType == typeof(StringAlignment):
                            fieldValue = Enum.Parse(typeof(StringAlignment), preferredStringValue, true);
                            break;

                        case var fieldFlagType when fieldType.ValueType == typeof(FieldFlag):
                            fieldValue = Enum.Parse(typeof(FieldFlag), preferredStringValue, true);
                            break;

                        case var preparedFilterType when fieldType.ValueType == typeof(FilterContainer.PreparedFilter):
                            fieldValue = Enum.Parse(typeof(FilterContainer.PreparedFilter), preferredStringValue, true);
                            break;

                        case var arrowHeadCombinationType when fieldType.ValueType == typeof(ArrowContainer.ArrowHeadCombination):
                            fieldValue = Enum.Parse(typeof(ArrowContainer.ArrowHeadCombination), preferredStringValue, true);
                            break;

                        default:
                            fieldValue = preferredStringValue;
                            break;
                        }
                    }
                    else
                    {
                        fieldValue = preferredValue;
                    }
                }
                else
                {
                    // Overwrite null value
                    editorConfiguration.LastUsedFieldValues[requestedField] = fieldValue;
                }
            }
            else
            {
                editorConfiguration.LastUsedFieldValues.Add(requestedField, fieldValue);
            }
            return(new Field(fieldType, requestingType)
            {
                Value = fieldValue
            });
        }
Exemplo n.º 13
0
 public EditorConfigWrapper(IEditorConfiguration config)
 {
     this.config = config;
 }