-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmsvcbuilderpreferences.cpp
More file actions
183 lines (144 loc) · 6.71 KB
/
msvcbuilderpreferences.cpp
File metadata and controls
183 lines (144 loc) · 6.71 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* KDevelop MSVC Support
*
* Copyright 2015 Ennio Barbaro <enniobarbaro@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "msvcbuilderpreferences.h"
#include "msvcconfig.h"
#include "msvcmodelitems.h"
#include "debug.h"
#include "ui_msvcconfig.h"
#include <algorithm>
#include <KLocalizedString>
#include <interfaces/iproject.h>
MsvcBuilderPreferences::MsvcBuilderPreferences(KDevelop::IPlugin* plugin,
const KDevelop::ProjectConfigOptions& options,
QWidget* parent) :
KDevelop::ConfigPage(plugin, nullptr, parent),
m_project(options.project),
m_configUi(new Ui::MsvcConfig)
{
m_configUi->setupUi(this);
auto compilers = MsvcConfig::findMSVC();
KComboBox * compVersionComboBox = m_configUi->version_combo;
for (auto const & x : compilers )
{
const int index = compVersionComboBox->count() - 1;
compVersionComboBox->insertItem( index, x.fullName, QVariant::fromValue(x.path) );
}
const int versionComboCount = compVersionComboBox->count();
compVersionComboBox->setCurrentIndex(0);
auto showHideCustomCompPath = [this, versionComboCount](int currentIndex)
{
// Show only if the current selected index is the last one.
const bool hidden = currentIndex < versionComboCount - 1;
m_configUi->devenv_exe_label->setHidden(hidden);
m_configUi->builder_path->setHidden(hidden);
};
showHideCustomCompPath( versionComboCount > 1);
// Fill configuration combo box
if ( MsvcSolutionItem * solItem = dynamic_cast<MsvcSolutionItem*>(m_project->projectItem()) )
{
QList<QString> configs = solItem->getConfigurations();
for ( QString & x : configs )
x = x.split('|').value(0);
std::sort( configs.begin(), configs.end() );
auto last = std::unique(configs.begin(), configs.end());
for ( auto iter = configs.begin(); iter != last; ++ iter)
m_configUi->config_combo->addItem( *iter );
}
connect(compVersionComboBox, static_cast<void (QComboBox::*)(int)>( &KComboBox::currentIndexChanged ),
this, showHideCustomCompPath);
connect(m_configUi->config_combo, static_cast<void (QComboBox::*)(const QString &)>( &KComboBox::currentIndexChanged ),
this, &MsvcBuilderPreferences::onConfigurationChanged );
// Emit changed signal!
connect( m_configUi->builder_path, &KUrlRequester::textChanged, this, [this](QString const &) { emit changed(); } );
connect( m_configUi->msvc_include, &KUrlRequester::textChanged, this, [this](QString const &) { emit changed(); } );
connect( m_configUi->config_combo, static_cast<void (QComboBox::*)(int)>( &QComboBox::currentIndexChanged ), this, [this](int) { emit changed(); } );
connect( m_configUi->arch_combo, static_cast<void (QComboBox::*)(int)>( &QComboBox::currentIndexChanged ), this, [this](int) { emit changed(); } );
}
MsvcBuilderPreferences::~MsvcBuilderPreferences()
{
delete m_configUi;
}
void MsvcBuilderPreferences::apply()
{
qCDebug(KDEV_MSVC) << "Saving data";
KConfigGroup cg(m_project->projectConfiguration(), MsvcConfig::CONFIG_GROUP);
KComboBox * compVersionComboBox = m_configUi->version_combo;
const bool customCompilerPath = compVersionComboBox->currentIndex() >= compVersionComboBox->count() - 1;
KDevelop::Path compilerPath = customCompilerPath ?
KDevelop::Path( m_configUi->builder_path->url() ) :
compVersionComboBox->itemData(compVersionComboBox->currentIndex()).value<KDevelop::Path>();
cg.writeEntry( MsvcConfig::DEVENV_BINARY, compilerPath.toLocalFile() );
cg.writeEntry( MsvcConfig::MSVC_INCLUDE, m_configUi->msvc_include->url().toLocalFile() );
//TODO saving currentText is not very pretty...
cg.writeEntry( MsvcConfig::ACTIVE_CONFIGURATION, m_configUi->config_combo->currentText() );
cg.writeEntry( MsvcConfig::ACTIVE_ARCHITECTURE, m_configUi->arch_combo->currentText() );
// Hidden for now
if ( !cg.hasKey( MsvcConfig::WINSDK_INCLUDE ) )
{
KDevelop::Path sdkPath = MsvcConfig::findWinSdk();
if ( sdkPath.isValid() )
{
cg.writeEntry( MsvcConfig::WINSDK_INCLUDE, sdkPath.toLocalFile() );
}
}
}
void MsvcBuilderPreferences::reset()
{
qCDebug(KDEV_MSVC) << "loading data";
// refresh combobox
KConfigGroup cg(m_project->projectConfiguration(), MsvcConfig::CONFIG_GROUP);
KDevelop::Path compilerPath (cg.readEntry( MsvcConfig::DEVENV_BINARY, QString() ) );
KComboBox * compVersionComboBox = m_configUi->version_combo;
int selectedIndex = compVersionComboBox->count() - 1;
for ( int i = 0; i < compVersionComboBox->count() - 1; ++i )
{
if ( compVersionComboBox->itemData(i).value<KDevelop::Path>() == compilerPath )
{
selectedIndex = i;
break;
}
}
compVersionComboBox->setCurrentIndex( selectedIndex );
m_configUi->builder_path->setUrl( compilerPath.toUrl() );
m_configUi->msvc_include->setUrl( cg.readEntry( MsvcConfig::MSVC_INCLUDE, QString() ) );
m_configUi->config_combo->setCurrentItem( cg.readEntry( MsvcConfig::ACTIVE_CONFIGURATION, QString() ) );
m_configUi->arch_combo->setCurrentItem( cg.readEntry( MsvcConfig::ACTIVE_ARCHITECTURE, QString() ) );
}
QString MsvcBuilderPreferences::name() const
{
return i18n("MSVC");
}
void MsvcBuilderPreferences::onConfigurationChanged(QString const & cfg)
{
MsvcSolutionItem * solItem = dynamic_cast<MsvcSolutionItem*>(m_project->projectItem());
if (!solItem)
return;
QList<QString> configs = solItem->getConfigurations();
auto last = std::remove_if( configs.begin(),
configs.end(),
[&cfg](const QString & name) { return !name.startsWith(cfg+"|"); } );
QComboBox * archCombo = m_configUi->arch_combo;
// Clean it up
archCombo->clear();
for ( auto iter = configs.begin(); iter != last; ++ iter )
{
archCombo->addItem( iter->split('|').at(1) );
}
}