private void imageDrop(object sender, DragEventArgs e) { Image imageControl = (Image)sender; int imageNum = int.Parse(imageControl.Tag as String); if ((e.Data.GetData(typeof(String)) != null)) { String tag = e.Data.GetData(typeof(String)) as String; switch (tag) { case "FolderAction": Actions[imageNum] = new FolderAction(); break; case "StartProgramAction": Actions[imageNum] = new LaunchAction(); break; case "TextStringAction": Actions[imageNum] = new TextStringAction(); break; case "HotkeyAction": Actions[imageNum] = new HotkeyAction(); break; } controller.AddAction(imageNum + 1, Actions[imageNum]); Notify("Action" + imageNum.ToString()); } else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (File.Exists(files[0])) { Actions[imageNum].Icon = Bitmap.FromFile(files[0]); controller.AddAction(imageNum + 1, Actions[imageNum]); Notify("Action" + imageNum.ToString()); } } }
public void Load() { allActions.Clear(); if (!File.Exists(SaveFileName)) { return; } XDocument doc = XDocument.Load(SaveFileName); foreach (XElement elem in doc.Element("root").Elements()) { string path = ""; IButtonPressAction action = null; switch (elem.Name.LocalName) { case "FolderAction": FolderAction folderAction = new FolderAction(); action = folderAction; path = elem.Attribute("Key").Value.ToString(); folderAction.Title = elem.Attribute("Title").Value.ToString(); folderAction.ExeConditionName = elem.Attribute("ExeCondition").Value.ToString(); if (elem.Attribute("BackgroundColor") != null) { folderAction.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString()); } if (elem.Attribute("Font") != null) { folderAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value); } folderAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False"); allActions.TryAdd(path, folderAction); break; case "LaunchAction": LaunchAction launchAction = new LaunchAction(); action = launchAction; path = elem.Attribute("Key").Value.ToString(); launchAction.Title = elem.Attribute("Title").Value.ToString(); launchAction.ExePath = elem.Attribute("ExePath").Value.ToString(); launchAction.Args = elem.Attribute("Args").Value.ToString(); if (elem.Attribute("BackgroundColor") != null) { launchAction.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString()); } if (elem.Attribute("Font") != null) { launchAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value); } launchAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False"); var result = LaunchAction.ProcessRunningAction.FocusOldProcess; Enum.TryParse(elem.Attribute("AlreadyRunningAction").Value.ToString(), out result); launchAction.AlreadyRunningAction = result; allActions.TryAdd(path, launchAction); break; case "StringAction": TextStringAction textAction = new TextStringAction(); action = textAction; path = elem.Attribute("Key").Value.ToString(); textAction.Title = elem.Attribute("Title").Value.ToString(); textAction.Value = elem.Attribute("Value").Value.ToString(); if (elem.Attribute("BackgroundColor") != null) { textAction.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString()); } if (elem.Attribute("Font") != null) { textAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value); } textAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False"); allActions.TryAdd(path, textAction); break; case "HotkeyAction": HotkeyAction hotkeyAction = new HotkeyAction(); action = hotkeyAction; path = elem.Attribute("Key").Value.ToString(); if (elem.Attribute("BackgroundColor") != null) { hotkeyAction.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString()); } if (elem.Attribute("Font") != null) { hotkeyAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value); } hotkeyAction.Title = elem.Attribute("Title").Value.ToString(); hotkeyAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False"); for (int i = 0; i < 3; i++) { VirtualKeyCode key = (VirtualKeyCode)int.Parse(elem.Attribute("Mod" + i).Value.ToString()); if (key != 0) { hotkeyAction.Modifiers.Add(key); } } hotkeyAction.MainKey = (VirtualKeyCode)int.Parse(elem.Attribute("MainKey").Value.ToString()); allActions.TryAdd(path, hotkeyAction); break; } if (File.Exists("Images/" + path + ".png")) { action.Icon = Bitmap.FromFile("Images/" + path + ".png"); } } }