Beispiel #1
0
    def commit_list_doubleclick(self,*rest):
        """
        Called when an entry is double-clicked.

        This callback changes the model's directory when
        invoked on a directory item.  When invoked on a file
        it allows the file to be saved.

        """
        current = self.view.commit_list.currentRow()
        directories = self.model.directories

        # A file item was double-clicked.
        # Create a save-as dialog and export the file,
        # or if in get_file mode, grab the filename and finish the dialog.
        if current >= len(directories):
            idx = current - len(directories)

            objtype, sha1, name = self.model.subtree_node(idx)

            if self.get_file:
                if self.model.directory:
                    curdir = self.model.directory
                    self.filename = os.path.join(curdir, name)
                else:
                    self.filename = name
                self.view.accept()
                return

            nameguess = os.path.join(self.model.directory, name)
            filename = qtutils.save_dialog(self.view, 'Save', nameguess)
            if not filename:
                return
            self.model.set_directory(os.path.dirname(filename))
            contents = git.cat_file(objtype, sha1, with_raw_output=True)
            utils.write(filename, contents)
            return

        dirent = directories[current]
        curdir = self.model.directory

        # "change directories"
        # '..' is a special case--it doesn't really exist...
        if dirent == '..':
            newdir = os.path.dirname(os.path.dirname(curdir))
            if newdir == '':
                self.model.set_directory(newdir)
            else:
                self.model.set_directory(newdir + os.sep)
        else:
            self.model.set_directory(curdir + dirent)
Beispiel #2
0
    def item_changed(self,*rest):
        """Called when the current item changes"""
        current = self.view.commit_list.currentRow()
        item = self.view.commit_list.item(current)
        if item is None or not item.isSelected():
            self.view.revision.setText('')
            self.view.commit_text.setText('')
            return
        directories = self.model.directories
        directory_entries = self.model.directory_entries
        if current < len(directories):
            # This is a directory...
            self.filename = None
            dirent = directories[current]
            if dirent != '..':
                # This is a real directory for which
                # we have child entries
                entries = directory_entries[dirent]
            else:
                # This is '..' which is a special case
                # since it doesn't really exist
                entries = []
            self.view.commit_text.setText('\n'.join(entries))
            self.view.revision.setText('')
        else:
            # This is a file entry.  The current row is absolute,
            # so get a relative index by subtracting the number
            # of directory entries
            idx = current - len(directories)
            if idx >= len(self.model.subtree_sha1s):
                # This can happen when changing directories
                self.filename = None
                return
            objtype, sha1, name = self.model.subtree_node(idx)

            curdir = self.model.directory
            if curdir:
                self.filename = os.path.join(curdir, name)
            else:
                self.filename = name

            catguts = git.cat_file(objtype, sha1, with_raw_output=True)
            self.view.commit_text.setText(catguts)

            self.view.revision.setText(sha1)
            self.view.revision.selectAll()

            # Copy the sha1 into the clipboard
            qtutils.set_clipboard(sha1)