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; } } }
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); } }
public void SetPresetGroups(PresetVoiLutGroupCollection groups) { try { XmlDocument document = new XmlDocument(); XmlElement rootElement = document.CreateElement("preset-voi-luts"); document.AppendChild(rootElement); foreach (PresetVoiLutGroup group in groups) { if (group.Presets.Count == 0) { continue; } XmlElement groupNode = document.CreateElement("group"); if (!String.IsNullOrEmpty(group.Modality)) { groupNode.SetAttribute("modality", group.Modality); } rootElement.AppendChild(groupNode); XmlElement presetsElement = document.CreateElement("presets"); groupNode.AppendChild(presetsElement); foreach (PresetVoiLut preset in group.Presets) { XmlElement presetElement = document.CreateElement("preset"); presetsElement.AppendChild(presetElement); if (preset.KeyStroke != XKeys.None) { presetElement.SetAttribute("keystroke", preset.KeyStroke.ToString()); } PresetVoiLutConfiguration configuration = preset.Operation.GetConfiguration(); presetElement.SetAttribute("factory", configuration.FactoryName); XmlElement configurationElement = document.CreateElement("configuration"); presetElement.AppendChild(configurationElement); foreach (KeyValuePair <string, string> configurationItem in configuration) { if (String.IsNullOrEmpty(configurationItem.Key) || String.IsNullOrEmpty(configurationItem.Value)) { continue; } XmlElement configurationItemElement = document.CreateElement("item"); configurationItemElement.SetAttribute("key", configurationItem.Key); configurationItemElement.SetAttribute("value", configurationItem.Value); configurationElement.AppendChild(configurationItemElement); } } } _presetGroups = null; string currentSettings = this.SettingsXml; this.SettingsXml = document.OuterXml; this.Save(); } catch (Exception e) { Platform.Log(LogLevel.Error, e); } }