File indexing completed on 2025-01-05 05:14:48
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "changedfilesdialog.h" 0008 #include "actions/changedfileactions.h" 0009 #include "commitpushdialog.h" 0010 #include "gitmanager.h" 0011 #include "models/changedfilesmodel.h" 0012 0013 #include <KLocalizedString> 0014 0015 #include <KSharedConfig> 0016 #include <KWindowConfig> 0017 #include <QWindow> 0018 0019 namespace 0020 { 0021 static const char myChangedFilesDialogGroupName[] = "ChangedFilesDialog"; 0022 } 0023 ChangedFilesDialog::ChangedFilesDialog(Git::Manager *git, QWidget *parent) 0024 : AppDialog(git, parent) 0025 , mActions(new ChangedFileActions(git, this)) 0026 , mModel(new ChangedFilesModel(git, false, this)) 0027 { 0028 setupUi(this); 0029 0030 connect(mActions, &ChangedFileActions::reloadNeeded, mModel, &ChangedFilesModel::reload); 0031 buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Commit/Push")); 0032 connect(buttonBox, &QDialogButtonBox::accepted, this, &ChangedFilesDialog::slotPushCommit); 0033 connect(buttonBox, &QDialogButtonBox::rejected, this, &ChangedFilesDialog::reject); 0034 connect(buttonBox, &QDialogButtonBox::clicked, this, &ChangedFilesDialog::slotButtonBoxClicked); 0035 connect(listView, &QListView::doubleClicked, this, &ChangedFilesDialog::slotItemDoubleClicked); 0036 connect(listView, &QListView::customContextMenuRequested, this, &ChangedFilesDialog::slotCustomContextMenuRequested); 0037 0038 buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(i18n("Reload")); 0039 0040 listView->setModel(mModel); 0041 mModel->reload(); 0042 readConfig(); 0043 } 0044 0045 ChangedFilesDialog::~ChangedFilesDialog() 0046 { 0047 writeConfig(); 0048 } 0049 0050 void ChangedFilesDialog::slotPushCommit() 0051 { 0052 CommitPushDialog d(mGit, this); 0053 d.exec(); 0054 mModel->reload(); 0055 } 0056 0057 void ChangedFilesDialog::slotButtonBoxClicked(QAbstractButton *button) 0058 { 0059 if (button == buttonBox->button(QDialogButtonBox::RestoreDefaults)) { 0060 mModel->reload(); 0061 } 0062 } 0063 0064 void ChangedFilesDialog::slotItemDoubleClicked(const QModelIndex &index) 0065 { 0066 if (!index.isValid()) 0067 return; 0068 0069 auto data = mModel->data(index.row()); 0070 if (data->oldFilePath != QString()) 0071 mActions->setFilePaths(data->oldFilePath, data->filePath); 0072 else 0073 mActions->setFilePath(data->filePath); 0074 mActions->diff(); 0075 } 0076 0077 void ChangedFilesDialog::slotCustomContextMenuRequested(const QPoint &pos) 0078 { 0079 Q_UNUSED(pos) 0080 if (!listView->currentIndex().isValid()) 0081 return; 0082 0083 mActions->setFilePath(mModel->filePath(listView->currentIndex().row())); 0084 mActions->popup(); 0085 } 0086 0087 void ChangedFilesDialog::readConfig() 0088 { 0089 create(); // ensure a window is created 0090 windowHandle()->resize(QSize(800, 300)); 0091 KConfigGroup group(KSharedConfig::openStateConfig(), myChangedFilesDialogGroupName); 0092 KWindowConfig::restoreWindowSize(windowHandle(), group); 0093 resize(windowHandle()->size()); // workaround for QTBUG-40584 0094 } 0095 0096 void ChangedFilesDialog::writeConfig() 0097 { 0098 KConfigGroup group(KSharedConfig::openStateConfig(), myChangedFilesDialogGroupName); 0099 KWindowConfig::saveWindowSize(windowHandle(), group); 0100 } 0101 0102 #include "moc_changedfilesdialog.cpp"