def on_query_context(self, view, key, operator, operand, match_all): # A key wants to be inserted, what context are we in for that? rc = False if(operator == sublime.OP_EQUAL and (util.isPotentialOrgFile(view.file_name()) or self.IsOrgSyntax(view))): if(key == 'org_heading'): rc = operand == self.ShouldLocalFold(view) elif(key == 'org_global'): rc = operand == self.ShouldGlobalFold(view) elif(key == 'org_link'): rc = operand == self.ShouldFoldLinks(view) elif(key == 'org_table'): rc = operand == self.ShouldTableTab(view) elif(key == 'org_block'): rc = operand == self.ShouldFoldBlock(view) elif(key == 'org_checkbox'): rc = operand == self.ShouldFoldCheckbox(view) return rc
def LoadNew(self, fileOrView): if(fileOrView == None): return None if(not hasattr(self,'orgPaths') or self.orgPaths == None): self.orgPaths = sets.Get("orgDirs",None) filename = self.FilenameFromFileOrView(fileOrView) if(util.isPotentialOrgFile(filename)): file = FileInfo(filename, loader.load(filename), self.orgPaths) self.AddFileInfo(file) return file elif(util.isView(fileOrView) and util.isOrgSyntax(fileOrView)): bufferContents = fileOrView.substr(sublime.Region(0, fileOrView.size())) file = FileInfo(filename if filename else util.getKey(fileOrView), loader.loads(bufferContents), self.orgPaths) self.AddFileInfo(file) return file else: log.debug("File is not an org file, not loading into the database: " + str(filename)) return None
def CreateLink(view): fn = view.file_name() # Org Files have a LOT more potential for making links! if (util.isPotentialOrgFile(fn)): r = view.curRow() line = view.getLine(r) linet = RE_TARGET.match(line) namet = RE_NAMED.match(line) link = None # have target on this line? if (linet): link = "[[file:{0}::{1}][{1}]]".format(view.file_name(), linet.group('target')) # have named object on this line? if (link == None and namet): link = "[[file:{0}::{1}][{1}]]".format(view.file_name(), namet.group('target')) n = db.Get().AtInView(view) if (link == None and n and not n.is_root()): p = n.get_property("ID") cp = n.get_property("CUSTOM_ID") if (p): link = "[[file:{0}::#{1}][{2}]]".format( view.file_name(), p, n.heading) # Have custom id? elif (cp): link = "[[file:{0}::#{1}][{2}]]".format( view.file_name(), cp, n.heading) # Am near a heading? else: link = "[[file:{0}::*{1}][{1}]]".format( view.file_name(), n.heading) # okay then just use row,col if (link == None): r, c = view.curRowCol() link = "[[file:{0}::{1},{2}][{3}]]".format( view.file_name(), r, c, os.path.basename(view.file_name())) return link else: # Other file types only have line and column r, c = view.curRowCol() link = "[[{0}::{1}::{2}][{3}]]".format(fn, r, c, os.path.basename(fn)) return link
def onLoad(view): if(view and view.file_name() and util.isPotentialOrgFile(view.file_name())): folding.onLoad(view) links.onLoad(view)
def on_activated(self, view): if(util.isPotentialOrgFile(view.file_name())): folding.onActivated(view)
def on_post_save(self, view): if(util.isPotentialOrgFile(view.file_name())): db.Get().Reload(view)