public static List <LibraryItem> ImportFile(string filename) { List <LibraryItem> result = new List <LibraryItem>(); string ext = Path.GetExtension(filename).ToUpperInvariant(); if (ext == ".SWF") { LibraryItem[] items = currentLibraryView.AddSwf(filename); result.AddRange(items); } else if (ext == ".BMP" || ext == ".JPG" || ext == ".GIF" || ext == ".PNG") { LibraryItem item = currentLibraryView.AddImage(filename); result.Add(item); } if (currentLibraryView.GetSelectedNode() == null && result.Count > 0) { currentLibraryView.SelectNode(result[0].DefinitionId); } else { currentLibraryView.RefreshCurrentNode(); } currentStage.HasSaveableChanges = true; currentStage.InvalidateAll(); currentLibraryView.Invalidate(); return(result); }
public void Execute() { StageView stage = MainForm.CurrentStage; LibraryView currentLibraryView = MainForm.CurrentLibraryView; string ext = Path.GetExtension(filename).ToUpperInvariant(); if (ext == ".SWF") { libraryItems = currentLibraryView.AddSwf(filename); } else if (ext == ".BMP" || ext == ".JPG" || ext == ".GIF" || ext == ".PNG") { libraryItems = new LibraryItem[] { currentLibraryView.AddImage(filename) }; } if (currentLibraryView.GetSelectedNode() == null && libraryItems.Length > 0) { currentLibraryView.SelectNode(libraryItems[0].DefinitionId); } else { currentLibraryView.RefreshCurrentNode(); } if (addToStage) { uint[] itemIds = new uint[libraryItems.Length]; Vex.Point[] locs = new Vex.Point[libraryItems.Length]; for (int i = 0; i < libraryItems.Length; i++) { itemIds[i] = libraryItems[i].Definition.Id; Vex.Point centerOffset = libraryItems[i].Definition.StrokeBounds.Center.Negate(); locs[i] = location.Translate(centerOffset); } AddInstancesCommand aic = new AddInstancesCommand(itemIds, locs); aic.Execute(); addInstanceCommands.Add(aic); stage.InvalidateAll(); } stage.HasSaveableChanges = true; currentLibraryView.Invalidate(); }