Code Blocks are now their own QDialog to try and reduce risk of getting trapped in / bleeding in/out of text in code blocks.
This commit is contained in:
parent
7a207df0f3
commit
57f11abb99
7 changed files with 429 additions and 203 deletions
58
bouquin/code_block_editor_dialog.py
Normal file
58
bouquin/code_block_editor_dialog.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtWidgets import (
|
||||
QDialog,
|
||||
QVBoxLayout,
|
||||
QPlainTextEdit,
|
||||
QDialogButtonBox,
|
||||
QComboBox,
|
||||
QLabel,
|
||||
)
|
||||
|
||||
from . import strings
|
||||
|
||||
|
||||
class CodeBlockEditorDialog(QDialog):
|
||||
def __init__(self, code: str, language: str | None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle(strings._("edit_code_block"))
|
||||
|
||||
self.setMinimumSize(650, 650)
|
||||
self._code_edit = QPlainTextEdit(self)
|
||||
self._code_edit.setPlainText(code)
|
||||
|
||||
# Language selector (optional)
|
||||
self._lang_combo = QComboBox(self)
|
||||
languages = [
|
||||
"",
|
||||
"bash",
|
||||
"css",
|
||||
"html",
|
||||
"javascript",
|
||||
"php",
|
||||
"python",
|
||||
]
|
||||
self._lang_combo.addItems(languages)
|
||||
if language and language in languages:
|
||||
self._lang_combo.setCurrentText(language)
|
||||
|
||||
# Buttons
|
||||
buttons = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel,
|
||||
parent=self,
|
||||
)
|
||||
buttons.accepted.connect(self.accept)
|
||||
buttons.rejected.connect(self.reject)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(QLabel(strings._("locale") + ":", self))
|
||||
layout.addWidget(self._lang_combo)
|
||||
layout.addWidget(self._code_edit)
|
||||
layout.addWidget(buttons)
|
||||
|
||||
def code(self) -> str:
|
||||
return self._code_edit.toPlainText()
|
||||
|
||||
def language(self) -> str | None:
|
||||
text = self._lang_combo.currentText().strip()
|
||||
return text or None
|
||||
Loading…
Add table
Add a link
Reference in a new issue