Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Repository/RepoTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/

#include <QDebug>
#include <QMessageBox>
#include <QSortFilterProxyModel>

#include "libGitWrap/Operations/RemoteOperations.hpp"

#include "libMacGitverCore/Widgets/TreeViewCtxMenu.hpp"

#include "libMacGitverCore/App/MacGitver.hpp"
Expand Down Expand Up @@ -143,6 +146,64 @@ void RepoTreeView::onRepoDeactivated(RM::Repo* repo)
}
}

/**
* @brief This slot is called, when a single fetch operation finishes.
*/
void RepoTreeView::fetchOperationFinished()
{
Git::FetchOperation* op = qobject_cast<Git::FetchOperation*>( sender() );
Q_ASSERT( op );

Git::Result r( op->result() );
if ( !r ) {
QMessageBox::warning( this, tr("Operation failed."),
tr("Failed to fetch repository '%1'.\nMessage: %2")
.arg(op->repository().name()).arg(r.errorText())
);
}

// delete the operation
op->deleteLater();
}

void RepoTreeView::onCtxFetchAll()
{
Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add a return; here, we could merge this code now and activate it when we're there...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this code does what it should do. Why should we remove that? 😄

In this special case, the action is actually working and we add value by adding the unfinished fetch operation. The only thing is: A "fetch" action currently works just with unencrypted protocols and it doesn't show progress yet.

⚡ Returning a function without doing anything is the worst thing a programmer could code in released code. How would you react to buttons without a function? For an example, see the "Remotes" menu 😄.

Btw.: How about providing a GW_TODO macro in libGitWrap, that produces an error Git::Result with error code GIT_EUSER and a message like this:

The method 'Git::BestOperationEver::run()' in file:line is not implemented yet. Want to help out? Please contact us: <-maintainer->@macgitver.org.

Inspirational credits go to Blender 😄.

Q_ASSERT( action );

RM::Repo* repo = qobject_cast< RM::Repo* >( action->activatedBy() );
if( repo ) {
Git::Result r;
Git::Repository gitRepo = repo->gitRepo();
const QStringList aliases( gitRepo.allRemoteNames(r) );
if ( !r ) {
QMessageBox::warning( this, tr("Lookup of remotes failed"),
tr("Unable to lookup remotes for repository '%1'."
"\nMessage: %2").arg(repo->displayName())
.arg(r.errorText())
);
return;
}

if ( aliases.isEmpty() ) {
QMessageBox::information( this, tr("No Remotes found"),
tr("No remotes configured for repository '%1'.")
.arg(repo->displayName())
);
return;
}

foreach (const QString& alias, aliases) {
Git::FetchOperation* op = new Git::FetchOperation( repo->gitRepo() );
op->setRemoteAlias( alias );
op->setBackgroundMode( true );
connect( op, SIGNAL(finished()), this, SLOT(fetchOperationFinished()) );
// TODO: create a central dialog to show progress of parallel operations
op->execute();
}
}
}

BlueSky::ViewContext* RepoTreeView::createContextObject() const
{
return new RepositoryContext;
Expand Down
5 changes: 5 additions & 0 deletions Repository/RepoTreeView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ private slots: // from actions
void onCtxActivate();
void onCtxClose();

void onCtxFetchAll();

private slots: // from mRepos
void contextMenu( const QModelIndex& index, const QPoint& globalPos );

private slots: // for MacGitver::repoMan()
void onRepoActivated(RM::Repo* repo);
void onRepoDeactivated(RM::Repo* repo);

private slots:
void fetchOperationFinished();

private:
QModelIndex deeplyMapToSource( QModelIndex current ) const;
BlueSky::ViewContext* createContextObject() const;
Expand Down
20 changes: 18 additions & 2 deletions Repository/RepoTreeViewCtxMenu.hid
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

Ui RepoTreeViewCtxMenu {



Action Activate {
Text "&Activate";
StatusToolTip "Make this repository the active one.";
Expand All @@ -30,17 +28,35 @@ Ui RepoTreeViewCtxMenu {
ConnectTo onCtxClose();
};


Action FetchAll {
Text "All Remotes";
StatusToolTip "Fetch repository changes from all remotes.";
ConnectTo onCtxFetchAll();
};


Menu MenuFetch {
Text "Fetch";
Action FetchAll;
Separator;
};

Menu CtxMenuRepo {

Action Activate;
Separator;
Menu MenuFetch;
Separator;
Action Close;

};

Menu CtxMenuSMRepo {

Action Activate;
Separator;
Menu MenuFetch;

};

Expand Down