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 pathRepositoryModule.cpp
More file actions
168 lines (135 loc) · 4.33 KB
/
RepositoryModule.cpp
File metadata and controls
168 lines (135 loc) · 4.33 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* MacGitver
* Copyright (C) 2012-2013 The MacGitver-Developers <dev@macgitver.org>
*
* (C) Sascha Cunz <sascha@macgitver.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 <QFileDialog>
#include <QtPlugin>
#include "libBlueSky/Application.hpp"
#include "libBlueSky/Windows.hpp"
#include "libMacGitverCore/Config/Config.h"
#include "libMacGitverCore/App/MacGitver.hpp"
#include "libMacGitverCore/RepoMan/RepoMan.hpp"
#include "RepositoryModule.h"
#include "RepoTreeView.hpp"
#include "CloneRepositoryDlg.h"
#include "CreateRepositoryDlg.h"
RepositoryModule::RepositoryModule()
: ConfigUser( "Repository" )
{
}
RepositoryModule::~RepositoryModule()
{
}
void RepositoryModule::setupConfigPages( ConfigDialog* dialog )
{
}
void RepositoryModule::initialize()
{
setupActions( this );
acRepositoryMenuAC->mergeInto( "RepositoryMenuMP" );
acRepositoryToolBarAC->mergeInto( "RepositoryToolBarMP" );
connect( damRecentlyUsed, SIGNAL(entryTriggered(QVariant)),
this, SLOT(onRecentRepositoryOpen(QVariant)) );
mMostRecentlyUsed = configGet( "MRU", QStringList() );
connect(&MacGitver::repoMan(), SIGNAL(repositoryOpened(RM::Repo*)),
this, SLOT(onCoreRepoOpen(RM::Repo*)));
updateMostRecentlyUsedMenu();
registerView<RepoTreeView>(tr("Repository"));
}
void RepositoryModule::deinitialize()
{
unregisterView<RepoTreeView>();
}
void RepositoryModule::onRepositoryClose()
{
}
void RepositoryModule::onRepositoryCreate()
{
CreateRepositoryDlg().exec();
}
void RepositoryModule::onRepositoryOpen()
{
QWidget* parent = BlueSky::Application::instance()->primaryWindow();
QFileDialog *fd = new QFileDialog( parent );
#ifdef Q_OS_MAC
fd->setFilter(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden);
#else
fd->setFileMode(QFileDialog::Directory);
#endif
QString lastUsedDir = Config::self().get( "Repository/lastUsedDir", "#" ).toString();
if( lastUsedDir != QLatin1String( "#" ) )
{
fd->setDirectory( lastUsedDir );
}
fd->setWindowTitle( trUtf8("Open a git repository") );
fd->open( this, SLOT(onRepositoryOpenHelper()) );
#ifdef Q_OS_MAC
// workaround for osx sheets without a parent
if (parent == 0)
fd->exec();
#endif
}
void RepositoryModule::onRepositoryOpenHelper()
{
QFileDialog *fd = qobject_cast<QFileDialog *>(sender());
Q_ASSERT(fd != 0);
if ( fd->selectedFiles().isEmpty() )
{
return;
}
//! @todo error handling
Git::Result r;
QString repoDir = Git::Repository::discover(r, fd->selectedFiles().first());
if( repoDir.isEmpty() )
{
return;
}
//! @todo error handling
Git::Repository repo = Git::Repository::open(r, repoDir);
if( !repo.isValid() )
return;
// If we successfully loaded the repository at that directory,
// we store the repository's work dir as "lastUsedDir".
// If it is a bare repository, we store the repository's directory.
Config::self().set( "Repository/lastUsedDir", repo.isBare() ? repoDir : repo.basePath() );
MacGitver::repoMan().open( repo );
}
void RepositoryModule::onRepositoryClone()
{
CloneRepositoryDlg().exec();
}
void RepositoryModule::onRecentRepositoryOpen( const QVariant& path )
{
QString repoPath = path.toString();
MacGitver::repoMan().open( repoPath );
}
void RepositoryModule::onCoreRepoOpen(RM::Repo* repo)
{
if( repo->isSubModule() )
{
return;
}
QString path = repo->path();
mMostRecentlyUsed.removeAll( path );
mMostRecentlyUsed.prepend( path );
configSet( "MRU", mMostRecentlyUsed );
updateMostRecentlyUsedMenu();
}
void RepositoryModule::updateMostRecentlyUsedMenu()
{
damRecentlyUsed->setMode( Heaven::DAMergerAdvancedList );
damRecentlyUsed->addStringList( mMostRecentlyUsed );
}