[rkward-cvs] [rkward] packages/rkwarddev: rkwarddev: added actual support for "comment" argument in i18n internally, only usable with rk.XML.cbox() as of now.

m.eik michalke meik.michalke at uni-duesseldorf.de
Mon Nov 24 15:42:24 UTC 2014


Git commit 6a8da3be366c2cf6e2bfbd15862b97e95fa4025f by m.eik michalke.
Committed on 24/11/2014 at 15:40.
Pushed by meikm into branch 'master'.

rkwarddev: added actual support for "comment" argument in i18n internally, only usable with rk.XML.cbox() as of now.

M  +3    -1    packages/rkwarddev/ChangeLog
M  +31   -19   packages/rkwarddev/R/rk-internal.R
M  +3    -3    packages/rkwarddev/R/rk.XML.cbox.R

http://commits.kde.org/rkward/6a8da3be366c2cf6e2bfbd15862b97e95fa4025f

diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index f8c56de..1148ac1 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -1,6 +1,6 @@
 ChangeLog for package rkwarddev
 
-changes in version 0.06-6 (2014-11-23)
+changes in version 0.06-6 (2014-11-24)
 fixed:
   - rk.XML.optionset() does now allow to re-use objects defined in the same
     function call (i.e., refer to optioncolumns in the logic section)
@@ -20,6 +20,8 @@ changed:
   - function i18n() was changed to be used in JavaScript generation only; this breaks code
     using the function introduced with 0.06-4, but that was to be shortlived from the start...
     the i18n features of 0.06-4 will be completely replaced with some proper methods now
+  - comment nodes (<!-- foo -->) are now globally allowed as child nodes in XML; important for
+    i18n comments
 
 changes in version 0.06-5 (2014-10-19)
 fixed:
diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index 7326eb9..836c349 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -738,28 +738,28 @@ all.valid.children <- list(
   # 'as' is not a node, but an attribute of <copy>
   as=c("browser", "checkbox", "column", "copy",
     "dropdown", "formula", "frame", "input", "page", "radio", "row", "saveobject",
-    "spinbox", "stretch", "tabbook", "text", "valueselector", "valueslot", "varselector", "varslot"),
-  component=c("dependencies"),
-  components=c("component"),
+    "spinbox", "stretch", "tabbook", "text", "valueselector", "valueslot", "varselector", "varslot", "!--"),
+  component=c("dependencies", "!--"),
+  components=c("component", "!--"),
   context=c("menu", "!--"),
   dialog=c("browser", "checkbox", "column", "copy",
     "dropdown", "embed", "formula", "frame", "include", "input", "insert", "matrix",
     "optionset", "preview", "radio", "row", "saveobject", "spinbox", "stretch", "tabbook",
     "text", "valueselector", "valueslot", "varselector", "varslot", "!--"),
-  dropdown=c("option"),
+  dropdown=c("option", "!--"),
   hierarchy=c("menu", "!--"),
   logic=c("connect", "convert", "dependency_check", "external", "include", "insert",
-    "script", "set", "switch"),
+    "script", "set", "switch", "!--"),
   menu=c("entry", "menu", "!--"),
-  optionset=c("content", "logic", "optioncolumn"),
+  optionset=c("content", "logic", "optioncolumn", "!--"),
   page=c("browser", "checkbox", "column", "copy",
     "dropdown", "formula", "frame", "input", "matrix", "optionset", "page", "radio",
     "row", "saveobject", "spinbox", "stretch", "tabbook", "text", "valueselector",
     "valueslot", "varselector", "varslot", "!--"),
-  radio=c("option"),
-  select=c("option"),
+  radio=c("option", "!--"),
+  select=c("option", "!--"),
   settings=c("setting", "caption", "!--"),
-  valueselector=c("option"),
+  valueselector=c("option", "!--"),
   wizard=c("browser", "checkbox", "column", "copy",
     "dropdown", "embed", "formula", "frame", "include", "input", "insert", "matrix",
     "optionset", "page", "preview", "radio", "row", "saveobject", "spinbox", "stretch",
@@ -777,17 +777,25 @@ all.valid.children <- list(
 valid.child <- function(parent, children, warn=FALSE, section=parent, node.names=NULL){
   if(is.null(node.names)){
     # check the node names and allow only valid ones
-    node.names <- sapply(child.list(children), function(this.child){
+    node.names <- unlist(sapply(child.list(children), function(this.child){
         # if this is a plot options object, by default extract the XML slot
         # and discard the rest
         this.child <- stripXML(this.child)
 
         if(is.XiMpLe.node(this.child)){
-          return(XMLName(this.child))
+          this.child.name <- XMLName(this.child)
+          if(identical(this.child.name, "")){
+            # special case: empty node name; this is used to combine
+            # comments with the node they belong to, so rather check
+            # the children of this special node
+            return(unlist(sapply(XMLChildren(this.child), XMLName)))
+          } else {
+            return(this.child.name)
+          }
         } else {
           stop(simpleError(paste0("Invalid object for ", section, " section, must be of class XiMpLe.node, but got class ", class(this.child), "!")))
         }
-      })
+      }))
   } else {}
 
   invalid.sets <- !node.names %in% all.valid.children[[parent]]
@@ -1360,10 +1368,11 @@ rk.register.options <- function(options, parent.node){
 #   or a charcter string (for wich it is assumed to describe a context),
 #   or FALSE; if the latter, "label" will be renamed to "noi18n_label", "title" to "noi18n_title"
 # attrs: a list of previously defined attributes
-# comment: if TRUE, returns a comment node, else a list of attributes
-check.i18n <- function(i18n=NULL, attrs=list(), comment=FALSE){
+# comment: if TRUE, returns a pseudo node (with name "") containing a comment node and the original node,
+#   else a list of attributes
+check.i18n <- function(i18n=NULL, attrs=list(), node=NULL, comment=FALSE){
   if(isTRUE(comment)){
-    result <- NULL
+    result <- node
   } else {
     result <- attrs
   }
@@ -1371,21 +1380,24 @@ check.i18n <- function(i18n=NULL, attrs=list(), comment=FALSE){
     return(result)
   } else {
     if(is.list(i18n)){
-      if(!names(i18n) %in% c("comment", "context")){
+      if(!all(names(i18n) %in% c("comment", "context"))){
         stop(simpleError("i18n: only elements named \"comment\" or \"context\" are supported!"))
       } else {}
       if(isTRUE(comment)){
         if("comment" %in% names(i18n)){
-          result <- rk.i18n.comment(i18n[["comment"]])
+          if(!is.XiMpLe.node(node)){
+            stop(simpleError("i18n: to add a \"comment\" to a node, an XML node must be present!"))
+          } else {}
+          result <- XMLNode("", rk.i18n.comment(i18n[["comment"]]), node)
         } else {}
       } else {
         if("context" %in% names(i18n)){
           result[["i18n_context"]] <- i18n[["context"]]
         } else{}
       }
-    } else if(is.character(i18n) & length(i18n) == 1){
+    } else if(is.character(i18n) & length(i18n) == 1 & !isTRUE(comment)){
       result[["i18n_context"]] <- i18n[[1]]
-    } else if(is.logical(i18n) & !isTRUE(i18n)){
+    } else if(is.logical(i18n) & !isTRUE(i18n) & !isTRUE(comment)){
       if("label" %in% names(result)){
         names(result)[names(result) == "label"] <- "noi18n_label"
       } else {}
diff --git a/packages/rkwarddev/R/rk.XML.cbox.R b/packages/rkwarddev/R/rk.XML.cbox.R
index f687e3d..d6ea644 100644
--- a/packages/rkwarddev/R/rk.XML.cbox.R
+++ b/packages/rkwarddev/R/rk.XML.cbox.R
@@ -64,7 +64,7 @@ rk.XML.cbox <- function(label, value="true", un.value=NULL, chk=FALSE, id.name="
   # check for additional i18n info; if FALSE, "label" will be renamed to "noi18n_label"
   attr.list <- check.i18n(i18n=i18n, attrs=attr.list)
 
-  checkbox <- XMLNode("checkbox", attrs=attr.list)
+  checkbox <- check.i18n(i18n=i18n, node=XMLNode("checkbox", attrs=attr.list), comment=TRUE)
 
   # check for .rkh content
   rk.set.rkh.prompter(component=component, id=id, help=help)
@@ -74,6 +74,6 @@ rk.XML.cbox <- function(label, value="true", un.value=NULL, chk=FALSE, id.name="
 
 ## wrapper for name scheme consistency
 #' @export
-rk.XML.checkbox <- function(label, value="true", un.value=NULL, chk=FALSE, id.name="auto", help=NULL, component=rk.get.comp()){
-  rk.XML.cbox(label=label, value=value, un.value=un.value, chk=chk, id.name=id.name, help=help, component=component)
+rk.XML.checkbox <- function(label, value="true", un.value=NULL, chk=FALSE, id.name="auto", help=NULL, component=rk.get.comp(), i18n=NULL){
+  rk.XML.cbox(label=label, value=value, un.value=un.value, chk=chk, id.name=id.name, help=help, component=component, i18n=i18n)
 }




More information about the rkward-tracker mailing list