File indexing completed on 2024-04-28 15:51:42
0001 /* 0002 SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dlgeditor.h" 0008 0009 #include "core/texteditors_p.h" 0010 0011 #include <KLocalizedString> 0012 0013 #include <QComboBox> 0014 #include <QFormLayout> 0015 #include <QLabel> 0016 #include <QLineEdit> 0017 #include <QStackedWidget> 0018 0019 DlgEditor::DlgEditor(QWidget *parent) 0020 : QWidget(parent) 0021 { 0022 // Set up the user interface 0023 m_layout = new QFormLayout(this); 0024 0025 // BEGIN "Editor" row: Combo box with a list of preset editors 0026 m_editorChooser = new QComboBox(this); 0027 m_editorChooser->setObjectName(QStringLiteral("kcfg_ExternalEditor")); 0028 m_editorChooser->setWhatsThis(i18nc("@info:whatsthis Config dialog, editor page", "Choose the editor you want to launch when Okular wants to open a source file.")); 0029 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "Custom Text Editor"), 0); 0030 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "Kate"), 1); 0031 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "Kile"), 2); 0032 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "SciTE"), 3); 0033 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "Emacs client"), 4); 0034 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "Lyx client"), 5); 0035 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "TeXstudio"), 6); 0036 m_editorChooser->addItem(i18nc("@item:inlistbox Config dialog, editor page", "TeXiFy IDEA"), 7); 0037 m_layout->addRow(i18nc("@label:listbox Config dialog, editor page", "Editor:"), m_editorChooser); 0038 // END "Editor" row 0039 0040 // BEGIN "Command" row: two line edits, one to display preset commands, one to enter custom command. 0041 m_editorCommandStack = new QStackedWidget(this); 0042 0043 m_editorCommandDisplay = new QLineEdit(this); 0044 m_editorCommandDisplay->setReadOnly(true); 0045 m_editorCommandStack->addWidget(m_editorCommandDisplay); 0046 // Let stack widget be layouted like a line edit: 0047 m_editorCommandStack->setSizePolicy(m_editorCommandDisplay->sizePolicy()); 0048 0049 m_editorCommandEditor = new QLineEdit(this); 0050 m_editorCommandEditor->setObjectName(QStringLiteral("kcfg_ExternalEditorCommand")); 0051 m_editorCommandEditor->setWhatsThis(i18nc("@info:whatsthis", 0052 "<qt>Set the command of a custom text editor to be launched.<br />\n" 0053 "You can also put few placeholders:\n" 0054 "<ul>\n" 0055 " <li>%f - the file name</li>\n" 0056 " <li>%l - the line of the file to be reached</li>\n" 0057 " <li>%c - the column of the file to be reached</li>\n" 0058 "</ul>\n" 0059 "If %f is not specified, then the file name is appended to the specified " 0060 "command.")); 0061 m_editorCommandStack->addWidget(m_editorCommandEditor); 0062 0063 m_layout->addRow(i18nc("@label:textbox Config dialog, editor page", "Command:"), m_editorCommandStack); 0064 0065 // Initialize 0066 editorChanged(0); 0067 // END "Command" row 0068 0069 setLayout(m_layout); 0070 0071 // Set up the logic 0072 m_editors = Okular::buildEditorsMap(); 0073 0074 connect(m_editorChooser, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DlgEditor::editorChanged); 0075 } 0076 0077 DlgEditor::~DlgEditor() 0078 { 0079 } 0080 0081 void DlgEditor::editorChanged(int which) 0082 { 0083 // map combobox index to editor index. Custom editor has index 0, and is not present in m_editors. 0084 const int whichEditor = m_editorChooser->itemData(which).toInt(); 0085 const QHash<int, QString>::const_iterator it = m_editors.constFind(whichEditor); 0086 if (it != m_editors.constEnd()) { 0087 // Show editor command display and manually connect buddy 0088 m_editorCommandDisplay->setText(it.value()); 0089 m_editorCommandStack->setCurrentIndex(0); 0090 if (QLabel *l = qobject_cast<QLabel *>(m_layout->labelForField(m_editorCommandStack))) { 0091 l->setBuddy(m_editorCommandDisplay); 0092 } 0093 } else { 0094 // Show editor command editor and manually connect buddy 0095 m_editorCommandStack->setCurrentIndex(1); 0096 if (QLabel *l = qobject_cast<QLabel *>(m_layout->labelForField(m_editorCommandStack))) { 0097 l->setBuddy(m_editorCommandEditor); 0098 } 0099 } 0100 }