def _on_encoding_changed(self, encoding): """Event handler for EncodingSelector. It sets file text to browser again with new encoding. """ self.encoding = encoding branch = self.branch if branch is None: branch = Branch.open_containing(self.filename)[0] if branch: get_set_encoding(encoding, branch) self._set_text(self.browser.edit, self.filename, self.text, self.encoding)
def _on_encoding_changed(self, encoding): self.encoding = encoding get_set_encoding(encoding, self.branch) self.throbber.show() try: self.branch.lock_read() try: self.annotate(self.annotate_tree, self.fileId, self.path) finally: self.branch.unlock() finally: self.throbber.hide()
def refresh(self): self.loaded = False self.clear() tree = WorkingTree.open_containing(self.directory)[0] tree.lock_read() try: manager = tree.get_shelf_manager() shelves = manager.active_shelves() for shelf_id in reversed(shelves): message = manager.get_metadata(shelf_id).get('message') item = QtWidgets.QTreeWidgetItem() item.setText(0, str(shelf_id)) item.setText(1, message or gettext('<no message>')) item.setIcon(0, get_icon("folder", 16)) item.shelf_id = shelf_id self.shelve_view.addTopLevelItem(item) self.tree = tree self.manager = manager branch = tree.branch if self.initial_encoding is None: encoding = get_set_encoding(None, branch) self.initial_encoding = encoding # save real encoding for the next time self.encoding_selector.encoding = encoding # set encoding selector tabwidth = get_set_tab_width_chars(branch) self.tabwidth_selector.setTabWidth(tabwidth) self._on_tabwidth_changed(tabwidth) finally: tree.unlock() self.update() self.loaded = True
def initial_load(self): """Called to perform the initial load of the form. Enables a throbber window, then loads the branches etc if they weren't specified in our constructor. """ self.throbber.show() try: if self.loader_func is not None: (self.branch, self.annotate_tree, self.working_tree, self.path, self.fileId) = self.loader_func(*self.loader_args) self.loader_func = self.loader_args = None # kill extra refs... QtCore.QCoreApplication.processEvents() self.encoding = get_set_encoding(self.encoding, self.branch) self.encoding_selector.encoding = self.encoding self.branch.lock_read() try: self.set_annotate_title() self.annotate(self.annotate_tree, self.fileId, self.path) finally: self.branch.unlock() finally: self.throbber.hide() QtCore.QTimer.singleShot(1, self._activate_line)
def refresh(self): cleanup = [] try: old_rev = self.revision old_changes = self._get_change_dictionary() self.clear(clear_message=False) shelver, creator = self._create_shelver_and_creator() cleanup.append(shelver.finalize) cleanup.append(creator.finalize) file_list = shelver.file_list if file_list: nfiles = len(file_list) if nfiles > 2: self.files_str = ngettext("%d file", "%d files", nfiles) % nfiles else: self.files_str = ", ".join(file_list) self.trees = (shelver.target_tree, shelver.work_tree) branch = shelver.work_tree.branch # current branch corresponding to working tree if self.initial_encoding is None: encoding = get_set_encoding(None, branch) self.initial_encoding = encoding # save real encoding for the next time self.encoding_selector.encoding = encoding # set encoding selector self.editor_available = (shelver.change_editor is not None) self.editor_button.setVisible(self.editor_available) tabwidth = get_set_tab_width_chars(branch) self.tabwidth_selector.setTabWidth(tabwidth) self._on_tabwidth_changed(tabwidth) self.revision = self.trees[0].get_revision_id() if self.revision != old_rev: old_changes = None for change in creator.iter_shelvable(): item = self._create_item(change, shelver, self.trees, old_changes) self.file_view.addTopLevelItem(item) finally: for func in cleanup: func() if self.select_all: self.check_all(True) self.select_all = False self.loaded = True
def load(self): self.throbber.show() self.processEvents() try: if not self.tree: branch, relpath = Branch.open_containing(self.filename) self.branch = branch self.encoding = get_set_encoding(self.encoding, branch) self.encoding_selector.encoding = self.encoding if self.revision is None: self.tree = branch.basis_tree() else: revision_id = self.revision[0].in_branch(branch).rev_id self.tree = branch.repository.revision_tree(revision_id) self.file_id = self.tree.path2id(relpath) if not self.file_id: self.file_id = self.tree.path2id(self.filename) if not self.file_id: raise errors.BzrCommandError( "%r is not present in revision %s" % (self.filename, self.tree.get_revision_id())) self.tree.lock_read() try: kind = self.tree.kind(self.filename) if kind == 'file': text = self.tree.get_file_text(self.filename) elif kind == 'symlink': text = self.tree.get_symlink_target(self.filename) else: text = '' finally: self.tree.unlock() self.processEvents() self.text = text self.kind = kind self._create_and_show_browser(self.filename, text, kind) finally: self.throbber.hide()
def show_file_content(self): """Launch qcat for one selected file.""" paths, file_ids = self.get_file_selection_paths_and_ids() ( top_revid, old_revid ), count = self.log_list.get_selection_top_and_parent_revids_and_count( ) gv = self.log_list.log_model.graph_viz branch = gv.get_revid_branch(top_revid) if top_revid.startswith(CURRENT_REVISION): tree = gv.working_trees[top_revid] else: tree = branch.repository.revision_tree(top_revid) encoding = get_set_encoding(None, branch) window = QBzrCatWindow(filename=paths[0], tree=tree, parent=self, encoding=encoding) window.show() self.window().windows.append(window)
def test_get_set_encoding_set(self): br = FakeBranch() util.get_set_encoding('ascii', br) # check that we don't overwrite encoding vaslue in bazaar.conf self.assertEqual('utf-8', util.get_set_encoding(None,None))
def test_get_set_encoding_get(self): br = FakeBranch() enc = util.get_set_encoding(None, br) self.assertEqual('utf-8', enc)
def load_branch_info(self): self.set_diff_title() self.encoding_selector_left.encoding = get_set_encoding(self.encoding, self.branches[0]) self.encoding_selector_right.encoding = get_set_encoding(self.encoding, self.branches[1]) self.processEvents()
def on_right_encoding_changed(encoding): if self.branches: get_set_encoding(encoding, self.branches[1]) self.click_refresh()