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;