From 8f8feda4d3270ae78e4c03c34f5af151a2e164c1 Mon Sep 17 00:00:00 2001 From: t-espave Date: Wed, 27 Jul 2011 15:57:34 -0700 Subject: not handling property bindings for controls (for now) --- .../Phone/PhoneInitializationTraverser.cs | 16 +++++---- .../PhoneControlsExtractor.py | 42 +++++++++++++++------- BCT/TranslationPlugins/PhoneControlsPlugin.cs | 3 +- 3 files changed, 40 insertions(+), 21 deletions(-) (limited to 'BCT') diff --git a/BCT/BytecodeTranslator/Phone/PhoneInitializationTraverser.cs b/BCT/BytecodeTranslator/Phone/PhoneInitializationTraverser.cs index 63e1321b..40d438c8 100644 --- a/BCT/BytecodeTranslator/Phone/PhoneInitializationTraverser.cs +++ b/BCT/BytecodeTranslator/Phone/PhoneInitializationTraverser.cs @@ -148,14 +148,16 @@ namespace BytecodeTranslator.Phone { // TODO check page name against container name IEnumerable controls= PhoneCodeHelper.PhonePlugin.getControlsForPage(methodBeingTraversed.Container.ToString()); IEnumerable injectedStatements = new List(); - foreach (ControlInfoStructure controlInfo in controls) { - injectedStatements = injectedStatements.Concat(getCodeForSettingEnabledness(controlInfo)); - injectedStatements = injectedStatements.Concat(getCodeForSettingCheckedState(controlInfo)); - injectedStatements = injectedStatements.Concat(getCodeForSettingVisibility(controlInfo)); - } + if (controls != null) { + foreach (ControlInfoStructure controlInfo in controls) { + injectedStatements = injectedStatements.Concat(getCodeForSettingEnabledness(controlInfo)); + injectedStatements = injectedStatements.Concat(getCodeForSettingCheckedState(controlInfo)); + injectedStatements = injectedStatements.Concat(getCodeForSettingVisibility(controlInfo)); + } - int stmtPos= block.Statements.IndexOf(statementAfter); - block.Statements.InsertRange(stmtPos+1, injectedStatements); + int stmtPos = block.Statements.IndexOf(statementAfter); + block.Statements.InsertRange(stmtPos + 1, injectedStatements); + } } private BoundExpression makeBoundControlFromControlInfo(ControlInfoStructure controlInfo) { diff --git a/BCT/PhoneControlsExtractor/PhoneControlsExtractor.py b/BCT/PhoneControlsExtractor/PhoneControlsExtractor.py index b16e9bfe..9285d6c8 100644 --- a/BCT/PhoneControlsExtractor/PhoneControlsExtractor.py +++ b/BCT/PhoneControlsExtractor/PhoneControlsExtractor.py @@ -11,6 +11,7 @@ CONTROL_NAMES= ["Button", "CheckBox", "RadioButton", "ApplicationBarIconButton"] # TODO (by directly manipulating the control's enabled value) or the parent becomes enabled CONTAINER_CONTROL_NAMES= ["Canvas", "Grid", "StackPanel", "ApplicationBar"] +COMMA_REPLACEMENT="###" staticControlsMap= {} mainPageXAML= None @@ -82,27 +83,28 @@ def addControlToMap(pageXAML, parentPage, controlNode): pass newControl["Type"]= controlNode.localName - newControl["Name"]= controlNode.getAttribute("Name") + newControl["Name"]= controlNode.getAttribute("Name").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) if (controlNode.hasAttribute("IsEnabled")): - newControl["IsEnabled"]= controlNode.getAttribute("IsEnabled") + newControl["IsEnabled"]= controlNode.getAttribute("IsEnabled").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) else: newControl["IsEnabled"]= "true" if (controlNode.hasAttribute("Visibility")): - newControl["Visibility"]= controlNode.getAttribute("Visibility") + newControl["Visibility"]= controlNode.getAttribute("Visibility").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) else: newControl["Visibility"]= "Visible" # TODO it is possible that more events are of interest, we should add as we discover them in existing applications - newControl["Click"] = controlNode.getAttribute("Click") - newControl["Checked"] = controlNode.getAttribute("Checked") - newControl["Unchecked"] = controlNode.getAttribute("Unchecked") + newControl["Click"] = controlNode.getAttribute("Click").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) + newControl["Checked"] = controlNode.getAttribute("Checked").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) + newControl["Unchecked"] = controlNode.getAttribute("Unchecked").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) newControl["XAML"]= pageXAML pageControls.append(newControl) staticControlsMap[parentPage]= pageControls def extractPhoneControlsFromPage(pageXAML): # maybe it is not a page file + print "extracting from " + pageXAML pageFile= open(pageXAML, "r") if not isPageFile(pageFile): return @@ -112,6 +114,7 @@ def extractPhoneControlsFromPage(pageXAML): controls= getControlNodes(pageFileXML) ownerPage = getOwnerPage(pageFileXML) if (ownerPage != None): + print pageXAML + " is not none" if (len(controls) == 0): # it is either a page with no controls, or controls that are dynamically created, or controls we do not track yet # in any case, just add a dummy control so as not to lose the page @@ -125,13 +128,15 @@ def extractPhoneControlsFromPage(pageXAML): def getOwnerPage(xmlNode): ownerPage= None - if (xmlNode.nodeType == xml.dom.Node.ELEMENT_NODE and xmlNode.localName == "PhoneApplicationPage"): - ownerPage= xmlNode.getAttribute("x:Class") + if (xmlNode.nodeType == xml.dom.Node.ELEMENT_NODE): + ownerPage= xmlNode.getAttribute("x:Class").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) + if ownerPage == "": + ownerPage= None else: - for child in xmlNode.childNodes: - ownerPage= getOwnerPage(child) - if (ownerPage != None): - break + for child in xmlNode.childNodes: + ownerPage= getOwnerPage(child) + if (ownerPage != None): + break return ownerPage @@ -146,11 +151,22 @@ def outputPhoneControls(outputFileName): outputFile.write("dummyMainAppName_unknown\n") # I could possibly deduce it from WMAppManifest.xml, but I'm unsure. Doing it later is safe anyway for page in staticControlsMap.keys(): for control in staticControlsMap[page]: + # TODO we still cannot handle bindings, and those we identified through commas and equality signs isEnabled= control["IsEnabled"] + if (isEnabled.find(COMMA_REPLACEMENT) != -1): + isEnabled= "" visibility= control["Visibility"] + if (visibility.find(COMMA_REPLACEMENT) != -1): + visibility= "" click= control["Click"] + if (click.find(COMMA_REPLACEMENT) != -1): + click= "" checked= control["Checked"] + if (checked.find(COMMA_REPLACEMENT) != -1): + checked= "" unchecked= control["Unchecked"] + if (unchecked.find(COMMA_REPLACEMENT) != -1): + unchecked= "" pageXAML= control["XAML"] # last comma is to account for bpl translation name, that is unknown for now # boogie string page name is unknown for now @@ -163,7 +179,7 @@ def getMainPageXAMLFromManifest(filename): manifest= minidom.parse(file) file.close() # interesting XPath location /App/Tasks/DefaultTask/@NavigationPage - return manifest.getElementsByTagName("DefaultTask")[0].getAttribute("NavigationPage") + return manifest.getElementsByTagName("DefaultTask")[0].getAttribute("NavigationPage").replace(",",COMMA_REPLACEMENT).replace("=",COMMA_REPLACEMENT) def extractPhoneControls(sourceDir): global mainPageXAML diff --git a/BCT/TranslationPlugins/PhoneControlsPlugin.cs b/BCT/TranslationPlugins/PhoneControlsPlugin.cs index 92e8cfaa..46e93911 100644 --- a/BCT/TranslationPlugins/PhoneControlsPlugin.cs +++ b/BCT/TranslationPlugins/PhoneControlsPlugin.cs @@ -152,9 +152,10 @@ namespace TranslationPlugins { } private void setPageAsMainPage(string pageXAML) { + KeyValuePair mainPageClass= pageStructureInfo.FirstOrDefault(keyValue => keyValue.Value.PageXAML == pageXAML); if (mainPageClass.Equals(default(KeyValuePair))) { - // do nothing. Pre is page was already parsed + // the main page doesn't exist because it has no tracked controls. While we cannot track those controls, create a page struct for it } else { mainPageClass.Value.IsMainPage = true; } -- cgit v1.2.3