initial work

- settings for git execute path
 - a git manager
This commit is contained in:
Roy Qu 2022-02-08 23:38:29 +08:00
parent cc43ac245a
commit 18d5a6c1ab
9 changed files with 277 additions and 5 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;

View File

@ -0,0 +1,68 @@
#include "toolsgitwidget.h"
#include "ui_toolsgitwidget.h"
#include "../iconsmanager.h"
#include "../settings.h"
#include "../systemconsts.h"
#include "../utils.h"
#include <QFileDialog>
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);
}

View File

@ -0,0 +1,32 @@
#ifndef TOOLSGITWIDGET_H
#define TOOLSGITWIDGET_H
#include <QWidget>
#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

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ToolsGitWidget</class>
<widget class="QWidget" name="ToolsGitWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="QPushButton" name="btnTestGit">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnBrowseGit">
<property name="toolTip">
<string>Browse</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/images/newlook24/053-open.png</normaloff>:/icons/images/newlook24/053-open.png</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtGitPath"/>
</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="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Path to Git Executable:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QLabel" name="lblGitInfo">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -0,0 +1,11 @@
#include "gitmanager.h"
GitManager::GitManager(QObject *parent) : QObject(parent),
mGitPathValid(false)
{
}
bool GitManager::gitPathValid() const
{
return mGitPathValid;
}

View File

@ -0,0 +1,26 @@
#ifndef GITMANAGER_H
#define GITMANAGER_H
#include <QObject>
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