Rework UnexpectedErrorPopup to be more practical

- Instead of opening a popup for every single error that occurs,
  combine them into an unique one

- Increase the maximum width, make those tracebacks readable
This commit is contained in:
miruka 2021-04-14 15:15:51 -04:00
parent 2aebab5919
commit 49f97d614e
3 changed files with 61 additions and 18 deletions

View File

@ -9,11 +9,12 @@ import "../Base/Buttons"
import "../PythonBridge" as PythonBridge import "../PythonBridge" as PythonBridge
HColumnPopup { HColumnPopup {
id: popup id: root
property string errorType property var errors: [] // [{type, message, traceback}]
property string message: ""
property string traceback: ""
contentWidthLimit: Math.min(window.width / 1.5, 864 * theme.uiScale)
page.footer: AutoDirectionLayout { page.footer: AutoDirectionLayout {
PositiveButton { PositiveButton {
@ -28,17 +29,37 @@ HColumnPopup {
CancelButton { CancelButton {
text: qsTr("Ignore") text: qsTr("Ignore")
onClicked: popup.close() onClicked: root.close()
} }
} }
onErrorsChanged: if (errors.length) open()
onOpened: reportButton.forceActiveFocus() onOpened: reportButton.forceActiveFocus()
onClosed: {
errors = []
errorsChanged()
}
Behavior on implicitHeight { HNumberAnimation {} }
SummaryLabel { SummaryLabel {
text: qsTr("Unexpected error occured: %1").arg( readonly property string types: {
utils.htmlColorize(errorType, theme.colors.accentText), const colored = []
) const color = theme.colors.accentText
for (const error of root.errors) {
const coloredType = utils.htmlColorize(error.type, color)
if (! colored.includes(coloredType)) colored.push(coloredType)
}
return colored.join(", ")
}
textFormat: Text.StyledText textFormat: Text.StyledText
text:
root.errors.length > 1 ?
qsTr("Unexpected errors occured: %1").arg(types) :
qsTr("Unexpected error occured: %1").arg(types)
} }
HScrollView { HScrollView {
@ -48,20 +69,37 @@ HColumnPopup {
Layout.fillHeight: true Layout.fillHeight: true
HTextArea { HTextArea {
text: [message, traceback].join("\n\n") || qsTr("No info available") id: detailsArea
readOnly: true readOnly: true
font.family: theme.fontFamily.mono font.family: theme.fontFamily.mono
focusItemOnTab: hideCheckBox focusItemOnTab: hideCheckBox
text: {
const parts = []
for (const error of root.errors) {
parts.push(error.type + ": " + (error.message || "..."))
parts.push(error.traceback || qsTr("Traceback missing"))
parts.push("─".repeat(30))
}
return parts.slice(0, -1).join("\n\n") // Leave out last
}
} }
} }
HCheckBox { HCheckBox {
id: hideCheckBox id: hideCheckBox
text: qsTr("Hide this type of error until restart") text:
onCheckedChanged: root.errors.length > 1 ?
checked ? qsTr("Hide these types of error until restart") :
PythonBridge.Globals.hideErrorTypes.add(errorType) : qsTr("Hide this type of error until restart")
PythonBridge.Globals.hideErrorTypes.delete(errorType)
onCheckedChanged: {
for (const error of errors)
checked ?
PythonBridge.Globals.hideErrorTypes.add(error.type) :
PythonBridge.Globals.hideErrorTypes.delete(error.type)
}
Layout.fillWidth: true Layout.fillWidth: true
} }

View File

@ -60,9 +60,8 @@ Python {
return return
} }
window.makePopup( const popup = window.mainUI.unexpectedErrorPopup
"Popups/UnexpectedErrorPopup.qml", popup.errors.unshift({type, message, traceback})
{ errorType: type, message, traceback }, popup.errorsChanged()
)
} }
} }

View File

@ -9,6 +9,7 @@ import QtGraphicalEffects 1.12
import "." import "."
import "Base" import "Base"
import "MainPane" import "MainPane"
import "Popups"
Item { Item {
id: mainUI id: mainUI
@ -38,6 +39,7 @@ Item {
readonly property alias debugConsole: debugConsole readonly property alias debugConsole: debugConsole
readonly property alias mainPane: mainPane readonly property alias mainPane: mainPane
readonly property alias pageLoader: pageLoader readonly property alias pageLoader: pageLoader
readonly property alias unexpectedErrorPopup: unexpectedErrorPopup
readonly property alias fontMetrics: fontMetrics readonly property alias fontMetrics: fontMetrics
readonly property alias idleManager: idleManager readonly property alias idleManager: idleManager
@ -177,4 +179,8 @@ Item {
GlobalTapHandlers { pageLoader: parent } GlobalTapHandlers { pageLoader: parent }
} }
UnexpectedErrorPopup {
id: unexpectedErrorPopup
}
} }