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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using EnvDTE;
namespace Ice.VisualStudio
{
public partial class ExtraCompilerOptionsView : UserControl
{
public ExtraCompilerOptionsView()
{
InitializeComponent();
toolTip.SetToolTip(txtExtraOptions, "Extra options passed to slice compiler.");
}
public void init(IceConfigurationDialog dialog, Project project)
{
_dialog = dialog;
_project = project;
}
public void load()
{
_configurationOptions = new Dictionary<string, string>();
comboBoxConfigurationName.Items.Add("All");
_configurationOptions["All"] = Util.getProjectProperty(_project, Util.PropertyIceExtraOptions);
object[] configurations = (object[])_project.ConfigurationManager.ConfigurationRowNames;
foreach(object name in configurations)
{
comboBoxConfigurationName.Items.Add(name);
_configurationOptions[name.ToString()] = Util.getProjectProperty(_project, Util.PropertyIceExtraOptions + "_" + name);
}
comboBoxConfigurationName.SelectedIndex = 0;
txtExtraOptions.Text = Util.getProjectProperty(_project, Util.PropertyIceExtraOptions);
}
public bool hasUnsavedChanges()
{
bool unsaved = false;
List<String> configurations = new List<String>();
configurations.Add("All");
foreach(object name in (object[])_project.ConfigurationManager.ConfigurationRowNames)
{
configurations.Add(name.ToString());
}
foreach(String name in configurations)
{
string property = Util.PropertyIceExtraOptions;
if(!name.Equals("All"))
{
property += "_" + name.ToString();
}
string value = "";
if(!_configurationOptions.TryGetValue(name.ToString(), out value))
{
unsaved = true;
break;
}
if(!value.Trim().Equals(Util.getProjectProperty(_project, property),
StringComparison.CurrentCulture))
{
unsaved = true;
break;
}
}
return unsaved;
}
public bool apply(ref bool changed)
{
changed = false;
if(hasUnsavedChanges())
{
if(!checkExtraOptions())
{
txtExtraOptions.Focus();
return false;
}
List<String> configurations = new List<String>();
configurations.Add("All");
foreach(object name in (object[])_project.ConfigurationManager.ConfigurationRowNames)
{
configurations.Add(name.ToString());
}
foreach(String name in configurations)
{
string property = Util.PropertyIceExtraOptions;
if(!name.Equals("All"))
{
property += "_" + name.ToString();
}
string value = "";
_configurationOptions.TryGetValue(name.ToString(), out value);
Util.setProjectProperty(_project, property, value.Trim());
}
if(Util.isCppProject(_project))
{
//
// If header or source extension has changed, we need to delete generated items
// from the project. The new items will be added when the project is build, on dialog
// close.
//
if(!Util.getHeaderExt(_project).Equals(_headerExt) ||
!Util.getSourceExt(_project).Equals(_sourceExt))
{
Util.cleanProject(_project, true);
}
Util.setProjectProperty(_project, Util.PropertyIceHeaderExt, _headerExt);
Util.setProjectProperty(_project, Util.PropertyIceSourceExt, _sourceExt);
}
changed = true;
_dialog.needSave();
}
return true;
}
public void setEnabled(bool enabled)
{
txtExtraOptions.Enabled = enabled;
}
private void txtExtraOptions_Enter(object sender, EventArgs e)
{
if(_dialog.editingIncludeDir())
{
_dialog.endEditIncludeDir(true);
}
}
private void txtExtraOptions_LostFocus(object sender, EventArgs e)
{
_configurationOptions[comboBoxConfigurationName.SelectedItem.ToString()] = txtExtraOptions.Text.Trim();
_dialog.needSave();
}
private void txtExtraOptions_TextChanged(object sender, EventArgs e)
{
_configurationOptions[comboBoxConfigurationName.SelectedItem.ToString()] = txtExtraOptions.Text.Trim();
_dialog.needSave();
}
private bool parseSlice2csOptions(String args)
{
Options opts = null;
return Util.parseSlice2csOptions(args, true, ref opts);
}
private bool parseSlice2cppOptions(String configuration, String args)
{
Options opts = null;
String headerExt = "";
String sourceExt = "";
bool success = Util.parseSlice2cppOptions(args, true, ref opts, ref headerExt, ref sourceExt);
//
// --header-ext and --source-ext can only be changed in the default configuration named "All".
//
if(configuration.Equals("All"))
{
_headerExt = headerExt;
_sourceExt = sourceExt;
}
else if(!headerExt.Equals("h") || !sourceExt.Equals("cpp"))
{
MessageBox.Show("Extra Options field contains some errors:\n" +
"--header-ext and --source-ext can only be used in the configuration named 'All'" +
" header-ext: " + headerExt + " source-ext: " + sourceExt,
"Ice Visual Studio Add-in", MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0);
success = false;
}
return success;
}
private bool checkExtraOptions()
{
bool isCppProject = Util.isCppProject(_project);
bool isCsharpProject = isCppProject ? false : Util.isCSharpProject(_project);
bool sucess = true;
foreach(KeyValuePair<string, string> entry in _configurationOptions)
{
if(String.IsNullOrEmpty(entry.Value))
{
continue;
}
if(isCppProject)
{
if(!parseSlice2cppOptions(entry.Key, entry.Value))
{
sucess = false;
}
}
else if(isCsharpProject)
{
if(!parseSlice2csOptions(entry.Value))
{
sucess = false;
}
}
}
return sucess;
}
private void comboBoxConfigurationName_SelectedIndexChanged(object sender, EventArgs e)
{
String name = comboBoxConfigurationName.SelectedItem.ToString();
String value = "";
if(_configurationOptions.TryGetValue(name, out value))
{
txtExtraOptions.Text = _configurationOptions[name];
}
else
{
txtExtraOptions.Text = "";
}
}
private Dictionary<String, String> _configurationOptions;
private IceConfigurationDialog _dialog;
private Project _project;
private string _headerExt = "h";
private string _sourceExt = "cpp";
}
}
|