def anchorClicked(url, c=self.c, p=p, te=te): url = str(url.toString()) # g.trace(url,te) # if QtCore.Qt.ShiftModifier & te.modifiers(): # sep = '\\' if '\\' in url else '/' # url = sep.join(url.split(sep)[:-1]) g.handleUrl(url,c=c,p=p)
def handleURL(self, url): """handleUrl - user clicked an URL / UNL link :param str url: URL for link """ g.es(url) # UNL detection copied from g.handleUrl() if ( url.lower().startswith('unl:' + '//') or url.lower().startswith('file://') and url.find('-->') > -1 or url.startswith('#') ): our_unl = 'unl://'+self.c.p.get_UNL(with_index=False) # don't use .get_UNL(with_proto=True), that # unecessarily does ' ' -> %20 conversion new_c = g.handleUnl(url, self.c) if new_c and hasattr(new_c, 'backlinkController'): unl = url.replace('%20', ' ').split('#', 1)[-1].split('-->') found, _, new_p = g.recursiveUNLFind(unl, new_c) if not found: g.es("No perfect match, not creating backlink") return new_c.backlinkController.initBacklink(new_p.v) if our_unl not in [i.rsplit('##', 1)[0] for i in new_p.v.u['_bklnk']['urls']]: new_p.v.u['_bklnk']['urls'].append("%s##%s" % (our_unl, self.c.p.h)) new_c.backlinkController.updateTabInt() new_p.setDirty() new_c.setChanged(True) g.es("NOTE: created back link automatically") else: g.handleUrl(url, c=self.c)
def button_clicked(self, event, bm, but, up=False): """button_clicked - handle a button being clicked :Parameters: - `event`: QPushButton event - `bm`: Bookmark associated with button - `but`: button widget """ if event.button() == QtCore.Qt.RightButton: return self.button_menu(event, bm, but, up=up) mods = event.modifiers() # Alt-Ctrl => update bookmark to point to current node if mods == (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier): self.update_bookmark(bm) return # Shift-Ctrl => rename bookmark if mods == (QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier): self.rename_bookmark(bm) return # Alt => edit the bookmark in the outline if mods == QtCore.Qt.AltModifier: self.edit_bookmark(bm) return # Ctrl => delete the bookmark if mods == QtCore.Qt.ControlModifier: self.delete_bookmark(bm) return # Shift => add child bookmark if mods == QtCore.Qt.ShiftModifier: cmd_bookmark_child(event={'c': bm.v.context}) return # Alt-Shift => navigate in bookmarks without changing nodes no_move = mods == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier) # Alt-Control-Shift => hoist outline after going to node hoist = mods == (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) # otherwise, look up the bookmark self.upwards = up self.second = not up and self.current == bm.v self.current = bm.v if up and not bm.url and bm.v != self.v: # folders are only current when you're in them pass # this causes bookmark position to go rootwards by two steps, disabled # self.current = self.current.parents[0] # in case something we didn't see changed the bookmarks self.show_list(self.get_list(), up=up) if bm.url and not up and not no_move: g.handleUrl(bm.url, c=self.c) if hoist: self.c.hoist() else: # don't leave focus adrift when clicking organizer node self.c.bodyWantsFocusNow()
def anchorClicked(url, c=self.c, p=p, te=te): url = str(url.toString()) # g.trace(url,te) # if QtCore.Qt.ShiftModifier & te.modifiers(): # sep = '\\' if '\\' in url else '/' # url = sep.join(url.split(sep)[:-1]) g.handleUrl(url, c=c, p=p)
def handleURL(self, url): """handleUrl - user clicked an URL / UNL link :param str url: URL for link """ g.es(url) # UNL detection copied from g.handleUrl() if (url.lower().startswith('unl://') or url.lower().startswith('file://') and url.find('-->') > -1 or url.startswith('#')): our_unl = 'unl://' + self.c.p.get_UNL() new_c = g.handleUnl(url, self.c) if new_c and hasattr(new_c, 'backlinkController'): unlList = url.replace('%20', ' ').split('#', 1)[-1].split('-->') new_p = g.findUNL(unlList, new_c) if not new_p: g.es("No perfect match, not creating backlink") return new_c.backlinkController.initBacklink(new_p.v) if our_unl not in [ i.rsplit('##', 1)[0] for i in new_p.v.u['_bklnk']['urls'] ]: new_p.v.u['_bklnk']['urls'].append("%s##%s" % (our_unl, self.c.p.h)) new_c.backlinkController.updateTabInt() new_p.setDirty() new_c.setChanged() g.es("NOTE: created back link automatically") else: g.handleUrl(url, c=self.c)
def cmd_open_node(event): c = event.get('c') if not c: return p = c.p url = g.getUrlFromNode(p) if url: # No need to handle url hooks here. g.handleUrl(url, c=c, p=p)
def cmd_open_node(event): c = event.get('c') if not c: return p = c.p url = g.getUrlFromNode(p) if url: # No need to handle url hooks here. g.handleUrl(url,c=c,p=p)
def button_clicked(self, event, bm, but, up=False): """button_clicked - handle a button being clicked :Parameters: - `event`: QPushButton event - `bm`: Bookmark associated with button - `but`: button widget """ MouseButtons = QtCore.Qt.MouseButtons if isQt6 else QtCore.Qt if event.button() == MouseButtons.RightButton: self.button_menu(event, bm, but, up=up) return action_name = self.mod_map.get(self.ModMap.get(event.modifiers())) if action_name is None: g.es("Bookmarks: unknown click type") print(int(event.modifiers())) for k, v in self.ModMap.items(): print(k, v) for k, v in self.mod_map.items(): print(k, v) return if action_name in ('update_bookmark', 'rename_bookmark', 'edit_bookmark', 'delete_bookmark', 'promote_bookmark'): # simple bookmark actions getattr(self, action_name)(bm) return if action_name == 'add_child': cmd_bookmark_child(event={'c': bm.v.context}) return no_move = action_name == 'navigate' hoist = action_name == 'hoist' # otherwise, look up the bookmark self.upwards = up self.second = not up and self.current == bm.v self.current = bm.v if up and not bm.url and bm.v != self.v: # folders are only current when you're in them pass # this causes bookmark position to go rootwards by two steps, disabled # self.current = self.current.parents[0] # in case something we didn't see changed the bookmarks self.show_list(self.get_list(), up=up) if bm.url and not up and not no_move: g.handleUrl(bm.url, c=self.c) if hoist: self.c.hoist() else: # don't leave focus adrift when clicking organizer node self.c.bodyWantsFocusNow()
def button_clicked(self, event, bm, but, up=False): """button_clicked - handle a button being clicked :Parameters: - `event`: QPushButton event - `bm`: Bookmark associated with button - `but`: button widget """ if event.button() == QtCore.Qt.RightButton: return self.button_menu(event, bm, but, up=up) action_name = self.mod_map.get(self.ModMap.get(int(event.modifiers()))) if action_name is None: g.es("Bookmarks: unknown click type") print(int(event.modifiers())) for k, v in self.ModMap.items(): print(k, v) for k, v in self.mod_map.items(): print(k, v) return if action_name in ('update_bookmark', 'rename_bookmark', 'edit_bookmark', 'delete_bookmark', 'promote_bookmark'): # simple bookmark actions getattr(self, action_name)(bm) return elif action_name == 'add_child': cmd_bookmark_child(event={'c': bm.v.context}) return no_move = action_name == 'navigate' hoist = action_name == 'hoist' # otherwise, look up the bookmark self.upwards = up self.second = not up and self.current == bm.v self.current = bm.v if up and not bm.url and bm.v != self.v: # folders are only current when you're in them pass # this causes bookmark position to go rootwards by two steps, disabled # self.current = self.current.parents[0] # in case something we didn't see changed the bookmarks self.show_list(self.get_list(), up=up) if bm.url and not up and not no_move: g.handleUrl(bm.url, c=self.c) if hoist: self.c.hoist() else: # don't leave focus adrift when clicking organizer node self.c.bodyWantsFocusNow()
def button_clicked(self, event, bm, but, up=False): """button_clicked - handle a button being clicked :Parameters: - `event`: QPushButton event - `bm`: Bookmark associated with button - `but`: button widget """ if event.button() == QtCore.Qt.RightButton: return self.button_menu(event, bm, but, up=up) mods = event.modifiers() # Alt-Ctrl => update bookmark to point to current node if mods == (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier): self.update_bookmark(bm) return # Shift-Ctrl => rename bookmark if mods == (QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier): self.rename_bookmark(bm) return # Alt => edit the bookmark in the outline if mods == QtCore.Qt.AltModifier: self.edit_bookmark(bm) return # Ctrl => delete the bookmark if mods == QtCore.Qt.ControlModifier: self.delete_bookmark(bm) return # Shift => add child bookmark if mods == QtCore.Qt.ShiftModifier: self.add_child_bookmark(bm) return # Alt-Shift => navigate in bookmarks without changing nodes no_move = mods == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier) # Alt-Control-Shift => hoist outline after going to node hoist = mods == (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) # otherwise, look up the bookmark self.upwards = up self.second = not up and self.current == bm.v self.current = bm.v # in case something we didn't see changed the bookmarks self.show_list(self.get_list(), up=up) if bm.url and not up and not no_move: g.handleUrl(bm.url, c=self.c) if hoist: self.c.hoist()
def anchorClicked(url, c=self.c, p=p, te=te, owner=self): if QtCore.Qt.AltModifier & te.modifiers: return if QtCore.Qt.ControlModifier & te.modifiers: owner.delete_bookmark(str(url.toString())) else: url = str(url.toString()) # g.trace(url,te) # if QtCore.Qt.ShiftModifier & te.modifiers(): # sep = '\\' if '\\' in url else '/' # url = sep.join(url.split(sep)[:-1]) self.show_list(self.current_list) # to clear red highlight of double added url g.handleUrl(url,c=c,p=p)
def anchorClicked(url, c=self.c, p=p, te=te, owner=self): if QtCore.Qt.AltModifier & te.modifiers: return if QtCore.Qt.ControlModifier & te.modifiers: owner.delete_bookmark(str(url.toString())) else: url = str(url.toString()) # g.trace(url,te) # if QtCore.Qt.ShiftModifier & te.modifiers(): # sep = '\\' if '\\' in url else '/' # url = sep.join(url.split(sep)[:-1]) self.show_list(self.current_list ) # to clear red highlight of double added url g.handleUrl(url, c=c, p=p)
def openFile(c, parent, d, autoload=False): """Open an existing file""" path = getPath(c, parent) if not os.path.isfile(path): return oversize = os.stat(path).st_size > c.__active_path['max_size'] if not autoload: junk, ext = g.os_path_splitext(path) extensions = c.config.getData('active_path_bin_open') or [] # #2103 binary_open = ext in extensions if not binary_open: try: start = open(path).read(100) for i in start: if ord(i) == 0: binary_open = True break except Exception: binary_open = True if binary_open: g.es('Treating file as binary') g.handleUrl('file://' + path, c=c) # if not query(c, "File may be binary, continue?"): # return return if oversize: if not query( c, "File size greater than %d bytes, continue?" % c.__active_path['max_size']): return if autoload and oversize: return atType = c.config.getString('active-path-attype') or 'auto' parent.h = '@' + atType + ' ' + parent.h c.selectPosition(parent) if atType == 'asis': parent.b = open(d).read() else: c.refreshFromDisk() c.bodyWantsFocus()
def button_clicked(self, event, bm, but, up=False): """button_clicked - handle a button being clicked :Parameters: - `event`: QPushButton event - `bm`: Bookmark associated with button - `but`: button widget """ if event.button() == QtCore.Qt.RightButton: return self.button_menu(event, bm, but, up=up) mods = event.modifiers() # Alt-Ctrl => update bookmark to point to current node if mods == (QtCore.Qt.AltModifier | QtCore.Qt.ControlModifier): self.update_bookmark(bm) return # Shift-Ctrl => rename bookmark if mods == (QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier): self.rename_bookmark(bm) return # Alt => edit the bookmark in the outline if mods == QtCore.Qt.AltModifier: self.edit_bookmark(bm) return # Ctrl => delete the bookmark if mods == QtCore.Qt.ControlModifier: self.delete_bookmark(bm) return # Shift => add child bookmark if mods == QtCore.Qt.ShiftModifier: self.add_child_bookmark(bm) return # Alt-Shift => navigate in bookmarks without changing nodes no_move = mods == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier) # otherwise, look up the bookmark self.upwards = up self.second = not up and self.current == bm.v self.current = bm.v # in case something we didn't see changed the bookmarks self.show_list(self.get_list(), up=up) if bm.url and not up and not no_move: g.handleUrl(bm.url, c=self.c)
def openFile(c,parent,d, autoload=False): """Open an existing file""" path = getPath(c, parent) if not os.path.isfile(path): return oversize = os.stat(path).st_size > c.__active_path['max_size'] if not autoload: binary_open = g.os_path_splitext(path)[-1].lower() in ( c.config.getData('active_path_bin_open') or '') if not binary_open: start = open(path).read(100) for i in start: if ord(i) == 0: binary_open = True break if binary_open: g.es('Treating file as binary') g.handleUrl('file://' + path,c=c) # if not query(c, "File may be binary, continue?"): # return return if oversize: if not query(c, "File size greater than %d bytes, continue?" % c.__active_path['max_size']): return if autoload and oversize: return atType = c.config.getString('active_path_attype') or 'auto' parent.h = '@' + atType + ' ' + parent.h c.selectPosition(parent) if atType == 'asis': parent.b = open(d).read() else: c.refreshFromDisk() c.bodyWantsFocus()
def openFile(c, parent, d, autoload=False): """Open an existing file""" # hdr = os.path.basename(d) # parent.h = '@auto '+hdr # parent.b = file(d).read() path = getPath(c, parent) if not os.path.isfile(path): return if not autoload: binary_open = g.os_path_splitext(path)[-1].lower() in ( c.config.getData('active_path_bin_open') or '') if not binary_open: start = open(path).read(100) for i in start: if ord(i) == 0: binary_open = True break if binary_open: g.es('Treating file as binary') g.handleUrl('file://' + path, c=c) # if not query(c, "File may be binary, continue?"): # return return if os.stat(path).st_size > c.__active_path['max_size']: if not query( c, "File size greater than %d bytes, continue?" % c.__active_path['max_size']): return c.importCommands.createOutline(d, parent=parent, atAuto=True) atType = c.config.getString('active_path_attype') or 'auto' parent.h = '@' + atType + ' ' + parent.h c.bodyWantsFocus()
def openFile(c,parent,d, autoload=False): """Open an existing file""" # hdr = os.path.basename(d) # parent.h = '@auto '+hdr # parent.b = file(d).read() path = getPath(c, parent) if not os.path.isfile(path): return if not autoload: binary_open = g.os_path_splitext(path)[-1].lower() in ( c.config.getData('active_path_bin_open') or '') if not binary_open: start = open(path).read(100) for i in start: if ord(i) == 0: binary_open = True break if binary_open: g.es('Treating file as binary') g.handleUrl('file://' + path,c=c) # if not query(c, "File may be binary, continue?"): # return return if os.stat(path).st_size > c.__active_path['max_size']: if not query(c, "File size greater than %d bytes, continue?" % c.__active_path['max_size']): return c.importCommands.createOutline(d,parent=parent,atAuto=True) atType = c.config.getString('active_path_attype') or 'auto' parent.h = '@' + atType + ' ' + parent.h c.bodyWantsFocus()
def openFile(c, parent, d, autoload=False): """Open an existing file""" path = getPath(c, parent) if not os.path.isfile(path): return if not autoload: binary_open = g.os_path_splitext(path)[-1].lower() in (c.config.getData("active_path_bin_open") or "") if not binary_open: start = open(path).read(100) for i in start: if ord(i) == 0: binary_open = True break if binary_open: g.es("Treating file as binary") g.handleUrl("file://" + path, c=c) # if not query(c, "File may be binary, continue?"): # return return if os.stat(path).st_size > c.__active_path["max_size"]: if not query(c, "File size greater than %d bytes, continue?" % c.__active_path["max_size"]): return atType = c.config.getString("active_path_attype") or "auto" parent.h = "@" + atType + " " + parent.h c.selectPosition(parent) if atType == "asis": parent.b = open(d).read() else: c.refreshFromDisk() c.bodyWantsFocus()
def visit_next_target(event): """visit_next_target - go to the UNL at the start of the list g._quickmove_target_list, rotating that UNL to the end of the list. Intialize list to quickmove target list if not already present. :param leo event event: event from Leo """ c = event.get('c') if not c: return if not hasattr(g, '_quickmove_target_list'): g._quickmove_target_list = [ i['unl'] for i in g.app.db['_quickmove']['global_targets'] ] if not g._quickmove_target_list: return unl = g._quickmove_target_list[0] g._quickmove_target_list = g._quickmove_target_list[1:] + [unl] g.handleUrl(unl, c)
def openurl_rclick_cb(): if not g.doHook("@url1",c=c,p=p,url=url): g.handleUrl(url,c=c,p=p) g.doHook("@url2",c=c,p=p)
def openurl_rclick_cb(): if not g.doHook("@url1", c=c, p=p, url=url): g.handleUrl(url, c=c, p=p) g.doHook("@url2", c=c, p=p)