/// <summary> /// this saves the currently selected addon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SaveAddon_Click(object sender, RoutedEventArgs e) { AddonManager.CurrentAddon = new C3Addon { Name = string.Empty, Class = string.Empty, Company = string.Empty, Author = string.Empty, Description = string.Empty, AddonCategory = string.Empty, Type = PluginType.SingleGlobalPlugin, Effect = new Effect(), ThemeCss = string.Empty, ThemeLangauge = string.Empty, IconXml = ResourceReader.Insatnce.GetResourceText("c3IDE.Templates.Files.icon.svg"), CreateDate = DateTime.Now }; Enum.TryParse <PluginType>(AddonTypeDropdown.SelectedValue.ToString(), out var pluginType); var addonCategory = string.IsNullOrWhiteSpace(AddonCategoryDropdown.Text)? "other": AddonCategoryDropdown.Text; AddonManager.CurrentAddon.Name = AddonNameText.Text; AddonManager.CurrentAddon.Class = AddonClassText.Text.Replace(" ", string.Empty).Trim(); AddonManager.CurrentAddon.Company = AuthorText.Text.Replace(" ", string.Empty).Trim(); AddonManager.CurrentAddon.Author = AuthorText.Text; AddonManager.CurrentAddon.AddonId = IdText.Text.Replace(" ", string.Empty).Trim(); AddonManager.CurrentAddon.Description = DescriptionText.Text; AddonManager.CurrentAddon.Type = pluginType; AddonManager.CurrentAddon.AddonCategory = addonCategory; AddonManager.CurrentAddon.IconXml = IconXml; AddonManager.CurrentAddon.Template = TemplateFactory.Insatnce.CreateTemplate(pluginType); AddonManager.CurrentAddon.LastModified = DateTime.Now; //add version AddonManager.CurrentAddon.MajorVersion = 1; AddonManager.CurrentAddon.MinorVersion = 0; AddonManager.CurrentAddon.RevisionVersion = 0; AddonManager.CurrentAddon.BuildVersion = 0; //validate addon if (!AddonManager.ValidateCurrentAddon()) { NotificationManager.PublishErrorNotification("addon data fields cannot be blank"); return; } AddonMetadataGrid.IsEnabled = false; await Task.Run(() => { IsSaved = true; AddonManager.CompileTemplates(); AddonManager.SaveCurrentAddon(); AddonManager.LoadAllAddons(); }); AddonMetadataGrid.IsEnabled = true; AddonManager.LoadAddon(AddonManager.CurrentAddon); NotificationManager.PublishNotification($"{AddonManager.CurrentAddon.Name} has been saved successfully"); WindowManager.ChangeWindow(ApplicationWindows.DashboardWindow); }
private async void ChangeAddonName_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error changing addon name, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); var newName = await WindowManager.ShowInputDialog("Change Addon Name", "enter new addon name", currentAddon.Name); var oldName = currentAddon.Name; if (!string.IsNullOrWhiteSpace(newName)) { AddonManager.CurrentAddon.Name = newName; Searcher.Insatnce.GlobalFind(oldName, this, newName); AddonManager.SaveCurrentAddon(); AddonManager.LoadAllAddons(); ApplicationWindows.DashboardWindow.OnExit(); ApplicationWindows.DashboardWindow.OnEnter(); } }
/// <summary> /// loads the selected addon as the current addon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadSelectedAddon_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error loading c3addon, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); }
/// <summary> /// exports the cuurently selected addon to c3ide project file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExportAddonProject_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error exporting c3addon, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); ProcessHelper.Insatnce.StartProcess(AddonManager.ExportAddonProject()); }
/// <summary> /// loads compiles and test the selected addon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CompileAndTest_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error compiling c3addon, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); WindowManager.ChangeWindow(ApplicationWindows.TestWidnow); await ApplicationWindows.TestWidnow.Test(); }
/// <summary> /// opens the change icon window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ChangeAddonIcon_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error changing addon icon, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); var changeIconWindow = new AddonIconWindow(); changeIconWindow.Init(currentAddon.IconXml); changeIconWindow.ShowDialog(); }
/// <summary> /// builds the c3addon zip file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BuildSelectedAddon_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error building c3addon, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); AddonExporter.Insatnce.ExportAddon(AddonManager.CurrentAddon); ProcessHelper.Insatnce.StartProcess(OptionsManager.CurrentOptions.C3AddonPath); AddonManager.IncrementVersion(); AddonManager.LoadAllAddons(); AddonListBox.ItemsSource = AddonManager.AllAddons; }
private async void ChangeAddonAuthor_Click(object sender, RoutedEventArgs e) { if (AddonListBox.SelectedIndex == -1) { NotificationManager.PublishErrorNotification("error changing addon author, no c3addon selected"); return; } var currentAddon = (C3Addon)AddonListBox.SelectedItem; AddonManager.LoadAddon(currentAddon); var newAuth = await WindowManager.ShowInputDialog("Change Addon Author", "enter new addon author", currentAddon.Author); var oldAuth = currentAddon.Author; if (!string.IsNullOrWhiteSpace(newAuth)) { AddonManager.CurrentAddon.Author = newAuth; Searcher.Insatnce.GlobalFind(oldAuth, this, newAuth); } }
//todo: we want to use the same guid, to overwrite existing addon. //todo: we want to parse a different version of the .c3ide file with relative paths //todo: abstract this functionaility out to a helper class /// <summary> /// when a file is dropped into the list box, if the file is a .c3ide file parse the file and load the addon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AddonFile_OnDrop(object sender, DragEventArgs e) { try { var file = ((string[])e.Data.GetData(DataFormats.FileDrop))?.FirstOrDefault(); var info = new FileInfo(file); C3Addon c3addon; if (info.Extension.Contains("c3ide")) { var addonInfo = File.ReadAllLines(info.FullName)[0]; if (addonInfo == "@@METADATA") { c3addon = ProjectManager.ReadProject(info.FullName); } else { var data = File.ReadAllText(info.FullName); c3addon = JsonConvert.DeserializeObject <C3Addon>(data); } //when you import the project, it should not overwrite any other project if (OptionsManager.CurrentOptions.OverwriteGuidOnImport) { c3addon.Id = Guid.NewGuid(); } c3addon.LastModified = DateTime.Now; //get the plugin template c3addon.Template = TemplateFactory.Insatnce.CreateTemplate(c3addon.Type); var addonIndex = AddonManager.AllAddons.Count - 1; AddonManager.CurrentAddon = c3addon; AddonManager.SaveCurrentAddon(); AddonManager.LoadAllAddons(); AddonListBox.ItemsSource = AddonManager.AllAddons; AddonManager.LoadAddon(c3addon); } else if (info.Extension.Contains("c3addon")) { var result = await WindowManager.ShowDialog("(EXPERIMENTAL) Importing C3Addon File", "Importing a C3addon file is an experimental feature. Please verify your file was improted correctly. If you encounter an issue please open a Github Issue Ticket"); if (result) { c3addon = await C3AddonImporter.Insatnce.Import(info.FullName); AddonManager.LoadAddon(c3addon); AddonManager.SaveCurrentAddon(); AddonManager.LoadAllAddons(); AddonListBox.ItemsSource = AddonManager.AllAddons; AddonManager.LoadAddon(c3addon); } } else if (info.Extension.Contains("c2addon")) { var result = await WindowManager.ShowDialog("(VERY EXPERIMENTAL) Importing C2Addon File", "Importing a C2addon file is an very experimental feature and expected to have BUGS. THIS DOES NOT FULLY CONVERT YOUR ADDON, it will attempt to generate stubs for the ACES. if you run into any issue importing please file Github Issue Ticket, please include the c2addon your trying to convert to help identify the issues, NOT ALL ISSUE WILL BE RESOLVED but i will do my best!!!"); if (result) { c3addon = await C2AddonImporter.Insatnce.Import2Addon(info.FullName); AddonManager.LoadAddon(c3addon); AddonManager.SaveCurrentAddon(); AddonManager.LoadAllAddons(); AddonListBox.ItemsSource = AddonManager.AllAddons; AddonManager.LoadAddon(c3addon); } } //else if (info.Extension.Contains("svg")) //{ // //todo: need to find a way to drag items into list box item //} else { throw new InvalidOperationException("invalid file type, for import"); } } catch (Exception exception) { LogManager.AddErrorLog(exception); NotificationManager.PublishErrorNotification($"error importing file, check import.log => {Path.Combine(OptionsManager.CurrentOptions.DataPath, "import.log")}"); } }