예제 #1
0
        public static void SaveExistingTemplate(AndroidWindowData template)
        {
            int index = elements.IndexOf(template);

            if (index == -1)
            {
                return;
            }
            EditorPrefs.SetString(keyPrefix + index, template.ToString());
        }
예제 #2
0
        public static AndroidWindowData ReloadTemplate(int i)
        {
            string savedPref = EditorPrefs.GetString(keyPrefix + i);
            string name      = savedPref.Substring(0, savedPref.IndexOf('<'));;
            string xml       = savedPref.Substring(savedPref.IndexOf('<'));

            elements[i]            = AndroidWindowData.CreateInstance(new AndroidXmlEditor(xml));
            elements[i].name       = name;
            elements[i].isTemplate = true;
            return(elements [i]);
        }
예제 #3
0
 public void ApplyChanges(AndroidWindowData data)
 {
     foreach (ManifestElement element in data.editedList)
     {
         element.ApplyChanges(manifestXML);
     }
     if (data.isTemplate)
     {
         AndroidTemplateManager.SaveExistingTemplate(data);
     }
     else
     {
         manifestXML.Save(manifestPath);
     }
 }
예제 #4
0
        public static List <AndroidWindowData> GetTemplates()
        {
            elements = new List <AndroidWindowData> ();
            int i = 0;

            while (EditorPrefs.HasKey(keyPrefix + i))
            {
                string savedPref = EditorPrefs.GetString(keyPrefix + i);
                string name      = savedPref.Substring(0, savedPref.IndexOf('<'));;
                string xml       = savedPref.Substring(savedPref.IndexOf('<'));
                elements.Add(AndroidWindowData.CreateInstance(new AndroidXmlEditor(xml)));
                elements[i].name       = name;
                elements[i].isTemplate = true;
                i++;
            }
            return(elements);
        }
예제 #5
0
 public static void SaveTemplate(AndroidWindowData template)
 {
     template.isTemplate = true;
     for (int i = 0; i < elements.Count; i++)
     {
         if (elements [i].name.Equals(template.name))
         {
             if (!EditorUtility.DisplayDialog("", "Save over existing template?", "Yes", "No"))
             {
                 return;
             }
             elements[i] = template;
             EditorPrefs.SetString(keyPrefix + i, template.ToString());
             return;
         }
     }
     elements.Add(template);
     EditorPrefs.SetString(keyPrefix + (elements.Count - 1), template.ToString());
 }
예제 #6
0
        public static AndroidWindowData CreateInstance(AndroidXmlEditor editor)
        {
            AndroidWindowData instance = ScriptableObject.CreateInstance <AndroidWindowData> ();

            instance.xmlEditor = editor;

            instance.activityList       = new List <ManifestActivity> ();
            instance.receiverList       = new List <ManifestReceiver> ();
            instance.serviceList        = new List <ManifestService> ();
            instance.providerList       = new List <ManifestProvider> ();
            instance.metaDataList       = new List <ManifestMetaData> ();
            instance.usesLibraryList    = new List <ManifestUsesLibrary> ();
            instance.permissionList     = new List <ManifestPermission> ();
            instance.usesPermissionList = new List <ManifestUsesPermission>();
            instance.usesFeatureList    = new List <ManifestUsesFeature> ();

            List <XmlNode> nodeList = instance.xmlEditor.GetManifestElements();

            foreach (XmlNode node in nodeList)
            {
                instance.BuildIManifestElement(node);
            }
            return(instance);
        }
예제 #7
0
        void OnGUI()
        {
            if (data == null)
            {
                OnEnable();
            }
            Undo.RecordObject(data, "Manifest Window");
            GUI.color = Color.white;
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            data.OnGUI();
            EditorGUILayout.Space();
            #region UpdateButton
            EditorGUILayout.BeginHorizontal();
            {
                if (data.dirty)
                {
                    GUI.color = Color.green;
                }
                else
                {
                    GUI.color = Color.grey;
                }
                if (GUILayout.Button("Apply Changes"))
                {
                    ApplyChanges();
                }
                if (data.dirty)
                {
                    GUI.color = Color.red;
                }
                else
                {
                    GUI.color = Color.grey;
                }
                if (GUILayout.Button("Clear Changes"))
                {
                    ReloadDocument();
                }
                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();
            #endregion
            EditorGUILayout.Space();

            templateName = EditorGUILayout.TextField("Template name: ", templateName);
            if (GUILayout.Button("Save as Template"))
            {
                AndroidXmlEditor  templateEditor = new AndroidXmlEditor(data.ToString());
                AndroidWindowData newTemplate    = AndroidWindowData.CreateInstance(templateEditor);
                newTemplate.name = templateName;
                AndroidTemplateManager.SaveTemplate(newTemplate);
            }
            for (int i = 0; i < templateElements.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    templateElements[i].display = EditorGUILayout.Foldout(templateElements[i].display, templateElements[i].name + ":");
                    if (GUILayout.Button("Import", GUILayout.Width(50)))
                    {
                        data.Merge(templateElements[i]);
                        data.dirty = true;
                    }
                    if (GUILayout.Button("Delete", GUILayout.Width(50)))
                    {
                        AndroidTemplateManager.DeleteTemplate(templateElements[i--]);
                        EditorGUILayout.EndHorizontal();
                        continue;
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (templateElements[i].display)
                {
                    BBGuiHelper.BeginIndent();
                    {
                        templateElements[i].OnGUI();
                        EditorGUILayout.BeginHorizontal();
                        {
                            if (templateElements[i].dirty)
                            {
                                GUI.color = Color.green;
                            }
                            else
                            {
                                GUI.color = Color.grey;
                            }
                            if (GUILayout.Button("Apply Changes"))
                            {
                                templateElements[i].ApplyChanges();
                            }
                            if (templateElements[i].dirty)
                            {
                                GUI.color = Color.red;
                            }
                            else
                            {
                                GUI.color = Color.grey;
                            }
                            if (GUILayout.Button("Clear Changes"))
                            {
                                AndroidTemplateManager.ReloadTemplate(i);
                            }
                            GUI.color = Color.white;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    BBGuiHelper.EndIndent();
                }
            }

            EditorGUILayout.EndScrollView();
            //Repaint on Undo
            if (Event.current.type == EventType.ValidateCommand)
            {
                switch (Event.current.commandName)
                {
                case "UndoRedoPerformed":
                    this.Repaint();
                    break;
                }
            }
        }
예제 #8
0
 void OnEnable()
 {
     data             = AndroidWindowData.CreateInstance(new AndroidXmlEditor());
     templateElements = AndroidTemplateManager.GetTemplates();
 }
예제 #9
0
        public static void DeleteTemplate(AndroidWindowData element)
        {
            int index = elements.IndexOf(element);

            DeleteTemplate(index);
        }
예제 #10
0
        public void Merge(AndroidWindowData data)
        {
            XmlElement applicationElement = document.GetElementsByTagName("application") [0] as XmlElement;
            XmlElement manifestElement    = document.GetElementsByTagName("manifest") [0] as XmlElement;

            foreach (ManifestActivity activity in data.activityList)
            {
                activity.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(activity.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestActivity newActivity = ManifestActivity.CreateInstance(element);
                for (int i = 0; i < activityList.Count; i++)
                {
                    if (activityList[i].name.Equals(newActivity.name))
                    {
                        activityList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                activityList.Add(newActivity);
            }
            foreach (ManifestReceiver receiver in data.receiverList)
            {
                receiver.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(receiver.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestReceiver newReceiver = ManifestReceiver.CreateInstance(element);
                for (int i = 0; i < receiverList.Count; i++)
                {
                    if (receiverList[i].name.Equals(newReceiver.name))
                    {
                        receiverList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                receiverList.Add(newReceiver);
            }
            foreach (ManifestProvider provider in data.providerList)
            {
                provider.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(provider.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestProvider newProvier = ManifestProvider.CreateInstance(element);
                for (int i = 0; i < providerList.Count; i++)
                {
                    if (providerList[i].name.Equals(newProvier.name))
                    {
                        providerList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                providerList.Add(newProvier);
            }
            foreach (ManifestService service in data.serviceList)
            {
                service.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(service.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestService newService = ManifestService.CreateInstance(element);
                for (int i = 0; i < serviceList.Count; i++)
                {
                    if (serviceList[i].name.Equals(newService.name))
                    {
                        serviceList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                serviceList.Add(newService);
            }
            foreach (ManifestMetaData metadata in data.metaDataList)
            {
                metadata.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(metadata.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestMetaData newMetaData = ManifestMetaData.CreateInstance(element);
                for (int i = 0; i < metaDataList.Count; i++)
                {
                    if (metaDataList[i].name.Equals(newMetaData.name))
                    {
                        metaDataList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                metaDataList.Add(newMetaData);
            }
            foreach (ManifestUsesLibrary usesLibrary in data.usesLibraryList)
            {
                usesLibrary.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(usesLibrary.node, true) as XmlElement;
                applicationElement.AppendChild(element);
                ManifestUsesLibrary newUsesLibrary = ManifestUsesLibrary.CreateInstance(element);
                for (int i = 0; i < usesLibraryList.Count; i++)
                {
                    if (usesLibraryList[i].name.Equals(newUsesLibrary.name))
                    {
                        usesLibraryList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                usesLibraryList.Add(newUsesLibrary);
            }
            foreach (ManifestPermission permission in data.permissionList)
            {
                permission.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(permission.node, true) as XmlElement;
                manifestElement.AppendChild(element);
                ManifestPermission newPermission = ManifestPermission.CreateInstance(element);
                for (int i = 0; i < permissionList.Count; i++)
                {
                    if (permissionList[i].name.Equals(permission.name))
                    {
                        permissionList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                permissionList.Add(newPermission);
            }
            foreach (ManifestUsesPermission usesPermission in data.usesPermissionList)
            {
                usesPermission.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(usesPermission.node, true) as XmlElement;
                manifestElement.AppendChild(element);
                ManifestUsesPermission newUsesPermission = ManifestUsesPermission.CreateInstance(element);
                for (int i = 0; i < usesPermissionList.Count; i++)
                {
                    if (usesPermissionList[i].name.Equals(newUsesPermission.name))
                    {
                        usesPermissionList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                usesPermissionList.Add(newUsesPermission);
            }
            foreach (ManifestUsesFeature usesFeature in data.usesFeatureList)
            {
                usesFeature.ElementEditStatus = EditStatus.EDITED;
                XmlElement element = document.ImportNode(usesFeature.node, true) as XmlElement;
                manifestElement.AppendChild(element);
                ManifestUsesFeature newUsesFeature = ManifestUsesFeature.CreateInstance(element);
                for (int i = 0; i < usesFeatureList.Count; i++)
                {
                    if (usesFeatureList[i].name.Equals(newUsesFeature.name))
                    {
                        usesFeatureList[i].ElementEditStatus = EditStatus.REMOVED;
                        break;
                    }
                }
                usesFeatureList.Add(newUsesFeature);
            }
        }