Example #1
0
        /// <summary>
        /// Opens the edit element style form for the element currently under the cursor.
        /// </summary>
        private void mnuEditElementStyle_Click(object sender, EventArgs e)
        {
            this.menuOpen = false;

            if (GlobalSettings.Settings.LoadedStyle == null)
            {
                MessageBox.Show("Please load or save a style before editing element styles.");
                return;
            }

            // Sanity check, don't try anything if there's no selected element.
            var relevantElement = this.selectedDefinition ?? this.elementUnderCursor;

            if (relevantElement == null)
            {
                return;
            }
            var id = relevantElement.Id;

            if (relevantElement is KeyDefinition)
            {
                using (var styleForm = new KeyStyleForm(
                           GlobalSettings.CurrentStyle.TryGetElementStyle <KeyStyle>(id),
                           GlobalSettings.CurrentStyle.DefaultKeyStyle))
                {
                    styleForm.StyleChanged += style =>
                    {
                        if (style.Loose == null && style.Pressed == null &&
                            GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                        {
                            GlobalSettings.CurrentStyle.ElementStyles.Remove(id);
                        }

                        if (!GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                        {
                            GlobalSettings.CurrentStyle.ElementStyles.Add(id, style);
                        }
                        else
                        {
                            GlobalSettings.CurrentStyle.ElementStyles[id] = style;
                        }

                        this.ResetBackBrushes();
                    };

                    styleForm.ShowDialog(this);
                }
            }

            if (relevantElement is MouseSpeedIndicatorDefinition)
            {
                using (var styleForm = new MouseSpeedStyleForm(
                           GlobalSettings.CurrentStyle.TryGetElementStyle <MouseSpeedIndicatorStyle>(id),
                           GlobalSettings.CurrentStyle.DefaultMouseSpeedIndicatorStyle))
                {
                    styleForm.StyleChanged += style =>
                    {
                        if (style == null && GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                        {
                            GlobalSettings.CurrentStyle.ElementStyles.Remove(id);
                        }

                        if (!GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                        {
                            GlobalSettings.CurrentStyle.ElementStyles.Add(id, style);
                        }
                        else
                        {
                            GlobalSettings.CurrentStyle.ElementStyles[id] = style;
                        }

                        this.ResetBackBrushes();
                    };

                    styleForm.ShowDialog(this);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Opens the edit element style form for the element currently under the cursor.
        /// </summary>
        private void mnuEditElementStyle_Click(object sender, EventArgs e)
        {
            if (GlobalSettings.Settings.LoadedStyle == null)
            {
                MessageBox.Show("Please load or save a style before editing element styles.");
                return;
            }

            // Sanity check, don't try anything if there's no selected element.
            if (this.elementUnderCursor == null) return;
            var id = this.elementUnderCursor.Id;

            if (this.elementUnderCursor is KeyDefinition)
            {
                using (var styleForm = new KeyStyleForm(
                    GlobalSettings.CurrentStyle.TryGetElementStyle<KeyStyle>(id),
                    GlobalSettings.CurrentStyle.DefaultKeyStyle))
                {
                    styleForm.StyleChanged += style =>
                    {
                        if (style.Loose == null && style.Pressed == null
                            && GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                            GlobalSettings.CurrentStyle.ElementStyles.Remove(id);

                        if (!GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                            GlobalSettings.CurrentStyle.ElementStyles.Add(id, style);
                        else
                            GlobalSettings.CurrentStyle.ElementStyles[id] = style;

                        this.ResetBackBrushes();
                    };

                    styleForm.ShowDialog(this);
                }
            }

            if (this.elementUnderCursor is MouseSpeedIndicatorDefinition)
            {
                using (var styleForm = new MouseSpeedStyleForm(
                        GlobalSettings.CurrentStyle.TryGetElementStyle<MouseSpeedIndicatorStyle>(id),
                    GlobalSettings.CurrentStyle.DefaultMouseSpeedIndicatorStyle))
                {
                    styleForm.StyleChanged += style =>
                    {
                        if (style == null && GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                            GlobalSettings.CurrentStyle.ElementStyles.Remove(id);

                        if (!GlobalSettings.CurrentStyle.ElementStyles.ContainsKey(id))
                            GlobalSettings.CurrentStyle.ElementStyles.Add(id, style);
                        else
                            GlobalSettings.CurrentStyle.ElementStyles[id] = style;

                        this.ResetBackBrushes();
                    };

                    styleForm.ShowDialog(this);
                }
            }
        }