so painful
authorRichard Fairhurst <richard@systemed.net>
Tue, 29 Jun 2010 16:30:41 +0000 (16:30 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 29 Jun 2010 16:30:41 +0000 (16:30 +0000)
net/systemeD/potlatch2/CategorySelector.mxml
net/systemeD/potlatch2/TagViewer.mxml

index 5856953..6713e85 100644 (file)
@@ -7,6 +7,7 @@
   <mx:HBox horizontalGap="0"> 
   <mx:ToggleButtonBar height="100%" dataProvider="{categoryStack}" direction="vertical"/>
   <mx:ViewStack id="categoryStack" width="100%" height="100%"
+      change="_formerIndex=event.newIndex;" 
       creationComplete="setSelectedFeature(_selectedType);">
       <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType(limit)}">
           <mx:VBox label="{catRep.currentItem.name}">
@@ -42,6 +43,7 @@
       private var settingSelection:Boolean = false;
       private var _selectedType:Feature;
       private var _limit:String;
+      private var _formerIndex:int=0;
       
       [Bindable(event="selectedType")]
       public function get selectedType():Feature {
           if ( categoryStack == null )
               return;
 
+          // set the tab to the selected item's category
+          // (we have to manually fire the IndexChangedEvent because Flex's ViewStack.as isn't competent 
+          //  enough to do it reliably. This is basically a direct crib from dispatchChangeEvent)
+          var index:int=0;
           if ( feature != null ) {
               var primaryCategory:Category = feature.findFirstCategory();
-          
-              // set the tab to the selected item's category
-              // (we have to manually fire the IndexChangedEvent because Flex's ViewStack.as isn't competent 
-              //  enough to do it reliably. This is basically a direct crib from dispatchChangeEvent)
-              var index:int = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
-              var former:int = categoryStack.selectedIndex;
-              if (index!=former) {
-                     var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
-                     event.oldIndex = former;
-                     event.newIndex = index;
-                     event.relatedObject = categoryStack.getChildAt(index);
-                     categoryStack.selectedIndex = index;
-                     categoryStack.dispatchEvent(event);
-              }
+              index = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
           }
+          var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
+          event.oldIndex = _formerIndex;
+          event.newIndex = index;
+          event.relatedObject = categoryStack.getChildAt(index);
+          categoryStack.selectedIndex = index;
+          categoryStack.dispatchEvent(event);
+          _formerIndex=index;
           
           // finalise the item selection
           ensureSelection();
       }
+      public function setNoSelectedFeature():void {
+           _selectedType=null;
+         }
       
       /**
        * Sets the selected feature on each category page to the current
index 3aa840a..f4b0f40 100644 (file)
 
       private function blankFeatureIcon(entity:Entity):void {
           iconImage.source = null;
+          popupChange.label = "unknown";
+          setLimitTypes(entity);
                  if (entity == null) { 
                        iconText.htmlText = "<i>Nothing selected</i>";
+            tw.setNoSelectedFeature();
                  } else if (entity.hasTags()) {
                        iconText.htmlText = "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
+            tw.setSelectedFeature(null);
                  } else {
                        iconText.htmlText = "<b>No tags set</b><br/>Use the menu above to say what this "+entity.getType()+" is";
+            tw.setSelectedFeature(null);
           }
-          popupChange.label = "unknown";
-          setLimitTypes(entity);
-          tw.setSelectedFeature(null);
           helpLabel.visible = false;
       }