File indexing completed on 2024-04-14 05:35:45

0001 // clang-format off
0002 /*
0003  * KDiff3 - Text Diff And Merge Tool
0004  *
0005  * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de
0006  * SPDX-FileCopyrightText: 2018-2020 Michael Reeves reeves.87@gmail.com
0007  * SPDX-License-Identifier: GPL-2.0-or-later
0008  */
0009 // clang-format on
0010 
0011 #include "kdiff3_shell.h"
0012 #include "compat.h"
0013 #include "kdiff3.h"
0014 
0015 #include <QApplication>
0016 #include <QCloseEvent>
0017 #include <QStatusBar>
0018 
0019 #include <KConfig>
0020 #include <KEditToolBar>
0021 #include <KLocalizedString>
0022 #include <KMessageBox>
0023 #include <KShortcutsDialog>
0024 #include <KStandardAction>
0025 #include <KToolBar>
0026 
0027 KDiff3Shell::KDiff3Shell(const QString& fn1, const QString& fn2, const QString& fn3)
0028 {
0029     m_widget = new KDiff3App(this, u8"KDiff3Part", this);
0030     assert(m_widget);
0031     setStandardToolBarMenuEnabled(true);
0032 
0033     setupGUI(Default, "kdiff3_shell.rc");
0034     // and a status bar
0035     statusBar()->show();
0036 
0037     setCentralWidget(m_widget);
0038 
0039     m_widget->completeInit(fn1, fn2, fn3);
0040     chk_connect_a(m_widget, &KDiff3App::createNewInstance, this, &KDiff3Shell::slotNewInstance);
0041 
0042     // apply the saved mainwindow settings, if any, and ask the mainwindow
0043     // to automatically save settings if changed: window size, toolbar
0044     // position, icon size, etc.
0045     setAutoSaveSettings();
0046 }
0047 
0048 KDiff3Shell::~KDiff3Shell() = default;
0049 
0050 bool KDiff3Shell::queryClose()
0051 {
0052     if(m_widget)
0053         return m_widget->queryClose();
0054     else
0055         return true;
0056 }
0057 
0058 bool KDiff3Shell::queryExit()
0059 {
0060     return true;
0061 }
0062 
0063 void KDiff3Shell::closeEvent(QCloseEvent* e)
0064 {
0065     if(queryClose())
0066     {
0067         e->accept();
0068         bool bFileSaved = m_widget->isFileSaved();
0069         bool bDirCompare = m_widget->isDirComparison();
0070         QApplication::exit(bFileSaved || bDirCompare ? 0 : 1);
0071     }
0072     else
0073         e->ignore();
0074 }
0075 
0076 void KDiff3Shell::optionsShowToolbar()
0077 {
0078     // this is all very cut and paste code for showing/hiding the
0079     // toolbar
0080     if(m_toolbarAction->isChecked())
0081         toolBar()->show();
0082     else
0083         toolBar()->hide();
0084 }
0085 
0086 void KDiff3Shell::optionsShowStatusbar()
0087 {
0088     // this is all very cut and paste code for showing/hiding the
0089     // statusbar
0090     if(m_statusbarAction->isChecked())
0091         statusBar()->show();
0092     else
0093         statusBar()->hide();
0094 }
0095 
0096 void KDiff3Shell::optionsConfigureKeys()
0097 {
0098     KShortcutsDialog::showDialog(actionCollection(), KShortcutsEditor::LetterShortcutsDisallowed);
0099 }
0100 
0101 void KDiff3Shell::optionsConfigureToolbars()
0102 {
0103     KConfigGroup mainWindowGroup(KSharedConfig::openConfig(), "MainWindow");
0104     saveMainWindowSettings(mainWindowGroup);
0105 
0106     // use the standard toolbar editor
0107     KEditToolBar dlg(factory());
0108     chk_connect_a(&dlg, &KEditToolBar::newToolBarConfig, this, &KDiff3Shell::applyNewToolbarConfig);
0109     dlg.exec();
0110 }
0111 
0112 void KDiff3Shell::applyNewToolbarConfig()
0113 {
0114     KConfigGroup mainWindowGroup(KSharedConfig::openConfig(), "MainWindow");
0115     applyMainWindowSettings(mainWindowGroup);
0116 }
0117 
0118 void KDiff3Shell::slotNewInstance(const QString& fn1, const QString& fn2, const QString& fn3)
0119 {
0120     [[maybe_unused]] static KDiff3Shell* pKDiff3Shell = new KDiff3Shell(fn1, fn2, fn3);
0121 }
0122 
0123 //#include "kdiff3_shell.moc"