Example #1
0
    def on_post_save(self, view):
        # Get current file name and Read file content
        file_name = view.file_name()
        try:
            body = open(file_name, encoding="utf-8").read()
        except:
            body = open(file_name, "rb").read()

        # Get component_name amd component_type
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # If this file is not ApexTrigger, ApexComponent,
        # ApexPage or ApexClass, just return
        if component_type not in ["ApexClass", "ApexPage", "ApexComponent", "ApexTrigger"]:
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Get component extension
        component_extension = toolingapi_settings[component_type]["extension"]

        # Get Workspace, if not exist, make it
        workspace = toolingapi_settings["workspace"] + "/history/" + component_type
        if not os.path.exists(workspace):
            os.makedirs(workspace)

        # Backup current file
        time_stamp = time.strftime("%Y-%m-%d-%H-%M", time.localtime())
        fp = open(workspace + "/" + component_name + "-" + time_stamp + component_extension, "w")

        fp.write(body)
        fp.close()
Example #2
0
def get_component_attribute(file_name):
    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component type
    component_name = util.get_component_name(file_name)
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    component_attribute = util.get_component_attribute(username, file_name)

    return (component_attribute, component_name)
Example #3
0
def get_component_attribute(file_name):
    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component type
    component_name = util.get_component_name(file_name)
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    component_attribute = util.get_component_attribute(username, file_name)

    return (component_attribute, component_name)
Example #4
0
    def on_post_save(self, view):
        # Get current file name and Read file content
        file_name = view.file_name()
        try:
            body = open(file_name, encoding="utf-8").read()
        except:
            body = open(file_name, "rb").read()

        # Get component_name amd component_type
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # If this file is not ApexTrigger, ApexComponent,
        # ApexPage or ApexClass, just return
        if component_type not in [
                "ApexClass", "ApexPage", "ApexComponent", "ApexTrigger",
                "StaticResource"
        ]:
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Get component extension
        component_extension = toolingapi_settings[component_type]["extension"]

        # Get Workspace, if not exist, make it
        workspace = toolingapi_settings[
            "workspace"] + "/history/" + component_type
        if not os.path.exists(workspace):
            os.makedirs(workspace)

        # Backup current file
        time_stamp = time.strftime("%Y-%m-%d-%H-%M", time.localtime())
        fp = open(workspace + "/" + component_name + "-" +\
            time_stamp + component_extension, "w")

        fp.write(body)
        fp.close()
Example #5
0
    def on_input(self, input):
        # Valid user input
        if "." not in input:
            sublime.error_message(message.INVALID_NEW_COMPONENT_FORMAT)
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Create component to local according to user input
        is_success, sobject_name, file_name = context.make_component(input)
        if is_success == False:
            sublime.error_message(message.INVALID_NEW_COMPONENT_FORMAT)
            return

        # Open Console
        self.window.run_command("show_panel", {
            "panel": "console",
            "toggle": False
        })

        self.window.open_file(file_name)

        # Before you save it to server, save it to local
        self.view = self.window.active_view()
        if self.view.is_dirty():
            self.view.run_command("save")

        # Get Current File Name
        file_name = self.view.file_name()
        print(file_name)

        # Read file content
        body = open(file_name).read()

        # Get component type and component_name (Class Name, Trigger Name, etc.)
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # There has bug on creating ApexTrigger, but fixed on 2013 May 6 at 21:
        # Create Trigger is different from others, we can't use tooling/sobjects/ApexTrigger,
        # We should use sobjects/ApexTrigger
        # http://salesforce.stackexchange.com/questions/9603/how-do-i-use-the-tooling-api-to-create-a-new-apex-trigger
        # If component type is not in range, just show error message
        if component_type not in toolingapi_settings["component_types"]:
            sublime.error_message(message.INVALID_COMPONENT)
            return

        # Get Component body Metadata Attribute in SFDC
        component_body = toolingapi_settings[component_type]["body"]

        # Compose data
        data = {
            "name": component_name,
            component_body: body,
        }
        if component_type == "ApexClass":
            data["IsValid"] = True
        elif component_type == "ApexTrigger":
            data["TableEnumOrId"] = sobject_name
        elif component_type in ["ApexPage", "ApexComponent"]:
            data["MasterLabel"] = component_name

        processor.handle_create_component(data, component_name, component_type)
Example #6
0
    def on_input(self, input):
        # Valid user input
        if "." not in input:
            sublime.error_message(message.INVALID_NEW_COMPONENT_FORMAT)
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Create component to local according to user input
        is_success, sobject_name, file_name = context.make_component(input)
        if is_success == False:
            sublime.error_message(message.INVALID_NEW_COMPONENT_FORMAT)
            return

        # Open Console
        self.window.run_command("show_panel", 
            {"panel": "console", "toggle": False})

        self.window.open_file(file_name)

        # Before you save it to server, save it to local
        self.view = self.window.active_view()
        if self.view.is_dirty():
            self.view.run_command("save")

        # Get Current File Name
        file_name = self.view.file_name()
        print(file_name)

        # Read file content
        body = open(file_name).read()
        
        # Get component type and component_name (Class Name, Trigger Name, etc.)
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # There has bug on creating ApexTrigger, but fixed on 2013 May 6 at 21:
        # Create Trigger is different from others, we can't use tooling/sobjects/ApexTrigger,
        # We should use sobjects/ApexTrigger
        # http://salesforce.stackexchange.com/questions/9603/how-do-i-use-the-tooling-api-to-create-a-new-apex-trigger
        # If component type is not in range, just show error message
        if component_type not in toolingapi_settings["component_types"]:
            sublime.error_message(message.INVALID_COMPONENT)
            return

        # Get Component body Metadata Attribute in SFDC
        component_body = toolingapi_settings[component_type]["body"]

        # Compose data
        data = {
            "name": component_name,
            component_body: body,
        }
        if component_type == "ApexClass":
            data["IsValid"] = True
        elif component_type == "ApexTrigger":
            data["TableEnumOrId"] = sobject_name
        elif component_type in ["ApexPage", "ApexComponent"]:
            data["MasterLabel"] = component_name

        processor.handle_create_component(data, component_name, component_type)