/// <summary> /// Runs the editor form of an asset /// </summary> /// <param name="name">Name of the asset</param> public AssetEditorBase Edit(string name) { if (Editor == null) { Trace.WriteDebugLine("[RegisteredAsset::Edit()] No editor defined for \"" + Tag + "\"."); return(null); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } // Create the form from the registred asset AssetEditorBase form = Activator.CreateInstance(Editor, new object[] { Get(name) }) as AssetEditorBase; if (form == null) { throw new NullReferenceException(""); } form.TabText = name + " (" + form.Asset.GetType().Name + ")"; return(form); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Wizard_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult != DialogResult.OK) { return; } // Invalid name if (string.IsNullOrEmpty(NameBox.Text)) { MessageBox.Show("Asset name invalid. Use another name !"); e.Cancel = true; return; } // Create the asset //foreach (Provider provider in ResourceManager.Providers) { //foreach (Type type in provider.Assets) foreach (RegisteredAsset ra in ResourceManager.RegisteredAssets) { if (ra.Tag == TypesBox.Text) { // Invoke the generic method like this : provider.Add<[Asset Type]>(NameBox.Text, null); //object[] args = { NameBox.Text, null }; //MethodInfo mi = provider.GetType().GetMethod("Add").MakeGenericMethod(type); //mi.Invoke(provider, args); ra.Add(NameBox.Text, null); // Open the editor windows //args = new object[] { NameBox.Text }; //mi = provider.GetType().GetMethod("EditAsset").MakeGenericMethod(type); //AssetEditorBase form = mi.Invoke(provider, args) as AssetEditorBase; AssetEditorBase form = ra.Edit(NameBox.Text); if (form == null) { return; } // Give a name to the asset form.Asset.Name = NameBox.Text; // Show the form form.DockHandler.Show(Dockpanel, DockState.Document); return; } } } }
/// <summary> /// Edit an asset /// </summary> /// <param name="node">Tree node</param> /// <returns>True if asset is editable</returns> private bool EditAsset(TreeNode node) { // Not an editable node if (node == null || node.Nodes.Count > 0) { return(false); } // Don not edit binaires if (node.Text.StartsWith("Binaries")) { new BinaryForm().Show(DockPanel, DockState.Document); return(true); } // Asset not editable if (node.Tag == null) { return(false); } // Get the asset definition RegisteredAsset ra = ResourceManager.GetRegisteredByType(node.Tag as Type); if (ra == null) { return(false); } // Get the editor AssetEditorBase form = ra.Edit(node.Text); if (form == null) { return(false); } form.Show(DockPanel, DockState.Document); return(true); }
/// <summary> /// Save all resources to a storage /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveResourcesToStorage(object sender, EventArgs e) { // Save all opened asset foreach (DockContent window in dockPanel.Contents) { if (window is AssetEditorBase) { AssetEditorBase asseteditor = window as AssetEditorBase; asseteditor.Save(); } } // Select a storage if (Storage == null) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Resource bank (*.bnk)|*.bnk|All Files (*.*)|*.*"; dlg.Title = "Save resource as..."; dlg.DefaultExt = ".bnk"; dlg.RestoreDirectory = true; dlg.AddExtension = true; dlg.CheckPathExists = true; dlg.OverwritePrompt = true; dlg.ValidateNames = true; DialogResult res = dlg.ShowDialog(); if (res != DialogResult.OK) { return; } Storage = new BankStorage(dlg.FileName); } Text = "ArcEngine Editor " + Storage; ResourceManager.SaveAssetsToStorage(Storage); }