Warning, file /sdk/kompare/src/dialogpages/diffpage.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2001-2004 Otto Bruggeman <otto.bruggeman@home.nl> 0003 SPDX-FileCopyrightText: 2007-2011 Kevin Kofler <kevin.kofler@chello.at> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "diffpage.h" 0009 0010 #include <QCheckBox> 0011 #include <QGroupBox> 0012 #include <QLabel> 0013 #include <QLayout> 0014 #include <QRadioButton> 0015 #include <QSpinBox> 0016 #include <QVBoxLayout> 0017 #include <QHBoxLayout> 0018 #include <QFormLayout> 0019 #include <QTabWidget> 0020 #include <QToolTip> 0021 #include <QButtonGroup> 0022 0023 #include <KComboBox> 0024 #include <KEditListWidget> 0025 #include <KLineEdit> 0026 #include <KLocalizedString> 0027 #include <KSharedConfig> 0028 #include <KUrlComboBox> 0029 #include <KUrlRequester> 0030 0031 #include <KompareDiff2/DiffSettings> 0032 0033 DiffPage::DiffPage() : QFrame(), m_ignoreRegExpDialog(nullptr) 0034 { 0035 QVBoxLayout* layout = new QVBoxLayout(this); 0036 m_tabWidget = new QTabWidget(this); 0037 0038 addDiffTab(); 0039 0040 addFormatTab(); 0041 0042 addOptionsTab(); 0043 0044 addExcludeTab(); 0045 layout->addWidget(m_tabWidget); 0046 } 0047 0048 DiffPage::~DiffPage() 0049 { 0050 m_settings = nullptr; 0051 } 0052 0053 void DiffPage::setSettings(KompareDiff2::DiffSettings* setts) 0054 { 0055 m_settings = setts; 0056 0057 m_diffURLRequester->setText(m_settings->m_diffProgram); 0058 0059 m_newFilesCheckBox->setChecked(m_settings->m_newFiles); 0060 m_smallerCheckBox->setChecked(m_settings->m_createSmallerDiff); 0061 m_largerCheckBox->setChecked(m_settings->m_largeFiles); 0062 m_tabsCheckBox->setChecked(m_settings->m_convertTabsToSpaces); 0063 m_caseCheckBox->setChecked(m_settings->m_ignoreChangesInCase); 0064 m_linesCheckBox->setChecked(m_settings->m_ignoreEmptyLines); 0065 m_whitespaceCheckBox->setChecked(m_settings->m_ignoreWhiteSpace); 0066 m_allWhitespaceCheckBox->setChecked(m_settings->m_ignoreAllWhiteSpace); 0067 m_ignoreTabExpansionCheckBox->setChecked(m_settings->m_ignoreChangesDueToTabExpansion); 0068 0069 m_ignoreRegExpCheckBox->setChecked(m_settings->m_ignoreRegExp); 0070 m_ignoreRegExpEdit->setCompletedItems(m_settings->m_ignoreRegExpTextHistory); 0071 m_ignoreRegExpEdit->setText(m_settings->m_ignoreRegExpText); 0072 0073 m_locSpinBox->setValue(m_settings->m_linesOfContext); 0074 0075 m_modeButtonGroup->button(m_settings->m_format)->setChecked(true); 0076 0077 m_excludeFilePatternGroupBox->setChecked(m_settings->m_excludeFilePattern); 0078 slotExcludeFilePatternToggled(m_settings->m_excludeFilePattern); 0079 m_excludeFilePatternEditListBox->insertStringList(m_settings->m_excludeFilePatternList); 0080 0081 m_excludeFileNameGroupBox->setChecked(m_settings->m_excludeFilesFile); 0082 slotExcludeFileToggled(m_settings->m_excludeFilesFile); 0083 m_excludeFileURLComboBox->setUrls(m_settings->m_excludeFilesFileHistoryList); 0084 m_excludeFileURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_excludeFilesFileURL, QDir::currentPath(), QUrl::AssumeLocalFile)); 0085 } 0086 0087 KompareDiff2::DiffSettings* DiffPage::settings() 0088 { 0089 return m_settings; 0090 } 0091 0092 void DiffPage::restore() 0093 { 0094 // this shouldn't do a thing... 0095 } 0096 0097 void DiffPage::apply() 0098 { 0099 m_settings->m_diffProgram = m_diffURLRequester->text(); 0100 0101 m_settings->m_newFiles = m_newFilesCheckBox->isChecked(); 0102 m_settings->m_largeFiles = m_largerCheckBox->isChecked(); 0103 m_settings->m_createSmallerDiff = m_smallerCheckBox->isChecked(); 0104 m_settings->m_convertTabsToSpaces = m_tabsCheckBox->isChecked(); 0105 m_settings->m_ignoreChangesInCase = m_caseCheckBox->isChecked(); 0106 m_settings->m_ignoreEmptyLines = m_linesCheckBox->isChecked(); 0107 m_settings->m_ignoreWhiteSpace = m_whitespaceCheckBox->isChecked(); 0108 m_settings->m_ignoreAllWhiteSpace = m_allWhitespaceCheckBox->isChecked(); 0109 m_settings->m_ignoreChangesDueToTabExpansion = m_ignoreTabExpansionCheckBox->isChecked(); 0110 0111 m_settings->m_ignoreRegExp = m_ignoreRegExpCheckBox->isChecked(); 0112 m_settings->m_ignoreRegExpText = m_ignoreRegExpEdit->text(); 0113 m_settings->m_ignoreRegExpTextHistory = m_ignoreRegExpEdit->completionObject()->items(); 0114 0115 m_settings->m_linesOfContext = m_locSpinBox->value(); 0116 0117 m_settings->m_format = static_cast<KompareDiff2::Format>(m_modeButtonGroup->checkedId()); 0118 0119 m_settings->m_excludeFilePattern = m_excludeFilePatternGroupBox->isChecked(); 0120 m_settings->m_excludeFilePatternList = m_excludeFilePatternEditListBox->items(); 0121 0122 m_settings->m_excludeFilesFile = m_excludeFileNameGroupBox->isChecked(); 0123 m_settings->m_excludeFilesFileURL = m_excludeFileURLComboBox->currentText(); 0124 m_settings->m_excludeFilesFileHistoryList = m_excludeFileURLComboBox->urls(); 0125 0126 m_settings->saveSettings(KSharedConfig::openConfig().data()); 0127 } 0128 0129 void DiffPage::setDefaults() 0130 { 0131 m_diffURLRequester->setText(QString()); 0132 m_newFilesCheckBox->setChecked(true); 0133 m_smallerCheckBox->setChecked(true); 0134 m_largerCheckBox->setChecked(true); 0135 m_tabsCheckBox->setChecked(false); 0136 m_caseCheckBox->setChecked(false); 0137 m_linesCheckBox->setChecked(false); 0138 m_whitespaceCheckBox->setChecked(false); 0139 m_allWhitespaceCheckBox->setChecked(false); 0140 m_ignoreTabExpansionCheckBox->setChecked(false); 0141 m_ignoreRegExpCheckBox->setChecked(false); 0142 0143 m_ignoreRegExpEdit->setText(QString()); 0144 0145 m_locSpinBox->setValue(3); 0146 0147 m_modeButtonGroup->button(KompareDiff2::Unified)->setChecked(true); 0148 0149 m_excludeFilePatternGroupBox->setChecked(false); 0150 0151 m_excludeFileNameGroupBox->setChecked(false); 0152 } 0153 0154 void DiffPage::slotExcludeFilePatternToggled(bool on) 0155 { 0156 m_excludeFilePatternEditListBox->setEnabled(on); 0157 } 0158 0159 void DiffPage::slotExcludeFileToggled(bool on) 0160 { 0161 m_excludeFileURLComboBox->setEnabled(on); 0162 m_excludeFileURLRequester->setEnabled(on); 0163 } 0164 0165 void DiffPage::addDiffTab() 0166 { 0167 QWidget* page = new QWidget(this); 0168 QVBoxLayout* layout = new QVBoxLayout(page); 0169 0170 // add diff program selector 0171 m_diffProgramGroup = new QGroupBox(page); 0172 layout->addWidget(m_diffProgramGroup); 0173 QVBoxLayout* bgLayout = new QVBoxLayout(m_diffProgramGroup); 0174 m_diffProgramGroup->setTitle(i18nc("@title:group", "Diff Program")); 0175 0176 // using the "text" property over the "url" property, to also allow plain executable names instead of full path 0177 m_diffURLRequester = new KUrlRequester(m_diffProgramGroup); 0178 m_diffURLRequester->setObjectName(QStringLiteral("diffURLRequester")); 0179 m_diffURLRequester->setWhatsThis(i18n("You can select a different diff program here. On Solaris the standard diff program does not support all the options that the GNU version does. This way you can select that version.")); 0180 m_diffURLRequester->setPlaceholderText(QStringLiteral("diff")); 0181 bgLayout->addWidget(m_diffURLRequester); 0182 0183 layout->addStretch(1); 0184 0185 m_tabWidget->addTab(page, i18nc("@title:tab", "Diff")); 0186 } 0187 0188 void DiffPage::addFormatTab() 0189 { 0190 QWidget* page = new QWidget(this); 0191 QVBoxLayout* layout = new QVBoxLayout(page); 0192 0193 // add diff modes 0194 m_modeButtonGroup = new QButtonGroup(page); 0195 QGroupBox* box = new QGroupBox(page); 0196 box->setWhatsThis(i18nc("@info:whatsthis", "Select the format of the output generated by diff. Unified is the one that is used most frequently because it is very readable. The KDE developers like this format the best so use it for sending patches.")); 0197 layout->addWidget(box); 0198 QVBoxLayout* bgLayout = new QVBoxLayout(box); 0199 box->setTitle(i18nc("@title:group", "Output Format")); 0200 0201 QRadioButton* radioButton = new QRadioButton(i18nc("@option:radio format type", "Context"), box); 0202 m_modeButtonGroup->addButton(radioButton, KompareDiff2::Context); 0203 bgLayout->addWidget(radioButton); 0204 radioButton = new QRadioButton(i18nc("@option:radio format type", "Normal"), box); 0205 m_modeButtonGroup->addButton(radioButton, KompareDiff2::Normal); 0206 bgLayout->addWidget(radioButton); 0207 radioButton = new QRadioButton(i18nc("@option:radio format type", "Unified"), box); 0208 m_modeButtonGroup->addButton(radioButton, KompareDiff2::Unified); 0209 bgLayout->addWidget(radioButton); 0210 0211 // #lines of context (loc) 0212 QGroupBox* groupBox = new QGroupBox(page); 0213 layout->addWidget(groupBox); 0214 QFormLayout* groupLayout = new QFormLayout(groupBox); 0215 groupBox->setTitle(i18nc("@title:group", "Lines of Context")); 0216 groupBox->setWhatsThis(i18nc("@info:whatsthis", "The number of context lines is normally 2 or 3. This makes the diff readable and applicable in most cases. More than 3 lines will only bloat the diff unnecessarily.")); 0217 0218 m_locSpinBox = new QSpinBox(groupBox); 0219 m_locSpinBox->setRange(0, 100); 0220 groupLayout->addRow(i18nc("@label:spinbox" ,"Number of context lines:"), m_locSpinBox); 0221 m_locSpinBox->setWhatsThis(i18nc("@info:whatsthis", "The number of context lines is normally 2 or 3. This makes the diff readable and applicable in most cases. More than 3 lines will only bloat the diff unnecessarily.")); 0222 0223 layout->addStretch(1); 0224 0225 m_tabWidget->addTab(page, i18nc("@title:tab", "Format")); 0226 } 0227 0228 void DiffPage::addOptionsTab() 0229 { 0230 QWidget* page = new QWidget(this); 0231 QVBoxLayout* layout = new QVBoxLayout(page); 0232 0233 // add diff options 0234 QGroupBox* optionButtonGroup = new QGroupBox(page); 0235 layout->addWidget(optionButtonGroup); 0236 QVBoxLayout* bgLayout = new QVBoxLayout(optionButtonGroup); 0237 optionButtonGroup->setTitle(i18nc("@title:group", "General")); 0238 0239 m_newFilesCheckBox = new QCheckBox(i18nc("@option:check", "&Treat new files as empty"), optionButtonGroup); 0240 m_newFilesCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -N diff option.")); 0241 m_newFilesCheckBox->setWhatsThis(i18nc("@info:whatsthis", "With this option enabled diff will treat a file that only exists in one of the directories as empty in the other directory. This means that the file is compared with an empty file and because of this will appear as one big insertion or deletion.")); 0242 bgLayout->addWidget(m_newFilesCheckBox); 0243 0244 m_smallerCheckBox = new QCheckBox(i18nc("@option:check", "&Look for smaller changes"), optionButtonGroup); 0245 m_smallerCheckBox->setToolTip(i18nc("@info:tooltip", "This corresponds to the -d diff option.")); 0246 m_smallerCheckBox->setWhatsThis(i18nc("@info:whatsthis", "With this option enabled diff will try a little harder (at the cost of more memory) to find fewer changes.")); 0247 bgLayout->addWidget(m_smallerCheckBox); 0248 m_largerCheckBox = new QCheckBox(i18nc("@option:check", "O&ptimize for large files"), optionButtonGroup); 0249 m_largerCheckBox->setToolTip(i18nc("@info:tooltip", "This corresponds to the -H diff option.")); 0250 m_largerCheckBox->setWhatsThis(i18nc("@info:whatsthis", "This option lets diff makes better diffs when using large files. The definition of large is nowhere to be found though.")); 0251 bgLayout->addWidget(m_largerCheckBox); 0252 m_caseCheckBox = new QCheckBox(i18nc("@option:check", "&Ignore changes in case"), optionButtonGroup); 0253 m_caseCheckBox->setToolTip(i18nc("@info:tooltip", "This corresponds to the -i diff option.")); 0254 m_caseCheckBox->setWhatsThis(i18nc("@info:whatsthis", "With this option to ignore changes in case enabled, diff will not indicate a difference when something in one file is changed into SoMEthing in the other file.")); 0255 bgLayout->addWidget(m_caseCheckBox); 0256 0257 QHBoxLayout* groupLayout = new QHBoxLayout(); 0258 layout->addLayout(groupLayout); 0259 groupLayout->setObjectName(QStringLiteral("regexp_horizontal_layout")); 0260 groupLayout->setSpacing(-1); 0261 0262 m_ignoreRegExpCheckBox = new QCheckBox(i18nc("@option:check", "Ignore regexp:"), page); 0263 m_ignoreRegExpCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -I diff option.")); 0264 m_ignoreRegExpCheckBox->setWhatsThis(i18nc("@info:whatsthis", "When this checkbox is enabled, an option to diff is given that will make diff ignore lines that match the regular expression.")); 0265 groupLayout->addWidget(m_ignoreRegExpCheckBox); 0266 m_ignoreRegExpEdit = new KLineEdit(page); 0267 m_ignoreRegExpEdit->setObjectName(QStringLiteral("regexplineedit")); 0268 m_ignoreRegExpEdit->setToolTip(i18nc("@info:tooltip", "Add the regular expression here that you want to use\nto ignore lines that match it.")); 0269 groupLayout->addWidget(m_ignoreRegExpEdit); 0270 0271 QGroupBox* moreOptionButtonGroup = new QGroupBox(page); 0272 layout->addWidget(moreOptionButtonGroup); 0273 bgLayout = new QVBoxLayout(moreOptionButtonGroup); 0274 moreOptionButtonGroup->setTitle(i18nc("@title:group", "Whitespace")); 0275 0276 m_tabsCheckBox = new QCheckBox(i18nc("@option:check", "E&xpand tabs to spaces in output"), moreOptionButtonGroup); 0277 m_tabsCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -t diff option.")); 0278 m_tabsCheckBox->setWhatsThis(i18nc("@info:whatsthis", "This option does not always produce the right result. Due to this expansion Kompare may have problems applying the change to the destination file.")); 0279 bgLayout->addWidget(m_tabsCheckBox); 0280 m_linesCheckBox = new QCheckBox(i18nc("@option:check", "I&gnore added or removed empty lines"), moreOptionButtonGroup); 0281 m_linesCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -B diff option.")); 0282 m_linesCheckBox->setWhatsThis(i18nc("@info:whatsthis", "This can be very useful in situations where code has been reorganized and empty lines have been added or removed to improve legibility.")); 0283 bgLayout->addWidget(m_linesCheckBox); 0284 m_whitespaceCheckBox = new QCheckBox(i18nc("@option:check", "Ig&nore changes in the amount of whitespace"), moreOptionButtonGroup); 0285 m_whitespaceCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -b diff option.")); 0286 m_whitespaceCheckBox->setWhatsThis(i18nc("@info:whatsthis", "If you are uninterested in differences arising due to, for example, changes in indentation, then use this option.")); 0287 bgLayout->addWidget(m_whitespaceCheckBox); 0288 m_allWhitespaceCheckBox = new QCheckBox(i18nc("@option:check", "Ign&ore all whitespace"), moreOptionButtonGroup); 0289 m_allWhitespaceCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -w diff option.")); 0290 m_allWhitespaceCheckBox->setWhatsThis(i18nc("@info:whatsthis", "This is useful for seeing the significant changes without being overwhelmed by all the white space changes.")); 0291 bgLayout->addWidget(m_allWhitespaceCheckBox); 0292 m_ignoreTabExpansionCheckBox = new QCheckBox(i18nc("@option:check", "Igno&re changes due to tab expansion"), moreOptionButtonGroup); 0293 m_ignoreTabExpansionCheckBox->setToolTip(i18nc("@info:tooltip", "This option corresponds to the -E diff option.")); 0294 m_ignoreTabExpansionCheckBox->setWhatsThis(i18nc("@info:whatsthis", "If there is a change because tabs have been expanded into spaces in the other file, then this option will make sure that these do not show up. Kompare currently has some problems applying such changes so be careful when you use this option.")); 0295 bgLayout->addWidget(m_ignoreTabExpansionCheckBox); 0296 0297 layout->addStretch(1); 0298 0299 m_tabWidget->addTab(page, i18nc("@title:tab", "Options")); 0300 } 0301 0302 void DiffPage::addExcludeTab() 0303 { 0304 QWidget* page = new QWidget(this); 0305 QVBoxLayout* layout = new QVBoxLayout(page); 0306 0307 m_excludeFilePatternGroupBox = new QGroupBox(page); 0308 m_excludeFilePatternGroupBox->setCheckable(true); 0309 QHBoxLayout* excludeFileLayout = new QHBoxLayout; 0310 m_excludeFilePatternGroupBox->setLayout(excludeFileLayout); 0311 m_excludeFilePatternGroupBox->setTitle(i18nc("@title:group", "File Pattern to Exclude")); 0312 m_excludeFilePatternGroupBox->setToolTip(i18nc("@info:tooltip", "If this is checked you can enter a shell pattern in the text box on the right or select entries from the list.")); 0313 m_excludeFilePatternEditListBox = new KEditListWidget; 0314 excludeFileLayout->addWidget(m_excludeFilePatternEditListBox); 0315 m_excludeFilePatternEditListBox->setObjectName(QStringLiteral("exclude_file_pattern_editlistbox")); 0316 m_excludeFilePatternEditListBox->setButtons(KEditListWidget::Add | KEditListWidget::Remove); 0317 m_excludeFilePatternEditListBox->setCheckAtEntering(false); 0318 m_excludeFilePatternEditListBox->setToolTip(i18nc("@info:tooltip", "Here you can enter or remove a shell pattern or select one or more entries from the list.")); 0319 layout->addWidget(m_excludeFilePatternGroupBox); 0320 0321 0322 connect(m_excludeFilePatternGroupBox, &QGroupBox::toggled, this, &DiffPage::slotExcludeFilePatternToggled); 0323 0324 m_excludeFileNameGroupBox = new QGroupBox(page); 0325 m_excludeFileNameGroupBox->setCheckable(true); 0326 excludeFileLayout = new QHBoxLayout; 0327 m_excludeFileNameGroupBox->setLayout(excludeFileLayout); 0328 m_excludeFileNameGroupBox->setTitle(i18nc("@title:group", "File with Filenames to Exclude")); 0329 m_excludeFileNameGroupBox->setToolTip(i18nc("@info:tooltip", "If this is checked you can enter a filename in the combo box below.")); 0330 m_excludeFileURLComboBox = new KUrlComboBox(KUrlComboBox::Files, true); 0331 excludeFileLayout->addWidget(m_excludeFileURLComboBox); 0332 m_excludeFileURLComboBox->setObjectName(QStringLiteral("exclude_file_urlcombo")); 0333 m_excludeFileURLComboBox->setToolTip(i18nc("@info:tooltip", "Here you can enter the URL of a file with shell patterns to ignore during the comparison of the folders.")); 0334 m_excludeFileURLRequester = new KUrlRequester(m_excludeFileURLComboBox, m_excludeFileNameGroupBox); 0335 excludeFileLayout->addWidget(m_excludeFileURLRequester); 0336 m_excludeFileURLRequester->setObjectName(QStringLiteral("exclude_file_name_urlrequester")); 0337 m_excludeFileURLRequester->setToolTip(i18nc("@info:tooltip", "Any file you select in the dialog that pops up when you click it will be put in the dialog to the left of this button.")); 0338 layout->addWidget(m_excludeFileNameGroupBox); 0339 0340 connect(m_excludeFileNameGroupBox, &QGroupBox::toggled, this, &DiffPage::slotExcludeFileToggled); 0341 0342 layout->addStretch(1); 0343 0344 m_tabWidget->addTab(page, i18nc("@title:tab", "Exclude")); 0345 } 0346 0347 #include "moc_diffpage.cpp" 0348 0349 //kate: replace-tabs 0; indent-width 4; tab-width 4;