Skip to content

Commit

Permalink
release 3.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
xjsender committed Mar 28, 2016
1 parent 9847802 commit b58aea9
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 31 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Release History

---------------

Release 3.3.6 (2016-03-28)
++++++++++++++++++
* Fix issue #98
* Add ``Return to First Step`` feature when open documentation by type
* Remove build-in reference settings which is replaced ``Reload Salesforce Document``
* Enhancement for ``Open Documentation`` feature
* Enhancement for ``Reload Project Cache`` feature


Release 3.3.5 (2016-03-26)
++++++++++++++++++
Expand Down
17 changes: 8 additions & 9 deletions completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ def on_query_completions(self, view, prefix, locations):
display = "%s\t%s" % (mo["xmlName"], "Metadata Type")
completion_list.append((display, mo["xmlName"]))

# Component Child
if "childXmlNames" in mo:
childXmlNames = mo["childXmlNames"]
if isinstance(childXmlNames, str):
childXmlNames = [childXmlNames]

for child in childXmlNames:
display = "%s\t%s" % (child, mo["xmlName"])
completion_list.append((display, child))
# Get all Children
childXmlNames = mo.get("childXmlNames", [])
if isinstance(childXmlNames, str):
childXmlNames = [childXmlNames]

for child in childXmlNames:
display = "%s\t%s" % (child, mo["xmlName"])
completion_list.append((display, child))

return completion_list

Expand Down
2 changes: 2 additions & 0 deletions config/menus/Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@
"command": "reload_project_cache"
},

{ "caption": "-" },

{
"caption": "Build Package.xml",
"command": "build_package_xml"
Expand Down
10 changes: 10 additions & 0 deletions config/messages/3.3.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Build 3.3.6
-----------
Release Date: 28 Mar 2016

* Fix issue #98
* Add ``Return to First Step`` feature when open documentation by type
* Remove build-in reference settings which is replaced ``Reload Salesforce Document``
* Enhancement for ``Open Documentation`` feature
* Enhancement for ``Reload Project Cache`` feature
* Restart your sublime when new version is installed
2 changes: 1 addition & 1 deletion config/settings/package.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haoide",
"version": "3.3.5",
"version": "3.3.6",
"description": "haoide is a Sublime Text 3 plugin for Salesforce and used for swift development on Force.com",
"author": "Hao Liu",
"email": "[email protected]",
Expand Down
5 changes: 3 additions & 2 deletions context.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ def build_metadata_objects_settings(settings, metadata_objects):
childXmlNames = mo["childXmlNames"]
if isinstance(childXmlNames, str):
childXmlNames = [childXmlNames]


mcopy = mo.copy(); del mcopy["childXmlNames"]
for child in childXmlNames:
settings[child] = mo
settings[child] = mcopy

return settings
4 changes: 2 additions & 2 deletions document.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def reload_document(self):
res = requests.get(toc_url)
result = res.json()
except Exception as e:
Printer.get("log").write("Reloading %s Failed, Reason: " % (
Printer.get("log").write("----->Failed to reload %s, reason: %s" % (
toc_label, str(e)
))
continue
Expand Down Expand Up @@ -115,7 +115,7 @@ def add_children(self, doc_references, children, base_url, level=1, prefix=""):
href = base_url + child["a_attr"]["href"]
title = child["text"]
doc_references.append({
"title": "%s%s%s" % (level * " ", prefix, title),
"title": "%s%s%s" % (level * " ", prefix, title),
"href": href
})

Expand Down
1 change: 1 addition & 0 deletions messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"3.3.3": "config/messages/3.3.3.md",
"3.3.4": "config/messages/3.3.4.md",
"3.3.5": "config/messages/3.3.5.md",
"3.3.6": "config/messages/3.3.6.md",
"install": "config/messages/install.txt"
}
80 changes: 63 additions & 17 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,8 @@ def run(self, callback_command=None):
self.metadata_objects.append(m)

# Add child metadata object
if "childXmlNames" in self.settings[m]:
child_xml_names = self.settings[m]["childXmlNames"]
if isinstance(child_xml_names, str):
child_xml_names = [child_xml_names]

for c in child_xml_names:
self.metadata_objects.append(c)

self.metadata_objects = sorted(self.metadata_objects)
child_types = util.get_child_types(m)
self.metadata_objects.extend(child_types)

self.selected_index = 0
self.chosen_metadata_objects = []
Expand All @@ -142,11 +135,20 @@ def build_items(self):
else:
self.items.append("[x]All")

for t in self.metadata_objects:
if t in self.chosen_metadata_objects:
self.items.append(" [√]%s" % t)
for m in sorted(self.settings["all_metadata_objects"]):
# Add parent to items
if m in self.chosen_metadata_objects:
self.items.append(" [%s]%s" % ("√", m))
else:
self.items.append(" [x]%s" % t)
self.items.append(" [%s]%s" % ("x", m))

# Add children to items
child_types = util.get_child_types(m)
for c in child_types:
if c in self.chosen_metadata_objects:
self.items.append(" [%s]%s" % ("√", c))
else:
self.items.append(" [%s]%s" % ("x", c))

sublime.set_timeout(lambda:self.window.show_quick_panel(self.items,
self.on_choose, sublime.MONOSPACE_FONT, self.selected_index), 10)
Expand Down Expand Up @@ -175,13 +177,57 @@ def on_choose(self, index):
else:
self.chosen_metadata_objects = self.metadata_objects[:]
else:
selected_metadata_object = selected_item[7:]
chosen_type = selected_item.strip()[3:]

# Get all children for chosen_type
# If chosen_type is child, child can't have children
attr = self.settings[chosen_type]
parent_type = attr["xmlName"]
child_types = util.get_child_types(parent_type)

if "[x]" in selected_item:
if selected_metadata_object not in self.chosen_metadata_objects:
self.chosen_metadata_objects.append(selected_metadata_object)
if chosen_type == parent_type:
if chosen_type not in self.chosen_metadata_objects:
self.chosen_metadata_objects.append(chosen_type)
for c in child_types:
self.chosen_metadata_objects.append(c)
else:
# Add chosen selected child metadata object
if chosen_type not in self.chosen_metadata_objects:
self.chosen_metadata_objects.append(chosen_type)

# Add parent metadata object of selected child
if parent_type not in self.chosen_metadata_objects:
self.chosen_metadata_objects.append(parent_type)
else:
self.chosen_metadata_objects.remove(selected_metadata_object)
# Get all chosen child xml names
parent_type = parent_type
child_types = util.get_child_types(parent_type)

chosen_child_types = []
for c in child_types:
if c in self.chosen_metadata_objects:
chosen_child_types.append(c)

if parent_type == chosen_type:
if len(child_types) == len(chosen_child_types):
self.chosen_metadata_objects.remove(chosen_type)

for c in child_types:
if c in self.chosen_metadata_objects:
self.chosen_metadata_objects.remove(c)
else:
for c in child_types:
if c not in self.chosen_metadata_objects:
self.chosen_metadata_objects.append(c)
else:
# Remove child
self.chosen_metadata_objects.remove(chosen_type)

# If all siblings are also not exist in selected list,
# parent should also be removed from selected list
if len(chosen_child_types) == 1:
self.chosen_metadata_objects.remove(parent_type)

self.build_items()

Expand Down
95 changes: 95 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,101 @@ def get_view_by_id(view_id):

return view

def get_child_types(parent_type):
""" Get child types by parent type
Parameter:
* parent_type -- Parent Metadata Object
Return:
* child_types -- Child Metadata Objects of parent
"""

settings = context.get_settings()
child_types = settings[parent_type].get("childXmlNames", [])
if isinstance(child_types, str):
child_types = [child_types]

return child_types

def parse_package_types(_types):
""" Build structure
From: {
"CustomObject": ["A__c", "B__c"],
"CustomField": ["A__c.A__c", "A__c.A1__c", "B__c.B__c"],
"ValidationRule": ["A__c.VR1", "B__c.BR2"]
"ApexClass": ["AClass", "BClass", "CClass"]
}
To: {
"CustomObject": {
"A__c": {
"CustomField": ["A.A__c", "A.B__c"],
"ValidationRule": ["A.VR1"]
},
"B__c": {
"CustomField": ["B__c.B__c"],
"ValidationRule": ["B__c.BR2"]
}
},
"ApexClass": ["A", "B", "C"]
}
"""
settings = context.get_settings()
package_types = {}
for _type, elements in _types.items():
attr = settings[_type]
_child_types = attr.get("childXmlNames", [])

# If _type is child type, for example,
# CustomField, ListView
if _type != attr["xmlName"]:
continue

# If no child XML
if not _child_types:
# If no elements, don't keep it
if not elements:
continue

# inFolder is false
if attr["inFolder"] == "false":
package_types[_type] = elements
else:
# Build structure as {folder: [elements]}
folder_elements = {}
for folder in [e for e in elements if "/" not in e]:
folder_elements[folder] = [
e for e in elements if e.startswith(folder) \
and "/" in e
]
package_types[_type] = folder_elements
continue

if isinstance(_child_types, str):
_child_types = [_child_types]

child_cache = {}
for _child_type in _child_types:
if _child_type not in _types:
continue

parent_to_children = {}
for parent in elements:
children = []
for _child_element in _types[_child_type]:
if _child_element.startswith(parent):
children.append(_child_element)

if children:
parent_to_children[parent] = children

child_cache[_child_type] = parent_to_children

package_types[_type] = child_cache

return package_types

def build_package_types(package_xml_content):
result = xmltodict.parse(package_xml_content)

Expand Down

0 comments on commit b58aea9

Please sign in to comment.