This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSubmodulesView.cpp
More file actions
103 lines (81 loc) · 2.82 KB
/
SubmodulesView.cpp
File metadata and controls
103 lines (81 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* MacGitver
* Copyright (C) 2012 Sascha Cunz <sascha@babbelbox.org>
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QStandardItemModel>
#include <QToolBar>
#include <QTreeView>
#include <QMessageBox>
#include "libGitWrap/ObjectId.hpp"
#include "libMacGitverCore/App/MacGitver.hpp"
#include "libMacGitverCore/MacGitver/FSWatcher.h"
#include "SubmodulesView.h"
#include "SubmodulesDelegate.h"
#include "SubmodulesCreateEditDlg.h"
SubmodulesView::SubmodulesView()
: View( "Submodules" )
{
setupActions( this );
setToolBar( tbSMViewToolbar );
mTree = new QTreeView;
mTree->setRootIsDecorated( false );
mTree->setHeaderHidden( true );
mTree->setFrameShape( QFrame::NoFrame );
setWidget( mTree );
mModel = new QStandardItemModel( this );
mTree->setModel( mModel );
mTree->setItemDelegate( new SubmodulesViewDelegate( this ) );
setViewName( trUtf8( "Submodules" ) );
connect( &MacGitver::self(), SIGNAL(repositoryChanged(Git::Repository)),
this, SLOT(repositoryChanged(Git::Repository)) );
Git::Repository repo = MacGitver::self().repository();
if( repo.isValid() )
{
repositoryChanged( repo );
}
// connect( MacGitver::self().watcher(), SIGNAL(repoGitFileChanged()),
// this, SLOT(readSubmodules()) );
}
void SubmodulesView::repositoryChanged( Git::Repository repo )
{
mRepo = repo;
readSubmodules();
}
void SubmodulesView::readSubmodules()
{
if( !mRepo.isValid() )
return;
Git::Result r;
QList<Git::Submodule> submodules( mRepo.submodules(r) );
if (!r)
{
QMessageBox::critical( 0, trUtf8("Error while reading submodules")
, trUtf8("Error while reading submodules:\n%1").arg(r.errorText()) );
}
// TODO: use IconProvider
QIcon decoration; // ( IconProvider::self().icon(QLatin1String("subrepo")) );
foreach( Git::Submodule module, submodules )
{
QStandardItem * it = new QStandardItem( decoration, trUtf8("<INVALID>") );
it->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
if( module.isValid() )
it->setData( QVariant::fromValue(module), Qt::UserRole + 1 );
mModel->appendRow( it );
}
}
void SubmodulesView::addSubmodule()
{
SubmodulesCreateEditDlg d;
d.exec();
}