@@ -48,6 +48,7 @@ namespace
48
48
TextAttachmentsPreviewWidget::TextAttachmentsPreviewWidget (QWidget* parent)
49
49
: QWidget(parent)
50
50
, m_ui(new Ui::TextAttachmentsPreviewWidget())
51
+ , m_userManuallySelectedType(false )
51
52
{
52
53
m_ui->setupUi (this );
53
54
@@ -63,6 +64,8 @@ void TextAttachmentsPreviewWidget::openAttachment(attachments::Attachment attach
63
64
}
64
65
65
66
m_attachment = std::move (attachments);
67
+ // Reset manual selection flag when opening a new attachment
68
+ m_userManuallySelectedType = false ;
66
69
67
70
updateUi ();
68
71
}
@@ -88,10 +91,13 @@ void TextAttachmentsPreviewWidget::initTypeCombobox()
88
91
filterProxyMode->sort (0 , Qt::SortOrder::DescendingOrder);
89
92
m_ui->typeComboBox ->setModel (filterProxyMode);
90
93
91
- connect (m_ui->typeComboBox ,
92
- QOverload<int >::of (&QComboBox::currentIndexChanged),
93
- this ,
94
- &TextAttachmentsPreviewWidget::onTypeChanged);
94
+ connect (m_ui->typeComboBox , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [this ](int index) {
95
+ m_userManuallySelectedType = true ;
96
+ onTypeChanged (index);
97
+ });
98
+
99
+ // Configure text browser to open external links
100
+ m_ui->previewTextBrowser ->setOpenExternalLinks (true );
95
101
96
102
m_ui->typeComboBox ->setCurrentIndex (m_ui->typeComboBox ->findData (PlainText));
97
103
@@ -100,11 +106,17 @@ void TextAttachmentsPreviewWidget::initTypeCombobox()
100
106
101
107
void TextAttachmentsPreviewWidget::updateUi ()
102
108
{
103
- if (!m_attachment.name .isEmpty ()) {
109
+ // Only auto-select format based on file extension if user hasn't manually chosen one
110
+ if (!m_userManuallySelectedType && !m_attachment.name .isEmpty ()) {
104
111
const auto mimeType = Tools::getMimeType (QFileInfo (m_attachment.name ));
105
112
106
113
auto index = m_ui->typeComboBox ->findData (ConvertToPreviewTextType (mimeType));
107
- m_ui->typeComboBox ->setCurrentIndex (index);
114
+ if (index >= 0 ) {
115
+ // Temporarily block signals to avoid triggering manual selection flag
116
+ m_ui->typeComboBox ->blockSignals (true );
117
+ m_ui->typeComboBox ->setCurrentIndex (index);
118
+ m_ui->typeComboBox ->blockSignals (false );
119
+ }
108
120
}
109
121
110
122
onTypeChanged (m_ui->typeComboBox ->currentIndex ());
0 commit comments