Skip to content

Commit

Permalink
add contextmenu for logview dialog which can copy, exclude and decode…
Browse files Browse the repository at this point in the history
… lines
  • Loading branch information
Germar committed Aug 20, 2017
1 parent 7519b7e commit 3bc25fa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Back In Time

Version 1.2.0~alpha0
* add contextmenu for logview dialog which can copy, exclude and decode lines
* move progressbar under statusbar
* Fix bug: backintime root crontab doesn't run; missinng line-feed 0x0A on last line (https://github.com/bit-team/backintime/issues/781)
* Fix bug: IndexError in inhibitSuspend (https://github.com/bit-team/backintime/issues/772)
Expand Down
50 changes: 49 additions & 1 deletion qt/logviewdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import encfstools
import snapshotlog
import tools
import messagebox

_=gettext.gettext

Expand Down Expand Up @@ -130,9 +131,13 @@ def __init__(self, parent, sid = None, systray = False):
self.watcher.addPath(log)
self.watcher.fileChanged.connect(self.updateLog)

self.txtLogView.setContextMenuPolicy(Qt.CustomContextMenu)
self.txtLogView.customContextMenuRequested.connect(self.contextMenuClicked)

def cbDecodeChanged(self):
if self.cbDecode.isChecked():
self.decode = encfstools.Decode(self.config)
if not self.decode:
self.decode = encfstools.Decode(self.config)
else:
if not self.decode is None:
self.decode.close()
Expand All @@ -158,6 +163,49 @@ def comboSnapshotsChanged(self, index):
def comboFilterChanged(self, index):
self.updateLog()

def contextMenuClicked(self, point):
menu = QMenu()
clipboard = qttools.createQApplication().clipboard()
cursor = self.txtLogView.textCursor()

btnCopy = menu.addAction(_('Copy'))
btnCopy.triggered.connect(lambda: clipboard.setText(cursor.selectedText()))
btnCopy.setEnabled(cursor.hasSelection())

btnAddExclude = menu.addAction(_('Add to Exclude'))
btnAddExclude.triggered.connect(self.btnAddExcludeClicked)
btnAddExclude.setEnabled(cursor.hasSelection())

btnDecode = menu.addAction(_('Decode'))
btnDecode.triggered.connect(self.btnDecodeClicked)
btnDecode.setEnabled(cursor.hasSelection())
btnDecode.setVisible(self.config.snapshotsMode() == 'ssh_encfs')

menu.exec_(self.txtLogView.mapToGlobal(point))

def btnAddExcludeClicked(self):
exclude = self.config.exclude()
path = self.txtLogView.textCursor().selectedText().strip()
if not path or path in exclude:
return
edit = QLineEdit(self)
edit.setText(path)
edit.setMinimumWidth(600)
options = {'widget': edit, 'retFunc': edit.text, 'id': 'path'}
confirm, opt = messagebox.warningYesNoOptions(self, _("Do you want to exclude this?"), (options, ))
if not confirm:
return
exclude.append(opt['path'])
self.config.setExclude(exclude)

def btnDecodeClicked(self):
if not self.decode:
self.decode = encfstools.Decode(self.config)
cursor = self.txtLogView.textCursor()
selection = cursor.selectedText().strip()
plain = self.decode.path(selection)
cursor.insertText(plain)

def updateProfiles(self):
current_profile_id = self.config.currentProfile()

Expand Down

0 comments on commit 3bc25fa

Please sign in to comment.