work save: commit
This commit is contained in:
parent
463779aa0d
commit
b5acf15467
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "widgets/newclassdialog.h"
|
||||
#include "widgets/newheaderdialog.h"
|
||||
#include "vcs/gitmanager.h"
|
||||
#include "vcs/gitrepository.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QComboBox>
|
||||
|
@ -744,6 +745,22 @@ void MainWindow::updateDPI()
|
|||
applySettings();
|
||||
}
|
||||
|
||||
void MainWindow::onFileSaved(const QString &path, bool inProject)
|
||||
{
|
||||
qDebug()<<path<<inProject<<mFileSystemModel.rootPath();
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QString> &set)
|
||||
{
|
||||
set.clear();
|
||||
foreach (const QString& s, filesList) {
|
||||
set.insert(includeTrailingPathDelimiter(mFolder)+s);
|
||||
set.insert(includeTrailingPathDelimiter(mRealFolder)+s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
QSet<QString> 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;
|
||||
|
|
Loading…
Reference in New Issue