diff --git a/BHoMUpgrades/CustomUpgrades/v100.cs b/BHoMUpgrades/CustomUpgrades/v100.cs index 1fdfb96..159304e 100644 --- a/BHoMUpgrades/CustomUpgrades/v100.cs +++ b/BHoMUpgrades/CustomUpgrades/v100.cs @@ -22,7 +22,6 @@ using BH.oM.Versioning; using System.Collections.Generic; -using System; namespace BH.Upgraders { @@ -33,6 +32,103 @@ public static class v100 /**** Public Methods ****/ /***************************************************/ + [VersioningTarget("BH.Revit.oM.UI.UIManagementSettings")] + public static Dictionary UpgradeUIManagementSettings(Dictionary oldVersion) + { + if (oldVersion == null) + return null; + + Dictionary newVersion = new Dictionary(); + newVersion["_t"] = "BH.Revit.oM.UI.ButtonLayoutSettings"; + + if (oldVersion.ContainsKey("Name")) + newVersion["Name"] = oldVersion["Name"]; + + if (oldVersion.ContainsKey("BHoM_Guid")) + newVersion["BHoM_Guid"] = oldVersion["BHoM_Guid"]; + + if (oldVersion.ContainsKey("CustomData")) + newVersion["CustomData"] = oldVersion["CustomData"]; + + if (oldVersion.ContainsKey("Fragments")) + newVersion["Fragments"] = oldVersion["Fragments"]; + + Dictionary buttonLayout = new Dictionary(); + buttonLayout["_t"] = "BH.Revit.oM.UI.ButtonLayout"; + buttonLayout["Tabs"] = new List>(); + + if (oldVersion.ContainsKey("PinnedItems")) + { + object[] pinnedItems = oldVersion["PinnedItems"] as object[]; + if (pinnedItems != null) + { + Dictionary>>> tabPanelMapping = new Dictionary>>>(); + foreach (object obj in pinnedItems) + { + Dictionary item = obj as Dictionary; + if (item == null) + continue; + + if (!item.ContainsKey("_t")) + continue; + + if (item["_t"] as string != "BH.Revit.oM.UI.PinnedItemInfo") + continue; + + if (!item.ContainsKey("PanelName") || !item.ContainsKey("TabName")) + continue; + + string tabName = item["TabName"] as string; + string panelName = item["PanelName"] as string; + + if (string.IsNullOrWhiteSpace(tabName) || string.IsNullOrWhiteSpace(panelName)) + continue; + + if (!tabPanelMapping.ContainsKey(tabName)) + tabPanelMapping[tabName] = new Dictionary>>(); + + if (!tabPanelMapping[tabName].ContainsKey(panelName)) + tabPanelMapping[tabName][panelName] = new List>(); + + Dictionary newItem = new Dictionary(item); + newItem["_t"] = "BH.Revit.oM.UI.PinnedButton"; + + if (newItem.ContainsKey("BHoM_Guid")) + newItem.Remove("BHoM_Guid"); + + if (newItem.ContainsKey("CustomData")) + newItem.Remove("CustomData"); + + if (newItem.ContainsKey("Fragments")) + newItem.Remove("Fragments"); + + tabPanelMapping[tabName][panelName].Add(newItem); + } + + foreach (KeyValuePair>>> tab in tabPanelMapping) + { + Dictionary tabDict = new Dictionary(); + tabDict["_t"] = "BH.Revit.oM.UI.TabLayout"; + tabDict["Name"] = tab.Key; + tabDict["Panels"] = new List>(); + foreach (KeyValuePair>> panel in tab.Value) + { + Dictionary panelDict = new Dictionary(); + panelDict["_t"] = "BH.Revit.oM.UI.Panel"; + panelDict["Name"] = panel.Key; + panelDict["Items"] = panel.Value; + (tabDict["Panels"] as List>).Add(panelDict); + } + (buttonLayout["Tabs"] as List>).Add(tabDict); + } + } + } + + newVersion["Layout"] = buttonLayout; + + return newVersion; + } + /***************************************************/ } } \ No newline at end of file