work save

This commit is contained in:
Roy Qu 2022-02-24 07:22:44 +08:00
parent 735eb92a13
commit 49a96e4c5b
15 changed files with 642 additions and 0 deletions

View File

@ -92,9 +92,13 @@ SOURCES += \
todoparser.cpp \
toolsmanager.cpp \
vcs/gitbranchdialog.cpp \
vcs/gitfetchdialog.cpp \
vcs/gitlogdialog.cpp \
vcs/gitmanager.cpp \
vcs/gitmergedialog.cpp \
vcs/gitpulldialog.cpp \
vcs/gitpushdialog.cpp \
vcs/gitremotedialog.cpp \
vcs/gitrepository.cpp \
vcs/gitresetdialog.cpp \
vcs/gitutils.cpp \
@ -229,9 +233,13 @@ HEADERS += \
todoparser.h \
toolsmanager.h \
vcs/gitbranchdialog.h \
vcs/gitfetchdialog.h \
vcs/gitlogdialog.h \
vcs/gitmanager.h \
vcs/gitmergedialog.h \
vcs/gitpulldialog.h \
vcs/gitpushdialog.h \
vcs/gitremotedialog.h \
vcs/gitrepository.h \
vcs/gitresetdialog.h \
vcs/gitutils.h \
@ -330,8 +338,12 @@ FORMS += \
settingsdialog/toolsgeneralwidget.ui \
settingsdialog/toolsgitwidget.ui \
vcs/gitbranchdialog.ui \
vcs/gitfetchdialog.ui \
vcs/gitlogdialog.ui \
vcs/gitmergedialog.ui \
vcs/gitpulldialog.ui \
vcs/gitpushdialog.ui \
vcs/gitremotedialog.ui \
vcs/gitresetdialog.ui \
widgets/aboutdialog.ui \
widgets/cpudialog.ui \

View File

@ -0,0 +1,14 @@
#include "gitfetchdialog.h"
#include "ui_gitfetchdialog.h"
GitFetchDialog::GitFetchDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GitFetchDialog)
{
ui->setupUi(this);
}
GitFetchDialog::~GitFetchDialog()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef GITFETCHDIALOG_H
#define GITFETCHDIALOG_H
#include <QDialog>
namespace Ui {
class GitFetchDialog;
}
class GitFetchDialog : public QDialog
{
Q_OBJECT
public:
explicit GitFetchDialog(QWidget *parent = nullptr);
~GitFetchDialog();
private:
Ui::GitFetchDialog *ui;
};
#endif // GITFETCHDIALOG_H

View File

@ -0,0 +1,18 @@
<ui version="4.0">
<class>GitFetchDialog</class>
<widget name="GitFetchDialog" class="QDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -218,6 +218,69 @@ QStringList GitManager::listConflicts(const QString &folder)
return textToLines(runGit(folder,args));
}
QStringList GitManager::listRemotes(const QString &folder)
{
QStringList args;
args.append("remote");
return textToLines(runGit(folder,args));
}
bool GitManager::removeRemote(const QString &folder, const QString &remoteName, QString& output)
{
QStringList args;
args.append("remote");
args.append("remove");
args.append(remoteName);
output = runGit(folder,args);
return !output.startsWith("error") && !output.startsWith("fatal");
}
bool GitManager::renameRemote(const QString &folder, const QString &oldName, const QString &newName, QString &output)
{
QStringList args;
args.append("remote");
args.append("rename");
args.append(oldName);
args.append(newName);
output = runGit(folder,args);
return !output.startsWith("error") && !output.startsWith("fatal");
}
bool GitManager::addRemote(const QString &folder, const QString &name, const QString &url, QString &output)
{
QStringList args;
args.append("remote");
args.append("add");
args.append(name);
args.append(url);
output = runGit(folder,args);
return !output.startsWith("error") && !output.startsWith("fatal");
}
bool GitManager::setRemoteURL(const QString &folder, const QString &name, const QString &newURL, QString &output)
{
QStringList args;
args.append("remote");
args.append("set-url");
args.append(name);
args.append(newURL);
output = runGit(folder,args);
return !output.startsWith("error") && !output.startsWith("fatal");
}
QString GitManager::getRemoteURL(const QString &folder, const QString &name)
{
QStringList args;
args.append("remote");
args.append("get-url");
args.append(name);
return runGit(folder,args);
}
QStringList GitManager::listBranches(const QString &folder, int &current)
{
QStringList args;

View File

@ -40,6 +40,16 @@ public:
QStringList listStagedFiles(const QString& folder);
QStringList listChangedFiles(const QString& folder);
QStringList listConflicts(const QString& folder);
QStringList listRemotes(const QString& folder);
bool removeRemote(const QString& folder, const QString& remoteName, QString& output);
bool renameRemote(const QString& folder, const QString& oldName,
const QString& newName, QString& output);
bool addRemote(const QString& folder, const QString& name,
const QString& url, QString& output);
bool setRemoteURL(const QString& folder, const QString& name,
const QString& newURL, QString& output);
QString getRemoteURL(const QString& folder, const QString& name);
QStringList listBranches(const QString& folder, int& current);
bool switchToBranch(const QString& folder, const QString& branch, bool create,

View File

@ -0,0 +1,14 @@
#include "gitpulldialog.h"
#include "ui_gitpulldialog.h"
GitPullDialog::GitPullDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GitPullDialog)
{
ui->setupUi(this);
}
GitPullDialog::~GitPullDialog()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef GITPULLDIALOG_H
#define GITPULLDIALOG_H
#include <QDialog>
namespace Ui {
class GitPullDialog;
}
class GitPullDialog : public QDialog
{
Q_OBJECT
public:
explicit GitPullDialog(QWidget *parent = nullptr);
~GitPullDialog();
private:
Ui::GitPullDialog *ui;
};
#endif // GITPULLDIALOG_H

View File

@ -0,0 +1,18 @@
<ui version="4.0">
<class>GitPullDialog</class>
<widget name="GitPullDialog" class="QDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,14 @@
#include "gitpushdialog.h"
#include "ui_gitpushdialog.h"
GitPushDialog::GitPushDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GitPushDialog)
{
ui->setupUi(this);
}
GitPushDialog::~GitPushDialog()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef GITPUSHDIALOG_H
#define GITPUSHDIALOG_H
#include <QDialog>
namespace Ui {
class GitPushDialog;
}
class GitPushDialog : public QDialog
{
Q_OBJECT
public:
explicit GitPushDialog(QWidget *parent = nullptr);
~GitPushDialog();
private:
Ui::GitPushDialog *ui;
};
#endif // GITPUSHDIALOG_H

View File

@ -0,0 +1,18 @@
<ui version="4.0">
<class>GitPushDialog</class>
<widget name="GitPushDialog" class="QDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,86 @@
#include "gitremotedialog.h"
#include "ui_gitremotedialog.h"
#include "gitmanager.h"
#include "../iconsmanager.h"
#include "../widgets/infomessagebox.h"
GitRemoteDialog::GitRemoteDialog(const QString& folder, QWidget *parent) :
QDialog(parent),
ui(new Ui::GitRemoteDialog),
mFolder(folder)
{
ui->setupUi(this);
GitManager manager;
ui->lstRemotes->addItems(manager.listRemotes(folder));
connect(pIconsManager, &IconsManager::actionIconsUpdated,
this, &GitRemoteDialog::updateIcons);
ui->btnRemove->setEnabled(false);
ui->pnlProcess->setVisible(false);
ui->grpDetail->setEnabled(false);
connect(ui->lstRemotes->selectionModel(),
&QItemSelectionModel::selectionChanged,
this,
&GitRemoteDialog::onRemotesSelectionChanged);
}
GitRemoteDialog::~GitRemoteDialog()
{
delete ui;
}
void GitRemoteDialog::updateIcons()
{
ui->btnAdd->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_ADD));
ui->btnRemove->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_REMOVE));
}
void GitRemoteDialog::onRemotesSelectionChanged()
{
bool enabled=(ui->lstRemotes->selectedItems().count()>0);
ui->btnRemove->setEnabled(enabled);
ui->pnlProcess->setVisible(enabled);
ui->grpDetail->setEnabled(enabled);
if (enabled) {
QString remoteName = ui->lstRemotes->selectedItems()[0]->text();
GitManager manager;
QString remoteURL = manager.getRemoteURL(mFolder,remoteName);
ui->txtName->setText(remoteName);
ui->txtURL->setText(remoteURL);
ui->btnProcess->setText(tr("Update"));
}
}
void GitRemoteDialog::on_btnAdd_clicked()
{
ui->grpDetail->setEnabled(true);
ui->pnlProcess->setVisible(true);
ui->btnProcess->setText(tr("Add"));
ui->btnRemove->setEnabled(false);
}
void GitRemoteDialog::on_btnRemove_clicked()
{
if (ui->lstRemotes->selectedItems().count()>0) {
QString remoteName = ui->lstRemotes->selectedItems()[0]->text();
GitManager manager;
QString output;
if (!manager.removeRemote(mFolder,remoteName,output)) {
InfoMessageBox infoBox;
infoBox.showMessage(output);
} else {
refresh();
}
}
}
void GitRemoteDialog::refresh()
{
ui->lstRemotes->clear();
GitManager manager;
ui->lstRemotes->addItems(manager.listRemotes(mFolder));
ui->btnRemove->setEnabled(false);
ui->pnlProcess->setVisible(false);
ui->grpDetail->setEnabled(false);
}

View File

@ -0,0 +1,30 @@
#ifndef GITREMOTEDIALOG_H
#define GITREMOTEDIALOG_H
#include <QDialog>
namespace Ui {
class GitRemoteDialog;
}
class GitRemoteDialog : public QDialog
{
Q_OBJECT
public:
explicit GitRemoteDialog(const QString& folder, QWidget *parent = nullptr);
~GitRemoteDialog();
private slots:
void updateIcons();
void onRemotesSelectionChanged();
void on_btnAdd_clicked();
void on_btnRemove_clicked();
void refresh();
private:
Ui::GitRemoteDialog *ui;
QString mFolder;
};
#endif // GITREMOTEDIALOG_H

View File

@ -0,0 +1,279 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GitRemoteDialog</class>
<widget class="QDialog" name="GitRemoteDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>906</width>
<height>502</height>
</rect>
</property>
<property name="windowTitle">
<string>Git Remote</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="widget_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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>
<widget class="QFrame" name="frame_2">
<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>
<widget class="QToolButton" name="btnAdd">
<property name="toolTip">
<string>Add Remote</string>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/images/newlook24/002-add.png</normaloff>:/icons/images/newlook24/002-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRemove">
<property name="toolTip">
<string>Remove Remote</string>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/images/newlook24/008-close.png</normaloff>:/icons/images/newlook24/008-close.png</iconset>
</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>
<item>
<widget class="QListWidget" name="lstRemotes">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="grpDetail">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Detail</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtURL"/>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QWidget" name="pnlProcess" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<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_3">
<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="btnProcess">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<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>781</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>