public override void Reload(object target)
        {
            if (_themeFile != null)
            {
                _themeFile.IsModified = true;

                if (tvThemes.Nodes[0].Text.StartsWith("[*] ") == false)
                {
                    tvThemes.Nodes[0].Text = "[*] " + tvThemes.Nodes[0].Text;
                }

                try
                {
                    NavigationReloadArguments args = target as NavigationReloadArguments;
                    if (args != null && args.OldThemeName.Length > 0)
                    {
                        if (args.OldThemeElementName.Length > 0)
                        {
                            TreeNode tn = FindThemeElementNode(args.OldThemeName, args.OldThemeElementName);
                            if (tn != null)
                            {
                                // Some action was done on a theme element.
                                if (args.OldThemeElementName != args.NewThemeElementName)
                                {
                                    // The theme element was renamed.
                                    tn.Text = args.NewThemeElementName;
                                }

                                string value       = _themeFile.Themes[args.NewThemeName].ThemeElements[args.NewThemeElementName];
                                bool   isColorNode = args.NewThemeElementName.ToLowerInvariant().Contains("color");
                                if (isColorNode)
                                {
                                    tn.ForeColor = ThemeManager.ForeColor;

                                    Color  c   = ThemeManager.SafeColorFromString(value);
                                    Bitmap bmp = CreateColorBitmap(c);
                                    if (bmp != null)
                                    {
                                        tn.ImageIndex = tn.SelectedImageIndex =
                                            _il.Images.Add(bmp, Color.Magenta);
                                    }

                                    tn.Text = string.Format("{0} -> RGB=[{1}], HEX=#{2}", args.NewThemeElementName, value,
                                                            ValueAsHex(value).ToUpperInvariant());
                                }
                                else
                                {
                                    tn.ForeColor = ThemeManager.HighlightColor;
                                    tn.Text      = args.NewThemeElementName;

                                    int  x         = 0;
                                    bool isNumeric = int.TryParse(value, out x);
                                    tn.ImageIndex = tn.SelectedImageIndex =
                                        isNumeric ? (int)NodeIndexes.NumericThemeElement : (int)NodeIndexes.StringThemeElement;
                                }

                                tn.Tag = new KeyValuePair <string, string>(args.NewThemeElementName,
                                                                           _themeFile.Themes[args.OldThemeName].ThemeElements[args.NewThemeElementName]);
                            }
                        }
                        else if (args.OldThemeName != args.NewThemeName)
                        {
                            // The theme was renamed.
                            TreeNode tn = FindThemeNode(args.OldThemeName);
                            if (tn != null)
                            {
                                tn.Text = args.NewThemeName;
                                tn.Tag  = new KeyValuePair <string, Theme>(args.NewThemeName, _themeFile.Themes[args.NewThemeName]);
                            }
                        }
                    }

                    tvThemes.Invalidate();
                }
                catch (Exception ex)
                {
                    ErrorDispatcher.DispatchError(ex, false);
                    DisplayThemeFile();
                }
            }
        }
Пример #2
0
        void OnPropertyChanged(object sender, EventArgs e)
        {
            if (_raiseEvents)
            {
                try
                {
                    if (_themeFile != null)
                    {
                        if (string.IsNullOrEmpty(txtNodeName.Text))
                        {
                            txtNodeName.Text = _lastText;
                            return;
                        }

                        _lastText = txtNodeName.Text;

                        if (sender == txtNodeName)
                        {
                            // Node name changed
                            // This can happen only for a theme node or a theme element node.

                            if (!string.IsNullOrEmpty(_editedThemeElementName) &&
                                !string.IsNullOrEmpty(_editedThemeName))
                            {
                                // We changed the name of a theme element node
                                string value = _themeFile.Themes[_editedThemeName].ThemeElements[_editedThemeElementName];
                                _themeFile.Themes[_editedThemeName].ThemeElements.Remove(_editedThemeElementName);
                                _themeFile.Themes[_editedThemeName].ThemeElements.Add(txtNodeName.Text, value);

                                NavigationReloadArguments args = new NavigationReloadArguments();
                                args.OldThemeElementName = _editedThemeElementName;
                                args.NewThemeElementName = txtNodeName.Text;
                                args.OldThemeName = args.NewThemeName = _editedThemeName;

                                _editedThemeElementName = txtNodeName.Text;
                                RaiseNavigationAction(OPMedia.Runtime.Addons.NavActionType.ActionReloadNavigation, null, args);
                            }
                            else if (!string.IsNullOrEmpty(_editedThemeName))
                            {
                                // We changed the name of a theme node
                                Theme theme = _themeFile.Themes[_editedThemeName];
                                theme.ThemeName = txtNodeName.Text;

                                _themeFile.Themes.Remove(_editedThemeName);
                                _themeFile.Themes.Add(txtNodeName.Text, theme);

                                NavigationReloadArguments args = new NavigationReloadArguments();
                                args.OldThemeName = _editedThemeName;
                                args.NewThemeName = txtNodeName.Text;

                                _editedThemeName = txtNodeName.Text;
                                RaiseNavigationAction(OPMedia.Runtime.Addons.NavActionType.ActionReloadNavigation, null, args);
                            }
                        }
                        else if (sender is IPropertyChooser)
                        {
                            // Node value changed. 
                            // This can happen only for a theme element node.

                            string value = (sender as IPropertyChooser).PropertyValue;

                            if (!string.IsNullOrEmpty(_editedThemeElementName) &&
                                !string.IsNullOrEmpty(_editedThemeName))
                            {
                                // We changed the value of a theme element node
                                _themeFile.Themes[_editedThemeName].ThemeElements[_editedThemeElementName] = value;

                                NavigationReloadArguments args = new NavigationReloadArguments();
                                args.NewThemeElementName = args.OldThemeElementName = _editedThemeElementName;
                                args.NewThemeName = args.OldThemeName = _editedThemeName;

                                RaiseNavigationAction(OPMedia.Runtime.Addons.NavActionType.ActionReloadNavigation, null, args);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorDispatcher.DispatchError(ex);
                }

                base.Modified = false;
            }
        }