[rkward] packages/rkwarddev: improved ID checks

m.eik michalke meik.michalke at uni-duesseldorf.de
Sun Oct 11 17:24:25 UTC 2015


Git commit d394189c49fc298ea9fede638322e1c2cbedd135 by m.eik michalke.
Committed on 11/10/2015 at 17:22.
Pushed by meikm into branch 'master'.

improved ID checks

  - rk.uniqueIDs() now checks <dialog> and <wizard> sections apart from each other to be enable to use the same IDs in both

M  +1    -0    packages/rkwarddev/ChangeLog
M  +38   -16   packages/rkwarddev/R/rk.uniqueIDs.R

http://commits.kde.org/rkward/d394189c49fc298ea9fede638322e1c2cbedd135

diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index cd7ced4..fb8a9f5 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -20,6 +20,7 @@ added:
 changed:
   - improved error handling in rk.JS.header(), error messages are more
     informative now
+  - rk.uniqueIDs() now checks "dialog" and "wizard" sections separately
 
 changes in version 0.07-3 (2015-06-29)
 fixed:
diff --git a/packages/rkwarddev/R/rk.uniqueIDs.R b/packages/rkwarddev/R/rk.uniqueIDs.R
index 616de73..a02c2b3 100644
--- a/packages/rkwarddev/R/rk.uniqueIDs.R
+++ b/packages/rkwarddev/R/rk.uniqueIDs.R
@@ -32,27 +32,49 @@
 #'    If \code{bool=TRUE} returns a logical value.
 
 rk.uniqueIDs <- function(obj, bool=FALSE, warning=TRUE, ignore=c("copy")){
-  allIDs <- XMLScanDeep(obj, find="id", search="attributes")
-  # ignore nodes
-  allIDs <- allIDs[!names(allIDs) %in% ignore]
-  duplicateIDs <- duplicated(allIDs)
-  if(any(duplicateIDs)){
-    # ok, let's get 'em
-    invalidIDs <- unique(allIDs[duplicateIDs])
-    result <- allIDs[allIDs %in% invalidIDs]
-    if(isTRUE(warning)){
-      warning(paste0("Duplicate IDs were found:\n  ", paste0(names(result), ": ", result, collapse="\n  ")), call.=FALSE)
-    } else {}
+  # plugins probably use identical IDs in <dialog> and <wizard> sections
+  # so we first check without the <wizard> section separately, then
+  # without the <dialog>
+  haveDialog <- XMLScan(obj, name="dialog")
+  haveWizard <- XMLScan(obj, name="wizard")
+  if(all(!is.null(haveDialog), !is.null(haveWizard))){
+    noWizard <- noDialog <- obj
+    XMLScan(noWizard, name="wizard") <- NULL
+    XMLScan(noDialog, name="dialog") <- NULL
+    allResults <- lapply(
+      list(noWizard, noDialog),
+      function(thisPart){
+        rk.uniqueIDs(obj=thisPart, bool=bool, warning=warning, ignore=ignore)
+      }
+    )
     if(isTRUE(bool)){
-      return(FALSE)
+      return(all(allResults))
     } else {
-      return(result)
+      return(unlist(allResults))
     }
   } else {
-    if(isTRUE(bool)){
-      return(TRUE)
+    allIDs <- XMLScanDeep(obj, find="id", search="attributes")
+    # ignore nodes
+    allIDs <- allIDs[!names(allIDs) %in% ignore]
+    duplicateIDs <- duplicated(allIDs)
+    if(any(duplicateIDs)){
+      # ok, let's get 'em
+      invalidIDs <- unique(allIDs[duplicateIDs])
+      result <- allIDs[allIDs %in% invalidIDs]
+      if(isTRUE(warning)){
+        warning(paste0("Duplicate IDs were found:\n  ", paste0(names(result), ": ", result, collapse="\n  ")), call.=FALSE)
+      } else {}
+      if(isTRUE(bool)){
+        return(FALSE)
+      } else {
+        return(result)
+      }
     } else {
-      return(invisible(NULL))
+      if(isTRUE(bool)){
+        return(TRUE)
+      } else {
+        return(invisible(NULL))
+      }
     }
   }
 }



More information about the rkward-tracker mailing list