work save: git - merge

This commit is contained in:
Roy Qu 2022-02-20 21:47:57 +08:00
parent 45bb056713
commit 7cc5cf4f45
13 changed files with 793 additions and 445 deletions

View File

@ -149,6 +149,7 @@ SOURCES += \
widgets/filepropertiesdialog.cpp \ widgets/filepropertiesdialog.cpp \
widgets/functiontooltipwidget.cpp \ widgets/functiontooltipwidget.cpp \
widgets/headercompletionpopup.cpp \ widgets/headercompletionpopup.cpp \
widgets/infomessagebox.cpp \
widgets/issuestable.cpp \ widgets/issuestable.cpp \
widgets/labelwithmenu.cpp \ widgets/labelwithmenu.cpp \
widgets/lightfusionstyle.cpp \ widgets/lightfusionstyle.cpp \
@ -284,6 +285,7 @@ HEADERS += \
widgets/filepropertiesdialog.h \ widgets/filepropertiesdialog.h \
widgets/functiontooltipwidget.h \ widgets/functiontooltipwidget.h \
widgets/headercompletionpopup.h \ widgets/headercompletionpopup.h \
widgets/infomessagebox.h \
widgets/issuestable.h \ widgets/issuestable.h \
widgets/labelwithmenu.h \ widgets/labelwithmenu.h \
widgets/lightfusionstyle.h \ widgets/lightfusionstyle.h \
@ -341,6 +343,7 @@ FORMS += \
settingsdialog/settingsdialog.ui \ settingsdialog/settingsdialog.ui \
widgets/custommakefileinfodialog.ui \ widgets/custommakefileinfodialog.ui \
widgets/filepropertiesdialog.ui \ widgets/filepropertiesdialog.ui \
widgets/infomessagebox.ui \
widgets/newclassdialog.ui \ widgets/newclassdialog.ui \
widgets/newheaderdialog.ui \ widgets/newheaderdialog.ui \
widgets/newprojectdialog.ui \ widgets/newprojectdialog.ui \

File diff suppressed because it is too large Load Diff

View File

@ -42,6 +42,7 @@
#include "vcs/gitmanager.h" #include "vcs/gitmanager.h"
#include "vcs/gitrepository.h" #include "vcs/gitrepository.h"
#include "vcs/gitbranchdialog.h" #include "vcs/gitbranchdialog.h"
#include "vcs/gitmergedialog.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
@ -3077,10 +3078,14 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
vcsMenu.addAction(ui->actionGit_Add_Files); vcsMenu.addAction(ui->actionGit_Add_Files);
} }
vcsMenu.addAction(ui->actionGit_Branch); vcsMenu.addAction(ui->actionGit_Branch);
vcsMenu.addAction(ui->actionGit_Merge);
vcsMenu.addAction(ui->actionGit_Commit); vcsMenu.addAction(ui->actionGit_Commit);
vcsMenu.addAction(ui->actionGit_Restore); vcsMenu.addAction(ui->actionGit_Restore);
ui->actionGit_Commit->setEnabled(true); bool canBranch = !mProject->model()->iconProvider()->VCSRepository()->hasChangedFiles()
&& !mProject->model()->iconProvider()->VCSRepository()->hasChangedFiles();
ui->actionGit_Merge->setEnabled(canBranch);
ui->actionGit_Commit->setEnabled(canBranch);
ui->actionGit_Branch->setEnabled(true); ui->actionGit_Branch->setEnabled(true);
ui->actionGit_Restore->setEnabled(true); ui->actionGit_Restore->setEnabled(true);
@ -3188,11 +3193,15 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
vcsMenu.addAction(ui->actionGit_Add_Files); vcsMenu.addAction(ui->actionGit_Add_Files);
} }
vcsMenu.addAction(ui->actionGit_Branch); vcsMenu.addAction(ui->actionGit_Branch);
vcsMenu.addAction(ui->actionGit_Merge);
vcsMenu.addAction(ui->actionGit_Commit); vcsMenu.addAction(ui->actionGit_Commit);
vcsMenu.addAction(ui->actionGit_Restore); vcsMenu.addAction(ui->actionGit_Restore);
bool canBranch = !mFileSystemModelIconProvider.VCSRepository()->hasChangedFiles()
&& !mFileSystemModelIconProvider.VCSRepository()->hasChangedFiles();
ui->actionGit_Branch->setEnabled(canBranch);
ui->actionGit_Merge->setEnabled(canBranch);
ui->actionGit_Commit->setEnabled(true); ui->actionGit_Commit->setEnabled(true);
ui->actionGit_Branch->setEnabled(true);
ui->actionGit_Restore->setEnabled(true); ui->actionGit_Restore->setEnabled(true);
// vcsMenu.addAction(ui->actionGit_Reset); // vcsMenu.addAction(ui->actionGit_Reset);
@ -5675,20 +5684,26 @@ void MainWindow::updateVCSActions()
{ {
bool hasRepository = false; bool hasRepository = false;
bool shouldEnable = false; bool shouldEnable = false;
bool canBranch = false;
if (ui->projectView->isVisible() && mProject) { if (ui->projectView->isVisible() && mProject) {
GitManager vcsManager; GitManager vcsManager;
QString branch; QString branch;
hasRepository = vcsManager.hasRepository(mProject->folder(),branch); hasRepository = vcsManager.hasRepository(mProject->folder(),branch);
shouldEnable = true; shouldEnable = true;
canBranch = !mProject->model()->iconProvider()->VCSRepository()->hasChangedFiles()
&& !mProject->model()->iconProvider()->VCSRepository()->hasChangedFiles();
} else if (ui->treeFiles->isVisible()) { } else if (ui->treeFiles->isVisible()) {
GitManager vcsManager; GitManager vcsManager;
QString branch; QString branch;
hasRepository = vcsManager.hasRepository(pSettings->environment().currentFolder(),branch); hasRepository = vcsManager.hasRepository(pSettings->environment().currentFolder(),branch);
shouldEnable = true; shouldEnable = true;
canBranch =!mFileSystemModelIconProvider.VCSRepository()->hasChangedFiles()
&& !mFileSystemModelIconProvider.VCSRepository()->hasChangedFiles();
} }
ui->actionGit_Create_Repository->setEnabled(!hasRepository && shouldEnable); ui->actionGit_Create_Repository->setEnabled(!hasRepository && shouldEnable);
ui->actionGit_Commit->setEnabled(hasRepository && shouldEnable); ui->actionGit_Commit->setEnabled(hasRepository && shouldEnable);
ui->actionGit_Branch->setEnabled(hasRepository && shouldEnable); ui->actionGit_Branch->setEnabled(hasRepository && shouldEnable && canBranch);
ui->actionGit_Merge->setEnabled(hasRepository && shouldEnable && canBranch);
ui->actionGit_Reset->setEnabled(hasRepository && shouldEnable); ui->actionGit_Reset->setEnabled(hasRepository && shouldEnable);
ui->actionGit_Restore->setEnabled(hasRepository && shouldEnable); ui->actionGit_Restore->setEnabled(hasRepository && shouldEnable);
ui->actionGit_Revert->setEnabled(hasRepository && shouldEnable); ui->actionGit_Revert->setEnabled(hasRepository && shouldEnable);
@ -6793,3 +6808,26 @@ void MainWindow::on_actionGit_Branch_triggered()
} }
} }
void MainWindow::on_actionGit_Merge_triggered()
{
QString folder;
if (ui->treeFiles->isVisible()) {
folder = pSettings->environment().currentFolder();
} else if (ui->projectView->isVisible() && mProject) {
folder = mProject->folder();
}
if (folder.isEmpty())
return;
GitMergeDialog dialog(folder);
if (dialog.exec()==QDialog::Accepted) {
//update project view
if (mProject) {
mProject->model()->beginUpdate();
mProject->model()->endUpdate();
}
//update files view
setFilesViewRoot(pSettings->environment().currentFolder());
}
}

View File

@ -590,6 +590,8 @@ private slots:
void on_actionGit_Branch_triggered(); void on_actionGit_Branch_triggered();
void on_actionGit_Merge_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -1604,6 +1604,8 @@
<addaction name="actionGit_Create_Repository"/> <addaction name="actionGit_Create_Repository"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionGit_Branch"/> <addaction name="actionGit_Branch"/>
<addaction name="actionGit_Merge"/>
<addaction name="separator"/>
<addaction name="actionGit_Commit"/> <addaction name="actionGit_Commit"/>
<addaction name="actionGit_Restore"/> <addaction name="actionGit_Restore"/>
</widget> </widget>
@ -2795,6 +2797,11 @@
<string>Branch/Switch</string> <string>Branch/Switch</string>
</property> </property>
</action> </action>
<action name="actionGit_Merge">
<property name="text">
<string>Merge</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -1,6 +1,7 @@
#include "gitbranchdialog.h" #include "gitbranchdialog.h"
#include "ui_gitbranchdialog.h" #include "ui_gitbranchdialog.h"
#include "gitmanager.h" #include "gitmanager.h"
#include "../widgets/infomessagebox.h"
GitBranchDialog::GitBranchDialog(const QString& folder, QWidget *parent) : GitBranchDialog::GitBranchDialog(const QString& folder, QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -47,6 +48,7 @@ void GitBranchDialog::on_btnOk_clicked()
else else
text = ui->lstBranches->currentText(); text = ui->lstBranches->currentText();
bool result = false; bool result = false;
QString output;
if (!text.isEmpty()) { if (!text.isEmpty()) {
result = mManager->switchToBranch( result = mManager->switchToBranch(
mFolder, mFolder,
@ -56,12 +58,17 @@ void GitBranchDialog::on_btnOk_clicked()
ui->chkMerge->isChecked(), ui->chkMerge->isChecked(),
ui->rbForceTrack->isChecked(), ui->rbForceTrack->isChecked(),
ui->rbForceNoTrack->isChecked(), ui->rbForceNoTrack->isChecked(),
ui->chkForceCreation->isChecked()); ui->chkForceCreation->isChecked(),
output);
} }
if (result) if (result) {
accept(); accept();
else } else if (!output.isEmpty()) {
InfoMessageBox box;
box.setMessage(output);
box.exec();
reject(); reject();
}
} }

View File

@ -1,14 +1,31 @@
#include "gitmergedialog.h" #include "gitmergedialog.h"
#include "ui_gitmergedialog.h" #include "ui_gitmergedialog.h"
#include "gitmanager.h" #include "gitmanager.h"
#include "../widgets/infomessagebox.h"
GitMergeDialog::GitMergeDialog(const QString& folder, QWidget *parent) : GitMergeDialog::GitMergeDialog(const QString& folder, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::GitMergeDialog), ui(new Ui::GitMergeDialog)
mFolder(folder)
{ {
ui->setupUi(this); ui->setupUi(this);
mManager = new GitManager(); mManager = new GitManager();
mCurrentBranchIndex=-1;
QStringList branches =mManager->listBranches(mFolder,mCurrentBranchIndex);
ui->cbBranch->addItems(branches);
ui->cbBranch->setCurrentIndex(mCurrentBranchIndex);
ui->btnOk->setEnabled(false);
ui->rbBranch->setChecked(true);
ui->txtMergeMessage->setPlainText(QObject::tr("<Auto Generated by Git>"));
mFolder = mManager->rootFolder(folder);
if (branches.isEmpty()) {
QString currentBranch;
if (mManager->hasRepository(folder,currentBranch)) {
ui->cbBranch->addItem(currentBranch);
ui->btnOk->setEnabled(false);
}
ui->grpOptions->setEnabled(false);
ui->txtMergeMessage->setEnabled(false);
}
} }
GitMergeDialog::~GitMergeDialog() GitMergeDialog::~GitMergeDialog()
@ -16,3 +33,41 @@ GitMergeDialog::~GitMergeDialog()
delete mManager; delete mManager;
delete ui; delete ui;
} }
void GitMergeDialog::on_btnCancel_clicked()
{
reject();
}
void GitMergeDialog::closeEvent(QCloseEvent */* event */)
{
reject();
}
void GitMergeDialog::on_btnOk_clicked()
{
QString output;
if (mManager->merge(mFolder,ui->cbBranch->currentText(),
ui->chkSquash->isChecked(),
ui->chkFastForwardOnly->isChecked(),
ui->chkNoFastFoward->isChecked(),
ui->chkNoCommit->isChecked(),
output,
ui->txtMergeMessage->toPlainText()
)) {
accept();
} else {
InfoMessageBox box;
box.setMessage(output);
box.exec();
reject();
}
}
void GitMergeDialog::on_cbBranch_currentIndexChanged(int index)
{
ui->btnOk->setEnabled(mCurrentBranchIndex!=index);
}

View File

@ -16,10 +16,22 @@ public:
explicit GitMergeDialog(const QString& folder, QWidget *parent = nullptr); explicit GitMergeDialog(const QString& folder, QWidget *parent = nullptr);
~GitMergeDialog(); ~GitMergeDialog();
private slots:
void on_btnCancel_clicked();
void on_btnOk_clicked();
void on_cbBranch_currentIndexChanged(int index);
private: private:
Ui::GitMergeDialog *ui; Ui::GitMergeDialog *ui;
GitManager *mManager; GitManager *mManager;
QString mFolder; QString mFolder;
int mCurrentBranchIndex;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
}; };
#endif // GITMERGEDIALOG_H #endif // GITMERGEDIALOG_H

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Merge</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
@ -133,7 +133,7 @@
<item> <item>
<widget class="QPushButton" name="btnCancel"> <widget class="QPushButton" name="btnCancel">
<property name="text"> <property name="text">
<string>PushButton</string> <string>Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -32,12 +32,18 @@ public:
bool isFileStaged(const QString& filePath) { bool isFileStaged(const QString& filePath) {
return mStagedFiles.contains(filePath); return mStagedFiles.contains(filePath);
} }
bool hasStagedFiles() {
return !mStagedFiles.isEmpty();
}
bool isFileChanged(const QFileInfo& fileInfo) { bool isFileChanged(const QFileInfo& fileInfo) {
return isFileChanged(fileInfo.absoluteFilePath()); return isFileChanged(fileInfo.absoluteFilePath());
} }
bool isFileChanged(const QString& filePath) { bool isFileChanged(const QString& filePath) {
return mChangedFiles.contains(filePath); return mChangedFiles.contains(filePath);
} }
bool hasChangedFiles() {
return !mChangedFiles.isEmpty();
}
void add(const QString& path); void add(const QString& path);
void remove(const QString& path); void remove(const QString& path);

View File

@ -0,0 +1,25 @@
#include "infomessagebox.h"
#include "ui_infomessagebox.h"
InfoMessageBox::InfoMessageBox(QWidget *parent) :
QDialog(parent),
ui(new Ui::InfoMessageBox)
{
ui->setupUi(this);
}
void InfoMessageBox::setMessage(const QString message)
{
ui->txtMessage->setText(message);
}
InfoMessageBox::~InfoMessageBox()
{
delete ui;
}
void InfoMessageBox::on_btnOk_clicked()
{
accept();
}

View File

@ -0,0 +1,26 @@
#ifndef INFOMESSAGEBOX_H
#define INFOMESSAGEBOX_H
#include <QDialog>
namespace Ui {
class InfoMessageBox;
}
class InfoMessageBox : public QDialog
{
Q_OBJECT
public:
explicit InfoMessageBox(QWidget *parent = nullptr);
void setMessage(const QString message);
~InfoMessageBox();
private slots:
void on_btnOk_clicked();
private:
Ui::InfoMessageBox *ui;
};
#endif // INFOMESSAGEBOX_H

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InfoMessageBox</class>
<widget class="QDialog" name="InfoMessageBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>459</height>
</rect>
</property>
<property name="windowTitle">
<string>Message</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="txtMessage">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnOk">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>