From 18d5a6c1abc9876c119ff511f68b093120459b9f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 8 Feb 2022 23:38:29 +0800 Subject: [PATCH] initial work - settings for git execute path - a git manager --- RedPandaIDE/RedPandaIDE.pro | 13 +++- RedPandaIDE/settings.cpp | 35 ++++++++- RedPandaIDE/settings.h | 15 ++++ RedPandaIDE/settingsdialog/settingsdialog.cpp | 5 ++ RedPandaIDE/settingsdialog/toolsgitwidget.cpp | 68 ++++++++++++++++ RedPandaIDE/settingsdialog/toolsgitwidget.h | 32 ++++++++ RedPandaIDE/settingsdialog/toolsgitwidget.ui | 77 +++++++++++++++++++ RedPandaIDE/vcs/gitmanager.cpp | 11 +++ RedPandaIDE/vcs/gitmanager.h | 26 +++++++ 9 files changed, 277 insertions(+), 5 deletions(-) create mode 100644 RedPandaIDE/settingsdialog/toolsgitwidget.cpp create mode 100644 RedPandaIDE/settingsdialog/toolsgitwidget.h create mode 100644 RedPandaIDE/settingsdialog/toolsgitwidget.ui create mode 100644 RedPandaIDE/vcs/gitmanager.cpp create mode 100644 RedPandaIDE/vcs/gitmanager.h diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index e6cf01f8..bfafd479 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -84,11 +84,13 @@ SOURCES += \ settingsdialog/projectoutputwidget.cpp \ settingsdialog/projectprecompilewidget.cpp \ settingsdialog/toolsgeneralwidget.cpp \ + settingsdialog/toolsgitwidget.cpp \ shortcutmanager.cpp \ symbolusagemanager.cpp \ thememanager.cpp \ todoparser.cpp \ toolsmanager.cpp \ + vcs/gitmanager.cpp \ widgets/aboutdialog.cpp \ widgets/bookmarkmodel.cpp \ widgets/classbrowser.cpp \ @@ -210,11 +212,13 @@ HEADERS += \ settingsdialog/projectoutputwidget.h \ settingsdialog/projectprecompilewidget.h \ settingsdialog/toolsgeneralwidget.h \ + settingsdialog/toolsgitwidget.h \ shortcutmanager.h \ symbolusagemanager.h \ thememanager.h \ todoparser.h \ toolsmanager.h \ + vcs/gitmanager.h \ widgets/aboutdialog.h \ widgets/bookmarkmodel.h \ widgets/classbrowser.h \ @@ -306,6 +310,7 @@ FORMS += \ settingsdialog/projectoutputwidget.ui \ settingsdialog/projectprecompilewidget.ui \ settingsdialog/toolsgeneralwidget.ui \ + settingsdialog/toolsgitwidget.ui \ widgets/aboutdialog.ui \ widgets/cpudialog.ui \ mainwindow.ui \ @@ -420,7 +425,7 @@ theme_files.files += $$files(themes/*.png, false) colorscheme_files.files += $$files(colorschemes/*.scheme, false) colorscheme_files.prefix = /colorschemes -RESOURCES += qmake_qm_files -RESOURCES += iconsets_files -RESOURCES += theme_files -RESOURCES += colorscheme_files +#RESOURCES += qmake_qm_files +#RESOURCES += iconsets_files +#RESOURCES += theme_files +#RESOURCES += colorscheme_files diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 155c976c..6b79d874 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -46,7 +46,8 @@ Settings::Settings(const QString &filename): mCodeCompletion(this), mCodeFormatter(this), mHistory(this), - mUI(this) + mUI(this), + mVCS(this) { load(); } @@ -106,6 +107,8 @@ void Settings::load() mCodeFormatter.load(); mUI.load(); mDirs.load(); + mVCS.load(); + } Settings::Dirs &Settings::dirs() @@ -153,6 +156,11 @@ Settings::UI &Settings::ui() return mUI; } +Settings::VCS &Settings::vcs() +{ + return mVCS; +} + Settings::History& Settings::history() { return mHistory; @@ -5074,3 +5082,28 @@ void Settings::UI::doLoad() mNewHeaderDialogWidth = intValue("new_header_dialog_width", 642*qApp->desktop()->width()/1920); mNewHeaderDialogHeight = intValue("new_header_dialog_height", 300*qApp->desktop()->height()/1080); } + +Settings::VCS::VCS(Settings *settings):_Base(settings,SETTING_VCS) +{ + +} + +void Settings::VCS::doSave() +{ + saveValue("git_path",mGitPath); +} + +void Settings::VCS::doLoad() +{ + mGitPath = stringValue("git_path", ""); +} + +const QString &Settings::VCS::gitPath() const +{ + return mGitPath; +} + +void Settings::VCS::setGitPath(const QString &newGitPath) +{ + mGitPath = newGitPath; +} diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 7e7f1361..d331b159 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -36,6 +36,7 @@ #define SETTING_DEBUGGER "Debugger" #define SETTING_HISTORY "History" #define SETTING_UI "UI" +#define SETTING_VCS "VCS" #define SETTING_CODE_COMPLETION "CodeCompletion" #define SETTING_CODE_FORMATTER "CodeFormatter" #define SETTING_COMPILTER_SETS "CompilerSets" @@ -881,6 +882,18 @@ public: void doLoad() override; }; + class VCS: public _Base { + public: + explicit VCS(Settings *settings); + const QString &gitPath() const; + void setGitPath(const QString &newGitPath); + private: + QString mGitPath; + protected: + void doSave() override; + void doLoad() override; + }; + class UI: public _Base { public: explicit UI(Settings *settings); @@ -1325,6 +1338,7 @@ public: CodeCompletion &codeCompletion(); CodeFormatter &codeFormatter(); UI &ui(); + VCS &vcs(); QString filename() const; private: @@ -1340,6 +1354,7 @@ private: CodeFormatter mCodeFormatter; History mHistory; UI mUI; + VCS mVCS; }; diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index d1dafffd..5e2d69c4 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -48,6 +48,7 @@ #include "projectmakefilewidget.h" #include "projectdllhostwidget.h" #include "toolsgeneralwidget.h" +#include "toolsgitwidget.h" #ifdef Q_OS_WIN #include "environmentfileassociationwidget.h" #include "projectversioninfowidget.h" @@ -219,6 +220,10 @@ PSettingsDialog SettingsDialog::optionDialog() widget = new ToolsGeneralWidget(tr("General"),tr("Tools")); dialog->addWidget(widget); + widget = new ToolsGitWidget(tr("Git"),tr("Tools")); + dialog->addWidget(widget); + + dialog->selectFirstWidget(); return dialog; diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.cpp b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp new file mode 100644 index 00000000..0f24384f --- /dev/null +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp @@ -0,0 +1,68 @@ +#include "toolsgitwidget.h" +#include "ui_toolsgitwidget.h" +#include "../iconsmanager.h" +#include "../settings.h" +#include "../systemconsts.h" +#include "../utils.h" + +#include + +ToolsGitWidget::ToolsGitWidget(const QString& name, const QString& group, QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::ToolsGitWidget) +{ + ui->setupUi(this); + ui->lblGitInfo->setVisible(false); +} + +ToolsGitWidget::~ToolsGitWidget() +{ + delete ui; +} + +void ToolsGitWidget::doLoad() +{ + ui->txtGitPath->setText(pSettings->vcs().gitPath()); +} + +void ToolsGitWidget::doSave() +{ + pSettings->vcs().setGitPath(ui->txtGitPath->text()); +} + +void ToolsGitWidget::updateIcons(const QSize &size) +{ + pIconsManager->setIcon(ui->btnBrowseGit,IconsManager::ACTION_FILE_OPEN_FOLDER); +} + +void ToolsGitWidget::on_btnBrowseGit_clicked() +{ + QString filename = QFileDialog::getOpenFileName( + this, + tr("Git Executable"), + QString(), + tr("All files (%1)").arg(ALL_FILE_WILDCARD)); + if (!filename.isEmpty() && fileExists(filename)) { + ui->txtGitPath->setText(filename); + } +} + + +void ToolsGitWidget::on_btnTestGit_clicked() +{ + QFileInfo fileInfo(ui->txtGitPath->text()); + if (!fileInfo.exists()) { + ui->lblGitInfo->setVisible(false); + return; + } + ui->lblGitInfo->setVisible(true); + ui->lblGitInfo->setText(""); + QStringList args; + args.append("--version"); + QString output = runAndGetOutput( + fileInfo.fileName(), + fileInfo.absolutePath(), + args); + ui->lblGitInfo->setText(output); +} + diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.h b/RedPandaIDE/settingsdialog/toolsgitwidget.h new file mode 100644 index 00000000..42d96d39 --- /dev/null +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.h @@ -0,0 +1,32 @@ +#ifndef TOOLSGITWIDGET_H +#define TOOLSGITWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class ToolsGitWidget; +} + +class ToolsGitWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit ToolsGitWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~ToolsGitWidget(); + +private: + Ui::ToolsGitWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; + void updateIcons(const QSize &size) override; +private slots: + void on_btnBrowseGit_clicked(); + void on_btnTestGit_clicked(); +}; + +#endif // TOOLSGITWIDGET_H diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.ui b/RedPandaIDE/settingsdialog/toolsgitwidget.ui new file mode 100644 index 00000000..c6a58cc0 --- /dev/null +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.ui @@ -0,0 +1,77 @@ + + + ToolsGitWidget + + + + 0 + 0 + 555 + 300 + + + + Form + + + + + + Test + + + + + + + Browse + + + ... + + + + :/icons/images/newlook24/053-open.png:/icons/images/newlook24/053-open.png + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Path to Git Executable: + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + + + + diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp new file mode 100644 index 00000000..801a6513 --- /dev/null +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -0,0 +1,11 @@ +#include "gitmanager.h" + +GitManager::GitManager(QObject *parent) : QObject(parent), + mGitPathValid(false) +{ +} + +bool GitManager::gitPathValid() const +{ + return mGitPathValid; +} diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h new file mode 100644 index 00000000..b6dba53e --- /dev/null +++ b/RedPandaIDE/vcs/gitmanager.h @@ -0,0 +1,26 @@ +#ifndef GITMANAGER_H +#define GITMANAGER_H + +#include + +class GitManager : public QObject +{ + Q_OBJECT +public: + explicit GitManager(QObject *parent = nullptr); + + bool gitPathValid() const; + bool createRepository(const QString& folder); + bool hasRepository(const QString& folder); + + +signals: +private: + void validate(); +private: + QString mGitPath; + bool mGitPathValid; + +}; + +#endif // GITMANAGER_H