src/eric7/UI/Previewers/PreviewerHTML.py

branch
eric7
changeset 9447
662075aa9361
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
diff -r b98500e6fec1 -r 662075aa9361 src/eric7/UI/Previewers/PreviewerHTML.py
--- a/src/eric7/UI/Previewers/PreviewerHTML.py	Sun Oct 30 10:57:29 2022 +0100
+++ b/src/eric7/UI/Previewers/PreviewerHTML.py	Mon Oct 31 10:48:45 2022 +0100
@@ -17,7 +17,7 @@
 import contextlib
 
 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QThread
-from PyQt6.QtGui import QCursor
+from PyQt6.QtGui import QCursor, QGuiApplication
 from PyQt6.QtWidgets import (
     QWidget,
     QVBoxLayout,
@@ -25,6 +25,8 @@
     QCheckBox,
     QSizePolicy,
     QToolTip,
+    QGridLayout,
+    QPushButton,
 )
 
 from eric7.EricWidgets.EricApplication import ericApp
@@ -84,21 +86,35 @@
         self.previewView.setUrl(QUrl("about:blank"))
         self.__layout.addWidget(self.previewView)
 
+        self.__footerLayout = QGridLayout()
+        sizePolicy = QSizePolicy(
+            QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
+        )
         self.jsCheckBox = QCheckBox(self.tr("Enable JavaScript"), self)
         self.jsCheckBox.setToolTip(
             self.tr("Select to enable JavaScript for HTML previews")
         )
-        self.__layout.addWidget(self.jsCheckBox)
+        self.jsCheckBox.setSizePolicy(sizePolicy)
+        self.__footerLayout.addWidget(self.jsCheckBox, 0, 0)
 
         self.ssiCheckBox = QCheckBox(self.tr("Enable Server Side Includes"), self)
         self.ssiCheckBox.setToolTip(
             self.tr("Select to enable support for Server Side Includes")
         )
-        self.__layout.addWidget(self.ssiCheckBox)
+        self.ssiCheckBox.setSizePolicy(sizePolicy)
+        self.__footerLayout.addWidget(self.ssiCheckBox, 1, 0)
+        self.__htmlButton = QPushButton(self.tr("Copy HTML"), self)
+        self.__htmlButton.setToolTip(
+            self.tr("Press to copy the HTML text of the preview to the clipboard")
+        )
+        self.__htmlButton.setEnabled(False)
+        self.__footerLayout.addWidget(self.__htmlButton, 1, 1)
+        self.__layout.addLayout(self.__footerLayout)
 
         self.jsCheckBox.clicked[bool].connect(self.on_jsCheckBox_clicked)
         self.ssiCheckBox.clicked[bool].connect(self.on_ssiCheckBox_clicked)
         self.previewView.titleChanged.connect(self.on_previewView_titleChanged)
+        self.__htmlButton.clicked.connect(self.on_htmlButton_clicked)
 
         self.jsCheckBox.setChecked(Preferences.getUI("ShowFilePreviewJS"))
         self.ssiCheckBox.setChecked(Preferences.getUI("ShowFilePreviewSSI"))
@@ -112,6 +128,7 @@
 
         self.__previewedPath = None
         self.__previewedEditor = None
+        self.__previewedHtml = ""
 
     def shutdown(self):
         """
@@ -248,6 +265,8 @@
             if rootPath
             else QUrl.fromLocalFile(filePath)
         )
+        self.__previewedHtml = html
+        self.__htmlButton.setEnabled(bool(html))
         self.previewView.setHtml(html, baseUrl=baseUrl)
         if self.__previewedEditor:
             self.__previewedEditor.setFocus()
@@ -325,6 +344,14 @@
         loop.exec()
         return resultDict["res"]
 
+    @pyqtSlot()
+    def on_htmlButton_clicked(self):
+        """
+        Private slot to copy the HTML contents to the clipboard.
+        """
+        if self.__previewedHtml:
+            QGuiApplication.clipboard().setText(self.__previewedHtml)
+
 
 class PreviewProcessingThread(QThread):
     """

eric ide

mercurial