From 929ca20eb3ca352cdeab3ae7eda91f47901b8709 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Thu, 29 Sep 2011 17:37:10 +0100 Subject: [PATCH 1/1] Enforce consistent order on tabs --- net/systemeD/potlatch2/TagViewer.mxml | 66 +++++++++++++++++++-------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/net/systemeD/potlatch2/TagViewer.mxml b/net/systemeD/potlatch2/TagViewer.mxml index 55bf6925..b2b62fdd 100644 --- a/net/systemeD/potlatch2/TagViewer.mxml +++ b/net/systemeD/potlatch2/TagViewer.mxml @@ -397,39 +397,55 @@ if ( selectedEntity == null || feature == null ) return; - var editorBox:VBox = createEditorBox(); - editorBox.label = "Basic"; - editorBox.icon=tabIconBasic; - editorStack.addChild(editorBox); + var basicEditorBox:VBox = createEditorBox(); + basicEditorBox.label = "Basic"; + basicEditorBox.icon=tabIconBasic; + editorStack.addChild(basicEditorBox); var tabs:Object = {}; + var tabList:Array = []; tabComponents = {}; var subpanels:Object = {}; subpanelComponents = {}; - // ** FIXME: we should do this so that the tabs are always in the same order + // First create the tabs for each (var factory:EditorFactory in feature.editors) { + var category:String = factory.category; + if (category!='') { + var tab:VBox = tabs[category]; + if ( tab == null) { + tab = createEditorBox(); + tab.label = category; + if (tabIcons[category]) tab.icon=tabIcons[category]; + tabs[category] = tab; + tabList.push(tab); + } + } + } + + // Put the tabs on-screen in order + tabList.sort(sortCategories,16); + for each (tab in tabList) { + editorStack.addChild(tab); + tabComponents[tab] = []; + } + + // Then add the individual editors to them + for each (factory in feature.editors) { + + // Add to basic editor box first if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) { var editor:DisplayObject = factory.createEditorInstance(selectedEntity); - if (editor) editorBox.addChild(editor); + if (editor) basicEditorBox.addChild(editor); } + // Then prepare to add to category panel + category=factory.category; + if (factory.category=='') continue; var catEditor:DisplayObject = factory.createEditorInstance(selectedEntity); if (!catEditor) continue; - - // Create tab if it doesn't already exist - var category:String = factory.category; - if (category=='') continue; - var tab:VBox = tabs[category]; - if (tab == null) { - tab = createEditorBox(); - tab.label = category; - if (tabIcons[category]) tab.icon=tabIcons[category]; - editorStack.addChild(tab); - tabs[category] = tab; - tabComponents[tab] = []; - } - + tab=tabs[category]; + // Create subcategory panel if needed if (factory.subcategory) { var subcategory:String = factory.subcategory; @@ -450,6 +466,16 @@ } } + // ** FIXME: Order probably shouldn't be hard-coded, but configurable + private static var categoryOrder:Array=["Restrictions","Transport","Cycle","Walk","Address","Details"]; // reverse order + private function sortCategories(a:VBox,b:VBox):int { + var a1:int=categoryOrder.indexOf(a.label); + var a2:int=categoryOrder.indexOf(b.label); + if (a1a2) { return -1; } + return 0; + } + private function createEditorBox():VBox { var box:VBox = new VBox(); box.percentWidth = 100; -- 2.36.1