Exemple #1
0
 def __init__(self, locateType):
     self.bound_chars = """/\?%*:|"<>(), \t\n.;@"""
     shext_locatedb_path = os.path.join(VinjaConf.getDataHome(),
                                        "locate.db")
     self.locatecmd = LocateCmd(shext_locatedb_path)
     self.locateType = locateType
     self.show_on_open = True
Exemple #2
0
 def __init__(self, locateType):
     self.bound_chars = """/\?%*:|"<>(), \t\n.;@"""
     shext_locatedb_path = os.path.join(VinjaConf.getDataHome(), "locate.db")
     self.locatecmd = LocateCmd(shext_locatedb_path)
     self.locateType = locateType
     self.show_on_open = True
Exemple #3
0
class FileContentManager(object):

    def __init__(self, locateType):
        self.bound_chars = """/\?%*:|"<>(), \t\n.;@"""
        shext_locatedb_path = os.path.join(VinjaConf.getDataHome(), "locate.db")
        self.locatecmd = LocateCmd(shext_locatedb_path)
        self.locateType = locateType
        self.show_on_open = True

    def get_init_prompt(self):
        buf = vim.current.buffer
        row, col = vim.current.window.cursor
        line = buf[row-1]
        if line.strip() == "" :
            return ""
        result = []
        for i in range(col,-1,-1):
            char = line[i]
            if char in self.bound_chars :
                break
            result.insert(0,char)
        for i in range(col+1,len(line)):
            char = line[i]
            if char in self.bound_chars :
                break
            result.append(char)
        v =  "".join(result)
        if len(v.strip()) < 3 :
            v = "" 
        return v


    def search_content(self,search_pat):
        cur_dir = os.getcwd()
        result = self.locatecmd.locateFile(search_pat,startWithAlias=True)

        rows = []
        self.start_dirs = {}
        for apath,alias,start_dir in result :
            if self.locateType == "all" :
                #rows.append(apath)
                rows.append(self.path_to_dis(apath))
            else :
                rtl_path = apath[apath.find(os.path.sep)+1:]
                abpath = os.path.join(start_dir, rtl_path)
                if cur_dir in abpath :
                    rows.append(self.path_to_dis(apath))
                    #rows.append(apath)
            self.start_dirs[alias] = start_dir
        rows = rows[0:30]
        return rows

    def path_to_dis(self,abpath):
        base_name = os.path.basename(abpath)
        dir_name = os.path.dirname(abpath)
        return base_name + " (" +dir_name + ")"

    def dis_to_path(self,line):
        index = line.find("(")
        abpath = os.path.join(line[index+1:-1],line[0:index])
        return abpath
        

    def open_content(self,line,mode="local"):
        fname = line.strip()
        fname = self.dis_to_path(fname)
        if not fname : return 

        alias = fname[0: fname.find(os.path.sep)]
        rtl_path = fname[fname.find(os.path.sep)+1:]
        fname = os.path.join(self.start_dirs[alias], rtl_path)

        bin_file_exts = ["doc","docx","ppt","xls","png","jpg","gif","bmp","zip","jar",\
                "war","rar","pdf","psd"]
        basename,ext = os.path.splitext(fname)
        if  len(ext) > 1 and ext[1:] in bin_file_exts :
            if sys.platform.startswith('darwin'):
                subprocess.Popen('open "%s"' % fname,shell=True)
            elif os.name == 'nt':
                os.startfile(fname)
            elif os.name == 'posix':
                subprocess.Popen('xdg-open "%s"' % fname,shell=True)
        else :
            if mode == "local" :
                vim.command("edit %s "  %(fname))
            elif mode == "buffer" :
                vim.command("split %s "  %(fname))
            elif mode == "tab" :
                vim.command("tabedit %s "  %(fname))
Exemple #4
0
class FileContentManager(object):
    def __init__(self, locateType):
        self.bound_chars = """/\?%*:|"<>(), \t\n.;@"""
        shext_locatedb_path = os.path.join(VinjaConf.getDataHome(),
                                           "locate.db")
        self.locatecmd = LocateCmd(shext_locatedb_path)
        self.locateType = locateType
        self.show_on_open = True

    def get_init_prompt(self):
        buf = vim.current.buffer
        row, col = vim.current.window.cursor
        line = buf[row - 1]
        if line.strip() == "":
            return ""
        result = []
        for i in range(col, -1, -1):
            char = line[i]
            if char in self.bound_chars:
                break
            result.insert(0, char)
        for i in range(col + 1, len(line)):
            char = line[i]
            if char in self.bound_chars:
                break
            result.append(char)
        v = "".join(result)
        if len(v.strip()) < 3:
            v = ""
        return v

    def search_content(self, search_pat):
        cur_dir = os.getcwd()
        result = self.locatecmd.locateFile(search_pat, startWithAlias=True)

        rows = []
        self.start_dirs = {}
        for apath, alias, start_dir in result:
            if self.locateType == "all":
                #rows.append(apath)
                rows.append(self.path_to_dis(apath))
            else:
                rtl_path = apath[apath.find(os.path.sep) + 1:]
                abpath = os.path.join(start_dir, rtl_path)
                if cur_dir in abpath:
                    rows.append(self.path_to_dis(apath))
                    #rows.append(apath)
            self.start_dirs[alias] = start_dir
        rows = rows[0:30]
        return rows

    def path_to_dis(self, abpath):
        base_name = os.path.basename(abpath)
        dir_name = os.path.dirname(abpath)
        return base_name + " (" + dir_name + ")"

    def dis_to_path(self, line):
        index = line.find("(")
        abpath = os.path.join(line[index + 1:-1], line[0:index])
        return abpath

    def open_content(self, line, mode="local"):
        fname = line.strip()
        fname = self.dis_to_path(fname)
        if not fname: return

        alias = fname[0:fname.find(os.path.sep)]
        rtl_path = fname[fname.find(os.path.sep) + 1:]
        fname = os.path.join(self.start_dirs[alias], rtl_path)

        bin_file_exts = ["doc","docx","ppt","xls","png","jpg","gif","bmp","zip","jar",\
                "war","rar","pdf","psd"]
        basename, ext = os.path.splitext(fname)
        if len(ext) > 1 and ext[1:] in bin_file_exts:
            if sys.platform.startswith('darwin'):
                subprocess.Popen('open "%s"' % fname, shell=True)
            elif os.name == 'nt':
                os.startfile(fname)
            elif os.name == 'posix':
                subprocess.Popen('xdg-open "%s"' % fname, shell=True)
        else:
            if mode == "local":
                vim.command("edit %s " % (fname))
            elif mode == "buffer":
                vim.command("split %s " % (fname))
            elif mode == "tab":
                vim.command("tabedit %s " % (fname))
Exemple #5
0
 def __init__(self, locateType):
     self.bound_chars = """/\?%*:|"<>(), \t\n"""
     shext_locatedb_path = os.path.join(SzToolsConfig.getDataHome(), "locate.db")
     self.locatecmd = LocateCmd(shext_locatedb_path)
     self.locateType = locateType
     self.show_on_open = False