def edit_file(self, name, syntax, use_template=None): editor = editors.get(name, None) if editor is None: if use_template is None: data = current_container().raw_data(name) if isbytestring(data) and syntax in { 'html', 'css', 'text', 'xml' }: try: data = data.decode('utf-8') except UnicodeDecodeError: return error_dialog( self.gui, _('Cannot decode'), _('Cannot edit %s as it appears to be in an unknown character encoding' ) % name, show=True) else: data = use_template editor = editors[name] = editor_from_syntax( syntax, self.gui.editor_tabs) self.init_editor(name, editor, data, use_template=bool(use_template)) self.show_editor(name) return editor
def edit_file(self, name, syntax): editor = editors.get(name, None) if editor is None: editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs) data = current_container().raw_data(name) self.init_editor(name, editor, data) self.show_editor(name)
def run_text_search(search, current_editor, current_editor_name, searchable_names, gui_parent, show_editor, edit_file): try: pat = get_search_regex(search) except InvalidRegex as e: return error_dialog(gui_parent, _('Invalid regex'), '<p>' + _( 'The regular expression you entered is invalid: <pre>{0}</pre>With error: {1}').format( prepare_string_for_xml(e.regex), error_message(e)), show=True) editor, where, files, do_all, marked = initialize_search_request(search, 'count', current_editor, current_editor_name, searchable_names) with BusyCursor(): if editor is not None: if editor.find_text(pat): return True if not files and editor.find_text(pat, wrap=True): return True for fname, syntax in iteritems(files): ed = editors.get(fname, None) if ed is not None: if ed.find_text(pat, complete=True): show_editor(fname) return True else: root = current_container().parsed(fname) if hasattr(root, 'xpath'): raw = tostring(root, method='text', encoding='unicode', with_tail=True) else: raw = current_container().raw_data(fname) if pat.search(raw) is not None: edit_file(fname, syntax) if editors[fname].find_text(pat, complete=True): return True msg = '<p>' + _('No matches were found for %s') % ('<pre style="font-style:italic">' + prepare_string_for_xml(search['find']) + '</pre>') return error_dialog(gui_parent, _('Not found'), msg, show=True)
def find_next(word, locations, current_editor, current_editor_name, gui_parent, show_editor, edit_file): files = OrderedDict() for l in locations: try: files[l.file_name].append(l) except KeyError: files[l.file_name] = [l] if current_editor_name not in files: current_editor_name = None locations = [(fname, {l.original_word for l in _locations}, False) for fname, _locations in files.iteritems()] else: # Re-order the list of locations to search so that we search in the # current editor first lfiles = list(files) idx = lfiles.index(current_editor_name) before, after = lfiles[:idx], lfiles[idx+1:] lfiles = after + before + [current_editor_name] locations = [(current_editor_name, {l.original_word for l in files[current_editor_name]}, True)] for fname in lfiles: locations.append((fname, {l.original_word for l in files[fname]}, False)) for file_name, original_words, from_cursor in locations: ed = editors.get(file_name, None) if ed is None: edit_file(file_name) ed = editors[file_name] if ed.find_spell_word(original_words, word[1].langcode, from_cursor=from_cursor): show_editor(file_name) return True return False
def do_find(): for p, __ in searches: if editor is not None: if editor.find(p, marked=marked, save_match='gui'): return True if wrap and not files and editor.find( p, wrap=True, marked=marked, save_match='gui'): return True for fname, syntax in files.iteritems(): ed = editors.get(fname, None) if ed is not None: if not wrap and ed is editor: continue if ed.find(p, complete=True, save_match='gui'): show_editor(fname) return True else: raw = current_container().raw_data(fname) if p.search(raw) is not None: edit_file(fname, syntax) if editors[fname].find(p, complete=True, save_match='gui'): return True return no_match()
def update_data(self): if not self.is_visible or self.preview_is_refreshing: return editor_name = self.current_name ed = editors.get(editor_name, None) if self.update_timer.isActive() or (ed is None and editor_name is not None): return QTimer.singleShot(100, self.update_data) if ed is not None: sourceline, tags = ed.current_tag(for_position_sync=False) if self.refresh_needed or self.now_showing != (editor_name, sourceline, tags): self.show_data(editor_name, sourceline, tags)
def edit_file(self, name, syntax, use_template=None): editor = editors.get(name, None) if editor is None: editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs) if use_template is None: data = current_container().raw_data(name) else: data = use_template self.init_editor(name, editor, data, use_template=bool(use_template)) self.show_editor(name) return editor
def update_data(self): if not self.is_visible or self.preview_is_refreshing: return editor_name = self.current_name ed = editors.get(editor_name, None) if self.update_timer.isActive() or (ed is None and editor_name is not None): return QTimer.singleShot(100, self.update_data) if ed is not None: sourceline, tags = ed.current_tag() if self.refresh_needed or self.now_showing != (editor_name, sourceline, tags): self.show_data(editor_name, sourceline, tags)
def edit_file(self, name, syntax, use_template=None): editor = editors.get(name, None) if editor is None: if use_template is None: data = current_container().raw_data(name) if isbytestring(data) and syntax in {'html', 'css', 'text', 'xml'}: try: data = data.decode('utf-8') except UnicodeDecodeError: return error_dialog(self.gui, _('Cannot decode'), _( 'Cannot edit %s as it appears to be in an unknown character encoding') % name, show=True) else: data = use_template editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs) self.init_editor(name, editor, data, use_template=bool(use_template)) self.show_editor(name) return editor
def do_find(): for p, __ in searches: if editor is not None: if editor.find(p, marked=marked, save_match='gui'): return if wrap and not files and editor.find(p, wrap=True, marked=marked, save_match='gui'): return for fname, syntax in files.iteritems(): ed = editors.get(fname, None) if ed is not None: if not wrap and ed is editor: continue if ed.find(p, complete=True, save_match='gui'): return show_editor(fname) else: raw = current_container().raw_data(fname) if p.search(raw) is not None: edit_file(fname, syntax) if editors[fname].find(p, complete=True, save_match='gui'): return return no_match()