diff --git a/api/src/main/scala/uk/ac/surrey/xw/api/ComponentWidget.scala b/api/src/main/scala/uk/ac/surrey/xw/api/ComponentWidget.scala index 010acc3..389d116 100644 --- a/api/src/main/scala/uk/ac/surrey/xw/api/ComponentWidget.scala +++ b/api/src/main/scala/uk/ac/surrey/xw/api/ComponentWidget.scala @@ -46,7 +46,7 @@ trait ComponentWidget .getOrElse(throw XWException("Widget " + key + " is not on any tab.")) .key def setTab(tabKey: WidgetKey): Unit = - ws.xwTabs.find(_.key == normalizeString(tabKey)) match { + ws.xwTabs.find(_.key == tabKey) match { case None ⇒ throw XWException("Tab " + tabKey + " does not exist.") case Some(newTab) ⇒ tab match { diff --git a/core/src/main/scala/uk/ac/surrey/xw/state/Reader.scala b/core/src/main/scala/uk/ac/surrey/xw/state/Reader.scala index d86a750..da6086d 100644 --- a/core/src/main/scala/uk/ac/surrey/xw/state/Reader.scala +++ b/core/src/main/scala/uk/ac/surrey/xw/state/Reader.scala @@ -50,13 +50,13 @@ class Reader( def widgetKeyVector: Vector[WidgetKey] = Vector() ++ widgetMap.keys private def mutablePropertyMap(widgetKey: WidgetKey): Either[XWException, MutablePropertyMap] = - widgetMap.get(normalizeString(widgetKey)).orException( + widgetMap.get(widgetKey).orException( "Widget " + widgetKey + " does not exist.") def propertyMap(widgetKey: WidgetKey): Either[XWException, PropertyMap] = mutablePropertyMap(widgetKey).right.map(_.toMap) - def contains(widgetKey: WidgetKey) = widgetMap.contains(normalizeString(widgetKey)) + def contains(widgetKey: WidgetKey) = widgetMap.contains(widgetKey) def propertyKeyVector(widgetKey: WidgetKey): Either[XWException, Vector[PropertyKey]] = mutablePropertyMap(widgetKey).right.map(Vector() ++ _.keysIterator) diff --git a/core/src/main/scala/uk/ac/surrey/xw/state/Writer.scala b/core/src/main/scala/uk/ac/surrey/xw/state/Writer.scala index 9a963eb..9e87bb2 100644 --- a/core/src/main/scala/uk/ac/surrey/xw/state/Writer.scala +++ b/core/src/main/scala/uk/ac/surrey/xw/state/Writer.scala @@ -37,20 +37,19 @@ class Writer( } def add(widgetKey: WidgetKey, propertyMap: PropertyMap): Unit = { - val wKey = normalizeString(widgetKey) val properties = propertyMap.normalizeKeys - reader.validateNonEmpty("widget key", wKey).rightOrThrow - reader.validateUnique("widget key", wKey).rightOrThrow + reader.validateNonEmpty("widget key", widgetKey).rightOrThrow + reader.validateUnique("widget key", widgetKey).rightOrThrow val kind = getKind(widgetKey, properties) val tabProperty: PropertyMap = kind match { case _: TabKind[_] ⇒ Map.empty case _ if properties.isDefinedAt(tabPropertyKey) ⇒ Map.empty case _ ⇒ Map(tabPropertyKey -> getLastTabKey) } - val keyProperty = Map(keyPropertyKey -> wKey) + val keyProperty = Map(keyPropertyKey -> widgetKey) val allProperties = kind.defaultValues ++ properties ++ tabProperty ++ keyProperty - widgetMap += wKey -> allProperties.asMutablePropertyMap - publish(AddWidget(wKey, allProperties)) + widgetMap += widgetKey -> allProperties.asMutablePropertyMap + publish(AddWidget(widgetKey, allProperties)) } def getKind(widgetKey: WidgetKey, propertyMap: PropertyMap): WidgetKind[_] = { @@ -86,16 +85,15 @@ class Writer( .getOrElse(throw new XWException("No widget tab has been created yet.")) def remove(widgetKey: WidgetKey): Unit = { - val wKey = normalizeString(widgetKey) // Special case: if we're removing a tab, also // remove the widgets on that tab from the widget map - if (reader.get(kindPropertyKey, wKey) == tabKindName) { + if (reader.get(kindPropertyKey, widgetKey) == tabKindName) { widgetMap --= widgetMap.collect { - case (k, ps) if ps.get(tabPropertyKey) == Some(wKey) ⇒ k + case (k, ps) if ps.get(tabPropertyKey) == Some(widgetKey) ⇒ k } } - widgetMap -= wKey - publish(RemoveWidget(wKey)) + widgetMap -= widgetKey + publish(RemoveWidget(widgetKey)) } def set( @@ -110,14 +108,13 @@ class Writer( propertyValue: PropertyValue, publishEvent: Boolean): Unit = { - val wKey = normalizeString(widgetKey) - val propertyMap = widgetMap.getOrElse(wKey, - throw XWException("Widget " + wKey + " does not exist.")) + val propertyMap = widgetMap.getOrElse(widgetKey, + throw XWException("Widget " + widgetKey + " does not exist.")) val pKey = normalizeString(propertyKey) val oldValue = propertyMap.get(pKey) if (Some(propertyValue) != oldValue) { propertyMap += pKey -> propertyValue - if (publishEvent) publish(SetProperty(wKey, pKey, propertyValue)) + if (publishEvent) publish(SetProperty(widgetKey, pKey, propertyValue)) } } diff --git a/xw/src/main/scala/uk/ac/surrey/xw/extension/WidgetContextManager.scala b/xw/src/main/scala/uk/ac/surrey/xw/extension/WidgetContextManager.scala index da6d048..0ef192a 100644 --- a/xw/src/main/scala/uk/ac/surrey/xw/extension/WidgetContextManager.scala +++ b/xw/src/main/scala/uk/ac/surrey/xw/extension/WidgetContextManager.scala @@ -2,7 +2,6 @@ package uk.ac.surrey.xw.extension import uk.ac.surrey.xw.api.WidgetKey import uk.ac.surrey.xw.api.XWException -import uk.ac.surrey.xw.api.normalizeString class WidgetContextManager { var stack: List[WidgetKey] = List.empty @@ -14,7 +13,7 @@ class WidgetContextManager { | block passed to xw:create-, xw:ask or xw:of. |""".stripMargin)) def withContext[A](key: WidgetKey)(f: () ⇒ A): A = { - stack = normalizeString(key) :: stack // push + stack = key :: stack // push val result = f() stack = stack.tail // pop result