def dlg_ibms_in_tab(self):
     ibms,   \
     msg     = self._ibms_in_tab(ed, self.bm_signs)
     if not ibms and msg:    return app.msg_status(msg)
     if not ibms:            return app.msg_status(_('No in-text bookmarks'))
     line_max= max([line_n for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms])
     ln_wd   = len(str(line_max))
     pass;                  #LOG and log('ln_wd={}',(ln_wd))
     ibms    = [(bm_msg, line_n, f('{} {}', str(1+line_n).rjust(ln_wd, ' '), line_s)) 
             for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms]
     pass;                  #LOG and log('ibms=¶{}',pf(ibms))
     rCrt    = ed.get_carets()[0][1]
     near    = min([(abs(line_n-rCrt), ind) 
             for ind, (bm_msg, line_n, line_s) in enumerate(ibms)])[1]
     if self.show_wo_alt:
         ans = app.dlg_menu(app.MENU_LIST, '\n'.join(
                 [f('{}\t{}', line_nd, bm_msg) for bm_msg, line_n, line_nd in ibms]
             ), near)
     else:
         ans = app.dlg_menu(app.MENU_LIST_ALT, '\n'.join(
                 [f('{}\t{}', bm_msg, line_nd) for bm_msg, line_n, line_nd in ibms]
             ), near)
     if ans is None:     return
     bm_msg, line_n, line_nd    = ibms[ans]
     ed.set_caret(0, line_n)
     if not (ed.get_prop(app.PROP_LINE_TOP) <= line_n <= ed.get_prop(app.PROP_LINE_BOTTOM)):
         ed.set_prop(app.PROP_LINE_TOP, str(max(0, line_n - max(5, apx.get_opt('find_indent_vert')))))
示例#2
0
def dlg_menu(how, its='', sel=0, cap='', clip=0, w=0, h=0):
    api = app.app_api_version()
#   if api<='1.0.193':  #  list/tuple, focused(?), caption
#   if api<='1.0.233':  #  MENU_NO_FUZZY, MENU_NO_FULLFILTER
#   if api<='1.0.275':  #  MENU_CENTERED
    if api<='1.0.334':  #  clip, w, h
        return  app.dlg_menu(how, its, focused=sel, caption=cap)
#   if api<='1.0.346':  #  MENU_EDITORFONT
    return      app.dlg_menu(how, its, focused=sel, caption=cap, clip=clip, w=w, h=h)
 def dlg_ibms_in_tabs(self):
     ibms    = []
     for h_tab in app.ed_handles(): 
         ted     = app.Editor(h_tab)
         t_ibms, \
         msg     = self._ibms_in_tab(ted, self.bm_signs)
         ibms   += t_ibms
        #for h_tab
     if not ibms:    return app.msg_status(_('No in-text bookmarks in tabs'))
     line_max= max([line_n for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms])
     ln_wd   = len(str(line_max))
     ibms    = [(tab_id, line_n, bm_msg, f('{} {}', str(1+line_n).rjust(ln_wd, ' '), line_s), tab_info) 
                 for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms]
     tid     = ed.get_prop(app.PROP_TAB_ID)
     rCrt    = ed.get_carets()[0][1]
     near    = min([(abs(line_n-rCrt) if tid==tab_id else 0xFFFFFF, ind) 
                 for ind, (tab_id, line_n, bm_msg, line_s, tab_info) in enumerate(ibms)])[1]
     ans     = app.dlg_menu(app.MENU_LIST_ALT, '\n'.join(
                 [f('({}) {}\t{}', tab_info, bm_msg, line_s) for tab_id, line_n, bm_msg, line_s, tab_info in ibms]
             ), near)
     if ans is None: return
     tab_id, line_n, bm_msg, line_s, tab_info    = ibms[ans]
     ted     = apx.get_tab_by_id(tab_id)
     ted.focus()
     ed.set_caret(0, line_n)
     if not (ed.get_prop(app.PROP_LINE_TOP) <= line_n <= ed.get_prop(app.PROP_LINE_BOTTOM)):
         ed.set_prop(app.PROP_LINE_TOP, str(max(0, line_n - max(5, apx.get_opt('find_indent_vert')))))
示例#4
0
    def dialog(self):

        lines = get_format_lines()
        lines = [do_format(s) for s in lines]

        res = app.dlg_menu(app.MENU_LIST, lines, caption='Insert Time')
        if res is None: return
        self.do_insert(lines[res])
示例#5
0
def find_tab():
    hlist = app.ed_handles()
    slist = [app.Editor(h).get_prop(app.PROP_TAB_TITLE) for h in hlist]
    cap = _('Find tab by title')
    res = app.dlg_menu(app.MENU_LIST, slist, caption=cap)
    if res is None: return
    ed_ = app.Editor(hlist[res])
    ed_.focus()
 def recent(self):
     ''' Show list, use user select '''
     if not _checkAPI(): return
     sess = self._loadSess(existing=True)
     rcnt = sess['recent']
     if 0 == len(rcnt):
         return app.msg_status(NO_RECENT)
     ssmenu = [nice_name(sfile) for sfile in rcnt]
     opt_n = 0 if app.app_api_version(
     ) < '1.0.233' else app.MENU_NO_FULLFILTER
     ans = app.dlg_menu(app.MENU_LIST + opt_n, ssmenu)
     if ans is None: return
     self.open(rcnt[ans])
 def recent(self):
     ''' Show list, use user select '''
     if not _checkAPI(): return
     sess    = self._loadSess(existing=True)
     rcnt    = sess['recent']
     if 0==len(rcnt):
         return app.msg_status(NO_RECENT)
     ssmenu  = '\n'.join(('{}\t{}'.format(juststem(sfile), os.path.dirname(sfile))
                             for sfile in rcnt
                         ))
     ans     = app.dlg_menu(app.MENU_LIST, ssmenu)
     if ans is None: return
     self.open(rcnt[ans])
示例#8
0
 def menu_dlg(self, items):
     names = [str(item) for item in items]
     if not names:
         ct.msg_status(_('No snippets for current lexer'))
         return
     try:
         focused = items.index(self.last_snippet)
     except ValueError:
         focused = 0
     i = ct.dlg_menu(ct.MENU_LIST, names, focused=focused, caption=_('Snippets'))
     if i is None:
         return
     self.last_snippet = items[i]
     self.last_snippet.insert(ct.ed)
示例#9
0
    def remove_vs_snip(self):
        rec = self.vs_local_dirs()

        if not rec:
            ct.msg_status(_('No VSCode snippets found'))
            return

        mnu = [s['name'] for s in rec]
        res = ct.dlg_menu(ct.MENU_LIST, mnu, caption=_('Remove snippets'))
        if res is None:
            return

        vs_snip_dir = rec[res]['dir']
        shutil.rmtree(vs_snip_dir)
        ct.msg_status(_('Snippets folder removed; restart CudaText to forget about it'))
示例#10
0
    def issues_vs(self):
        rec = self.vs_local_dirs()
        if not rec:
            ct.msg_status(_('No VSCode snippets found'))
            return

        mnu = [s['name']+'\t'+s['url'] for s in rec]
        res = ct.dlg_menu(ct.MENU_LIST_ALT, mnu, caption=_('Visit page of snippets'))
        if res is None:
            return

        url = rec[res]['url']
        if not url:
            ct.msg_status(_("No URL found"))
            return
        ct.msg_status(_('Opened: ')+url)
        webbrowser.open_new_tab(url)
示例#11
0
    def show_usages(self):
        if not self.app.environment:
            return

        cursor = self.app.cursor
        if not cursor:
            return

        items = self.app.script.get_references(
            line=cursor.row,
            column=cursor.x)

        if items:
            usages = []
            for d in items:
                modfile = d.module_path
                if modfile and os.path.isfile(modfile):
                    usages += [(modfile, d.line-1, d.column)]
        else:
            return

        if not usages:
            ct.msg_status('Cannot find usages')
            return

        items_show = []
        for item in usages:
            _fn = item[0]
            _fn1 = os.path.basename(_fn)
            _dir = pretty_path(os.path.dirname(_fn))
            _line = item[1]
            _col = item[2]
            _s = '?'
            if os.path.isfile(_fn):
                with open(_fn, encoding='utf8', errors='replace') as f:
                    for i in range(_line+1):
                        _s = f.readline()
            _s = _s.lstrip(' \t').rstrip('\n\r')
            items_show.append('{}:{}:{} ({})\t  {}'.format(_fn1, _line+1, _col+1, _dir, _s))

        res = ct.dlg_menu(ct.MENU_LIST_ALT, items_show, caption='Usages', w=opt_menu_w, h=opt_menu_h)
        if res is None:
            return

        item = usages[res]
        goto_file(item[0], item[1], item[2])
示例#12
0
def select_env():
    items = list(jedi.find_system_environments())
    names = [repr(i).replace('Environment:', 'Python') for i in items]
    names.append('Other...')
    i = ct.dlg_menu(ct.MENU_LIST, names, caption='Select Python interpreter')
    if i is None:
        return
    elif i == len(names) - 1:
        filters = 'Executables|*.exe' if IS_NT else ''
        fn = ct.dlg_file(True, '!', '', filters)
        if not fn:
            return
    else:
        fn = items[i].executable
    env = create_env(fn)
    if env:
        ct.ini_write(cfg_file, cfg_section, cfg_opt_env, fn)
        return env