ask user before creating a clipboard larger than 5 MB
This commit is contained in:
15
bigtext.py
15
bigtext.py
@@ -12,6 +12,7 @@ from PyQt6.QtGui import QMouseEvent
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from ScaledScrollBar import ScaledScrollBar
|
||||
from conversion import humanbytes
|
||||
from highlight import Highlight
|
||||
from highlight_regex import HighlightRegex
|
||||
from highlight_selection import HighlightSelection
|
||||
@@ -227,6 +228,20 @@ class InnerBigText(QWidget):
|
||||
if self.selection_highlight.start_byte != self.selection_highlight.end_byte:
|
||||
start = min(self.selection_highlight.start_byte, self.selection_highlight.end_byte)
|
||||
end = max(self.selection_highlight.start_byte, self.selection_highlight.end_byte)
|
||||
if end - start > (1024 ** 2) * 5:
|
||||
you_sure = QMessageBox(
|
||||
QMessageBox.Icon.Warning,
|
||||
self.tr("copy to clipboard"),
|
||||
self.tr(
|
||||
"You are about to copy <b>%s</b> to the clipboard. Are you sure you want to do that?" % humanbytes(
|
||||
end - start)))
|
||||
you_sure.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
||||
you_sure.setDefaultButton(QMessageBox.StandardButton.No)
|
||||
result = you_sure.exec()
|
||||
if result != QMessageBox.StandardButton.Yes:
|
||||
# abort
|
||||
return
|
||||
|
||||
selected_text = self.model.read_range(start, end)
|
||||
cb = QApplication.clipboard()
|
||||
cb.setText(selected_text)
|
||||
|
||||
Reference in New Issue
Block a user