From 18d5a6c1abc9876c119ff511f68b093120459b9f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 8 Feb 2022 23:38:29 +0800 Subject: [PATCH 1/9] 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 From 149148a635129c4d54027897c0e122d63ade621b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 9 Feb 2022 14:58:39 +0800 Subject: [PATCH 2/9] work save - basic git operations --- RedPandaIDE/vcs/gitmanager.cpp | 143 +++++++++++++++++++++++++++++++++ RedPandaIDE/vcs/gitmanager.h | 31 ++++++- 2 files changed, 173 insertions(+), 1 deletion(-) diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 801a6513..69b585ce 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -1,4 +1,7 @@ #include "gitmanager.h" +#include "../utils.h" + +#include GitManager::GitManager(QObject *parent) : QObject(parent), mGitPathValid(false) @@ -9,3 +12,143 @@ bool GitManager::gitPathValid() const { return mGitPathValid; } + +void GitManager::createRepository(const QString &folder) +{ + if (hasRepository(folder)) + throw GitError(tr("Folder \"%1\" already has a repository!")); + QStringList args; + args.append("init"); + runGit(folder,args); +} + +bool GitManager::hasRepository(const QString &folder) +{ + + QStringList args; + args.append("status"); + QString output = runGit(folder,args); + return !output.startsWith("fatal:"); +} + +void GitManager::add(const QString &folder, const QString &path) +{ + QStringList args; + args.append("add"); + args.append(path); + runGit(folder,args); +} + +void GitManager::remove(const QString &folder, const QString &path) +{ + QStringList args; + args.append("rm"); + args.append(path); + runGit(folder,args); +} + +void GitManager::rename(const QString &folder, const QString &oldName, const QString &newName) +{ + QStringList args; + args.append("mv"); + args.append(oldName); + args.append(newName); + runGit(folder,args); +} + +void GitManager::restore(const QString &folder, const QString &path) +{ + QStringList args; + args.append("restore"); + args.append(path); + runGit(folder,args); +} + +QStringList GitManager::listFiles(const QString &folder) +{ + QStringList args; + args.append("ls-files"); + return textToLines(runGit(folder,args)); +} + +void GitManager::clone(const QString &folder, const QString &url) +{ + QStringList args; + args.append("clone"); + args.append(url); + runGit(folder,args); +} + +void GitManager::commit(const QString &folder, const QString &message) +{ + QStringList args; + args.append("commit"); + args.append("-m"); + args.append(message); + runGit(folder,args); +} + +void GitManager::revert(const QString &folder) +{ + QStringList args; + args.append("revert"); + runGit(folder,args); +} + +void GitManager::reset(const QString &folder, const QString &commit, ResetStrategy strategy) +{ + //todo reset type + QStringList args; + args.append("reset"); + switch(strategy) { + case ResetStrategy::Soft: + args.append("--soft"); + break; + case ResetStrategy::Hard: + args.append("--hard"); + break; + case ResetStrategy::Mixed: + args.append("--mixed"); + break; + case ResetStrategy::Merge: + args.append("--merge"); + break; + case ResetStrategy::Keep: + args.append("--keep"); + break; + } + args.append(commit); + runGit(folder,args); +} + +void GitManager::validate() +{ + QStringList args; + args.append("--version"); + QString output = runGit("",args); + mGitPathValid = output.startsWith("git version"); +} + +QString GitManager::runGit(const QString& workingFolder, const QStringList &args) +{ + QFileInfo fileInfo(mGitPath); + if (!fileInfo.exists()) + throw GitError("fatal: git doesn't exist"); + emit gitCmdRunning(QString("Running in \"%1\": \n \"%2\" \"%3\"") + .arg(workingFolder, + mGitPath, + args.join("\" \""))); + QString output = runAndGetOutput( + fileInfo.absoluteFilePath(), + workingFolder, + args); + emit gitCmdFinished(output); + if (output.startsWith("fatal:")) + throw GitError(output); + return output; +} + +GitError::GitError(const QString &reason):BaseError(reason) +{ + +} diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index b6dba53e..fc66b06f 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -2,21 +2,50 @@ #define GITMANAGER_H #include +#include "utils.h" + +class GitError: public BaseError { +public: + explicit GitError(const QString& reason); +}; + + class GitManager : public QObject { Q_OBJECT public: + enum class ResetStrategy { + Soft, + Hard, + Merge, + Mixed, + Keep + }; + explicit GitManager(QObject *parent = nullptr); bool gitPathValid() const; - bool createRepository(const QString& folder); + void createRepository(const QString& folder); bool hasRepository(const QString& folder); + void add(const QString& folder, const QString& path); + void remove(const QString& folder, const QString& path); + void rename(const QString& folder, const QString& oldName, const QString& newName); + void restore(const QString& folder, const QString& path); + QStringList listFiles(const QString& folder); + + void clone(const QString& folder, const QString& url); + void commit(const QString& folder, const QString& message); + void revert(const QString& folder); + void reset(const QString& folder, const QString& commit, ResetStrategy strategy); signals: + void gitCmdRunning(const QString& gitCmd); + void gitCmdFinished(const QString& message); private: void validate(); + QString runGit(const QString& workingFolder, const QStringList& args); private: QString mGitPath; bool mGitPathValid; From e53a66614d1c9fb34b868953addff4516a162e37 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 9 Feb 2022 20:10:28 +0800 Subject: [PATCH 3/9] work save --- RedPandaIDE/RedPandaIDE.pro | 8 ++++---- RedPandaIDE/vcs/gitmanager.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index bfafd479..6952a0de 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -425,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/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index fc66b06f..684fa748 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -49,7 +49,6 @@ private: private: QString mGitPath; bool mGitPathValid; - }; #endif // GITMANAGER_H From 4e16a2e1866ac136997ae08ee51b7b368330760e Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 10 Feb 2022 12:03:56 +0800 Subject: [PATCH 4/9] - change: rename "compile log" panel to "tools output" - fix: debug panel can't be correctly show/hide - enhancement: redesign tools output's context menu, add "clear" menu item - update translations --- NEWS.md | 3 + RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/RedPandaIDE_zh_CN.ts | 1130 ++++++++++-------- RedPandaIDE/compiler/compilermanager.cpp | 8 +- RedPandaIDE/mainwindow.cpp | 86 +- RedPandaIDE/mainwindow.h | 15 +- RedPandaIDE/mainwindow.ui | 48 +- RedPandaIDE/settingsdialog/toolsgitwidget.ui | 2 +- RedPandaIDE/vcs/gitmanager.cpp | 12 +- RedPandaIDE/vcs/gitmanager.h | 12 +- RedPandaIDE/vcs/gitrepository.cpp | 84 ++ RedPandaIDE/vcs/gitrepository.h | 48 + 12 files changed, 899 insertions(+), 551 deletions(-) create mode 100644 RedPandaIDE/vcs/gitrepository.cpp create mode 100644 RedPandaIDE/vcs/gitrepository.h diff --git a/NEWS.md b/NEWS.md index f25e1c35..860f7778 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ Red Panda C++ Version 0.14.2 - enhancement: file system view mode for project - enhancement: remove / rename / create new folder in the files view - fix: crash when there are catch blocks in the upper most scope + - change: rename "compile log" panel to "tools output" + - fix: debug panel can't be correctly show/hide + - enhancement: redesign tools output's context menu, add "clear" menu item Red Panda C++ Version 0.14.1 - enhancement: custom theme diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 6952a0de..d85ec5b3 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -91,6 +91,7 @@ SOURCES += \ todoparser.cpp \ toolsmanager.cpp \ vcs/gitmanager.cpp \ + vcs/gitrepository.cpp \ widgets/aboutdialog.cpp \ widgets/bookmarkmodel.cpp \ widgets/classbrowser.cpp \ @@ -219,6 +220,7 @@ HEADERS += \ todoparser.h \ toolsmanager.h \ vcs/gitmanager.h \ + vcs/gitrepository.h \ widgets/aboutdialog.h \ widgets/bookmarkmodel.h \ widgets/classbrowser.h \ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts index 47b2defd..f8930252 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -3096,6 +3096,14 @@ Are you really want to continue? 启用保持多语句单行选项。 + + GitManager + + + Folder "%1" already has a repository! + 文件夹"%1"中已存在仓库! + + InitChooseLanguageWidget @@ -3270,65 +3278,63 @@ Are you really want to continue? 小熊猫C++ - - - - - - - + + + + + + + Issues 编译器 - - Compile Log - 编译日志 + 编译日志 - + File 文件 - + Tools 工具 - - + + Run 运行 - + Edit 编辑 - - + + Project 项目 - + Watch 监视 - + Structure 结构 - + Files 文件 @@ -3337,85 +3343,85 @@ Are you really want to continue? 资源 - - - - - + + + + + Debug 调试 - + Evaluate: 求值 - + Debug Console 调试主控台 - + Call Stack 调用栈 - + Breakpoints 断点 - + Locals 局部变量 - - - + + + Search 查找 - + History: 历史: - + Search Again 重新查找 - + Replace with: 替换为: - + Replace 替换 - + Close 关闭 - + Execute 运行 - - + + Code 代码 - + Window 窗口 @@ -3433,390 +3439,403 @@ Are you really want to continue? 新建 - + Ctrl+N Ctrl+N - + Open... 打开... - + Ctrl+O Ctrl+O - + Save 保存 - + Ctrl+S Ctrl+S - + Save As... 另存为... - + Save As 另存为 - + Save All 全部保存 - + Ctrl+Shift+S Ctrl+Shift+S - + Options 选项 - - - + + + Compile 编译 - + + + Tools Output + 工具输出 + + + Tool Panels 工具面板 - + + Git + Git + + + F9 F9 - + F10 F10 - + Undo 恢复 - + Ctrl+Z Ctrl+Z - + Redo 重做 - + Ctrl+Y Ctrl+Y - + Cut 剪切 - + Ctrl+X Ctrl+X - + + Copy 复制 - + Ctrl+C Ctrl+C - + Paste 粘贴 - + Ctrl+V Ctrl+V - + + Select All 选择全部 - + Ctrl+A Ctrl+A - + Indent 缩进 - + UnIndent 取消缩进 - + Toggle Comment 切换注释 - + Ctrl+/ Ctrl+/ - + Collapse All 全部收起 - + Uncollapse All 全部展开 - + Encode in ANSI 使用ANSI编码 - + Encode in UTF-8 使用UTF-8编码 - + Auto Detect 自动检测 - + Convert to ANSI 转换为ANSI编码 - + Convert to UTF-8 转换为UTF-8编码 - - + + Compile & Run 编译运行 - + F11 F11 - - + + Rebuild All 全部重编译 - + F12 F12 - + Stop Execution 停止执行 - + F6 F6 - + F5 F5 - + Step Over 单步跳过 - + F7 F7 - + Step Into 单步进入 - - - + + + Problem Set 试题集 - - - + + + New Problem Set 新建试题集 - - + + Add Problem 添加试题 - - + + Remove Problem 删除试题 - - - + + + Save Problem Set 保存试题集 - - - + + + Load Problem Set 载入试题集 - + Memory 内存 - + Address Expression: Address: 地址表达式: - + Cancel 取消 - - + + TODO TODO - - + + Bookmark 书签 - - - + + + Problem 试题 - - + + Add Probem Case 添加试题案例 - - + + Remove Problem Case Remove Problem Set 删除试题集 - - + + Open Anwser Source File 打开答案源代码文件 - - + + Run All Cases Run Current Case 运行所有案例 - + Problem Cases Validation Options 测试案例验证选项 - + %v/%m %v/%m - + Output 输出 - + Input 输入 - + Expected 期望输出 - + Help 帮助 - + Refactor 重构 - + View 视图 @@ -3825,441 +3844,461 @@ Are you really want to continue? 工具窗口 - + Main 主工具栏 - + Compiler Set 编译器配置集 - - + + New Source File 新建源代码文件 - + Tab Tab - + Shift+Tab Shift+Tab - + F8 F8 - + Step Out 单步跳出 - + Ctrl+F8 Ctrl+F8 - + Run To Cursor 执行到光标处 - + Ctrl+F5 Ctrl+F5 - + Continue 继续执行 - + F4 F4 - + Add Watch... 添加监视 - + View CPU Window... 打开CPU信息窗口... - + Exit 退出 - + Find... 查找... - + Ctrl+F Ctrl+F - + Find in Files... 在文件中查找... - + Ctrl+Shift+F Ctrl+Shift+F - + Replace... 替换 - + Ctrl+R Ctrl+R - + Find Next 查找下一个 - + F3 F3 - + Find Previous 查找前一个 - + Shift+F3 Shift+F3 - + Remove Watch 删除监视值 - + Remove All Watches Remove All 删除全部监视值 - + Modify Watch... 修改监视值 - + Reformat Code 对代码重新排版 - + Ctrl+Shift+A Ctrl+Shift+A - + Go back 前一次编辑位置 - + Ctrl+Alt+Left Ctrl+Alt+Left - + Forward 后一次编辑位置 - + Ctrl+Alt+Right Ctrl+Alt+Right - + Ctrl+W Ctrl+W - + Close All 全部关闭 - + Ctrl+Shift+W Ctrl+Shift+W - + Maximize Editor 最大化编辑器 - + Ctrl+F11 Ctrl+F11 - + Next 下一窗口 - + Ctrl+Tab Ctrl+Tab - + Previous 前一窗口 - + Ctrl+Shift+Tab Ctrl+Shift+Tab - + Toggle breakpoint 切换断点 - + Ctrl+F4 Ctrl+F4 - - + + Clear all breakpoints 删除所有断点 - + Breakpoint property... 设置断点条件... - + Goto Declaration 跳转到声明处 - + Goto Definition 跳转到定义处 - + Find references 查找符号的引用 - + Open containing folder 打开所在的文件夹 - + Ctrl+B Ctrl+B - + Open a terminal here 打开命令行窗口 - + File Properties... 文件属性... - + Close Project 关闭项目 - + Project options 项目属性 - + New Project... 新建项目... - + New File 新建项目文件 - + Add to project... 添加到项目... - + Remove from project 从项目删除 - + View Makefile 查看Makefile - + Clean 清理构建文件 - + Open Folder in Explorer 在浏览器中打开 - + Open In Terminal 在终端中打开 - + About 关于 - - + + Rename Symbol 重命名符号 - + Shift+F6 Shift+F6 - + Print... 打印... - + Ctrl+P Ctrl+P - - + + Export As RTF 导出为RTF - - + + Export As HTML 导出为HTML - + Move To Other View 移动到其他视图 - + Ctrl+M Ctrl+M - - + + C++ Reference C++参考手册 - + C Reference C参考手册 - + Show Tool Panels 显示全部工具面板 + + + Create Repository + 创建仓库 + + + + Commit + 提交(Commit) + + + + Revert + 撤销(Revert) + + + + Reset + 回滚(Reset) + Tool Window Bars 工具窗口栏 - + Status Bar 状态栏 - + Ctrl+Backspace Ctrl+Backspace - + Interrupt 中断 - - + + Delete To Word Begin 删除到单词开头 - + Ctrl+Shift+B Ctrl+Shift+B - + Delete to Word End 删除到单词结尾 - + Ctrl+Shift+E Ctrl+Shift+E - + New Class... Add Class... 新建类... - - + + New Header... New Header 新建头文件... @@ -4269,47 +4308,47 @@ Are you really want to continue? 插入行 - + Delete Line 删除当前行 - + Ctrl+D Ctrl+D - + Duplicate Line 复制当前行 - + Ctrl+E Ctrl+E - + Delete Word 删除当前单词 - + Ctrl+Shift+D Ctrl+Shift+D - + Delete to EOL 删除到行尾 - + Ctrl+Del Ctrl+Del - + Delete to BOL 删除到行首 @@ -4318,43 +4357,43 @@ Are you really want to continue? C/C++参考 - + EGE Manual EGE图形库手册 - + Add Bookmark 添加书签 - + Remove Bookmark 删除书签 - + Modify Bookmark Description 修改书签说明 - + Locate in Files View 在文件视图中定位 - - + + Open Folder 打开文件夹 - + Running Parameters... 运行参数... - + File Encoding 文件编码 @@ -4569,6 +4608,7 @@ Are you really want to continue? + Clear 清除 @@ -4584,7 +4624,7 @@ Are you really want to continue? - + Problem Set %1 试题集%1 @@ -4658,15 +4698,15 @@ Are you really want to continue? - - + + Bookmark Description 书签描述 - - + + Description: 描述: @@ -4777,170 +4817,205 @@ Are you really want to continue? 跳转到定义处 - + + + + New Folder + 新建文件夹 + + + + + + + Delete + 删除 + + + Open in Editor 在编辑器中打开 - + Open in External Program 使用外部程序打开 - + Open in Terminal 在终端中打开 - + Open in Windows Explorer 在Windows浏览器中打开 - + Character sets 字符集 - + %1 files autosaved 已自动保存%1个文件 - + Set answer to... 设置答案源代码... - + select other file... 选择其他文件... - + Select Answer Source File 选择答案源代码文件 - + C/C++Source Files (*.c *.cpp *.cc *.cxx) C/C++Source Files (*.c *.cpp *.cc *.cxx C/C++源代码文件 (*.c *.cpp *.cc *.cxx) - + + Do you really want to delete %1? + 你真的要删除%1吗? + + + + Do you really want to delete %1 files? + 你真的要删除%1个文件吗? + + + Save project 保存项目 - + The project '%1' has modifications. 项目'%1'有改动。 - - + + Do you want to save it? 需要保存吗? - - + + File Changed 文件已发生变化 - + New Project File? 新建项目文件? - + Do you want to add the new file to the project? 您是否要将新建的文件加入项目? - - - - + + + + Save Error 保存失败 - + Change Project Compiler Set 改变项目编译器配置集 - + Change the project's compiler set will lose all custom compiler set options. 改变项目的编译器配置集会导致所有的自定义编译器选项被重置。 - + Do you really want to do that? 你真的想要做那些吗? - + Do you really want to clear all breakpoints in this file? 您真的要清除该文件的所有断点吗? - + New project 新建项目 - + Close %1 and start new project? 关闭'%1'以打开新项目? - + Folder not exist 文件夹不存在 - + Folder '%1' doesn't exist. Create it now? 文件夹'%1'不存在。是否创建? - + Can't create folder 无法创建文件夹 - + Failed to create folder '%1'. 创建文件夹'%1'失败。 - + Save new project as - - + + Folder %1 is not empty. + 文件夹%1不是空的。 + + + + Do you really want to delete it? + 你真的要删除它吗? + + + + Header Exists 头文件已存在 - - + + Header file "%1" already exists! 头文件"%1"已存在! - + Source Exists 源文件已存在! - + Source file "%1" already exists! 源文件"%1"已存在! @@ -4949,125 +5024,125 @@ Are you really want to continue? 小熊猫Dev-C++项目文件 (*.dev) - + New project fail 新建项目失败 - + Can't assign project template 无法使用模板创建项目 - + Remove file 删除文件 - + Remove the file from disk? 同时从硬盘上删除文件? - + untitled 无标题 - + New Project File Name 新的项目文件名 - + File Name: 文件名: - + File Already Exists! 文件已存在! - + File '%1' already exists! 文件'%1'已经存在! - + Add to project 添加到项目 - + Red Panda C++ project file (*.dev) 小熊猫C++项目文件(*.dev) - + Rename Error 重命名出错 - + Symbol '%1' is defined in system header. 符号'%1'在系统头文件中定义,无法修改。 - + New Name 新名称 - - + + Replace Error 替换出错 - + Can't open file '%1' for replace! 无法打开文件'%1'进行替换! - + Contents has changed since last search! 内容和上次查找时不一致。 - + Rich Text Format Files (*.rtf) RTF格式文件 (*.rtf) - + HTML Files (*.html) HTML文件 (*.html) - + The current problem set is not empty. 当前的试题集不是空的。 - + Problem %1 试题%1 - - + + Problem Set Files (*.pbs) 试题集文件 (*.pbs) - + Load Error 载入失败 - - + + Problem Case %1 试题案例%1 @@ -5080,13 +5155,13 @@ Are you really want to continue? - - - - - - - + + + + + + + Error 错误 @@ -5101,75 +5176,75 @@ Are you really want to continue? 载入主题失败 - + File '%1' was changed. 磁盘文件'%1'已被修改。 - + Reload its content from disk? 是否重新读取它的内容? - + File '%1' was removed. 磁盘文件'%1'已被删除。 - + Keep it open? 是否保持它在小熊猫C++中打开的编辑窗口? - + Open 打开 - + Compile Failed 编译失败 - + Run Failed 运行失败 - - + + Confirm Convertion 确认转换 - - + + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? - + New Watch Expression 新监视表达式 - + Enter Watch Expression (it is recommended to use 'this->' for class members): 输入监视表达式 - + Parsing file %1 of %2: "%3" (%1/%2)正在解析文件"%3" - - + + Done parsing %1 files in %2 seconds 完成%1个文件的解析,用时%2秒 - + (%1 files per second) (每秒%1个文件) @@ -5406,93 +5481,93 @@ Are you really want to continue? 无标题 - + Can't save file 无法保存文件 - + Can't save file '%1' 无法保存文件'%1'. - + Error Load File 载入文件错误 - + File Exists 文件已存在 - + File '%1' is already in the project 文件'%1'已在项目中 - + Project Updated 项目已升级 - + Your project was succesfully updated to a newer file format! 已成功将项目升级到新的格式 - + If something has gone wrong, we kept a backup-file: '%1'... 旧项目文件备份在'%1'。 - + Headers 头文件 - + Sources 源文件 - + Others 其他文件 - + Settings need update 设置需要更新 - + The compiler settings format of Red Panda C++ has changed. The compiler settings format of Dev-C++ has changed. 小熊猫C++的编译器设置格式已发生改变。 - + Please update your settings at Project >> Project Options >> Compiler and save your project. 请在项目 >> 项目属性 >> 编译器设置中修改您的设置并保存您的项目 - + Compiler not found 未找到编译器 - + The compiler set you have selected for this project, no longer exists. 您为该项目设置的编译器不存在。 - + It will be substituted by the global compiler set. 它将会被全局编译器设置代替。 - + Developed using the Red Panda C++ IDE Developed using the Red Panda Dev-C++ IDE 使用小熊猫C++编辑器开发 @@ -5899,24 +5974,24 @@ Are you really want to continue? ProjectModel - + File exists 文件已存在 - + File '%1' already exists. Delete it now? 文件'%1'已存在。是否删除? - - + + Remove failed 删除失败 - - + + Failed to remove file '%1' 无法删除文件'%1' @@ -6215,200 +6290,200 @@ Are you really want to continue? 无法载入自动链接设置 - - - - + + + + The following %1 directories don't exist: 下列%1文件夹不存在: - - + + binary 二进制 - + No %1 directories have been specified. 未指定%1文件夹 - + C include C包含 - - + + C++ include C++包含 - - - - + + + + Cannot find the %1 "%2" 无法找到%1程序"%2" - + C Compiler C编译器 - + C++ Compiler C++编译器 - + Maker 构建程序(Make) - + Debugger 调试器 - + C options C语言选项 - + Support all ANSI standard C programs (-ansi) 支持所有ANSI标准C程序(-ansi) - + Do not recognize asm,inline or typeof as a keyword (-fno-asm) 不支持将asm、inline和typeof作为关键字(-fno-asm) - + Imitate traditional C preprocessors (-traditional-cpp) 模仿传统C预处理器行为(-traditional-cpp) - + Code Generation 代码生成 - + Optimize for the following machine (-march) 生成特定机器的专用指令(-march) - + Optimize less, while maintaining full compatibility (-tune) 完整兼容特定机器,较少优化(-tune) - + Enable use of specific instructions (-mx) 启用特定指令集(-mx) - + Optimization level (-Ox) 优化级别(-Ox) - + Compile with the following pointer size (-mx) 使用下列指针大小编译(-mx) - + Language standard (-std) 语言标准(-std) - + Profile 性能分析 - + Generate debugging information (-g3) 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? - + Generate profiling info for analysis (-pg) 生成性能分析信息(-pg) - + Warnings 代码警告 - + Inhibit all warning messages (-w) 忽略所有警告信息(-w) - + Show most warnings (-Wall) 启用常见问题警告(-Wall) - + Show some more warnings (-Wextra) 启用更多问题警告(-Wextra) - + Check ISO C/C++/C++0x conformance (-pedantic) 检查ISO C/C++/C++0x语法一致性(-pedantic) - + Only check the code for syntax errors (-fsyntax-only) 只进行语法检查(不编译)(-fsyntax-only) - + Make all warnings into errors (-Werror) 将警告作为错误处理(-Werror) - + Abort compilation on first error (-Wfatal-errors) 遇到第一个错误后立即中止编译(-Wfatal-errors) - + Linker 链接器 - + Link an Objective C program (-lobjc) 链接Objective-C程序 (-lobjc) - + Do not use standard system libraries (-nostdlib) 不使用标准库和系统启动文件(-nostdlib) - + Do not create a console window (-mwindows) 不产生控制台窗口(-mwindows) - + Strip executable (-s) 剥除附加信息(-s) @@ -6417,54 +6492,54 @@ Are you really want to continue? 链接Ojbective C程序(-lobjc) - + Output 输出 - + Put comments in generated assembly code (-fverbose-asm) 在生成的汇编代码中加入注释(-fverbose-asm) - + Use pipes instead of temporary files during compilation (-pipe) 编译时使用管道而不是临时文件(-pipe) - + Do not assemble, compile and generate the assemble code (-S) 只生成汇编代码(-S) - - + + Confirm 确认 - + The following problems were found during validation of compiler set "%1": 在验证编译器设置"%1"时遇到了下列问题: - + Would you like Red Panda C++ to remove them for you and add the default paths to the valid paths? 是否让小熊猫C++删除这些配置,并尝试重新建立配置? - + Leaving those directories will lead to problems during compilation.<br /><br />Unless you know exactly what you're doing, it is recommended that you click Yes. 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -7215,7 +7290,7 @@ Are you really want to continue? SettingsDialog - + Options 选项 @@ -7241,239 +7316,245 @@ Are you really want to continue? 取消 - + Appearence 外观 - - - - - - + + + + + + Environment 环境 - + File Association 文件关联 - + Shortcuts 快捷键 - + Folders 文件夹 - + Terminal 终端程序 - + Performance 性能 - - + + Compiler Set 编译器配置集 - - + + Compiler 编译器 - + Auto Link 自动链接 - - - - - - - + + + + + + + General 通用 - - - - - - - - - - - + + + + + + + + + + + Editor 编辑器 - + Font 字体 - + Copy & Export 复制/导出 - + Color 配色 - + Code Completion 代码补全 - + Symbol Completion 符号补全 - + Snippet 代码模板 - + Auto Syntax Checking 自动语法检查 - + Tooltips 信息提示 - + Auto save 自动保存 - + Misc 杂项 - - - - + + + + Program Runner 程序运行 - - + + Problem Set 试题集 - + Debugger 调试器 - - + + Code Formatter 代码排版 - + Program 程序 - + + Tools 工具 - + + Git + Git + + + Project Options 项目选项 - - - - - - - - - - + + + + + + + + + + Project 项目 - + Files 文件 - + Custom Compile options 自定义编译选项 - + Directories 文件夹 - + Precompiled Header 预编译头文件 - + Makefile Makefile - + Output 输出 - + DLL host DLL宿主 - + Version info 版本信息 - + Save Changes 保存修改 - + There are changes in the settings, do you want to save them before swtich to other page? 本页中有尚未保存的设置修改,是否保存后再切换到其他页? @@ -7756,6 +7837,53 @@ Are you really want to continue? 可执行文件 (*.exe) + + ToolsGitWidget + + Form + 表单 + + + + Git + Git + + + + Test + 测试 + + + + Browse + 浏览 + + + + ... + ... + + + + Path to Git Executable: + Git程序路径 + + + + TextLabel + 选项 + + + + Git Executable + Git程序文件 + + + + All files (%1) + 所有文件 (%1) + + ToolsManager diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index fe32c699..6a146dd5 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -99,7 +99,7 @@ void CompilerManager::compile(const QString& filename, const QByteArray& encodin connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue); connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onCompileStarted); - connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog); + connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput); connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue); connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured); mCompiler->start(); @@ -129,7 +129,7 @@ void CompilerManager::compileProject(std::shared_ptr project, bool rebu connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue); connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onCompileStarted); - connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog); + connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput); connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue); connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured); mCompiler->start(); @@ -161,7 +161,7 @@ void CompilerManager::cleanProject(std::shared_ptr project) connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue); connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onCompileStarted); - connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog); + connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput); connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue); connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured); mCompiler->start(); @@ -209,7 +209,7 @@ void CompilerManager::checkSyntax(const QString &filename, const QString &conten connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, this, &CompilerManager::onSyntaxCheckIssue); connect(mBackgroundSyntaxChecker, &Compiler::compileStarted, pMainWindow, &MainWindow::onCompileStarted); connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this, &CompilerManager::onSyntaxCheckFinished); - connect(mBackgroundSyntaxChecker, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog); + connect(mBackgroundSyntaxChecker, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput); connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue); connect(mBackgroundSyntaxChecker, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured); mBackgroundSyntaxChecker->start(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index eba87d58..d35e0a72 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -677,8 +677,8 @@ void MainWindow::applyUISettings() ui->actionIssues->setChecked(settings.showIssues()); showHideMessagesTab(ui->tabIssues,settings.showIssues()); - ui->actionCompile_Log->setChecked(settings.showCompileLog()); - showHideMessagesTab(ui->tabCompilerOutput,settings.showCompileLog()); + ui->actionTools_Output->setChecked(settings.showCompileLog()); + showHideMessagesTab(ui->tabToolsOutput,settings.showCompileLog()); ui->actionDebug_Window->setChecked(settings.showDebug()); showHideMessagesTab(ui->tabDebug,settings.showDebug()); ui->actionSearch->setChecked(settings.showSearch()); @@ -1280,6 +1280,8 @@ void MainWindow::updateActionIcons() mBreakpointViewRemoveAllAction->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_CLEAN)); mBreakpointViewRemoveAction->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_CROSS)); + //Tools Output + //classbrowser mClassBrowser_Sort_By_Name->setIcon(pIconsManager->getIcon(IconsManager::ACTION_EDIT_SORT_BY_NAME)); mClassBrowser_Sort_By_Type->setIcon(pIconsManager->getIcon(IconsManager::ACTION_EDIT_SORT_BY_TYPE)); @@ -1336,14 +1338,12 @@ void MainWindow::updateActionIcons() idx = ui->tabMessages->indexOf(ui->tabSearch); if (idx>=0) ui->tabMessages->setTabIcon(idx,pIconsManager->getIcon(IconsManager::ACTION_EDIT_SEARCH)); - idx = ui->tabMessages->indexOf(ui->tabCompilerOutput); + idx = ui->tabMessages->indexOf(ui->tabToolsOutput); if (idx>=0) ui->tabMessages->setTabIcon(idx,pIconsManager->getIcon(IconsManager::ACTION_VIEW_COMPILELOG)); idx = ui->tabMessages->indexOf(ui->tabTODO); if (idx>=0) ui->tabMessages->setTabIcon(idx,pIconsManager->getIcon(IconsManager::ACTION_VIEW_TODO)); - - idx = ui->tabMessages->indexOf(ui->tabBookmark); if (idx>=0) ui->tabMessages->setTabIcon(idx,pIconsManager->getIcon(IconsManager::ACTION_VIEW_BOOKMARK)); @@ -1410,7 +1410,7 @@ bool MainWindow::compile(bool rebuild) mCompileSuccessionTask->filename = mProject->executable(); } openCloseBottomPanel(true); - ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput); + ui->tabMessages->setCurrentWidget(ui->tabToolsOutput); mCompilerManager->compileProject(mProject,rebuild); updateCompileActions(); updateAppTitle(); @@ -1426,7 +1426,7 @@ bool MainWindow::compile(bool rebuild) mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename()); } openCloseBottomPanel(true); - ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput); + ui->tabMessages->setCurrentWidget(ui->tabToolsOutput); mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild); updateCompileActions(); updateAppTitle(); @@ -2742,6 +2742,26 @@ void MainWindow::buildContextMenus() hlayout->addStretch(); } + //context menu signal for class browser + ui->txtToolsOutput->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->txtToolsOutput,&QWidget::customContextMenuRequested, + this, &MainWindow::onToolsOutputContextMenu); + mToolsOutput_Clear = createActionFor( + tr("Clear"), + ui->txtToolsOutput); + connect(mToolsOutput_Clear, &QAction::triggered, + this, &MainWindow::onToolsOutputClear); + mToolsOutput_Copy = createActionFor( + tr("Copy"), + ui->txtToolsOutput); + mToolsOutput_Copy->setShortcut(QKeySequence("Ctrl+C")); + connect(mToolsOutput_Copy, &QAction::triggered, + this, &MainWindow::onToolsOutputCopy); + mToolsOutput_SelectAll = createActionFor( + tr("Select All"), + ui->txtToolsOutput); + connect(mToolsOutput_SelectAll, &QAction::triggered, + this, &MainWindow::onToolsOutputSelectAll); } void MainWindow::buildEncodingMenu() @@ -3117,6 +3137,16 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) menu.exec(ui->lstProblemSet->mapToGlobal(pos)); } +void MainWindow::onToolsOutputContextMenu(const QPoint &pos) +{ + QMenu menu(this); + menu.addAction(mToolsOutput_Copy); + menu.addAction(mToolsOutput_SelectAll); + menu.addSeparator(); + menu.addAction(mToolsOutput_Clear); + menu.exec(ui->txtToolsOutput->mapToGlobal(pos)); +} + void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QModelIndex &/* previous */) { QModelIndex idx = current; @@ -3269,6 +3299,21 @@ void MainWindow::onEditorClosed() updateAppTitle(); } +void MainWindow::onToolsOutputClear() +{ + ui->txtToolsOutput->clear(); +} + +void MainWindow::onToolsOutputCopy() +{ + ui->txtToolsOutput->copy(); +} + +void MainWindow::onToolsOutputSelectAll() +{ + ui->txtToolsOutput->selectAll(); +} + void MainWindow::onShowInsertCodeSnippetMenu() { mMenuInsertCodeSnippet->clear(); @@ -3962,12 +4007,12 @@ void MainWindow::onCompilerSetChanged(int index) pSettings->compilerSets().saveDefaultIndex(); } -void MainWindow::onCompileLog(const QString& msg) +void MainWindow::logToolsOutput(const QString& msg) { - ui->txtCompilerOutput->appendPlainText(msg); - ui->txtCompilerOutput->moveCursor(QTextCursor::End); - ui->txtCompilerOutput->moveCursor(QTextCursor::StartOfLine); - ui->txtCompilerOutput->ensureCursorVisible(); + ui->txtToolsOutput->appendPlainText(msg); + ui->txtToolsOutput->moveCursor(QTextCursor::End); + ui->txtToolsOutput->moveCursor(QTextCursor::StartOfLine); + ui->txtToolsOutput->ensureCursorVisible(); } void MainWindow::onCompileIssue(PCompileIssue issue) @@ -3993,9 +4038,14 @@ void MainWindow::onCompileIssue(PCompileIssue issue) } } +void MainWindow::clearToolsOutput() +{ + ui->txtToolsOutput->clear(); +} + void MainWindow::onCompileStarted() { - ui->txtCompilerOutput->clear(); + //do nothing } void MainWindow::onCompileFinished(bool isCheckSyntax) @@ -6124,17 +6174,17 @@ void MainWindow::on_actionIssues_triggered() } -void MainWindow::on_actionCompile_Log_triggered() +void MainWindow::on_actionTools_Output_triggered() { - bool state = ui->actionCompile_Log->isChecked(); - ui->actionCompile_Log->setChecked(state); - showHideMessagesTab(ui->tabCompilerOutput,state); + bool state = ui->actionTools_Output->isChecked(); + ui->actionTools_Output->setChecked(state); + showHideMessagesTab(ui->tabToolsOutput,state); } void MainWindow::on_actionDebug_Window_triggered() { - bool state = ui->actionCompile_Log->isChecked(); + bool state = ui->actionDebug_Window->isChecked(); ui->actionDebug_Window->setChecked(state); showHideMessagesTab(ui->tabDebug, state); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9473a659..8202b641 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -183,8 +183,9 @@ public: bool openningFiles() const; public slots: - void onCompileLog(const QString& msg); + void logToolsOutput(const QString& msg); void onCompileIssue(PCompileIssue issue); + void clearToolsOutput(); void onCompileStarted(); void onCompileFinished(bool isCheckSyntax); void onCompileErrorOccured(const QString& reason); @@ -267,12 +268,17 @@ private slots: void onFileEncodingContextMenu(const QPoint& pos); void onFilesViewContextMenu(const QPoint& pos); void onLstProblemSetContextMenu(const QPoint& pos); + void onToolsOutputContextMenu(const QPoint&pos); + void onProblemSetIndexChanged(const QModelIndex ¤t, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex ¤t, const QModelIndex &previous); void onProblemNameChanged(int index); void onNewProblemConnection(); void updateProblemTitle(); void onEditorClosed(); + void onToolsOutputClear(); + void onToolsOutputCopy(); + void onToolsOutputSelectAll(); void onShowInsertCodeSnippetMenu(); @@ -534,7 +540,7 @@ private slots: void on_actionIssues_triggered(); - void on_actionCompile_Log_triggered(); + void on_actionTools_Output_triggered(); void on_actionDebug_Window_triggered(); @@ -690,6 +696,11 @@ private: QAction * mProblem_OpenSource; QAction * mProblem_Properties; + //action for tools output + QAction * mToolsOutput_Clear; + QAction * mToolsOutput_SelectAll; + QAction * mToolsOutput_Copy; + QSortFilterProxyModel* mProjectProxyModel; // QWidget interface diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index d904fb8f..3f0216e1 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -518,7 +518,7 @@ QTabWidget::South - 6 + 1 @@ -552,7 +552,6 @@ - 50 false @@ -581,14 +580,14 @@ - + :/icons/images/newlook24/015-compres.png - Compile Log + Tools Output @@ -604,7 +603,7 @@ 5 - + false @@ -1398,7 +1397,7 @@ 0 0 1114 - 26 + 25 @@ -1561,7 +1560,7 @@ - + @@ -1572,6 +1571,16 @@ + + + Git + + + + + + + @@ -1580,6 +1589,7 @@ + @@ -2590,12 +2600,12 @@ Issues - + true - Compile Log + Tools Output @@ -2719,6 +2729,26 @@ New Header... + + + Create Repository + + + + + Commit + + + + + Revert + + + + + Reset + + diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.ui b/RedPandaIDE/settingsdialog/toolsgitwidget.ui index c6a58cc0..d41a85c7 100644 --- a/RedPandaIDE/settingsdialog/toolsgitwidget.ui +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.ui @@ -11,7 +11,7 @@ - Form + Git diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 69b585ce..02ea4f29 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -95,25 +95,25 @@ void GitManager::revert(const QString &folder) runGit(folder,args); } -void GitManager::reset(const QString &folder, const QString &commit, ResetStrategy strategy) +void GitManager::reset(const QString &folder, const QString &commit, GitResetStrategy strategy) { //todo reset type QStringList args; args.append("reset"); switch(strategy) { - case ResetStrategy::Soft: + case GitResetStrategy::Soft: args.append("--soft"); break; - case ResetStrategy::Hard: + case GitResetStrategy::Hard: args.append("--hard"); break; - case ResetStrategy::Mixed: + case GitResetStrategy::Mixed: args.append("--mixed"); break; - case ResetStrategy::Merge: + case GitResetStrategy::Merge: args.append("--merge"); break; - case ResetStrategy::Keep: + case GitResetStrategy::Keep: args.append("--keep"); break; } diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index 684fa748..7a4ebf28 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -3,25 +3,17 @@ #include #include "utils.h" +#include "gitrepository.h" class GitError: public BaseError { public: explicit GitError(const QString& reason); }; - - class GitManager : public QObject { Q_OBJECT public: - enum class ResetStrategy { - Soft, - Hard, - Merge, - Mixed, - Keep - }; explicit GitManager(QObject *parent = nullptr); @@ -38,7 +30,7 @@ public: void clone(const QString& folder, const QString& url); void commit(const QString& folder, const QString& message); void revert(const QString& folder); - void reset(const QString& folder, const QString& commit, ResetStrategy strategy); + void reset(const QString& folder, const QString& commit, GitResetStrategy strategy); signals: void gitCmdRunning(const QString& gitCmd); diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp new file mode 100644 index 00000000..40c86e4d --- /dev/null +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -0,0 +1,84 @@ +#include "gitrepository.h" +#include "gitmanager.h" + +GitRepository::GitRepository(const QString& folder, GitManager *manager, QObject *parent) + : QObject{parent}, + mFolder(folder), + mManager(manager) +{ + Q_ASSERT(manager!=nullptr); +} + +const QString &GitRepository::folder() const +{ + return mFolder; +} + +void GitRepository::createRepository() +{ + mManager->createRepository(mFolder); +} + +bool GitRepository::hasRepository() +{ + return mManager->hasRepository(mFolder); +} + +void GitRepository::add(const QString &path) +{ + mManager->add(mFolder,path); +} + +void GitRepository::remove(const QString &path) +{ + mManager->remove(mFolder,path); +} + +void GitRepository::rename(const QString &oldName, const QString &newName) +{ + mManager->rename(mFolder, oldName, newName); +} + +void GitRepository::restore(const QString &path) +{ + mManager->restore(mFolder, path); +} + +QStringList GitRepository::listFiles(bool refresh) +{ + if (refresh || mFiles.isEmpty()) { + mFiles = mManager->listFiles(mFolder); + } + return mFiles; +} + +void GitRepository::clone(const QString &url) +{ + mManager->clone(mFolder,url); +} + +void GitRepository::commit(const QString &message) +{ + mManager->commit(mFolder, message); +} + +void GitRepository::revert() +{ + mManager->revert(mFolder); +} + +void GitRepository::reset(const QString &commit, GitResetStrategy strategy) +{ + mManager->reset(mFolder,commit,strategy); +} + +GitManager *GitRepository::manager() const +{ + return mManager; +} + +void GitRepository::setManager(GitManager *newManager) +{ + Q_ASSERT(newManager!=nullptr); + mManager = newManager; +} diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h new file mode 100644 index 00000000..4710e337 --- /dev/null +++ b/RedPandaIDE/vcs/gitrepository.h @@ -0,0 +1,48 @@ +#ifndef GITREPOSITORY_H +#define GITREPOSITORY_H + +#include +#include + +enum class GitResetStrategy { + Soft, + Hard, + Merge, + Mixed, + Keep +}; + +class GitManager; +class GitRepository : public QObject +{ + Q_OBJECT +public: + explicit GitRepository(const QString& folder, GitManager* manager, QObject *parent = nullptr); + + const QString &folder() const; + + void createRepository(); + bool hasRepository(); + + void add(const QString& path); + void remove(const QString& path); + void rename(const QString& oldName, const QString& newName); + void restore(const QString& path); + QStringList listFiles(bool refresh); + + void clone(const QString& url); + void commit(const QString& message); + void revert(); + void reset(const QString& commit, GitResetStrategy strategy); + + GitManager *manager() const; + void setManager(GitManager *newManager); + +signals: +private: + QString mFolder; + GitManager* mManager; + QStringList mFiles; +}; + +#endif // GITREPOSITORY_H From 76ea34709d10fb51f51a71b2118ccc8d6c867c2b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 13 Feb 2022 21:50:20 +0800 Subject: [PATCH 5/9] add icons for vcs --- .../newlook/filesystem/cfile-vcs-changed.svg | 119 ++++++++++++ .../newlook/filesystem/cfile-vcs-nochange.svg | 123 +++++++++++++ .../filesystem/cppfile-vcs-changed.svg | 150 ++++++++++++++++ .../filesystem/cppfile-vcs-nochange.svg | 151 ++++++++++++++++ .../newlook/filesystem/file-vcs-changed.svg | 115 ++++++++++++ .../newlook/filesystem/file-vcs-nochange.svg | 119 ++++++++++++ .../newlook/filesystem/folder-vcs-changed.svg | 92 ++++++++++ .../filesystem/folder-vcs-nochange.svg | 93 ++++++++++ .../newlook/filesystem/hfile-vcs-changed.svg | 119 ++++++++++++ .../newlook/filesystem/hfile-vcs-nochange.svg | 123 +++++++++++++ .../filesystem/projectfile-vcs-changed.svg | 165 +++++++++++++++++ .../filesystem/projectfile-vcs-nochange.svg | 169 ++++++++++++++++++ .../newlook/filesystem/{git.svg => vcs.svg} | 0 RedPandaIDE/widgets/customfilesystemmodel.cpp | 21 +++ RedPandaIDE/widgets/customfilesystemmodel.h | 25 +++ 15 files changed, 1584 insertions(+) create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-nochange.svg rename RedPandaIDE/resources/iconsets/newlook/filesystem/{git.svg => vcs.svg} (100%) create mode 100644 RedPandaIDE/widgets/customfilesystemmodel.cpp create mode 100644 RedPandaIDE/widgets/customfilesystemmodel.h diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-changed.svg new file mode 100644 index 00000000..9774f39a --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-nochange.svg new file mode 100644 index 00000000..324065c7 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-changed.svg new file mode 100644 index 00000000..7c09e1a1 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-changed.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-nochange.svg new file mode 100644 index 00000000..31718dba --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-nochange.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-changed.svg new file mode 100644 index 00000000..bc727ca3 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-changed.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-nochange.svg new file mode 100644 index 00000000..8420fab5 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-nochange.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-changed.svg new file mode 100644 index 00000000..5a9abb6b --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-changed.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-nochange.svg new file mode 100644 index 00000000..4df3204f --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-nochange.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-changed.svg new file mode 100644 index 00000000..af8fe84d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-nochange.svg new file mode 100644 index 00000000..75e83585 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-changed.svg new file mode 100644 index 00000000..ba7a50cd --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-changed.svg @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-nochange.svg new file mode 100644 index 00000000..88541b45 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-nochange.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/git.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/vcs.svg similarity index 100% rename from RedPandaIDE/resources/iconsets/newlook/filesystem/git.svg rename to RedPandaIDE/resources/iconsets/newlook/filesystem/vcs.svg diff --git a/RedPandaIDE/widgets/customfilesystemmodel.cpp b/RedPandaIDE/widgets/customfilesystemmodel.cpp new file mode 100644 index 00000000..34c6fc62 --- /dev/null +++ b/RedPandaIDE/widgets/customfilesystemmodel.cpp @@ -0,0 +1,21 @@ +#include "customfilesystemmodel.h" +#include "../vcs/gitmanager.h" +#include "../vcs/gitrepository.h" + +CustomFileSystemModel::CustomFileSystemModel(QObject *parent) : QFileSystemModel(parent) +{ + mGitManager = new GitManager(this); + mGitRepository = new GitRepository("",mGitManager,mGitManager); + connect(this,&QFileSystemModel::rootPathChanged, + this, &CustomFileSystemModel::onRootPathChanged); +} + +QVariant CustomFileSystemModel::data(const QModelIndex &index, int role) const +{ + return QFileSystemModel::data(index,role); +} + +void CustomFileSystemModel::onRootPathChanged(const QString &folder) +{ + mGitRepository->setFolder(folder); +} diff --git a/RedPandaIDE/widgets/customfilesystemmodel.h b/RedPandaIDE/widgets/customfilesystemmodel.h new file mode 100644 index 00000000..04762279 --- /dev/null +++ b/RedPandaIDE/widgets/customfilesystemmodel.h @@ -0,0 +1,25 @@ +#ifndef CUSTOMFILESYSTEMMODEL_H +#define CUSTOMFILESYSTEMMODEL_H + +#include + + +class GitRepository; +class GitManager; +class CustomFileSystemModel : public QFileSystemModel +{ + Q_OBJECT +public: + explicit CustomFileSystemModel(QObject *parent = nullptr); + + // QAbstractItemModel interface +public: + QVariant data(const QModelIndex &index, int role) const override; +private slots: + void onRootPathChanged(const QString& folder); +private: + GitRepository *mGitRepository; + GitManager *mGitManager; +}; + +#endif // CUSTOMFILESYSTEMMODEL_H From 0d71282a1a2685e513d351faee0e62edd16c7de5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 14 Feb 2022 00:13:00 +0800 Subject: [PATCH 6/9] work save: icons for files tracked by git --- RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/customfileiconprovider.cpp | 60 ++++++- RedPandaIDE/customfileiconprovider.h | 5 +- RedPandaIDE/iconsmanager.cpp | 18 ++ RedPandaIDE/iconsmanager.h | 18 ++ RedPandaIDE/mainwindow.ui | 6 +- RedPandaIDE/project.cpp | 40 +++-- RedPandaIDE/project.h | 5 +- .../newlook/filesystem/cfile-vcs-staged.svg | 134 ++++++++++++++ .../newlook/filesystem/cppfile-vcs-staged.svg | 148 ++++++++++++++++ .../newlook/filesystem/file-vcs-staged.svg | 120 +++++++++++++ .../newlook/filesystem/folder-vcs-staged.svg | 94 ++++++++++ .../newlook/filesystem/{vcs.svg => git.svg} | 0 .../newlook/filesystem/hfile-vcs-staged.svg | 124 +++++++++++++ .../filesystem/projectfile-vcs-staged.svg | 166 ++++++++++++++++++ RedPandaIDE/settingsdialog/toolsgitwidget.cpp | 1 + RedPandaIDE/vcs/gitmanager.cpp | 78 +++++--- RedPandaIDE/vcs/gitmanager.h | 11 +- RedPandaIDE/vcs/gitrepository.cpp | 9 +- RedPandaIDE/vcs/gitrepository.h | 4 +- 20 files changed, 993 insertions(+), 50 deletions(-) create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-staged.svg rename RedPandaIDE/resources/iconsets/newlook/filesystem/{vcs.svg => git.svg} (100%) create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-staged.svg diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 12e4592b..f1befd7e 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -139,6 +139,7 @@ SOURCES += \ widgets/coloredit.cpp \ widgets/consolewidget.cpp \ widgets/customdisablediconengine.cpp \ + widgets/customfilesystemmodel.cpp \ widgets/custommakefileinfodialog.cpp \ widgets/darkfusionstyle.cpp \ widgets/editorstabwidget.cpp \ @@ -270,6 +271,7 @@ HEADERS += \ widgets/coloredit.h \ widgets/consolewidget.h \ widgets/customdisablediconengine.h \ + widgets/customfilesystemmodel.h \ widgets/custommakefileinfodialog.h \ widgets/darkfusionstyle.h \ widgets/editorstabwidget.h \ diff --git a/RedPandaIDE/customfileiconprovider.cpp b/RedPandaIDE/customfileiconprovider.cpp index c28af730..3a11b57a 100644 --- a/RedPandaIDE/customfileiconprovider.cpp +++ b/RedPandaIDE/customfileiconprovider.cpp @@ -1,9 +1,15 @@ #include "customfileiconprovider.h" #include "iconsmanager.h" +#include "vcs/gitmanager.h" CustomFileIconProvider::CustomFileIconProvider() { + mVCSManager = new GitManager(); +} +CustomFileIconProvider::~CustomFileIconProvider() +{ + delete mVCSManager; } QIcon CustomFileIconProvider::icon(IconType type) const @@ -20,14 +26,56 @@ QIcon CustomFileIconProvider::icon(IconType type) const QIcon CustomFileIconProvider::icon(const QFileInfo &info) const { QIcon icon; - if (isHFile(info.fileName())) - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE); - else if (isCppFile(info.fileName())) { - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE); + if (info.isDir()) { + if (mVCSManager && mVCSManager->isFileInRepository(info)) { + if (mVCSManager->isFileInStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_STAGED); + else if (mVCSManager->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE); + } else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER); + } if (isHFile(info.fileName())) { + if (mVCSManager && mVCSManager->isFileInRepository(info)) { + if (mVCSManager->isFileInStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_STAGED); + else if (mVCSManager->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_NOCHANGE); + } else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE); + } else if (isCppFile(info.fileName())) { + if (mVCSManager && mVCSManager->isFileInRepository(info)) { + if (mVCSManager->isFileInStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_STAGED); + else if (mVCSManager->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_NOCHANGE); + } else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE); } else if (isCFile(info.fileName())) { - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE); + if (mVCSManager && mVCSManager->isFileInRepository(info)) { + if (mVCSManager->isFileInStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_STAGED); + else if (mVCSManager->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_NOCHANGE); + } else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE); } else if (info.suffix()=="dev") { - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE); + if (mVCSManager && mVCSManager->isFileInRepository(info)) { + if (mVCSManager->isFileInStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_STAGED); + else if (mVCSManager->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_NOCHANGE); + } else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE); } if (!icon.isNull()) return icon; diff --git a/RedPandaIDE/customfileiconprovider.h b/RedPandaIDE/customfileiconprovider.h index 890ca9f9..c5e339f2 100644 --- a/RedPandaIDE/customfileiconprovider.h +++ b/RedPandaIDE/customfileiconprovider.h @@ -3,11 +3,14 @@ #include +class GitManager; class CustomFileIconProvider : public QFileIconProvider { public: CustomFileIconProvider(); - + ~CustomFileIconProvider(); +private: + GitManager* mVCSManager; // QFileIconProvider interface public: QIcon icon(IconType type) const override; diff --git a/RedPandaIDE/iconsmanager.cpp b/RedPandaIDE/iconsmanager.cpp index 12e2be12..b4159153 100644 --- a/RedPandaIDE/iconsmanager.cpp +++ b/RedPandaIDE/iconsmanager.cpp @@ -181,11 +181,29 @@ void IconsManager::updateFileSystemIcons(const QString &iconSet, int size) updateMakeDisabledIconDarker(iconSet); mIconPixmaps.insert(FILESYSTEM_GIT, createSVGIcon(iconFolder+"git.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_FOLDER, createSVGIcon(iconFolder+"folder.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_CHANGED, createSVGIcon(iconFolder+"folder-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_NOCHANGE, createSVGIcon(iconFolder+"folder-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_STAGED, createSVGIcon(iconFolder+"folder-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_FILE, createSVGIcon(iconFolder+"file.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FILE_VCS_CHANGED, createSVGIcon(iconFolder+"file-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"file-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_FILE_VCS_STAGED, createSVGIcon(iconFolder+"file-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_CFILE, createSVGIcon(iconFolder+"cfile.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_CHANGED, createSVGIcon(iconFolder+"cfile-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"cfile-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_STAGED, createSVGIcon(iconFolder+"cfile-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_HFILE, createSVGIcon(iconFolder+"hfile.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_CHANGED, createSVGIcon(iconFolder+"hfile-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"hfile-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_STAGED, createSVGIcon(iconFolder+"hfile-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_CPPFILE, createSVGIcon(iconFolder+"cppfile.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_CHANGED, createSVGIcon(iconFolder+"cppfile-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"cppfile-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_STAGED, createSVGIcon(iconFolder+"cppfile-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_PROJECTFILE, createSVGIcon(iconFolder+"projectfile.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_CHANGED, createSVGIcon(iconFolder+"projectfile-vcs-changed.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"projectfile-vcs-nochange.svg",size,size)); + mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_STAGED, createSVGIcon(iconFolder+"projectfile-vcs-staged.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_HEADERS_FOLDER, createSVGIcon(iconFolder+"headerfolder.svg",size,size)); mIconPixmaps.insert(FILESYSTEM_SOURCES_FOLDER, createSVGIcon(iconFolder+"sourcefolder.svg",size,size)); } diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index 13138c6f..703230bd 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -72,6 +72,24 @@ public: FILESYSTEM_HFILE, FILESYSTEM_PROJECTFILE, FILESYSTEM_CPPFILE, + FILESYSTEM_FOLDER_VCS_CHANGED, + FILESYSTEM_FILE_VCS_CHANGED, + FILESYSTEM_CFILE_VCS_CHANGED, + FILESYSTEM_HFILE_VCS_CHANGED, + FILESYSTEM_PROJECTFILE_VCS_CHANGED, + FILESYSTEM_CPPFILE_VCS_CHANGED, + FILESYSTEM_FOLDER_VCS_NOCHANGE, + FILESYSTEM_FILE_VCS_NOCHANGE, + FILESYSTEM_CFILE_VCS_NOCHANGE, + FILESYSTEM_HFILE_VCS_NOCHANGE, + FILESYSTEM_PROJECTFILE_VCS_NOCHANGE, + FILESYSTEM_CPPFILE_VCS_NOCHANGE, + FILESYSTEM_FOLDER_VCS_STAGED, + FILESYSTEM_FILE_VCS_STAGED, + FILESYSTEM_CFILE_VCS_STAGED, + FILESYSTEM_HFILE_VCS_STAGED, + FILESYSTEM_PROJECTFILE_VCS_STAGED, + FILESYSTEM_CPPFILE_VCS_STAGED, FILESYSTEM_HEADERS_FOLDER, FILESYSTEM_SOURCES_FOLDER, diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 16578ae6..7f07ab76 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -291,6 +291,9 @@ QAbstractItemView::ExtendedSelection + + false + @@ -573,6 +576,7 @@ + 50 false @@ -1418,7 +1422,7 @@ 0 0 1114 - 25 + 26 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 6db736ff..2ff7d963 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -36,6 +36,7 @@ #include "customfileiconprovider.h" #include #include "settings.h" +#include "vcs/gitmanager.h" Project::Project(const QString &filename, const QString &name, QObject *parent) : QObject(parent), @@ -1909,6 +1910,12 @@ ProjectModel::ProjectModel(Project *project, QObject *parent): mProject(project) { mUpdateCount = 0; + mVCSManager = new GitManager(); +} + +ProjectModel::~ProjectModel() +{ + delete mVCSManager; } void ProjectModel::beginUpdate() @@ -1980,7 +1987,14 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const ProjectModelNode* p = static_cast(index.internalPointer()); if (!p) return QVariant(); - if (role == Qt::DisplayRole || role==Qt::EditRole) { + if (role == Qt::DisplayRole) { + if (p == mProject->rootNode().get()) { + QString branch; + if (mVCSManager->hasRepository(mProject->folder(),branch)) + return QString("%1 [%2]").arg(p->text,branch); + } + return p->text; + } else if (role==Qt::EditRole) { return p->text; } else if (role == Qt::DecorationRole) { CustomFileIconProvider provider; @@ -1988,15 +2002,21 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const if (p->unitIndex>=0) { icon = provider.icon(mProject->units()[p->unitIndex]->fileName()); } else { - switch(p->folderNodeType) { - case ProjectSpecialFolderNode::HEADERS: - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HEADERS_FOLDER); - break; - case ProjectSpecialFolderNode::SOURCES: - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_SOURCES_FOLDER); - break; - default: - icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER); + if (p == mProject->rootNode().get()) { + QString branch; + if (mVCSManager->hasRepository(mProject->folder(),branch)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT); + } else { + switch(p->folderNodeType) { + case ProjectSpecialFolderNode::HEADERS: + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HEADERS_FOLDER); + break; + case ProjectSpecialFolderNode::SOURCES: + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_SOURCES_FOLDER); + break; + default: + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER); + } } if (icon.isNull()) icon = provider.icon(QFileIconProvider::Folder); diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 73927200..d55477b7 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -101,16 +101,20 @@ private: using PProjectUnit = std::shared_ptr; +class GitManager; class ProjectModel : public QAbstractItemModel { Q_OBJECT public: explicit ProjectModel(Project* project, QObject* parent=nullptr); + ~ProjectModel(); void beginUpdate(); void endUpdate(); private: Project* mProject; + GitManager *mVCSManager; int mUpdateCount; + // QAbstractItemModel interface public: QModelIndex index(int row, int column, const QModelIndex &parent) const override; @@ -143,7 +147,6 @@ protected: bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; }; - class ProjectTemplate; class Project : public QObject { diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-staged.svg new file mode 100644 index 00000000..3828e08e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cfile-vcs-staged.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-staged.svg new file mode 100644 index 00000000..d157b152 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/cppfile-vcs-staged.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-staged.svg new file mode 100644 index 00000000..8109db78 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/file-vcs-staged.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-staged.svg new file mode 100644 index 00000000..4f4f113e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/folder-vcs-staged.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/vcs.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/git.svg similarity index 100% rename from RedPandaIDE/resources/iconsets/newlook/filesystem/vcs.svg rename to RedPandaIDE/resources/iconsets/newlook/filesystem/git.svg diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-staged.svg new file mode 100644 index 00000000..2852d6d2 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/hfile-vcs-staged.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-staged.svg new file mode 100644 index 00000000..d099b25d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/newlook/filesystem/projectfile-vcs-staged.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.cpp b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp index 0f24384f..780ff259 100644 --- a/RedPandaIDE/settingsdialog/toolsgitwidget.cpp +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp @@ -28,6 +28,7 @@ void ToolsGitWidget::doLoad() void ToolsGitWidget::doSave() { pSettings->vcs().setGitPath(ui->txtGitPath->text()); + pSettings->vcs().save(); } void ToolsGitWidget::updateIcons(const QSize &size) diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 02ea4f29..9454887e 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -1,34 +1,74 @@ #include "gitmanager.h" #include "../utils.h" +#include "../settings.h" #include -GitManager::GitManager(QObject *parent) : QObject(parent), - mGitPathValid(false) +GitManager::GitManager(QObject *parent) : QObject(parent) { } -bool GitManager::gitPathValid() const -{ - return mGitPathValid; -} - void GitManager::createRepository(const QString &folder) { - if (hasRepository(folder)) + QString currentBranch; + if (hasRepository(folder,currentBranch)) throw GitError(tr("Folder \"%1\" already has a repository!")); QStringList args; args.append("init"); runGit(folder,args); } -bool GitManager::hasRepository(const QString &folder) +bool GitManager::hasRepository(const QString &folder, QString& currentBranch) { QStringList args; args.append("status"); + args.append("-b"); + args.append("-u"); + args.append("no"); + args.append("--ignored=no"); QString output = runGit(folder,args); - return !output.startsWith("fatal:"); + bool result = output.startsWith("On branch"); + if (result) { + int pos = QString("On branch").length(); + while (posvcs().gitPath()); if (!fileInfo.exists()) - throw GitError("fatal: git doesn't exist"); + return "fatal: git doesn't exist"; emit gitCmdRunning(QString("Running in \"%1\": \n \"%2\" \"%3\"") .arg(workingFolder, - mGitPath, + pSettings->vcs().gitPath(), args.join("\" \""))); QString output = runAndGetOutput( fileInfo.absoluteFilePath(), workingFolder, args); emit gitCmdFinished(output); - if (output.startsWith("fatal:")) - throw GitError(output); +// if (output.startsWith("fatal:")) +// throw GitError(output); return output; } diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index 7a4ebf28..05373d9f 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -2,6 +2,7 @@ #define GITMANAGER_H #include +#include #include "utils.h" #include "gitrepository.h" @@ -17,9 +18,12 @@ public: explicit GitManager(QObject *parent = nullptr); - bool gitPathValid() const; void createRepository(const QString& folder); - bool hasRepository(const QString& folder); + bool hasRepository(const QString& folder, QString& currentBranch); + + bool isFileInRepository(const QFileInfo& fileInfo); + bool isFileInStaged(const QFileInfo& fileInfo); + bool isFileChanged(const QFileInfo& fileInfo); void add(const QString& folder, const QString& path); void remove(const QString& folder, const QString& path); @@ -36,11 +40,8 @@ signals: void gitCmdRunning(const QString& gitCmd); void gitCmdFinished(const QString& message); private: - void validate(); QString runGit(const QString& workingFolder, const QStringList& args); private: - QString mGitPath; - bool mGitPathValid; }; #endif // GITMANAGER_H diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index 40c86e4d..3134c764 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -19,9 +19,9 @@ void GitRepository::createRepository() mManager->createRepository(mFolder); } -bool GitRepository::hasRepository() +bool GitRepository::hasRepository(QString& currentBranch) { - return mManager->hasRepository(mFolder); + return mManager->hasRepository(mFolder, currentBranch); } void GitRepository::add(const QString &path) @@ -82,3 +82,8 @@ void GitRepository::setManager(GitManager *newManager) Q_ASSERT(newManager!=nullptr); mManager = newManager; } + +void GitRepository::setFolder(const QString &newFolder) +{ + mFolder = newFolder; +} diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h index 4710e337..96cf84ab 100644 --- a/RedPandaIDE/vcs/gitrepository.h +++ b/RedPandaIDE/vcs/gitrepository.h @@ -22,7 +22,7 @@ public: const QString &folder() const; void createRepository(); - bool hasRepository(); + bool hasRepository(QString& currentBranch); void add(const QString& path); void remove(const QString& path); @@ -38,6 +38,8 @@ public: GitManager *manager() const; void setManager(GitManager *newManager); + void setFolder(const QString &newFolder); + signals: private: QString mFolder; From de230c63c707cef5a4ff9cced2f24765cd1b9fee Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 14 Feb 2022 09:53:16 +0800 Subject: [PATCH 7/9] add icons --- .../bluesky/filesystem/cfile-vcs-changed.svg | 119 ++++++++++++ .../bluesky/filesystem/cfile-vcs-nochange.svg | 123 +++++++++++++ .../bluesky/filesystem/cfile-vcs-staged.svg | 134 ++++++++++++++ .../iconsets/bluesky/filesystem/cfile.svg | 108 +++++++++++ .../filesystem/cppfile-vcs-changed.svg | 150 ++++++++++++++++ .../filesystem/cppfile-vcs-nochange.svg | 151 ++++++++++++++++ .../bluesky/filesystem/cppfile-vcs-staged.svg | 148 +++++++++++++++ .../iconsets/bluesky/filesystem/cppfile.svg | 132 ++++++++++++++ .../bluesky/filesystem/file-vcs-changed.svg | 115 ++++++++++++ .../bluesky/filesystem/file-vcs-nochange.svg | 119 ++++++++++++ .../bluesky/filesystem/file-vcs-staged.svg | 120 +++++++++++++ .../iconsets/bluesky/filesystem/file.svg | 104 +++++++++++ .../bluesky/filesystem/folder-vcs-changed.svg | 92 ++++++++++ .../filesystem/folder-vcs-nochange.svg | 93 ++++++++++ .../bluesky/filesystem/folder-vcs-staged.svg | 94 ++++++++++ .../iconsets/bluesky/filesystem/folder.svg | 78 ++++++++ .../bluesky/filesystem/headerfolder.svg | 82 +++++++++ .../bluesky/filesystem/hfile-vcs-changed.svg | 119 ++++++++++++ .../bluesky/filesystem/hfile-vcs-nochange.svg | 123 +++++++++++++ .../bluesky/filesystem/hfile-vcs-staged.svg | 124 +++++++++++++ .../iconsets/bluesky/filesystem/hfile.svg | 108 +++++++++++ .../filesystem/projectfile-vcs-changed.svg | 165 +++++++++++++++++ .../filesystem/projectfile-vcs-nochange.svg | 169 ++++++++++++++++++ .../filesystem/projectfile-vcs-staged.svg | 166 +++++++++++++++++ .../bluesky/filesystem/projectfile.svg | 150 ++++++++++++++++ .../bluesky/filesystem/sourcefolder.svg | 82 +++++++++ .../contrast/filesystem/cfile-vcs-changed.svg | 119 ++++++++++++ .../filesystem/cfile-vcs-nochange.svg | 123 +++++++++++++ .../contrast/filesystem/cfile-vcs-staged.svg | 134 ++++++++++++++ .../iconsets/contrast/filesystem/cfile.svg | 108 +++++++++++ .../filesystem/cppfile-vcs-changed.svg | 150 ++++++++++++++++ .../filesystem/cppfile-vcs-nochange.svg | 151 ++++++++++++++++ .../filesystem/cppfile-vcs-staged.svg | 148 +++++++++++++++ .../iconsets/contrast/filesystem/cppfile.svg | 132 ++++++++++++++ .../contrast/filesystem/file-vcs-changed.svg | 115 ++++++++++++ .../contrast/filesystem/file-vcs-nochange.svg | 119 ++++++++++++ .../contrast/filesystem/file-vcs-staged.svg | 120 +++++++++++++ .../iconsets/contrast/filesystem/file.svg | 104 +++++++++++ .../filesystem/folder-vcs-changed.svg | 92 ++++++++++ .../filesystem/folder-vcs-nochange.svg | 93 ++++++++++ .../contrast/filesystem/folder-vcs-staged.svg | 94 ++++++++++ .../iconsets/contrast/filesystem/folder.svg | 78 ++++++++ .../contrast/filesystem/headerfolder.svg | 82 +++++++++ .../contrast/filesystem/hfile-vcs-changed.svg | 119 ++++++++++++ .../filesystem/hfile-vcs-nochange.svg | 123 +++++++++++++ .../contrast/filesystem/hfile-vcs-staged.svg | 124 +++++++++++++ .../iconsets/contrast/filesystem/hfile.svg | 108 +++++++++++ .../filesystem/projectfile-vcs-changed.svg | 165 +++++++++++++++++ .../filesystem/projectfile-vcs-nochange.svg | 169 ++++++++++++++++++ .../filesystem/projectfile-vcs-staged.svg | 166 +++++++++++++++++ .../contrast/filesystem/projectfile.svg | 150 ++++++++++++++++ .../contrast/filesystem/sourcefolder.svg | 82 +++++++++ 52 files changed, 6336 insertions(+) create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/file.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/folder.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/headerfolder.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile.svg create mode 100644 RedPandaIDE/resources/iconsets/bluesky/filesystem/sourcefolder.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cfile.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/file.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/folder.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/headerfolder.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/hfile.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-changed.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-nochange.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-staged.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile.svg create mode 100644 RedPandaIDE/resources/iconsets/contrast/filesystem/sourcefolder.svg diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-changed.svg new file mode 100644 index 00000000..9774f39a --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-nochange.svg new file mode 100644 index 00000000..324065c7 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-staged.svg new file mode 100644 index 00000000..3828e08e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile-vcs-staged.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile.svg new file mode 100644 index 00000000..650c0de9 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cfile.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-changed.svg new file mode 100644 index 00000000..7c09e1a1 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-changed.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-nochange.svg new file mode 100644 index 00000000..31718dba --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-nochange.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-staged.svg new file mode 100644 index 00000000..d157b152 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile-vcs-staged.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile.svg new file mode 100644 index 00000000..d7d2c0a8 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/cppfile.svg @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-changed.svg new file mode 100644 index 00000000..bc727ca3 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-changed.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-nochange.svg new file mode 100644 index 00000000..8420fab5 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-nochange.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-staged.svg new file mode 100644 index 00000000..8109db78 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file-vcs-staged.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/file.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file.svg new file mode 100644 index 00000000..819de1ed --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/file.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-changed.svg new file mode 100644 index 00000000..5a9abb6b --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-changed.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-nochange.svg new file mode 100644 index 00000000..4df3204f --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-nochange.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-staged.svg new file mode 100644 index 00000000..4f4f113e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder-vcs-staged.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder.svg new file mode 100644 index 00000000..714caabb --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/folder.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/headerfolder.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/headerfolder.svg new file mode 100644 index 00000000..5021a799 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/headerfolder.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-changed.svg new file mode 100644 index 00000000..af8fe84d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-nochange.svg new file mode 100644 index 00000000..75e83585 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-staged.svg new file mode 100644 index 00000000..2852d6d2 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile-vcs-staged.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile.svg new file mode 100644 index 00000000..dec5a3f6 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/hfile.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-changed.svg new file mode 100644 index 00000000..ba7a50cd --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-changed.svg @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-nochange.svg new file mode 100644 index 00000000..88541b45 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-nochange.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-staged.svg new file mode 100644 index 00000000..d099b25d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile-vcs-staged.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile.svg new file mode 100644 index 00000000..03095458 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/projectfile.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/bluesky/filesystem/sourcefolder.svg b/RedPandaIDE/resources/iconsets/bluesky/filesystem/sourcefolder.svg new file mode 100644 index 00000000..7712f510 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/bluesky/filesystem/sourcefolder.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-changed.svg new file mode 100644 index 00000000..9774f39a --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-nochange.svg new file mode 100644 index 00000000..324065c7 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-staged.svg new file mode 100644 index 00000000..3828e08e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile-vcs-staged.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile.svg new file mode 100644 index 00000000..650c0de9 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cfile.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-changed.svg new file mode 100644 index 00000000..7c09e1a1 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-changed.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-nochange.svg new file mode 100644 index 00000000..31718dba --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-nochange.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-staged.svg new file mode 100644 index 00000000..d157b152 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile-vcs-staged.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile.svg new file mode 100644 index 00000000..d7d2c0a8 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/cppfile.svg @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-changed.svg new file mode 100644 index 00000000..bc727ca3 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-changed.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-nochange.svg new file mode 100644 index 00000000..8420fab5 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-nochange.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-staged.svg new file mode 100644 index 00000000..8109db78 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/file-vcs-staged.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/file.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/file.svg new file mode 100644 index 00000000..819de1ed --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/file.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-changed.svg new file mode 100644 index 00000000..5a9abb6b --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-changed.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-nochange.svg new file mode 100644 index 00000000..4df3204f --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-nochange.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-staged.svg new file mode 100644 index 00000000..4f4f113e --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder-vcs-staged.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/folder.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder.svg new file mode 100644 index 00000000..714caabb --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/folder.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/headerfolder.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/headerfolder.svg new file mode 100644 index 00000000..5021a799 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/headerfolder.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-changed.svg new file mode 100644 index 00000000..af8fe84d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-changed.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-nochange.svg new file mode 100644 index 00000000..75e83585 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-nochange.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-staged.svg new file mode 100644 index 00000000..2852d6d2 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile-vcs-staged.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile.svg new file mode 100644 index 00000000..dec5a3f6 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/hfile.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-changed.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-changed.svg new file mode 100644 index 00000000..ba7a50cd --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-changed.svg @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-nochange.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-nochange.svg new file mode 100644 index 00000000..88541b45 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-nochange.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-staged.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-staged.svg new file mode 100644 index 00000000..d099b25d --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile-vcs-staged.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile.svg new file mode 100644 index 00000000..03095458 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/projectfile.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RedPandaIDE/resources/iconsets/contrast/filesystem/sourcefolder.svg b/RedPandaIDE/resources/iconsets/contrast/filesystem/sourcefolder.svg new file mode 100644 index 00000000..7712f510 --- /dev/null +++ b/RedPandaIDE/resources/iconsets/contrast/filesystem/sourcefolder.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + From 664922a301aa397ba4a351dce62bf59c0e4cb860 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 15 Feb 2022 00:01:50 +0800 Subject: [PATCH 8/9] - fix: convert to encoding setting in compiler set option not correctly handled work save: git repository class --- NEWS.md | 4 + RedPandaIDE/compiler/compiler.cpp | 3 +- RedPandaIDE/customfileiconprovider.cpp | 48 +++--- RedPandaIDE/customfileiconprovider.h | 6 +- RedPandaIDE/editor.cpp | 2 +- RedPandaIDE/main.cpp | 5 + RedPandaIDE/mainwindow.cpp | 142 +++++++++++++++++- RedPandaIDE/mainwindow.h | 10 +- RedPandaIDE/mainwindow.ui | 7 +- RedPandaIDE/project.cpp | 17 ++- RedPandaIDE/project.h | 6 +- RedPandaIDE/settings.cpp | 57 ++++++- RedPandaIDE/settings.h | 5 + .../compilersetoptionwidget.cpp | 2 +- RedPandaIDE/settingsdialog/toolsgitwidget.cpp | 2 + RedPandaIDE/systemconsts.h | 2 + RedPandaIDE/utils.cpp | 2 + RedPandaIDE/vcs/gitmanager.cpp | 123 ++++++++++++++- RedPandaIDE/vcs/gitmanager.h | 9 +- RedPandaIDE/vcs/gitrepository.cpp | 62 +++++--- RedPandaIDE/vcs/gitrepository.h | 37 ++++- RedPandaIDE/widgets/customfilesystemmodel.cpp | 8 - RedPandaIDE/widgets/customfilesystemmodel.h | 5 - 23 files changed, 479 insertions(+), 85 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0ce389c3..9f962658 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,15 @@ - change: rename "compile log" panel to "tools output" - fix: debug panel can't be correctly show/hide - enhancement: redesign tools output's context menu, add "clear" menu item + - enhancement: tools -> git in the options dialog + - enhancement: auto detect git in PATH + - enhancement: basic git commands Red Panda C++ Version 0.14.3 - fix: wrong code completion font size, when screen dpi changed - enhancement: replace Files View Panel's path lineedit control with combo box - enhancement: custome icons for project view + - fix: convert to encoding setting in compiler set option not correctly handled Red Panda C++ Version 0.14.2 - enhancement: file system view mode for project diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 7114bd31..a84fa2cb 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -292,8 +292,7 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding) } else { encodingName = encoding; } - if (compilerSetExecCharset == ENCODING_SYSTEM_DEFAULT - || compilerSetExecCharset.isEmpty()) { + if (compilerSetExecCharset == ENCODING_SYSTEM_DEFAULT || compilerSetExecCharset.isEmpty()) { execEncodingName = systemEncodingName; } else { execEncodingName = compilerSetExecCharset; diff --git a/RedPandaIDE/customfileiconprovider.cpp b/RedPandaIDE/customfileiconprovider.cpp index 3a11b57a..9610c5ea 100644 --- a/RedPandaIDE/customfileiconprovider.cpp +++ b/RedPandaIDE/customfileiconprovider.cpp @@ -1,15 +1,25 @@ #include "customfileiconprovider.h" #include "iconsmanager.h" -#include "vcs/gitmanager.h" +#include "vcs/gitrepository.h" CustomFileIconProvider::CustomFileIconProvider() { - mVCSManager = new GitManager(); + mVCSRepository = new GitRepository(""); } CustomFileIconProvider::~CustomFileIconProvider() { - delete mVCSManager; + delete mVCSRepository; +} + +void CustomFileIconProvider::setRootFolder(const QString &folder) +{ + mVCSRepository->setFolder(folder); +} + +void CustomFileIconProvider::update() +{ + mVCSRepository->update(); } QIcon CustomFileIconProvider::icon(IconType type) const @@ -27,50 +37,50 @@ QIcon CustomFileIconProvider::icon(const QFileInfo &info) const { QIcon icon; if (info.isDir()) { - if (mVCSManager && mVCSManager->isFileInRepository(info)) { - if (mVCSManager->isFileInStaged(info)) + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_STAGED); - else if (mVCSManager->isFileChanged(info)) + else if (mVCSRepository->isFileChanged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_CHANGED); else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE); } else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER); - } if (isHFile(info.fileName())) { - if (mVCSManager && mVCSManager->isFileInRepository(info)) { - if (mVCSManager->isFileInStaged(info)) + } else if (isHFile(info.fileName())) { + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_STAGED); - else if (mVCSManager->isFileChanged(info)) + else if (mVCSRepository->isFileChanged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_CHANGED); else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE_VCS_NOCHANGE); } else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HFILE); } else if (isCppFile(info.fileName())) { - if (mVCSManager && mVCSManager->isFileInRepository(info)) { - if (mVCSManager->isFileInStaged(info)) + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_STAGED); - else if (mVCSManager->isFileChanged(info)) + else if (mVCSRepository->isFileChanged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_CHANGED); else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE_VCS_NOCHANGE); } else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CPPFILE); } else if (isCFile(info.fileName())) { - if (mVCSManager && mVCSManager->isFileInRepository(info)) { - if (mVCSManager->isFileInStaged(info)) + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_STAGED); - else if (mVCSManager->isFileChanged(info)) + else if (mVCSRepository->isFileChanged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_CHANGED); else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE_VCS_NOCHANGE); } else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_CFILE); } else if (info.suffix()=="dev") { - if (mVCSManager && mVCSManager->isFileInRepository(info)) { - if (mVCSManager->isFileInStaged(info)) + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_STAGED); - else if (mVCSManager->isFileChanged(info)) + else if (mVCSRepository->isFileChanged(info)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_CHANGED); else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_NOCHANGE); diff --git a/RedPandaIDE/customfileiconprovider.h b/RedPandaIDE/customfileiconprovider.h index c5e339f2..5e79a45a 100644 --- a/RedPandaIDE/customfileiconprovider.h +++ b/RedPandaIDE/customfileiconprovider.h @@ -3,14 +3,16 @@ #include -class GitManager; +class GitRepository; class CustomFileIconProvider : public QFileIconProvider { public: CustomFileIconProvider(); ~CustomFileIconProvider(); + void setRootFolder(const QString& folder); + void update(); private: - GitManager* mVCSManager; + GitRepository* mVCSRepository; // QFileIconProvider interface public: QIcon icon(IconType type) const override; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 638614bd..e0a4b75f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -68,7 +68,7 @@ const char* SaveException::what() const noexcept { } Editor::Editor(QWidget *parent): - Editor(parent,QObject::tr("untitled"),ENCODING_SYSTEM_DEFAULT,false,true,nullptr) + Editor(parent,QObject::tr("untitled"),ENCODING_AUTO_DETECT,false,true,nullptr) { } diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 4097dc21..7e6e1803 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -162,6 +162,11 @@ int main(int argc, char *argv[]) //set default open folder QDir::setCurrent(pSettings->environment().defaultOpenFolder()); + //auto detect git in path + if (!pSettings->vcs().gitOk()) { + pSettings->vcs().detectGitInPath(); + } + MainWindow mainWindow; pMainWindow = &mainWindow; if (app.arguments().count()>1) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 3ffc4cdf..c893fe5e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -39,6 +39,7 @@ #include "iconsmanager.h" #include "widgets/newclassdialog.h" #include "widgets/newheaderdialog.h" +#include "vcs/gitmanager.h" #include #include @@ -287,7 +288,7 @@ MainWindow::MainWindow(QWidget *parent) //files view ui->treeFiles->setModel(&mFileSystemModel); mFileSystemModel.setReadOnly(false); - mFileSystemModel.setIconProvider(&mFileIconProvider); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); setFilesViewRoot(pSettings->environment().currentFolder()); for (int i=1;itreeFiles->hideColumn(i); @@ -324,6 +325,9 @@ MainWindow::MainWindow(QWidget *parent) ui->actionEGE_Manual->setVisible(pSettings->environment().language()=="zh_CN"); + //git menu + connect(ui->menuGit, &QMenu::aboutToShow, + this, &MainWindow::updateVCSActions); buildContextMenus(); updateAppTitle(); //applySettings(); @@ -425,7 +429,8 @@ void MainWindow::updateEditorActions() ui->actionAuto_Detect->setEnabled(true); ui->actionEncode_in_ANSI->setEnabled(true); ui->actionEncode_in_UTF_8->setEnabled(true); - ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT && e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT); + ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT + && e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT); ui->actionConvert_to_UTF_8->setEnabled(e->encodingOption()!=ENCODING_UTF8 && e->fileEncoding()!=ENCODING_UTF8); ui->actionCopy->setEnabled(e->selAvail()); @@ -663,6 +668,8 @@ void MainWindow::applySettings() // ui->cbFilesPath->setItemIcon(i,pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); // } + ui->menuGit->menuAction()->setVisible(pSettings->vcs().gitOk()); + } void MainWindow::applyUISettings() @@ -2968,7 +2975,12 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos) onRoot = true; } } + GitManager vcsManager; + QString branch; + bool hasRepository = vcsManager.hasRepository(mProject->folder(),branch); + QMenu menu(this); + QMenu vcsMenu(this); updateProjectActions(); menu.addAction(ui->actionProject_New_File); menu.addAction(ui->actionNew_Class); @@ -2981,6 +2993,15 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos) menu.addAction(mProject_Rename_Unit); } menu.addSeparator(); + if (pSettings->vcs().gitOk()) { + if (hasRepository) { + menu.addMenu(&vcsMenu); + } else { + ui->actionGit_Create_Repository->setEnabled(true); + menu.addAction(ui->actionGit_Create_Repository); + } + menu.addSeparator(); + } if (onFolder && mProject->modelType()==ProjectModelType::Custom) { menu.addAction(mProject_Add_Folder); if (!onRoot) { @@ -3001,6 +3022,18 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos) } menu.addAction(ui->actionProject_options); + if (pSettings->vcs().gitOk() && hasRepository) { + vcsMenu.setTitle(tr("VCS")); + if (ui->projectView->selectionModel()->hasSelection()) + vcsMenu.addAction(ui->actionGit_Add_Files); + vcsMenu.addAction(ui->actionGit_Commit); + vcsMenu.addAction(ui->actionGit_Reset); + vcsMenu.addAction(ui->actionGit_Revert); + + ui->actionGit_Commit->setEnabled(true); + ui->actionGit_Reset->setEnabled(true); + ui->actionGit_Revert->setEnabled(true); + } menu.exec(ui->projectView->mapToGlobal(pos)); } @@ -3054,12 +3087,24 @@ void MainWindow::onFileEncodingContextMenu(const QPoint &pos) void MainWindow::onFilesViewContextMenu(const QPoint &pos) { - + GitManager vcsManager; + QString branch; + bool hasRepository = vcsManager.hasRepository(pSettings->environment().currentFolder(),branch); QMenu menu(this); + QMenu vcsMenu(this); menu.addAction(ui->actionOpen_Folder); menu.addSeparator(); menu.addAction(mFilesView_CreateFolder); menu.addSeparator(); + if (pSettings->vcs().gitOk()) { + if (hasRepository) { + menu.addMenu(&vcsMenu); + } else { + ui->actionGit_Create_Repository->setEnabled(true); + menu.addAction(ui->actionGit_Create_Repository); + } + menu.addSeparator(); + } menu.addAction(mFilesView_Open); menu.addAction(mFilesView_OpenWithExternal); menu.addSeparator(); @@ -3071,6 +3116,19 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos) mFilesView_OpenWithExternal->setEnabled(info.isFile()); mFilesView_OpenInTerminal->setEnabled(!path.isEmpty()); mFilesView_OpenInExplorer->setEnabled(!path.isEmpty()); + + if (pSettings->vcs().gitOk() && hasRepository) { + vcsMenu.setTitle(tr("VCS")); + if (ui->treeFiles->selectionModel()->hasSelection()) + vcsMenu.addAction(ui->actionGit_Add_Files); + vcsMenu.addAction(ui->actionGit_Commit); + vcsMenu.addAction(ui->actionGit_Reset); + vcsMenu.addAction(ui->actionGit_Revert); + + ui->actionGit_Commit->setEnabled(true); + ui->actionGit_Reset->setEnabled(true); + ui->actionGit_Revert->setEnabled(true); + } menu.exec(ui->treeFiles->mapToGlobal(pos)); } @@ -5501,6 +5559,7 @@ void MainWindow::newProjectUnitFile() PProjectUnit newUnit = mProject->newUnit( mProject->pointerToNode(node),newFileName); idx = mProject->units().count()-1; + mProject->rebuildNodes(); mProject->saveUnits(); updateProjectView(); Editor * editor = mProject->openUnit(idx); @@ -5528,6 +5587,27 @@ void MainWindow::doFilesViewRemoveFile(const QModelIndex &index) } } +void MainWindow::updateVCSActions() +{ + bool hasRepository = false; + bool shouldEnable = false; + if (ui->projectView->isVisible()) { + GitManager vcsManager; + QString branch; + hasRepository = vcsManager.hasRepository(mProject->folder(),branch); + shouldEnable = true; + } else if (ui->treeFiles->isVisible()) { + GitManager vcsManager; + QString branch; + hasRepository = vcsManager.hasRepository(pSettings->environment().currentFolder(),branch); + shouldEnable = true; + } + ui->actionGit_Create_Repository->setEnabled(!hasRepository && shouldEnable); + ui->actionGit_Commit->setEnabled(hasRepository && shouldEnable); + ui->actionGit_Reset->setEnabled(hasRepository && shouldEnable); + ui->actionGit_Revert->setEnabled(hasRepository && shouldEnable); +} + void MainWindow::invalidateProjectProxyModel() { mProjectProxyModel->invalidate(); @@ -5663,6 +5743,7 @@ void MainWindow::showSearchReplacePanel(bool show) void MainWindow::setFilesViewRoot(const QString &path) { + mFileSystemModelIconProvider.setRootFolder(path); mFileSystemModel.setRootPath(path); ui->treeFiles->setRootIndex(mFileSystemModel.index(path)); pSettings->environment().setCurrentFolder(path); @@ -6450,3 +6531,58 @@ void MainWindow::on_actionNew_Class_triggered() pSettings->ui().setNewHeaderDialogHeight(dialog.height()); } + +void MainWindow::on_actionGit_Create_Repository_triggered() +{ + if (ui->treeFiles->isVisible()) { + GitManager vcsManager; + vcsManager.createRepository(pSettings->environment().currentFolder()); + int pos = ui->cbFilesPath->findText(pSettings->environment().currentFolder()); + if (pos>=0) { + ui->cbFilesPath->setItemIcon(pos, pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); + } + } else if (ui->projectView->isVisible()) { + GitManager vcsManager; + vcsManager.createRepository(mProject->folder()); + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + } +} + + +void MainWindow::on_actionGit_Add_Files_triggered() +{ + if (ui->treeFiles->isVisible()) { + GitManager vcsManager; + QModelIndexList indices = ui->treeFiles->selectionModel()->selectedRows(); + foreach (const QModelIndex index,indices) { + QFileInfo info = mFileSystemModel.fileInfo(index); + vcsManager.add(info.absolutePath(),info.fileName()); + } + //update icons in files view + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + } else if (ui->projectView->isVisible()) { + GitManager vcsManager; + QModelIndexList indices = ui->projectView->selectionModel()->selectedRows(); + foreach (const QModelIndex index,indices) { + QModelIndex realIndex = mProjectProxyModel->mapToSource(index); + ProjectModelNode * node = static_cast(realIndex.internalPointer()); + PProjectModelNode folderNode = mProject->pointerToNode(node); + if (!folderNode) + continue; + if (folderNode->unitIndex>=0) { + PProjectUnit unit = mProject->units()[folderNode->unitIndex]; + QFileInfo info(unit->fileName()); + vcsManager.add(info.absolutePath(),info.fileName()); + } + } + //update icons in project view + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + //update icons in files view too + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + } +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 169736a0..214c52cf 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -38,6 +38,7 @@ #include "widgets/labelwithmenu.h" #include "widgets/bookmarkmodel.h" #include "widgets/ojproblemsetmodel.h" +#include "widgets/customfilesystemmodel.h" #include "customfileiconprovider.h" @@ -253,6 +254,7 @@ private: void doFilesViewRemoveFile(const QModelIndex& index); private slots: + void updateVCSActions(); void invalidateProjectProxyModel(); void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); void onAutoSaveTimeout(); @@ -576,6 +578,10 @@ private slots: void on_actionNew_Header_triggered(); + void on_actionGit_Create_Repository_triggered(); + + void on_actionGit_Add_Files_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; @@ -615,8 +621,8 @@ private: PCodeSnippetManager mCodeSnippetManager; PTodoParser mTodoParser; PToolsManager mToolsManager; - QFileSystemModel mFileSystemModel; - CustomFileIconProvider mFileIconProvider; + CustomFileSystemModel mFileSystemModel; + CustomFileIconProvider mFileSystemModelIconProvider; OJProblemSetModel mOJProblemSetModel; OJProblemModel mOJProblemModel; int mOJProblemSetNameCounter; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 7f07ab76..35a5c356 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -229,7 +229,7 @@ - 0 + 2 0 @@ -2774,6 +2774,11 @@ Reset + + + Add Files + + diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 2ff7d963..1d166bf5 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -1910,12 +1910,14 @@ ProjectModel::ProjectModel(Project *project, QObject *parent): mProject(project) { mUpdateCount = 0; - mVCSManager = new GitManager(); + mVCSRepository = new GitRepository(""); + mIconProvider = new CustomFileIconProvider(); } ProjectModel::~ProjectModel() { - delete mVCSManager; + delete mVCSRepository; + delete mIconProvider; } void ProjectModel::beginUpdate() @@ -1930,6 +1932,8 @@ void ProjectModel::endUpdate() { mUpdateCount--; if (mUpdateCount==0) { + mVCSRepository->setFolder(mProject->folder()); + mIconProvider->setRootFolder(mProject->folder()); endResetModel(); } } @@ -1990,21 +1994,20 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { if (p == mProject->rootNode().get()) { QString branch; - if (mVCSManager->hasRepository(mProject->folder(),branch)) + if (mVCSRepository->hasRepository(branch)) return QString("%1 [%2]").arg(p->text,branch); } return p->text; } else if (role==Qt::EditRole) { return p->text; } else if (role == Qt::DecorationRole) { - CustomFileIconProvider provider; QIcon icon; if (p->unitIndex>=0) { - icon = provider.icon(mProject->units()[p->unitIndex]->fileName()); + icon = mIconProvider->icon(mProject->units()[p->unitIndex]->fileName()); } else { if (p == mProject->rootNode().get()) { QString branch; - if (mVCSManager->hasRepository(mProject->folder(),branch)) + if (mVCSRepository->hasRepository(branch)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT); } else { switch(p->folderNodeType) { @@ -2019,7 +2022,7 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const } } if (icon.isNull()) - icon = provider.icon(QFileIconProvider::Folder); + icon = mIconProvider->icon(QFileIconProvider::Folder); } return icon; } diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index d55477b7..063dc19e 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -101,7 +101,8 @@ private: using PProjectUnit = std::shared_ptr; -class GitManager; +class GitRepository; +class CustomFileIconProvider; class ProjectModel : public QAbstractItemModel { Q_OBJECT public: @@ -111,8 +112,9 @@ public: void endUpdate(); private: Project* mProject; - GitManager *mVCSManager; + GitRepository *mVCSRepository; int mUpdateCount; + CustomFileIconProvider* mIconProvider; // QAbstractItemModel interface diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 6b79d874..d0d7d47c 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -5083,9 +5083,9 @@ void Settings::UI::doLoad() mNewHeaderDialogHeight = intValue("new_header_dialog_height", 300*qApp->desktop()->height()/1080); } -Settings::VCS::VCS(Settings *settings):_Base(settings,SETTING_VCS) +Settings::VCS::VCS(Settings *settings):_Base(settings,SETTING_VCS), + mGitOk(false) { - } void Settings::VCS::doSave() @@ -5095,7 +5095,7 @@ void Settings::VCS::doSave() void Settings::VCS::doLoad() { - mGitPath = stringValue("git_path", ""); + setGitPath(stringValue("git_path", "")); } const QString &Settings::VCS::gitPath() const @@ -5105,5 +5105,54 @@ const QString &Settings::VCS::gitPath() const void Settings::VCS::setGitPath(const QString &newGitPath) { - mGitPath = newGitPath; + if (mGitPath!=newGitPath) { + mGitPath = newGitPath; + validateGit(); + } +} + +void Settings::VCS::validateGit() +{ + mGitOk = false; + QFileInfo fileInfo(mGitPath); + if (!fileInfo.exists()) { + return; + } + QStringList args; + args.append("--version"); + QString output = runAndGetOutput( + fileInfo.fileName(), + fileInfo.absolutePath(), + args); + mGitOk = output.startsWith("git version"); +} + +bool Settings::VCS::gitOk() const +{ + return mGitOk; +} + +void Settings::VCS::detectGitInPath() +{ + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + QString path = env.value("PATH"); + QStringList pathList = path.split(PATH_SEPARATOR); + QSet searched; + foreach (const QString& s, pathList){ + if (searched.contains(s)) + continue;; + searched.insert(s); + QDir dir(s); + if (dir.exists(GIT_PROGRAM)) { + QString oldPath = mGitPath; + setGitPath(dir.filePath(GIT_PROGRAM)); + if (mGitOk) { + doSave(); + return; + } else { + mGitPath = oldPath; + } + } + + } } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index d331b159..1b198018 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -887,8 +887,13 @@ public: explicit VCS(Settings *settings); const QString &gitPath() const; void setGitPath(const QString &newGitPath); + bool gitOk() const; + void detectGitInPath(); + private: + void validateGit(); private: QString mGitPath; + bool mGitOk; protected: void doSave() override; void doLoad() override; diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index 5a8a535f..e3850d49 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -246,7 +246,7 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet() if (ui->cbEncodingDetails->isVisible()) { pSet->setExecCharset(ui->cbEncodingDetails->currentText()); } else { - pSet->setExecCharset(ui->cbEncoding->currentText()); + pSet->setExecCharset(ui->cbEncoding->currentData().toString()); } //read values in the options widget diff --git a/RedPandaIDE/settingsdialog/toolsgitwidget.cpp b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp index 780ff259..2be01b35 100644 --- a/RedPandaIDE/settingsdialog/toolsgitwidget.cpp +++ b/RedPandaIDE/settingsdialog/toolsgitwidget.cpp @@ -4,6 +4,7 @@ #include "../settings.h" #include "../systemconsts.h" #include "../utils.h" +#include "../mainwindow.h" #include @@ -29,6 +30,7 @@ void ToolsGitWidget::doSave() { pSettings->vcs().setGitPath(ui->txtGitPath->text()); pSettings->vcs().save(); + pMainWindow->applySettings(); } void ToolsGitWidget::updateIcons(const QSize &size) diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index e60b313f..498821d6 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -31,6 +31,7 @@ #define GPROF_PROGRAM "gprof.exe" #define CLEAN_PROGRAM "del /q /f" #define CPP_PROGRAM "cpp.exe" +#define GIT_PROGRAM "git.exe" #elif defined(Q_OS_LINUX) #define GCC_PROGRAM "gcc" #define GPP_PROGRAM "g++" @@ -42,6 +43,7 @@ #define GPROF_PROGRAM "gprof" #define CLEAN_PROGRAM "rm -rf" #define CPP_PROGRAM "cpp" +#define GIT_PROGRAM "git" #else #error "Only support windows and linux now!" #endif diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 5e6ef97c..4b0bd02e 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -1140,3 +1140,5 @@ void copyFolder(const QString &fromDir, const QString &toDir) } } } + + diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 9454887e..c77ae6a5 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -2,6 +2,7 @@ #include "../utils.h" #include "../settings.h" +#include #include GitManager::GitManager(QObject *parent) : QObject(parent) @@ -16,6 +17,16 @@ void GitManager::createRepository(const QString &folder) QStringList args; args.append("init"); runGit(folder,args); + + QStringList contents; + contents.append(".git"); + contents.append("*.o"); + contents.append("*.exe"); + contents.append("*."); + + QDir dir(folder); + stringsToFile(contents,dir.filePath(".gitignore")); + add(folder,".gitignore"); } bool GitManager::hasRepository(const QString &folder, QString& currentBranch) @@ -50,7 +61,7 @@ bool GitManager::isFileInRepository(const QFileInfo& fileInfo) return output.trimmed() == fileInfo.fileName(); } -bool GitManager::isFileInStaged(const QFileInfo &fileInfo) +bool GitManager::isFileStaged(const QFileInfo &fileInfo) { QStringList args; args.append("diff"); @@ -111,6 +122,23 @@ QStringList GitManager::listFiles(const QString &folder) return textToLines(runGit(folder,args)); } +QStringList GitManager::listStagedFiles(const QString &folder) +{ + QStringList args; + args.append("diff"); + args.append("--staged"); + args.append("--name-only"); + return textToLines(runGit(folder,args)); +} + +QStringList GitManager::listChangedFiles(const QString &folder) +{ + QStringList args; + args.append("diff"); + args.append("--name-only"); + return textToLines(runGit(folder,args)); +} + void GitManager::clone(const QString &folder, const QString &url) { QStringList args; @@ -161,8 +189,15 @@ void GitManager::reset(const QString &folder, const QString &commit, GitResetStr runGit(folder,args); } +bool GitManager::isValid() +{ + return pSettings->vcs().gitOk(); +} + QString GitManager::runGit(const QString& workingFolder, const QStringList &args) { + if (!isValid()) + return ""; QFileInfo fileInfo(pSettings->vcs().gitPath()); if (!fileInfo.exists()) return "fatal: git doesn't exist"; @@ -174,12 +209,98 @@ QString GitManager::runGit(const QString& workingFolder, const QStringList &args fileInfo.absoluteFilePath(), workingFolder, args); + output = escapeUTF8String(output.toUtf8()); emit gitCmdFinished(output); // if (output.startsWith("fatal:")) // throw GitError(output); return output; } +QString GitManager::escapeUTF8String(const QByteArray &rawString) +{ + QByteArray stringValue; + int p = 0; + while (p=rawString.length() || + rawString[p+i]<'0' || rawString[p+i]>'7') + break; + } + bool ok; + unsigned char ch = rawString.mid(p,i).toInt(&ok,8); + stringValue+=ch; + p+=i; + break; + } + } + } else { + if (ch!='\"') + stringValue+=ch; + p++; + } + } + return QString::fromUtf8(stringValue); +} + GitError::GitError(const QString &reason):BaseError(reason) { diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index 05373d9f..4cf1a204 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -3,6 +3,7 @@ #include #include +#include #include "utils.h" #include "gitrepository.h" @@ -22,7 +23,7 @@ public: bool hasRepository(const QString& folder, QString& currentBranch); bool isFileInRepository(const QFileInfo& fileInfo); - bool isFileInStaged(const QFileInfo& fileInfo); + bool isFileStaged(const QFileInfo& fileInfo); bool isFileChanged(const QFileInfo& fileInfo); void add(const QString& folder, const QString& path); @@ -30,17 +31,23 @@ public: void rename(const QString& folder, const QString& oldName, const QString& newName); void restore(const QString& folder, const QString& path); QStringList listFiles(const QString& folder); + QStringList listStagedFiles(const QString& folder); + QStringList listChangedFiles(const QString& folder); void clone(const QString& folder, const QString& url); void commit(const QString& folder, const QString& message); void revert(const QString& folder); void reset(const QString& folder, const QString& commit, GitResetStrategy strategy); + bool isValid(); + signals: void gitCmdRunning(const QString& gitCmd); void gitCmdFinished(const QString& message); private: QString runGit(const QString& workingFolder, const QStringList& args); + + QString escapeUTF8String(const QByteArray& rawString); private: }; diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index 3134c764..f6e6a70e 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -1,12 +1,17 @@ #include "gitrepository.h" #include "gitmanager.h" -GitRepository::GitRepository(const QString& folder, GitManager *manager, QObject *parent) +GitRepository::GitRepository(const QString& folder, QObject *parent) : QObject{parent}, - mFolder(folder), - mManager(manager) + mInRepository(false) { - Q_ASSERT(manager!=nullptr); + mManager = new GitManager(); + setFolder(folder); +} + +GitRepository::~GitRepository() +{ + delete mManager; } const QString &GitRepository::folder() const @@ -21,7 +26,8 @@ void GitRepository::createRepository() bool GitRepository::hasRepository(QString& currentBranch) { - return mManager->hasRepository(mFolder, currentBranch); + currentBranch = mBranch; + return mInRepository; } void GitRepository::add(const QString &path) @@ -44,12 +50,11 @@ void GitRepository::restore(const QString &path) mManager->restore(mFolder, path); } -QStringList GitRepository::listFiles(bool refresh) +QSet GitRepository::listFiles(bool refresh) { - if (refresh || mFiles.isEmpty()) { - mFiles = mManager->listFiles(mFolder); - } - return mFiles; + if (refresh) + update(); + return mFilesInRepositories; } void GitRepository::clone(const QString &url) @@ -72,18 +77,33 @@ void GitRepository::reset(const QString &commit, GitResetStrategy strategy) mManager->reset(mFolder,commit,strategy); } -GitManager *GitRepository::manager() const -{ - return mManager; -} - -void GitRepository::setManager(GitManager *newManager) -{ - Q_ASSERT(newManager!=nullptr); - mManager = newManager; -} - void GitRepository::setFolder(const QString &newFolder) { mFolder = newFolder; + update(); } + +void GitRepository::update() +{ + if (!mManager->isValid()) { + mInRepository = false; + mBranch = ""; + mFilesInRepositories.clear(); + mChangedFiles.clear(); + mStagedFiles.clear(); + } else { + mInRepository = mManager->hasRepository(mFolder,mBranch); + convertFilesListToSet(mManager->listFiles(mFolder),mFilesInRepositories); + convertFilesListToSet(mManager->listChangedFiles(mFolder),mChangedFiles); + convertFilesListToSet(mManager->listStagedFiles(mFolder),mStagedFiles); + } +} + +void GitRepository::convertFilesListToSet(const QStringList &filesList, QSet &set) +{ + set.clear(); + foreach (const QString& s, filesList) { + set.insert(includeTrailingPathDelimiter(mFolder)+s); + } +} + diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h index 96cf84ab..7b6e1db0 100644 --- a/RedPandaIDE/vcs/gitrepository.h +++ b/RedPandaIDE/vcs/gitrepository.h @@ -1,7 +1,9 @@ #ifndef GITREPOSITORY_H #define GITREPOSITORY_H +#include #include +#include #include enum class GitResetStrategy { @@ -17,34 +19,59 @@ class GitRepository : public QObject { Q_OBJECT public: - explicit GitRepository(const QString& folder, GitManager* manager, QObject *parent = nullptr); + explicit GitRepository(const QString& folder, QObject *parent = nullptr); + ~GitRepository(); const QString &folder() const; void createRepository(); bool hasRepository(QString& currentBranch); + bool isFileInRepository(const QFileInfo& fileInfo) { + return isFileInRepository(fileInfo.absoluteFilePath()); + } + bool isFileInRepository(const QString& filePath) { + return mFilesInRepositories.contains(filePath); + } + bool isFileStaged(const QFileInfo& fileInfo) { + return isFileStaged(fileInfo.absoluteFilePath()); + } + bool isFileStaged(const QString& filePath) { + return mStagedFiles.contains(filePath); + } + bool isFileChanged(const QFileInfo& fileInfo) { + return isFileChanged(fileInfo.absoluteFilePath()); + } + bool isFileChanged(const QString& filePath) { + return mChangedFiles.contains(filePath); + } + void add(const QString& path); void remove(const QString& path); void rename(const QString& oldName, const QString& newName); void restore(const QString& path); - QStringList listFiles(bool refresh); + QSet listFiles(bool refresh); void clone(const QString& url); void commit(const QString& message); void revert(); void reset(const QString& commit, GitResetStrategy strategy); - GitManager *manager() const; - void setManager(GitManager *newManager); void setFolder(const QString &newFolder); + void update(); signals: private: QString mFolder; + bool mInRepository; + QString mBranch; GitManager* mManager; - QStringList mFiles; + QSet mFilesInRepositories; + QSet mChangedFiles; + QSet mStagedFiles; +private: + void convertFilesListToSet(const QStringList& filesList,QSet& set); }; #endif // GITREPOSITORY_H diff --git a/RedPandaIDE/widgets/customfilesystemmodel.cpp b/RedPandaIDE/widgets/customfilesystemmodel.cpp index 34c6fc62..6bf3e517 100644 --- a/RedPandaIDE/widgets/customfilesystemmodel.cpp +++ b/RedPandaIDE/widgets/customfilesystemmodel.cpp @@ -4,10 +4,6 @@ CustomFileSystemModel::CustomFileSystemModel(QObject *parent) : QFileSystemModel(parent) { - mGitManager = new GitManager(this); - mGitRepository = new GitRepository("",mGitManager,mGitManager); - connect(this,&QFileSystemModel::rootPathChanged, - this, &CustomFileSystemModel::onRootPathChanged); } QVariant CustomFileSystemModel::data(const QModelIndex &index, int role) const @@ -15,7 +11,3 @@ QVariant CustomFileSystemModel::data(const QModelIndex &index, int role) const return QFileSystemModel::data(index,role); } -void CustomFileSystemModel::onRootPathChanged(const QString &folder) -{ - mGitRepository->setFolder(folder); -} diff --git a/RedPandaIDE/widgets/customfilesystemmodel.h b/RedPandaIDE/widgets/customfilesystemmodel.h index 04762279..a87730ed 100644 --- a/RedPandaIDE/widgets/customfilesystemmodel.h +++ b/RedPandaIDE/widgets/customfilesystemmodel.h @@ -15,11 +15,6 @@ public: // QAbstractItemModel interface public: QVariant data(const QModelIndex &index, int role) const override; -private slots: - void onRootPathChanged(const QString& folder); -private: - GitRepository *mGitRepository; - GitManager *mGitManager; }; #endif // CUSTOMFILESYSTEMMODEL_H From b5acf154678934e86cedc639d6fd330a5c7d1f4a Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 15 Feb 2022 17:22:44 +0800 Subject: [PATCH 9/9] work save: commit --- RedPandaIDE/editor.cpp | 2 +- RedPandaIDE/editor.h | 1 + RedPandaIDE/editorlist.cpp | 2 + RedPandaIDE/mainwindow.cpp | 63 +++++++++++++++++++++++++++---- RedPandaIDE/mainwindow.h | 4 +- RedPandaIDE/vcs/gitmanager.cpp | 8 ++++ RedPandaIDE/vcs/gitmanager.h | 2 + RedPandaIDE/vcs/gitrepository.cpp | 35 +++++++++++------ RedPandaIDE/vcs/gitrepository.h | 5 ++- 9 files changed, 101 insertions(+), 21 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index e0a4b75f..f3670d70 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -226,7 +226,7 @@ void Editor::saveFile(QString filename) { this->lines()->saveToFile(file,mEncodingOption, pSettings->editor().useUTF8ByDefault()? ENCODING_UTF8 : QTextCodec::codecForLocale()->name(), mFileEncoding); - pMainWindow->updateForEncodingInfo(); + emit fileSaved(filename, mInProject); } void Editor::convertToEncoding(const QByteArray &encoding) diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index beef612c..9eb62ed5 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -225,6 +225,7 @@ public: void tab() override; signals: void renamed(const QString& oldName, const QString& newName, bool firstSave); + void fileSaved(const QString& filename, bool inProject); private slots: void onStatusChanged(SynStatusChanges changes); void onGutterClicked(Qt::MouseButton button, int x, int y, int line); diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 4ebf7ccc..03f4727d 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -62,6 +62,8 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin e->setInProject(true); } } + connect(e,&Editor::fileSaved, + pMainWindow, &MainWindow::onFileSaved); return e; } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index c893fe5e..917b7ae6 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -40,6 +40,7 @@ #include "widgets/newclassdialog.h" #include "widgets/newheaderdialog.h" #include "vcs/gitmanager.h" +#include "vcs/gitrepository.h" #include #include @@ -744,6 +745,22 @@ void MainWindow::updateDPI() applySettings(); } +void MainWindow::onFileSaved(const QString &path, bool inProject) +{ + qDebug()<model()->beginUpdate(); + mProject->model()->endUpdate(); + } + QModelIndex index = mFileSystemModel.index(path); + if (index.isValid()) { + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + ui->treeFiles->update(index); + } + pMainWindow->updateForEncodingInfo(); +} + void MainWindow::updateAppTitle() { QString appName=tr("Red Panda C++"); @@ -5591,7 +5608,7 @@ void MainWindow::updateVCSActions() { bool hasRepository = false; bool shouldEnable = false; - if (ui->projectView->isVisible()) { + if (ui->projectView->isVisible() && mProject) { GitManager vcsManager; QString branch; hasRepository = vcsManager.hasRepository(mProject->folder(),branch); @@ -5747,6 +5764,7 @@ void MainWindow::setFilesViewRoot(const QString &path) mFileSystemModel.setRootPath(path); ui->treeFiles->setRootIndex(mFileSystemModel.index(path)); pSettings->environment().setCurrentFolder(path); + QDir::setCurrent(path); int pos = ui->cbFilesPath->findText(path); if (pos<0) { ui->cbFilesPath->addItem(mFileSystemModel.iconProvider()->icon(QFileIconProvider::Folder),path); @@ -6541,9 +6559,11 @@ void MainWindow::on_actionGit_Create_Repository_triggered() if (pos>=0) { ui->cbFilesPath->setItemIcon(pos, pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); } - } else if (ui->projectView->isVisible()) { + } else if (ui->projectView->isVisible() && mProject) { GitManager vcsManager; vcsManager.createRepository(mProject->folder()); + } + if (mProject) { mProject->model()->beginUpdate(); mProject->model()->endUpdate(); } @@ -6562,7 +6582,7 @@ void MainWindow::on_actionGit_Add_Files_triggered() //update icons in files view mFileSystemModelIconProvider.update(); mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); - } else if (ui->projectView->isVisible()) { + } else if (ui->projectView->isVisible() && mProject) { GitManager vcsManager; QModelIndexList indices = ui->projectView->selectionModel()->selectedRows(); foreach (const QModelIndex index,indices) { @@ -6577,12 +6597,41 @@ void MainWindow::on_actionGit_Add_Files_triggered() vcsManager.add(info.absolutePath(),info.fileName()); } } - //update icons in project view + } + //update icons in project view + if (mProject) { mProject->model()->beginUpdate(); mProject->model()->endUpdate(); - //update icons in files view too - mFileSystemModelIconProvider.update(); - mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); } + //update icons in files view too + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); +} + + +void MainWindow::on_actionGit_Commit_triggered() +{ + QString folder; + if (ui->treeFiles->isVisible()) { + folder = pSettings->environment().currentFolder(); + } else if (ui->projectView->isVisible() && mProject) { + folder = mProject->folder(); + } + if (folder.isEmpty()) + return; + QString message = QInputDialog::getText(this,tr("Commit Message"),"Commit Message:"); + if (message.isEmpty()) + return; + GitRepository repository(folder); + repository.commit(message,true); + + //update project view + if (mProject) { + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + } + //update files view + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 214c52cf..b848d186 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -218,6 +218,7 @@ public slots: void onTodoParseFinished(); void setActiveBreakpoint(QString FileName, int Line, bool setFocus); void updateDPI(); + void onFileSaved(const QString& path, bool inProject); private: void prepareProjectForCompile(); @@ -260,7 +261,6 @@ private slots: void onAutoSaveTimeout(); void onFileChanged(const QString& path); void onFilesViewPathChanged(); - void onWatchViewContextMenu(const QPoint& pos); void onBookmarkContextMenu(const QPoint& pos); void onTableIssuesContextMenu(const QPoint& pos); @@ -582,6 +582,8 @@ private slots: void on_actionGit_Add_Files_triggered(); + void on_actionGit_Commit_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index c77ae6a5..eb072f9b 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -52,6 +52,14 @@ bool GitManager::hasRepository(const QString &folder, QString& currentBranch) return result; } +QString GitManager::rootFolder(const QString &folder) +{ + QStringList args; + args.append("rev-parse"); + args.append("--show-toplevel"); + return runGit(folder,args).trimmed(); +} + bool GitManager::isFileInRepository(const QFileInfo& fileInfo) { QStringList args; diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index 4cf1a204..ef54245f 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -22,6 +22,8 @@ public: void createRepository(const QString& folder); bool hasRepository(const QString& folder, QString& currentBranch); + QString rootFolder(const QString& folder); + bool isFileInRepository(const QFileInfo& fileInfo); bool isFileStaged(const QFileInfo& fileInfo); bool isFileChanged(const QFileInfo& fileInfo); diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index f6e6a70e..0a882bad 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -16,12 +16,12 @@ GitRepository::~GitRepository() const QString &GitRepository::folder() const { - return mFolder; + return mRealFolder; } void GitRepository::createRepository() { - mManager->createRepository(mFolder); + mManager->createRepository(mRealFolder); } bool GitRepository::hasRepository(QString& currentBranch) @@ -62,24 +62,32 @@ void GitRepository::clone(const QString &url) mManager->clone(mFolder,url); } -void GitRepository::commit(const QString &message) +void GitRepository::commit(const QString &message, bool autoAdd) { - mManager->commit(mFolder, message); + if (autoAdd) { + convertFilesListToSet(mManager->listChangedFiles(mRealFolder),mChangedFiles); + foreach(const QString& s, mChangedFiles) { + QFileInfo info(s); + mManager->add(info.absolutePath(),info.fileName()); + } + } + mManager->commit(mRealFolder, message); } void GitRepository::revert() { - mManager->revert(mFolder); + mManager->revert(mRealFolder); } void GitRepository::reset(const QString &commit, GitResetStrategy strategy) { - mManager->reset(mFolder,commit,strategy); + mManager->reset(mRealFolder,commit,strategy); } void GitRepository::setFolder(const QString &newFolder) { mFolder = newFolder; + mRealFolder = mManager->rootFolder(mFolder); update(); } @@ -92,18 +100,23 @@ void GitRepository::update() mChangedFiles.clear(); mStagedFiles.clear(); } else { - mInRepository = mManager->hasRepository(mFolder,mBranch); - convertFilesListToSet(mManager->listFiles(mFolder),mFilesInRepositories); - convertFilesListToSet(mManager->listChangedFiles(mFolder),mChangedFiles); - convertFilesListToSet(mManager->listStagedFiles(mFolder),mStagedFiles); + mInRepository = mManager->hasRepository(mRealFolder,mBranch); + convertFilesListToSet(mManager->listFiles(mRealFolder),mFilesInRepositories); + convertFilesListToSet(mManager->listChangedFiles(mRealFolder),mChangedFiles); + convertFilesListToSet(mManager->listStagedFiles(mRealFolder),mStagedFiles); } } +const QString &GitRepository::realFolder() const +{ + return mRealFolder; +} + void GitRepository::convertFilesListToSet(const QStringList &filesList, QSet &set) { set.clear(); foreach (const QString& s, filesList) { - set.insert(includeTrailingPathDelimiter(mFolder)+s); + set.insert(includeTrailingPathDelimiter(mRealFolder)+s); } } diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h index 7b6e1db0..2f8d55f7 100644 --- a/RedPandaIDE/vcs/gitrepository.h +++ b/RedPandaIDE/vcs/gitrepository.h @@ -53,7 +53,7 @@ public: QSet listFiles(bool refresh); void clone(const QString& url); - void commit(const QString& message); + void commit(const QString& message, bool autoAdd=true); void revert(); void reset(const QString& commit, GitResetStrategy strategy); @@ -61,8 +61,11 @@ public: void setFolder(const QString &newFolder); void update(); + const QString &realFolder() const; + signals: private: + QString mRealFolder; QString mFolder; bool mInRepository; QString mBranch;