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')))))
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')))))
def _jump_to_ibm(self, what): 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')) rCrt = ed.get_carets()[0][1] if 1==len(ibms) \ and rCrt==ibms[0][1]: return app.msg_status(_('No more bookmarks')) line_ns = [ line_n for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms ] if self.wrap: line_ns = [-line_ns[-1]] + line_ns + [line_ns[0] + 0xFFFFFFFF] line_cns = [ line_n for line_n in line_ns if (line_n > rCrt if what == 'next' else line_n < rCrt) ] if not line_cns: return app.msg_status(_('No bookmark for jump')) line_n = min(line_cns) if what == 'next' else max(line_cns) line_n = -line_n if line_n < 0 else line_n line_n = line_n - 0xFFFFFFFF if line_n >= 0xFFFFFFFF else line_n 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')))))
def update_tree(self, ed, lexer): getter = self.get_getter(lexer) if not getter: return filename = ed.get_filename() lines = ed.get_text_all().split("\n") heads = list(getter(filename, lines)) ed.set_prop(app.PROP_CODETREE, False) app.tree_proc(self.h_tree, app.TREE_LOCK) app.tree_proc(self.h_tree, app.TREE_ITEM_DELETE, 0) last_levels = {0: 0} for index, data in enumerate(heads): pos = data[0] level = data[1] header = data[2] icon_index = data[3] if len(data) > 3 else -1 for test_level in reversed(range(level)): parent = last_levels.get(test_level) if parent is None: continue identity = app.tree_proc(self.h_tree, app.TREE_ITEM_ADD, parent, index=-1, text=header, image_index=icon_index) # when adding level K, forget all levels > K last_levels = { k: v for k, v in last_levels.items() if k <= level } last_levels[level] = identity if type(pos) == int: if index == len(heads) - 1: end_y = len(lines) - 1 s = ed.get_text_line(end_y) if s is None: end_x = 0 else: end_x = len(s) else: end_y = heads[index + 1][0] # line_index of next header end_x = 0 rng = (0, pos, end_x, end_y) else: rng = pos app.tree_proc(self.h_tree, app.TREE_ITEM_SET_RANGE, identity, index=-1, text=rng) break app.tree_proc(self.h_tree, app.TREE_UNLOCK)
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 = dlg_menu( (app.DMENU_LIST if self.show_wo_alt else app.DMENU_LIST_ALT) + app.DMENU_EDITORFONT + app.DMENU_CENTERED, w=900, h=800, cap=f(_('In-text bookmarks (all tabs): {}'), len(ibms)), its=[ f('({}) {}', tab_info, bm_msg) for tab_id, line_n, bm_msg, line_s, tab_info in ibms ] if self.show_wo_alt else [ f('({}) {}\t{}', tab_info, bm_msg, line_s) for tab_id, line_n, bm_msg, line_s, tab_info in ibms ], sel=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')))))
def _jump_to_ibm(self, what): 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')) rCrt = ed.get_carets()[0][1] if 1==len(ibms) \ and rCrt==ibms[0][1]: return app.msg_status(_('No more bookmarks')) line_ns = [line_n for (tab_id, line_n, bm_msg, line_s, tab_info) in ibms] if self.wrap: line_ns = [-line_ns[-1]] + line_ns + [line_ns[0]+0xFFFFFFFF] line_cns= [line_n for line_n in line_ns if (line_n>rCrt if what=='next' else line_n<rCrt)] if not line_cns: return app.msg_status(_('No bookmark for jump')) line_n = min(line_cns) if what=='next' else max(line_cns) line_n = -line_n if line_n<0 else line_n line_n = line_n-0xFFFFFFFF if line_n>=0xFFFFFFFF else line_n 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')))))
def move_tab(how=''): group = ed.get_prop(app.PROP_INDEX_GROUP) gr_cnt = 0 for h in app.ed_handles(): edH = app.Editor(h) if (group == edH.get_prop(app.PROP_INDEX_GROUP) and gr_cnt < edH.get_prop(app.PROP_INDEX_TAB)): gr_cnt = edH.get_prop(app.PROP_INDEX_TAB) gr_cnt += 1 old_pos = ed.get_prop(app.PROP_INDEX_TAB) new_pos = None if how == '': new_pos = app.dlg_input(_(f'New position (max={gr_cnt})'), str(old_pos + 1)) if new_pos is None: return new_pos = max(0, min(gr_cnt, int(new_pos) - 1)) else: step = -1 if how == 'l' else 1 new_pos = (old_pos + step) % gr_cnt if new_pos == old_pos: return ed.set_prop(app.PROP_INDEX_TAB, str(new_pos))
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)) pass #LOG and log('self.show_wo_alt={}',(self.show_wo_alt)) 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] ans = dlg_menu( (app.DMENU_LIST if self.show_wo_alt else app.DMENU_LIST_ALT) + app.DMENU_EDITORFONT, w=900, cap=f(_('Tab in-text bookmarks: {}'), len(ibms)), its=[ f('{}\t{}', line_nd, bm_msg) for bm_msg, line_n, line_nd in ibms ] if self.show_wo_alt else [f('{}\t{}', bm_msg, line_nd) for bm_msg, line_n, line_nd in ibms], sel=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')))))
def do_setv(self, aid, ag, data): M,m = self.__class__,self pass; #LOG and log('aid,m.cur_op={}',(aid,m.cur_op)) if not m.cur_op: return [] #m.col_ws= [ci['wd'] for ci in m.ag.cattr('lvls', 'cols')] cur_val = data trg = 'lexer '+m.lexr+'.json' if m.for_ulf=='l' else 'user.join' key4v = m.for_ulf+'val' op = m.cur_op oi = m.opts_full[op] frm = oi['frm'] dval = oi.get( 'def') uval = oi.get('uval') lval = oi.get('lval') fval = oi.get('fval') ulfvl = oi.get(key4v ) #fval if m.for_ulf=='f' else lval if m.for_ulf=='l' else uval jval = oi['jlvl'] if m.for_ulf=='l' else \ oi['juvl'] if m.for_ulf=='u' else \ oi['jfvl'] # Get new value newv = None erpt_s = '' if False:pass elif aid=='setd' and m.for_ulf=='f' and op in apx.OPT2PROP: # Remove from file - set over def/user/lex val newv = oi.get('lval', oi.get('uval', oi.get('def'))) if newv==ulfvl: #m.stbr_act(M.STBR_MSG, _('No need changes')) return [] erpt_s = 'reset-f' m.ed.set_prop(apx.OPT2PROP[op], newv) elif aid=='setd' and ulfvl is not None and m.for_ulf!='f': # Remove from user/lexer newv= None elif aid=='setv': # Add/Set opt for user/lexer/file # Enter from edit. Need parse some string #newv = m.ag.cval('eded') newv = cur_val try: newv = int(newv) if frm=='int' else \ float(newv) if frm=='float' else \ newv except Exception as ex: app.msg_box(f(_('Incorrect value. It\'s needed in format: {}'), frm) , app.MB_OK+app.MB_ICONWARNING) return d(form=d(fid='eded')) if frm=='#rgb' or frm=='#rgb-e' and newv: # Testing new val try: apx.html_color_to_int(newv) except Exception as ex: app.msg_box(f(_('Incorrect value. It\'s needed in format: {}'), '#RGB or #RRGGBB') , app.MB_OK+app.MB_ICONWARNING) return d(form=d(fid='eded')) ### Use new value to change env if newv is not None and newv==ulfvl: #m.stbr_act(M.STBR_MSG, _('No need changes')) return [] if m.for_ulf=='f' and newv is not None and op in apx.OPT2PROP: # Change for file erpt_s = 'set-f' ed.set_prop(apx.OPT2PROP[op], newv) if m.for_ulf!='f': # Change target file pass; #LOG and log('?? do_erpt',()) erpt_s =('reset-u' if newv is None and m.for_ulf=='u' else 'reset-l' if newv is None and m.for_ulf=='l' else 'add-u' if ulfvl is None and m.for_ulf=='u' else 'add-l' if ulfvl is None and m.for_ulf=='l' else 'set-u' if m.for_ulf=='u' else 'set-l' if m.for_ulf=='l' else '') pass; #LOG and log('?? set_opt',()) apx.set_opt(op ,newv ,apx.CONFIG_LEV_LEX if m.for_ulf=='l' else apx.CONFIG_LEV_USER ,ed_cfg =None ,lexer =m.lexr if m.for_ulf=='l' else None ,user_json=m.how.get('stor_json', 'user.json') ) if not m.apply_one: pass; #LOG and log('?? OpsReloadAndApply',()) ed.cmd(cmds.cmd_OpsReloadAndApply) else: m.apply_need = True # Use new value to change dlg data pass; #LOG and log('?? oi={}',(oi)) pass; #LOG and log('?? m.opts_full={}',pf(m.opts_full)) if False:pass elif aid=='setd': oi.pop(key4v, None) if m.for_ulf!='f' else 0 else: pass; #LOG and log('key4v, newv={}',(key4v, newv)) oi[key4v] = newv pass; #LOG and log('oi={}',(oi)) upd_cald_vals(m.opts_full) pass; #LOG and log('oi={}',(oi)) jnewv = oi['jlvl'] if m.for_ulf=='l' else oi['juvl'] if m.for_ulf=='u' else oi['jfvl'] #m.do_erpt(erpt_s, jnewv, jval) pass; #LOG and log('ok oi={}',(oi)) pass; #LOG and log('ok m.opts_full={}',pf(m.opts_full)) pass; #LOG and log('?? get_cnts',()) if m.for_ulf!='f' and m.auto4file and op in apx.OPT2PROP: # Change FILE to over (("over" - override?)) newv = oi.get('lval', oi.get('uval', oi.get('def'))) if newv!=oi.get('fval'): erpt_s = 'reset-f' m.ed.set_prop(apx.OPT2PROP[op], newv) oi['fval'] = newv jval = oi['jfvl'] upd_cald_vals(m.opts_full) jnewv = oi['jfvl'] #m.do_erpt('auset-f', jnewv, jval) pass; #LOG and log('m.get_vals(lvls-cur)={}',(m.get_vals('lvls-cur')))