From 6177398ce64eb988f43287f8d21276baaf20ebde Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 15 Feb 2022 21:39:17 +0800 Subject: [PATCH] - enhancement: git - restore --- NEWS.md | 16 +- RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/RedPandaIDE_zh_CN.ts | 1098 ++++++++++++------------ RedPandaIDE/customfileiconprovider.cpp | 14 + RedPandaIDE/customfileiconprovider.h | 1 + RedPandaIDE/mainwindow.cpp | 155 +++- RedPandaIDE/mainwindow.h | 2 + RedPandaIDE/mainwindow.ui | 14 +- RedPandaIDE/project.cpp | 18 +- RedPandaIDE/project.h | 2 +- RedPandaIDE/vcs/gitmanager.cpp | 9 +- RedPandaIDE/vcs/gitmanager.h | 5 +- RedPandaIDE/vcs/gitrepository.cpp | 11 +- RedPandaIDE/vcs/gitrepository.h | 11 +- RedPandaIDE/vcs/gitutils.cpp | 2 + RedPandaIDE/vcs/gitutils.h | 12 + 16 files changed, 762 insertions(+), 610 deletions(-) create mode 100644 RedPandaIDE/vcs/gitutils.cpp create mode 100644 RedPandaIDE/vcs/gitutils.h diff --git a/NEWS.md b/NEWS.md index 9f962658..3b93a500 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,15 +1,17 @@ - - 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 + - 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: git - create repository + - enhancement: git - add files + - enhancement: git - commit + - enhancement: git - restore Red Panda C++ Version 0.14.2 - enhancement: file system view mode for project diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index f1befd7e..82b78de5 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -93,6 +93,7 @@ SOURCES += \ toolsmanager.cpp \ vcs/gitmanager.cpp \ vcs/gitrepository.cpp \ + vcs/gitutils.cpp \ widgets/aboutdialog.cpp \ widgets/bookmarkmodel.cpp \ widgets/classbrowser.cpp \ @@ -224,6 +225,7 @@ HEADERS += \ toolsmanager.h \ vcs/gitmanager.h \ vcs/gitrepository.h \ + vcs/gitutils.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 f8930252..7a4ba211 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -581,7 +581,7 @@ p, li { white-space: pre-wrap; } [说明] - + The compiler process for '%1' failed to start. 无法启动编译器进程'%1'。 @@ -590,27 +590,27 @@ p, li { white-space: pre-wrap; } 无法启动编译进程。 - + The compiler process crashed after starting successfully. 编译进程启动后崩溃。 - + The last waitFor...() function timed out. waitFor()函数等待超时。 - + An error occurred when attempting to write to the compiler process. 在向编译进程输入内容时出错。 - + An error occurred when attempting to read from the compiler process. 在从编译进程读取内容时出错。 - + An unknown error occurred. 发生了未知错误。 @@ -3099,7 +3099,7 @@ Are you really want to continue? GitManager - + Folder "%1" already has a repository! 文件夹"%1"中已存在仓库! @@ -3273,18 +3273,18 @@ Are you really want to continue? MainWindow - + Red Panda C++ 小熊猫C++ - - - - - - - + + + + + + + Issues 编译器 @@ -3293,48 +3293,48 @@ Are you really want to continue? 编译日志 - + File 文件 - + Tools 工具 - - + + Run 运行 - + Edit 编辑 - - + + Project 项目 - + Watch 监视 - + Structure 结构 - + Files 文件 @@ -3343,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 窗口 @@ -3434,408 +3434,408 @@ Are you really want to continue? 工具栏2 - + New 新建 - + 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 视图 @@ -3844,461 +3844,472 @@ 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 - 创建仓库 + + Create Git Repository + Create Repository + 创建Git仓库 - + Commit 提交(Commit) - + Revert 撤销(Revert) - + Reset 回滚(Reset) + + + Add Files + 添加文件 + + + + Restore + 还原(Restore) + 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 新建头文件... @@ -4308,47 +4319,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 删除到行首 @@ -4357,78 +4368,78 @@ 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 文件编码 - + Recent Files 文件历史 - - - - - - + + + + + + Debugging 正在调试 - - - - - - + + + + + + Running 正在运行 - - - - - - + + + + + + Compiling 正在编译 @@ -4437,194 +4448,194 @@ Are you really want to continue? 行:%1 列:%2 已选择:%3 总行数:%4 总长度:%5 - + Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5 Line: %1 Col: %2 Selected: %3 Lines: %4 Length: %5 行: %1 列: %2 已选择 :%3 总行数: %4 总长度: %5 - + Read Only 只读 - + Insert 插入 - + Overwrite 覆写 - + Close project 关闭项目 - + Are you sure you want to close %1? 你确定要关闭'%1'吗? - - + + Confirm 确认 - - - + + + Source file is not compiled. 源文件尚未编译。 - - + + Compile now? 现在编译? - - + + Source file is more recent than executable. 源文件比可执行程序新。 - + Recompile now? 重新编译? - + No compiler set 无编译器设置 - + No compiler set is configured. 没有配置编译器设置。 - + Can't start debugging. 无法启动调试器 - - + + Enable debugging 启用调试参数 - - + + You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now? 当前编译设置中未启用调试选项(-g3),或启用了信息剥除选项(-s)<br /><br/>是否纠正这一问题? - + Project not built 项目尚未构建 - + Project hasn't been built. Build it now? 项目尚未构建。是否构建? - + Host applcation missing 宿主程序不存在 - + DLL project needs a host application to run. 动态链接库(DLL)需要一个宿主程序来运行。 - + But it's missing. 但它不存在。 - + Host application not exists 宿主程序不存在 - + Host application file '%1' doesn't exist. 宿主程序'%1'不存在。 - + Recompile? 重新编译? - - + + Save last open info error 保存上次打开信息失败 - + Can't remove old last open information file '%1' 无法删除旧上次打开信息文件'%1' - + Can't save last open info file '%1' 无法保存上次打开信息文件'%1' - + Load last open info error 载入上次打开信息失败 - + Can't load last open info file '%1' 无法载入上次打开信息文件'%1' - + Open Source File 打开源代码文件 - + Show detail debug logs 显示详细调试器日志 - + Copy all 全部复制 - - - + + + Clear 清除 - + Export 导出 - + Insert Snippet 插入代码段 - - + + Problem Set %1 试题集%1 @@ -4645,68 +4656,68 @@ Are you really want to continue? 或者选择使用其他的网络端口。 - - + + Rebuild Project 重新构建项目 - - + + Project has been modified, do you want to rebuild it? 项目已经被修改过,是否需要重新构建? - + Auto Save Error 自动保存出错 - + Auto save "%1" to "%2" failed:%3 自动保存"%1"到"%2"失败:%3 - + Properties... 试题属性... - + Set Problem Set Name 设置试题集名称 - + Problem Set Name: 试题集名称: - + Remove 删除 - + Remove All Bookmarks 删除全部书签 - + Modify Description 修改描述 - - - + + + Bookmark Description 书签描述 - - - + + + Description: 描述: @@ -4715,536 +4726,557 @@ Are you really want to continue? 在调试主控台中显示调试器输出 - + Remove this search 清除这次搜索 - + Clear all searches 删除所有搜索 - + Breakpoint condition... 断点条件... - + Break point condition 断点条件 - + Enter the condition of the breakpoint: 输入当前断点的生效条件: - + Remove All Breakpoints Remove all breakpoints 删除所有断点 - + Remove Breakpoint 删除当前断点 - + Rename File 重命名文件 - - + + Add Folder 添加文件夹 - + New folder 新文件夹 - + Folder name: 文件夹: - + Rename Folder 重命名 - + Remove Folder 删除文件夹 - + Switch to normal view 切换为普通视图 - + Switch to custom view 切换为自定义视图 - + Sort By Type 按类型排序 - + Sort alphabetically 按名称排序 - + Show inherited members 显示继承的成员 - + Goto declaration 跳转到声明处 - + Goto definition 跳转到定义处 - - - + + + 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"已存在! + + + Commit Message + 提交信息 + + + + Commit Failed + 提交失败 + + + + Commit message shouldn't be empty! + 提交信息不能为空! + Red panda Dev-C++ project file (*.dev) 小熊猫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 - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + Error 错误 - + Recent Projects 项目历史 - + Load Theme Error 载入主题失败 - + + + Version Control + 版本控制 + + + 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个文件) @@ -5466,108 +5498,108 @@ Are you really want to continue? Project - + File Not Found 未找到文件 - + Project file '%1' can't be found! 找不到项目文件'%1'! - + untitled 无标题 - + 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++编辑器开发 @@ -5974,24 +6006,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,7 +6247,7 @@ Are you really want to continue? QApplication - + Error 错误 @@ -6223,12 +6255,12 @@ Are you really want to continue? QObject - + Save 保存 - + Save changes to %1? 将修改保存到"%1"? @@ -6413,7 +6445,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -6512,34 +6544,34 @@ Are you really want to continue? 只生成汇编代码(-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 @@ -7373,7 +7405,7 @@ Are you really want to continue? 自动链接 - + @@ -7449,15 +7481,15 @@ Are you really want to continue? 杂项 - - + + Program Runner 程序运行 - + Problem Set 试题集 @@ -7874,12 +7906,12 @@ Are you really want to continue? 选项 - + Git Executable Git程序文件 - + All files (%1) 所有文件 (%1) diff --git a/RedPandaIDE/customfileiconprovider.cpp b/RedPandaIDE/customfileiconprovider.cpp index 9610c5ea..4c827c1d 100644 --- a/RedPandaIDE/customfileiconprovider.cpp +++ b/RedPandaIDE/customfileiconprovider.cpp @@ -22,6 +22,11 @@ void CustomFileIconProvider::update() mVCSRepository->update(); } +GitRepository *CustomFileIconProvider::VCSRepository() const +{ + return mVCSRepository; +} + QIcon CustomFileIconProvider::icon(IconType type) const { if (type == IconType::Folder) { @@ -86,6 +91,15 @@ QIcon CustomFileIconProvider::icon(const QFileInfo &info) const icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE_VCS_NOCHANGE); } else icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_PROJECTFILE); + } else { + if (mVCSRepository->isFileInRepository(info)) { + if (mVCSRepository->isFileStaged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_STAGED); + else if (mVCSRepository->isFileChanged(info)) + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_CHANGED); + else + icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FILE_VCS_NOCHANGE); + } //use default system icon } if (!icon.isNull()) return icon; diff --git a/RedPandaIDE/customfileiconprovider.h b/RedPandaIDE/customfileiconprovider.h index 5e79a45a..aac770d5 100644 --- a/RedPandaIDE/customfileiconprovider.h +++ b/RedPandaIDE/customfileiconprovider.h @@ -17,6 +17,7 @@ private: public: QIcon icon(IconType type) const override; QIcon icon(const QFileInfo &info) const override; + GitRepository *VCSRepository() const; }; #endif // CUSTOMFILEICONPROVIDER_H diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 917b7ae6..df4ea79f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -747,16 +747,17 @@ void MainWindow::updateDPI() 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); + if (pSettings->vcs().gitOk()) { + if (inProject && mProject) { + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + } + QModelIndex index = mFileSystemModel.index(path); + if (index.isValid()) { + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + ui->treeFiles->update(index); + } } pMainWindow->updateForEncodingInfo(); } @@ -2974,6 +2975,7 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos) bool onUnit = false; bool onRoot = false; bool folderEmpty = false; + bool multiSelection = ui->projectView->selectionModel()->selectedRows().count()>1; int unitIndex = -1; QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->selectionModel()->currentIndex()); if (current.isValid() && mProject) { @@ -3006,7 +3008,7 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos) if (!onFolder) { menu.addAction(ui->actionRemove_from_project); } - if (onUnit) { + if (onUnit && !multiSelection) { menu.addAction(mProject_Rename_Unit); } menu.addSeparator(); @@ -3040,16 +3042,41 @@ 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.setTitle(tr("Version Control")); + if (ui->projectView->selectionModel()->hasSelection()) { + bool shouldAdd = true; + foreach (const QModelIndex& index, ui->projectView->selectionModel()->selectedRows()) { + if (!index.isValid()) { + shouldAdd=false; + break; + } + QModelIndex realIndex = mProjectProxyModel->mapToSource(index); + ProjectModelNode * node = static_cast(realIndex.internalPointer()); + if (!node || node->unitIndex<0) { + shouldAdd=false; + break; + } + PProjectUnit pUnit=mProject->units()[node->unitIndex]; + if (mProject->model()->iconProvider()->VCSRepository()->isFileInRepository( + pUnit->fileName() + )) { + shouldAdd=false; + break; + } + } + if (shouldAdd) + vcsMenu.addAction(ui->actionGit_Add_Files); + } vcsMenu.addAction(ui->actionGit_Commit); - vcsMenu.addAction(ui->actionGit_Reset); - vcsMenu.addAction(ui->actionGit_Revert); + vcsMenu.addAction(ui->actionGit_Restore); ui->actionGit_Commit->setEnabled(true); - ui->actionGit_Reset->setEnabled(true); - ui->actionGit_Revert->setEnabled(true); + ui->actionGit_Restore->setEnabled(true); + +// vcsMenu.addAction(ui->actionGit_Reset); +// vcsMenu.addAction(ui->actionGit_Revert); +// ui->actionGit_Reset->setEnabled(true); +// ui->actionGit_Revert->setEnabled(true); } menu.exec(ui->projectView->mapToGlobal(pos)); } @@ -3135,16 +3162,30 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos) 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.setTitle(tr("Version Control")); + if (ui->treeFiles->selectionModel()->hasSelection()) { + bool shouldAdd = true; + foreach (const QModelIndex& index, ui->treeFiles->selectionModel()->selectedRows()) { + if (mFileSystemModelIconProvider.VCSRepository()->isFileInRepository( + mFileSystemModel.fileInfo(index) + )) { + shouldAdd=false; + break; + } + } + if (shouldAdd) + vcsMenu.addAction(ui->actionGit_Add_Files); + } vcsMenu.addAction(ui->actionGit_Commit); - vcsMenu.addAction(ui->actionGit_Reset); - vcsMenu.addAction(ui->actionGit_Revert); + vcsMenu.addAction(ui->actionGit_Restore); ui->actionGit_Commit->setEnabled(true); - ui->actionGit_Reset->setEnabled(true); - ui->actionGit_Revert->setEnabled(true); + ui->actionGit_Restore->setEnabled(true); + +// vcsMenu.addAction(ui->actionGit_Reset); +// vcsMenu.addAction(ui->actionGit_Revert); +// ui->actionGit_Reset->setEnabled(true); +// ui->actionGit_Revert->setEnabled(true); } menu.exec(ui->treeFiles->mapToGlobal(pos)); } @@ -6555,17 +6596,38 @@ void MainWindow::on_actionGit_Create_Repository_triggered() if (ui->treeFiles->isVisible()) { GitManager vcsManager; vcsManager.createRepository(pSettings->environment().currentFolder()); + //update files view; int pos = ui->cbFilesPath->findText(pSettings->environment().currentFolder()); if (pos>=0) { ui->cbFilesPath->setItemIcon(pos, pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); } + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + //update project view + if (mProject && mProject->folder() == mFileSystemModel.rootPath()) { + mProject->addUnit(includeTrailingPathDelimiter(mProject->folder())+".gitignore", mProject->rootNode(), true); + } else if (mProject && mFileSystemModel.index(mProject->folder()).isValid()) { + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + } } else if (ui->projectView->isVisible() && mProject) { GitManager vcsManager; vcsManager.createRepository(mProject->folder()); - } - if (mProject) { - mProject->model()->beginUpdate(); - mProject->model()->endUpdate(); + vcsManager.add(mProject->folder(), extractFileName(mProject->filename())); + //update project view + mProject->addUnit(includeTrailingPathDelimiter(mProject->folder())+".gitignore", mProject->rootNode(), true); + mProject->saveAll(); + if (mProject->folder() == mFileSystemModel.rootPath() + || mFileSystemModel.rootPath().startsWith(includeTrailingPathDelimiter(mProject->folder()), PATH_SENSITIVITY)) { + + //update files view; + int pos = ui->cbFilesPath->findText(pSettings->environment().currentFolder()); + if (pos>=0) { + ui->cbFilesPath->setItemIcon(pos, pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); + } + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); + } } } @@ -6620,10 +6682,39 @@ void MainWindow::on_actionGit_Commit_triggered() if (folder.isEmpty()) return; QString message = QInputDialog::getText(this,tr("Commit Message"),"Commit Message:"); - if (message.isEmpty()) + if (message.isEmpty()) { + QMessageBox::critical(this, + tr("Commit Failed"), + tr("Commit message shouldn't be empty!") + ); return; - GitRepository repository(folder); - repository.commit(message,true); + } + GitManager vcsManager; + vcsManager.commit(folder,message,true); + + //update project view + if (mProject) { + mProject->model()->beginUpdate(); + mProject->model()->endUpdate(); + } + //update files view + mFileSystemModelIconProvider.update(); + mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider); +} + + +void MainWindow::on_actionGit_Restore_triggered() +{ + QString folder; + if (ui->treeFiles->isVisible()) { + folder = pSettings->environment().currentFolder(); + } else if (ui->projectView->isVisible() && mProject) { + folder = mProject->folder(); + } + if (folder.isEmpty()) + return; + GitManager vcsManager; + vcsManager.restore(folder,""); //update project view if (mProject) { diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index b848d186..12b53b82 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -584,6 +584,8 @@ private slots: void on_actionGit_Commit_triggered(); + void on_actionGit_Restore_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 35a5c356..dd4263cc 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 3 + 0 true @@ -126,7 +126,7 @@ Qt::MoveAction - QAbstractItemView::SingleSelection + QAbstractItemView::ExtendedSelection QAbstractItemView::SelectRows @@ -1603,8 +1603,7 @@ - - + @@ -2756,7 +2755,7 @@ - Create Repository + Create Git Repository @@ -2779,6 +2778,11 @@ Add Files + + + Restore + + diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 1d166bf5..c8f07497 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -36,7 +36,7 @@ #include "customfileiconprovider.h" #include #include "settings.h" -#include "vcs/gitmanager.h" +#include "vcs/gitrepository.h" Project::Project(const QString &filename, const QString &name, QObject *parent) : QObject(parent), @@ -904,10 +904,6 @@ PProjectUnit Project::addUnit(const QString &inFileName, PProjectModelNode paren newUnit->setOverrideBuildCmd(false); newUnit->setBuildCmd(""); if (rebuild) { - mModel.beginUpdate(); - auto action = finally([this]{ - mModel.endUpdate(); - }); rebuildNodes(); } setModified(true); @@ -1910,13 +1906,11 @@ ProjectModel::ProjectModel(Project *project, QObject *parent): mProject(project) { mUpdateCount = 0; - mVCSRepository = new GitRepository(""); mIconProvider = new CustomFileIconProvider(); } ProjectModel::~ProjectModel() { - delete mVCSRepository; delete mIconProvider; } @@ -1932,12 +1926,16 @@ void ProjectModel::endUpdate() { mUpdateCount--; if (mUpdateCount==0) { - mVCSRepository->setFolder(mProject->folder()); mIconProvider->setRootFolder(mProject->folder()); endResetModel(); } } +CustomFileIconProvider *ProjectModel::iconProvider() const +{ + return mIconProvider; +} + Project *ProjectModel::project() const { return mProject; @@ -1994,7 +1992,7 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { if (p == mProject->rootNode().get()) { QString branch; - if (mVCSRepository->hasRepository(branch)) + if (mIconProvider->VCSRepository()->hasRepository(branch)) return QString("%1 [%2]").arg(p->text,branch); } return p->text; @@ -2007,7 +2005,7 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const } else { if (p == mProject->rootNode().get()) { QString branch; - if (mVCSRepository->hasRepository(branch)) + if (mIconProvider->VCSRepository()->hasRepository(branch)) icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT); } else { switch(p->folderNodeType) { diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 063dc19e..61feb624 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -112,7 +112,6 @@ public: void endUpdate(); private: Project* mProject; - GitRepository *mVCSRepository; int mUpdateCount; CustomFileIconProvider* mIconProvider; @@ -136,6 +135,7 @@ public: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; QMimeData *mimeData(const QModelIndexList &indexes) const override; Project *project() const; + CustomFileIconProvider *iconProvider() const; }; class ProjectModelSortFilterProxy : public QSortFilterProxyModel diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index eb072f9b..f109232f 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -119,7 +119,10 @@ void GitManager::restore(const QString &folder, const QString &path) { QStringList args; args.append("restore"); - args.append(path); + if (path.isEmpty()) + args.append("."); + else + args.append(path); runGit(folder,args); } @@ -155,10 +158,12 @@ void GitManager::clone(const QString &folder, const QString &url) runGit(folder,args); } -void GitManager::commit(const QString &folder, const QString &message) +void GitManager::commit(const QString &folder, const QString &message, bool autoStage) { QStringList args; args.append("commit"); + if (autoStage) + args.append("-a"); args.append("-m"); args.append(message); runGit(folder,args); diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index ef54245f..06bff104 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -5,7 +5,7 @@ #include #include #include "utils.h" -#include "gitrepository.h" +#include "gitutils.h" class GitError: public BaseError { public: @@ -32,12 +32,13 @@ public: 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); 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 commit(const QString& folder, const QString& message, bool autoStage); void revert(const QString& folder); void reset(const QString& folder, const QString& commit, GitResetStrategy strategy); diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index 0a882bad..c5a29727 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -62,16 +62,9 @@ void GitRepository::clone(const QString &url) mManager->clone(mFolder,url); } -void GitRepository::commit(const QString &message, bool autoAdd) +void GitRepository::commit(const QString &message, bool autoStage) { - 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); + mManager->commit(mRealFolder, message, autoStage); } void GitRepository::revert() diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h index 2f8d55f7..16bb236f 100644 --- a/RedPandaIDE/vcs/gitrepository.h +++ b/RedPandaIDE/vcs/gitrepository.h @@ -5,14 +5,7 @@ #include #include #include - -enum class GitResetStrategy { - Soft, - Hard, - Merge, - Mixed, - Keep -}; +#include "gitutils.h" class GitManager; class GitRepository : public QObject @@ -53,7 +46,7 @@ public: QSet listFiles(bool refresh); void clone(const QString& url); - void commit(const QString& message, bool autoAdd=true); + void commit(const QString& message, bool autoStage=true); void revert(); void reset(const QString& commit, GitResetStrategy strategy); diff --git a/RedPandaIDE/vcs/gitutils.cpp b/RedPandaIDE/vcs/gitutils.cpp new file mode 100644 index 00000000..d7321e94 --- /dev/null +++ b/RedPandaIDE/vcs/gitutils.cpp @@ -0,0 +1,2 @@ +#include "gitutils.h" + diff --git a/RedPandaIDE/vcs/gitutils.h b/RedPandaIDE/vcs/gitutils.h new file mode 100644 index 00000000..d42214d6 --- /dev/null +++ b/RedPandaIDE/vcs/gitutils.h @@ -0,0 +1,12 @@ +#ifndef GITUTILS_H +#define GITUTILS_H + +enum class GitResetStrategy { + Soft, + Hard, + Merge, + Mixed, + Keep +}; + +#endif // GITUTILS_H