- enhancement: git - remotes

This commit is contained in:
royqh1979@gmail.com 2022-02-24 11:07:37 +08:00
parent 49a96e4c5b
commit 0764c9afbc
7 changed files with 665 additions and 460 deletions

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@
#include "vcs/gitbranchdialog.h"
#include "vcs/gitmergedialog.h"
#include "vcs/gitlogdialog.h"
#include "vcs/gitremotedialog.h"
#include "widgets/infomessagebox.h"
#include <QCloseEvent>
@ -3107,6 +3108,7 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
if (shouldAdd)
vcsMenu.addAction(ui->actionGit_Add_Files);
}
vcsMenu.addAction(ui->actionGit_Remotes);
vcsMenu.addAction(ui->actionGit_Log);
vcsMenu.addAction(ui->actionGit_Branch);
vcsMenu.addAction(ui->actionGit_Merge);
@ -3118,6 +3120,7 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
ui->actionGit_Branch->setEnabled(canBranch);
ui->actionGit_Merge->setEnabled(canBranch);
ui->actionGit_Commit->setEnabled(true);
ui->actionGit_Remotes->setEnabled(true);
ui->actionGit_Log->setEnabled(true);
ui->actionGit_Restore->setEnabled(true);
@ -3229,6 +3232,7 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
if (shouldAdd)
vcsMenu.addAction(ui->actionGit_Add_Files);
}
vcsMenu.addAction(ui->actionGit_Remotes);
vcsMenu.addAction(ui->actionGit_Log);
vcsMenu.addAction(ui->actionGit_Branch);
vcsMenu.addAction(ui->actionGit_Merge);
@ -3240,6 +3244,7 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
ui->actionGit_Branch->setEnabled(canBranch);
ui->actionGit_Merge->setEnabled(canBranch);
ui->actionGit_Log->setEnabled(true);
ui->actionGit_Remotes->setEnabled(true);
ui->actionGit_Commit->setEnabled(true);
ui->actionGit_Restore->setEnabled(true);
@ -5754,6 +5759,7 @@ void MainWindow::updateVCSActions()
canBranch =!mFileSystemModelIconProvider.VCSRepository()->hasChangedFiles()
&& !mFileSystemModelIconProvider.VCSRepository()->hasStagedFiles();
}
ui->actionGit_Remotes->setEnabled(hasRepository && shouldEnable);
ui->actionGit_Create_Repository->setEnabled(!hasRepository && shouldEnable);
ui->actionGit_Log->setEnabled(hasRepository && shouldEnable);
ui->actionGit_Commit->setEnabled(hasRepository && shouldEnable);
@ -6922,3 +6928,18 @@ void MainWindow::on_actionGit_Log_triggered()
return ;
}
void MainWindow::on_actionGit_Remotes_triggered()
{
QString folder;
if (ui->treeFiles->isVisible()) {
folder = pSettings->environment().currentFolder();
} else if (ui->projectView->isVisible() && mProject) {
folder = mProject->folder();
}
if (folder.isEmpty())
return;
GitRemoteDialog dialog(folder);
dialog.exec();
}

View File

@ -596,6 +596,8 @@ private slots:
void on_actionGit_Log_triggered();
void on_actionGit_Remotes_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -1422,7 +1422,7 @@
<x>0</x>
<y>0</y>
<width>1114</width>
<height>26</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -1603,6 +1603,8 @@
</property>
<addaction name="actionGit_Create_Repository"/>
<addaction name="separator"/>
<addaction name="actionGit_Remotes"/>
<addaction name="separator"/>
<addaction name="actionGit_Log"/>
<addaction name="actionGit_Branch"/>
<addaction name="actionGit_Merge"/>
@ -2811,6 +2813,11 @@
<string>Show Log</string>
</property>
</action>
<action name="actionGit_Remotes">
<property name="text">
<string>Remotes...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -278,7 +278,7 @@ QString GitManager::getRemoteURL(const QString &folder, const QString &name)
args.append("remote");
args.append("get-url");
args.append(name);
return runGit(folder,args);
return runGit(folder,args).trimmed();
}
QStringList GitManager::listBranches(const QString &folder, int &current)

View File

@ -11,7 +11,8 @@ GitRemoteDialog::GitRemoteDialog(const QString& folder, QWidget *parent) :
{
ui->setupUi(this);
GitManager manager;
ui->lstRemotes->addItems(manager.listRemotes(folder));
mRemotes = manager.listRemotes(folder);
ui->lstRemotes->addItems(mRemotes);
connect(pIconsManager, &IconsManager::actionIconsUpdated,
this, &GitRemoteDialog::updateIcons);
ui->btnRemove->setEnabled(false);
@ -50,6 +51,30 @@ void GitRemoteDialog::onRemotesSelectionChanged()
}
}
void GitRemoteDialog::checkDetails()
{
if (ui->txtURL->text().isEmpty()) {
ui->btnProcess->setEnabled(false);
return;
}
if (ui->txtName->text().isEmpty()) {
ui->btnProcess->setEnabled(false);
return;
}
if (ui->btnProcess->text() == tr("Add")) {
ui->btnProcess->setEnabled(!mRemotes.contains(ui->txtName->text()));
} else {
if (ui->lstRemotes->selectedItems().count()>0) {
QString remoteName = ui->lstRemotes->selectedItems()[0]->text();
ui->btnProcess->setEnabled(ui->txtName->text()==remoteName
|| !mRemotes.contains(ui->txtName->text()) );
} else
ui->btnProcess->setEnabled(false);
}
}
void GitRemoteDialog::on_btnAdd_clicked()
{
ui->grpDetail->setEnabled(true);
@ -76,11 +101,66 @@ void GitRemoteDialog::on_btnRemove_clicked()
void GitRemoteDialog::refresh()
{
ui->txtName->setText("");
ui->txtURL->setText("");
ui->lstRemotes->clear();
GitManager manager;
ui->lstRemotes->addItems(manager.listRemotes(mFolder));
mRemotes = manager.listRemotes(mFolder);
ui->lstRemotes->addItems(mRemotes);
ui->btnRemove->setEnabled(false);
ui->pnlProcess->setVisible(false);
ui->grpDetail->setEnabled(false);
}
void GitRemoteDialog::on_btnProcess_clicked()
{
if (ui->btnProcess->text() == tr("Add")) {
// add remote
QString remoteName = ui->txtName->text();
QString remoteURL = ui->txtURL->text();
GitManager manager;
QString output;
if (!manager.addRemote(mFolder, remoteName, remoteURL, output)) {
InfoMessageBox infoBox;
infoBox.showMessage(output);
} else {
refresh();
}
} else {
// update remote
if (ui->lstRemotes->selectedItems().count()<=0)
return;
QString oldName = ui->lstRemotes->selectedItems()[0]->text();
QString newName = ui->txtName->text();
QString url = ui->txtURL->text();
GitManager manager;
QString output;
if (!manager.setRemoteURL(mFolder,oldName,url,output)) {
InfoMessageBox infoBox;
infoBox.showMessage(output);
return;
}
if (oldName != newName) {
if (!manager.setRemoteURL(mFolder,oldName,url,output)) {
InfoMessageBox infoBox;
infoBox.showMessage(output);
return;
}
}
refresh();
}
}
void GitRemoteDialog::on_txtName_textChanged(const QString &/*arg1*/)
{
checkDetails();
}
void GitRemoteDialog::on_txtURL_textChanged(const QString & /*arg1*/)
{
checkDetails();
}

View File

@ -18,13 +18,22 @@ public:
private slots:
void updateIcons();
void onRemotesSelectionChanged();
void checkDetails();
void refresh();
void on_btnAdd_clicked();
void on_btnRemove_clicked();
void refresh();
void on_btnProcess_clicked();
void on_txtName_textChanged(const QString &arg1);
void on_txtURL_textChanged(const QString &arg1);
private:
Ui::GitRemoteDialog *ui;
QString mFolder;
QStringList mRemotes;
};
#endif // GITREMOTEDIALOG_H