public void OnAdd()
        {
            if (!AddEnabled)
            {
                return;
            }

            try
            {
                IPresetVoiLutOperationComponent addComponent = SelectedAddFactory.Factory.GetEditComponent(null);
                addComponent.EditContext = EditContext.Add;

                PresetVoiLutOperationsComponentContainer container =
                    new PresetVoiLutOperationsComponentContainer(GetUnusedKeyStrokes(null), addComponent);

                if (ApplicationComponentExitCode.Accepted != ApplicationComponent.LaunchAsDialog(this.Host.DesktopWindow, container, SR.TitleAddPreset))
                {
                    return;
                }

                PresetVoiLut preset = container.GetPresetVoiLut();
                Platform.CheckForNullReference(preset, "preset");

                List <PresetVoiLut> conflictingItems = CollectionUtils.Select <PresetVoiLut>(_voiLutPresets.Items,
                                                                                             delegate(PresetVoiLut test){ return(preset.Equals(test)); });

                if (conflictingItems.Count == 0)
                {
                    _voiLutPresets.Items.Add(preset);
                    Selection = null;

                    this.Modified = true;
                }
                else
                {
                    this.Host.DesktopWindow.ShowMessageBox(SR.MessageNameOrKeystrokeConflictsWithExistingPreset, MessageBoxActions.Ok);
                }
            }
            catch (Exception e)
            {
                ExceptionHandler.Report(e, SR.MessageFailedToAddPreset, this.Host.DesktopWindow);
            }
        }
示例#2
0
        private void DeserializeGroupPresets(PresetVoiLutCollection presets, XmlNodeList presetNodes)
        {
            foreach (XmlElement presetNode in presetNodes)
            {
                string keyStrokeAttribute = presetNode.GetAttribute("keystroke");
                XKeys  keyStroke          = XKeys.None;
                if (!String.IsNullOrEmpty(keyStrokeAttribute))
                {
                    keyStroke = (XKeys)_xkeysConverter.ConvertFromInvariantString(keyStrokeAttribute);
                }

                string factoryName = presetNode.GetAttribute("factory");

                IPresetVoiLutOperationFactory factory = PresetVoiLutOperationFactories.GetFactory(factoryName);
                if (factory == null)
                {
                    continue;
                }

                PresetVoiLutConfiguration configuration = PresetVoiLutConfiguration.FromFactory(factory);

                XmlNodeList configurationItems = presetNode.SelectNodes("configuration/item");
                foreach (XmlElement configurationItem in configurationItems)
                {
                    configuration[configurationItem.GetAttribute("key")] = configurationItem.GetAttribute("value");
                }

                try
                {
                    IPresetVoiLutOperation operation = factory.Create(configuration);
                    PresetVoiLut           preset    = new PresetVoiLut(operation);
                    preset.KeyStroke = keyStroke;
                    presets.Add(preset);
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e);
                    continue;
                }
            }
        }
        private List <XKeys> GetUnusedKeyStrokes(PresetVoiLut include)
        {
            List <XKeys> keyStrokes = new List <XKeys>(AvailablePresetVoiLutKeyStrokeSettings.Default.GetAvailableKeyStrokes());

            foreach (PresetVoiLut presetVoiLut in _voiLutPresets.Items)
            {
                if (include != null && include.KeyStroke == presetVoiLut.KeyStroke)
                {
                    continue;
                }

                keyStrokes.Remove(presetVoiLut.KeyStroke);
            }

            if (!keyStrokes.Contains(XKeys.None))
            {
                keyStrokes.Add(XKeys.None);
            }

            //put 'None' at the top.
            keyStrokes.Sort();

            return(keyStrokes);
        }
        public void OnEditSelected()
        {
            if (!EditEnabled)
            {
                return;
            }

            if (this.SelectedPresetVoiLut == null)
            {
                this.Host.DesktopWindow.ShowMessageBox(SR.MessagePleaseSelectAnItemToEdit, MessageBoxActions.Ok);
                return;
            }

            try
            {
                PresetVoiLutConfiguration       configuration = this.SelectedPresetOperation.GetConfiguration();
                IPresetVoiLutOperationComponent editComponent = this.SelectedPresetOperation.SourceFactory.GetEditComponent(configuration);
                editComponent.EditContext = EditContext.Edit;
                PresetVoiLutOperationsComponentContainer container = new PresetVoiLutOperationsComponentContainer(GetUnusedKeyStrokes(this.SelectedPresetVoiLut), editComponent);
                container.SelectedKeyStroke = this.SelectedPresetVoiLut.KeyStroke;

                if (ApplicationComponentExitCode.Accepted != ApplicationComponent.LaunchAsDialog(this.Host.DesktopWindow, container, SR.TitleEditPreset))
                {
                    return;
                }

                PresetVoiLut preset = container.GetPresetVoiLut();
                Platform.CheckForNullReference(preset, "preset");

                List <PresetVoiLut> conflictingItems = CollectionUtils.Select <PresetVoiLut>(_voiLutPresets.Items,
                                                                                             delegate(PresetVoiLut test){ return(preset.Equals(test)); });

                if (conflictingItems.Count == 0 ||
                    (conflictingItems.Count == 1 && conflictingItems[0].Equals(this.SelectedPresetVoiLut)))
                {
                    PresetVoiLut selected = this.SelectedPresetVoiLut;

                    int index = _voiLutPresets.Items.IndexOf(selected);
                    _voiLutPresets.Items.Remove(selected);

                    if (index < _voiLutPresets.Items.Count)
                    {
                        _voiLutPresets.Items.Insert(index, preset);
                    }
                    else
                    {
                        _voiLutPresets.Items.Add(preset);
                    }

                    Selection = null;

                    this.Modified = true;
                }
                else
                {
                    this.Host.DesktopWindow.ShowMessageBox(SR.MessageNameOrKeystrokeConflictsWithExistingPreset, MessageBoxActions.Ok);
                }
            }
            catch (Exception e)
            {
                ExceptionHandler.Report(e, SR.MessageFailedToEditPreset, this.Host.DesktopWindow);
            }
        }