Add shortcut for previous item

Julien LepillerThu Aug 16 16:08:24+0200 2018

cfdf4fd

Add shortcut for previous item

offlate/window.py

111111
        index = self.treeWidget.currentIndex()
112112
        nextItem = self.treeWidget.itemFromIndex(self.treeWidget.indexBelow(index))
113113
        self.treeWidget.setCurrentItem(nextItem)
114-
        self.msgstr.setFocus()
114+
115+
    def previousItem(self):
116+
        index = self.treeWidget.currentIndex()
117+
        nextItem = self.treeWidget.itemFromIndex(self.treeWidget.indexAbove(index))
118+
        self.treeWidget.setCurrentItem(nextItem)
115119
116120
    def selectItem(self, current, old):
117121
        if current == None:

123127
        self.msgstr.deleteLater()
124128
125129
        font = "monospace" if self.monospace else "sans-serif"
130+
        focuser = None
126131
127132
        if len(data.msgstrs) > 1:
128133
            self.msgid = QTabWidget();

144149
                form.setText(msgstr)
145150
                form.textChanged.connect(self.modify)
146151
                self.msgstr.addTab(form, str(i))
152+
                if i == 0:
153+
                    focuser = form
147154
                i=i+1
148155
        else:
149156
            self.msgid = QTextEdit()

154161
            self.msgstr.setFont(QFont(font))
155162
            self.msgstr.setText(data.msgstrs[0])
156163
            self.msgstr.textChanged.connect(self.modify)
164+
            focuser = self.msgstr
157165
        self.hbox.addWidget(self.msgid)
158166
        self.hbox.addWidget(self.msgstr)
167+
        focuser.setFocus()
159168
160169
    def modify(self):
161170
        item = self.treeWidget.currentItem()

473482
            total += 1
474483
            if d.isTranslated() and not d.isFuzzy():
475484
                translated += 1
476-
        percent = 100 if total == 0 else math.floor(100 * translated / total)
485+
        percent = 100 if total == 0 else math.floor(1000 * translated / total)/10
477486
        self.countLabel.setText(self.tr("{} translated on {} total ({}%).").format(translated, total, percent))
478487
479488
    def save(self):

516525
        for i in range(0, self.tabs.count()):
517526
            self.tabs.widget(i).setFont(self.monospaceAct.isChecked())
518527
528+
    def previousItem(self):
529+
        self.tabs.currentWidget().previousItem()
530+
519531
    def nextItem(self):
520532
        self.tabs.currentWidget().nextItem()
521533

568580
        self.monospaceAct.setChecked(False)
569581
        self.monospaceAct.triggered.connect(self.setFont)
570582
571-
        self.nextShortcut = QShortcut(QKeySequence("Ctrl+Return"), self)
583+
        self.previousShortcut = QShortcut(QKeySequence("Ctrl+Up"), self)
584+
        self.previousShortcut.activated.connect(self.previousItem)
585+
586+
        self.previous2Shortcut = QShortcut(QKeySequence("Ctrl+Shift+Return"), self)
587+
        self.previous2Shortcut.activated.connect(self.previousItem)
588+
589+
        self.nextShortcut = QShortcut(QKeySequence("Ctrl+Down"), self)
572590
        self.nextShortcut.activated.connect(self.nextItem)
573591
592+
        self.next2Shortcut = QShortcut(QKeySequence("Ctrl+Return"), self)
593+
        self.next2Shortcut.activated.connect(self.nextItem)
594+
574595
        self.countLabel = QLabel()
575596
        self.statusBar()
576597
        self.statusBar().addWidget(self.countLabel)