def update_settings(): """ restart projectFiles with new plugin and project settings """ # invalidate cache global scope_cache scope_cache = {} # update settings global_settings = Settings.update() # update project settings ProjectManager.initialize(Project, global_settings)
def run(self, edit): project = ProjectManager.get_current_project() if project: settings = project.get_settings() json_string = json.dumps(settings, indent=4, sort_keys=True) new_file = sublime.active_window().new_file() new_file.insert(edit, 0, json_string) new_file.set_syntax_file("Packages/JavaScript/Json.tmLanguage")
def run(self, edit): current_directory = os.path.dirname(self.view.file_name()) context = Context.get_context(self.view) if context.get("valid") is False: return log(ID, "abort, no valid path given:", context.get("needle")) path = context.get("needle") project = ProjectManager.get_current_project() if not (path and project): return log(ID, "path or project invalid", path, project) is_relative = Path.is_relative(path) if is_relative: path = Path.get_absolute_path(current_directory, path) path = re.sub(project.get_directory(), "", path) path = re.sub("^[\\\\/\.]", "", path) files = project.find_file(path) if len(files) == 0: return log(ID, "failed finding file", path) if len(files) == 1: self.open_file(project.get_directory(), files[0]) else: # if javascript, search for index.js current_scope = self.view.scope_name(Selection.get_position(self.view)) if re.search("\.js ", current_scope): for file in files: if "index.js" in file: return self.open_file(project.get_directory(), file) self.files = files self.project_folder = project.get_directory() self.view.show_popup_menu(files, self.select_file)
def on_activated(self, view): # view has gained focus CurrentFile.evaluate_current(view, ProjectManager.get_current_project())
def on_post_save_async(self, view): if CurrentFile.is_temp(): verbose(ID, "temp file saved, reevaluate") CurrentFile.cache[view.id()] = None ProjectManager.rebuild_filecache() self.on_activated(view)
def run(self, edit): ProjectManager.rebuild_filecache()
def run(self, edit): project = ProjectManager.get_current_project() if project: Validate.view(self.view, project.get_settings(), True)
def on_query_completions(view, project_folder, current_folder): global Context, Selection current_scope = Selection.get_scope(view) if not Query.by_command(): triggers = get_matching_autotriggers(current_scope, config["TRIGGER"]) else: triggers = config["TRIGGER"] if not bool(triggers): verbose(ID, "abort query, no valid scope-regex for current context") return False # parse current context, may contain 'is_valid: False' expression = Context.get_context(view) if expression["error"] and not Query.by_command(): verbose(ID, "abort not a valid context") return False # check if there is a trigger for the current expression trigger = Context.find_trigger(expression, current_scope, triggers) # verbose("trigger", trigger) # expression | trigger | force | ACTION | CURRENT # -----------|----------|-------|-------------------|-------- # invalid | False | False | abort | abort # invalid | False | True | query needle | abort # invalid | True | False | query | # invalid | True | True | query +override | # valid | False | False | abort | abort # valid | False | True | query needle | abort # valid | True | False | query | # valid | True | True | query +override | # currently trigger is required in Query.build if trigger is False: verbose(ID, "abort completion, no trigger found") return False if not expression["valid_needle"]: word = Selection.get_word(view) expression["needle"] = re.sub("[^\.A-Za-z0-9\-\_$]", "", word) verbose(ID, "changed invalid needle to {0}".format(expression["needle"])) else: verbose(ID, "context evaluation {0}".format(expression)) if Query.build(expression.get("needle"), trigger, current_folder, project_folder) is False: # query is valid, but may not be triggered: not forced, no auto-options verbose(ID, "abort valid query: auto trigger disabled") return False verbose(ID, ".───────────────────────────────────────────────────────────────") verbose(ID, "| scope settings: {0}".format(trigger)) verbose(ID, "| search needle: '{0}'".format(Query.needle)) verbose(ID, "| in base path: '{0}'".format(Query.base_path)) FuzzyFilePath.start_expression = expression completions = ProjectManager.search_completions(Query.needle, project_folder, Query.extensions, Query.base_path) if completions and len(completions[0]) > 0: Completion.start(Query.replace_on_insert) view.run_command('_enter_insert_mode') # vintageous log("| => {0} completions found".format(len(completions))) else: sublime.status_message("FFP no filepaths found for '" + Query.needle + "'") Completion.stop() log("| => no valid files found for needle: {0}".format(Query.needle)) log("") Query.reset() return completions
def on_query_completions(view, project_folder, current_folder): global Context, Selection current_scope = Selection.get_scope(view) if not Query.by_command(): triggers = get_matching_autotriggers(current_scope, config["TRIGGER"]) else: triggers = config["TRIGGER"] if not bool(triggers): verbose(ID, "abort query, no valid scope-regex for current context") return False # parse current context, may contain 'is_valid: False' expression = Context.get_context(view) if expression["error"] and not Query.by_command(): verbose(ID, "abort not a valid context") return False # check if there is a trigger for the current expression trigger = Context.find_trigger(expression, current_scope, triggers) # verbose("trigger", trigger) # expression | trigger | force | ACTION | CURRENT # -----------|----------|-------|-------------------|-------- # invalid | False | False | abort | abort # invalid | False | True | query needle | abort # invalid | True | False | query | # invalid | True | True | query +override | # valid | False | False | abort | abort # valid | False | True | query needle | abort # valid | True | False | query | # valid | True | True | query +override | # currently trigger is required in Query.build if trigger is False: verbose(ID, "abort completion, no trigger found") return False if not expression["valid_needle"]: word = Selection.get_word(view) expression["needle"] = re.sub("[^\.A-Za-z0-9\-\_$]", "", word) verbose( ID, "changed invalid needle to {0}".format(expression["needle"])) else: verbose(ID, "context evaluation {0}".format(expression)) if Query.build(expression.get("needle"), trigger, current_folder, project_folder) is False: # query is valid, but may not be triggered: not forced, no auto-options verbose(ID, "abort valid query: auto trigger disabled") return False verbose( ID, ".───────────────────────────────────────────────────────────────") verbose(ID, "| scope settings: {0}".format(trigger)) verbose(ID, "| search needle: '{0}'".format(Query.needle)) verbose(ID, "| in base path: '{0}'".format(Query.base_path)) FuzzyFilePath.start_expression = expression completions = ProjectManager.search_completions( Query.needle, project_folder, Query.extensions, Query.base_path) if completions and len(completions[0]) > 0: Completion.start(Query.replace_on_insert) view.run_command('_enter_insert_mode') # vintageous log("| => {0} completions found".format(len(completions))) else: sublime.status_message("FFP no filepaths found for '" + Query.needle + "'") Completion.stop() log("| => no valid files found for needle: {0}".format( Query.needle)) log("") Query.reset() return completions
def changeDirectoryDone(text): project = ProjectManager.get_current_project() if project: project.set_setting("project_directory", text) else: print("abort. current project was not found")
def on_project_activated(self, view): ProjectManager.activate_project(view.window())