Selaa lähdekoodia

Bug: #82862 - ESP should be able to redefine an existing menu link

Also clean several lines using setProp().

Signed-off-by: Kevin Wang <kevin.wang@lexisnexis.com>
Kevin Wang 14 vuotta sitten
vanhempi
commit
561e1ecf6e
2 muutettua tiedostoa jossa 26 lisäystä ja 23 poistoa
  1. 1 1
      esp/platform/espbinding.hpp
  2. 25 22
      esp/platform/espprotocol.cpp

+ 1 - 1
esp/platform/espbinding.hpp

@@ -59,7 +59,7 @@ public:
     IPropertyTree *ensureNavDynFolder(IPropertyTree &root, const char *name, const char *tooltip, const char *parms, const char *menu=NULL);
     IPropertyTree *addNavException(IPropertyTree &root, const char *message=NULL, int code=0, const char *source=NULL);
 
-    IPropertyTree *ensureNavLink(IPropertyTree &folder, const char *name, const char *path, const char *tooltip, const char *menu=NULL, const char *navPath=NULL, unsigned relPosition = 0);
+    IPropertyTree *ensureNavLink(IPropertyTree &folder, const char *name, const char *path, const char *tooltip, const char *menu=NULL, const char *navPath=NULL, unsigned relPosition = 0, bool force = false);
     virtual void getNavigationData(IEspContext &context, IPropertyTree & data);
     virtual void getDynNavData(IEspContext &context, IProperties *params, IPropertyTree & data);
     virtual bool showSchemaLinks() { return false; }

+ 25 - 22
esp/platform/espprotocol.cpp

@@ -347,10 +347,8 @@ IPropertyTree *CEspBinding::ensureNavFolder(IPropertyTree &root, const char *nam
         ret=createPTree("Folder", false);
         ret->addProp("@name", name);
         ret->addProp("@tooltip", tooltip);
-        if (menuname)
-            ret->addProp("@menu", menuname);
-        if (sort)
-            ret->addPropBool("@sort", true);
+        ret->setProp("@menu", menuname);
+        ret->setPropBool("@sort", true);
         ret->addPropInt("@relPosition", relPosition);
 
         root.addPropTree("Folder", ret);
@@ -402,35 +400,41 @@ IPropertyTree *CEspBinding::ensureNavDynFolder(IPropertyTree &root, const char *
         ret->addProp("@name", name);
         ret->addProp("@tooltip", tooltip);
         ret->addProp("@params", params);
-        if (menuname)
-            ret->addProp("@menu", menuname);
+        ret->setProp("@menu", menuname);
         root.addPropTree("DynamicFolder", ret);
     }
     return ret;
 }
 
-IPropertyTree *CEspBinding::ensureNavLink(IPropertyTree &folder, const char *name, const char *path, const char *tooltip, const char *menuname, const char *navPath, unsigned relPosition)
+IPropertyTree *CEspBinding::ensureNavLink(IPropertyTree &folder, const char *name, const char *path, const char *tooltip, const char *menuname, const char *navPath, unsigned relPosition, bool force)
 {
     StringBuffer xpath;
     xpath.appendf("Link[@name=\"%s\"]", name);
 
+    bool addNew = true;
     IPropertyTree *ret = folder.queryPropTree(xpath.str());
-    if (!ret)
+    if (ret)
     {
+        bool forced = ret->getPropBool("@force");
+        if (forced || !force)
+            return ret;
+
+        addNew = false;
+    }
+
+    if (addNew)
         ret=createPTree("Link", false);
-        ret->addProp("@name", name);
-        if (tooltip)
-            ret->addProp("@tooltip", tooltip);
-        if (path)
-            ret->addProp("@path", path);
-        if (menuname)
-            ret->addProp("@menu", menuname);
-        if (navPath)
-            ret->addProp("@navPath", navPath);
-        ret->addPropInt("@relPosition", relPosition);
 
+    ret->setProp("@name", name);
+    ret->setProp("@tooltip", tooltip);
+    ret->setProp("@path", path);
+    ret->setProp("@menu", menuname);
+    ret->setProp("@navPath", navPath);
+    ret->setPropInt("@relPosition", relPosition);
+    ret->setPropBool("@force", force);
+
+    if (addNew)
         folder.addPropTree("Link", ret);
-    }
 
     return ret;
 }
@@ -439,10 +443,9 @@ IPropertyTree *CEspBinding::ensureNavLink(IPropertyTree &folder, const char *nam
 IPropertyTree *CEspBinding::addNavException(IPropertyTree &folder, const char *message/*=NULL*/, int code/*=0*/, const char *source/*=NULL*/)
 {
     IPropertyTree *ret = folder.addPropTree("Exception", createPTree(false));
-   ret->addProp("@message", message ? message : "Unknown exception");
+    ret->addProp("@message", message ? message : "Unknown exception");
     ret->setPropInt("@code", code); 
-   if (source)
-       ret->addProp("@source", source);
+    ret->setProp("@source", source);
     return ret;
 }