/// <summary> /// This event gets called when an item is dropped on the dock /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DisplayGrid_Drop(object sender, System.Windows.DragEventArgs e) { //TODO : We could make it so you are able to add multiple icons at the same time var files = (string[])e.Data.GetData(DataFormats.FileDrop); FileInfo fileInfo = new FileInfo(files[0]); //Create the image of the Icon System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(files[0]); //Create the name that this icon image is going to be stored under var newIconImageName = fileInfo.Name.Replace(fileInfo.Extension.ToString(), "") + ".png"; string startupPath = Environment.CurrentDirectory; if (!File.Exists(startupPath + "\\icons\\" + newIconImageName)) { icon.ToBitmap().Save(startupPath + "\\icons\\" + newIconImageName); } // instantiate a new shortcut object temporarily with enough information to generate an XML fragment var button = new Bauble.Buttons.Shortcut("icons/" + newIconImageName, fileInfo.Name, files[0]) as IBaubleButton; // have the settings object create a fully instantiated button object button = _settings.AddShortcut(button); // load the button onto the current dock DisplayButton(DisplayGrid.ColumnDefinitions.Count + 1, button); // Allow the IconFlow to initialize the button for any animations it uses _settings.IconFlow.Initialize(button); // save the new button list out to the file system _settings.SaveButtonList(); }
/// <summary> /// This event gets called when an item is dropped on the dock /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DisplayGrid_Drop(object sender, System.Windows.DragEventArgs e) { //TODO : We could make it so you are able to add multiple icons at the same time var files = (string[])e.Data.GetData(DataFormats.FileDrop); string filename = files[0]; string startupPath = Environment.CurrentDirectory; System.Drawing.Icon icon = null; string newIconImageName = string.Empty; FileInfo fileInfo = null; string workingDirectory = string.Empty; string text = string.Empty; IconExtractor ie = null; //if (files[0].ToLower().EndsWith("lnk")) //{ // var link = Lnk.Lnk.LoadFile(filename); // fileInfo = new FileInfo(link.LocalPath); // filename = fileInfo.Name; // workingDirectory = link.WorkingDirectory; // text = link.Name; // string iconFile = link.IconLocation; // if (!string.IsNullOrWhiteSpace(iconFile)) // { // int iconIndex = link.Header.IconIndex; // iconFile = Environment.ExpandEnvironmentVariables(iconFile); // if (!string.IsNullOrWhiteSpace(iconFile)) // { // ie = new IconExtractor(iconFile); // icon = ie.GetIcon(iconIndex); // } // } // else // { // icon = System.Drawing.Icon.ExtractAssociatedIcon(link.IconLocation); // } //} //else //{ // if (File.Exists(files[0])) // { fileInfo = new FileInfo(files[0]); filename = fileInfo.Name; text = fileInfo.Name; //Create the image of the Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(files[0]); // } // else if (Directory.Exists(files[0])) // { // newIconImageName = "folder.png"; // } //} if (icon != null && fileInfo != null) { //Create the name that this icon image is going to be stored under newIconImageName = fileInfo.Name.Replace(fileInfo.Extension.ToString(), "") + ".png"; if (!File.Exists(startupPath + "\\icons\\" + newIconImageName)) { IconUtil.ToBitmap(icon).Save(startupPath + "\\icons\\" + newIconImageName); var icons = ie.GetAllIcons(); for (int i = 0; i < icons.Length; i++) { IconUtil.ToBitmap(icons[i]).Save(startupPath + "\\icons\\imageres\\" + i.ToString() + ".png"); } } } // instantiate a new shortcut object temporarily with enough information to generate an XML fragment var button = new Bauble.Buttons.Shortcut("icons/" + newIconImageName, text, filename, workingDirectory) as IBaubleButton; // have the settings object create a fully instantiated button object button = _settings.AddShortcut(button); // load the button onto the current dock DisplayButton(DisplayGrid.ColumnDefinitions.Count + 1, button); // Allow the IconFlow to initialize the button for any animations it uses _settings.IconFlow.Initialize(button); // save the new button list out to the file system _settings.SaveButtonList(); }