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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
//
// CodeGenerationPanel.cs: Code generation panel to configure project
//
// Authors:
// Marcos David Marin Amador <MarcosMarin@gmail.com>
//
// Copyright (C) 2007 Marcos David Marin Amador
//
//
// This source code is licenced under The MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using MonoDevelop.Core;
using MonoDevelop.Ide.Gui.Dialogs;
using MonoDevelop.Components;
using MonoDevelop.Ide;
namespace CBinding
{
public partial class CodeGenerationPanel : Gtk.Bin
{
private CProjectConfiguration configuration;
private Gtk.ListStore libStore = new Gtk.ListStore (typeof(string));
private Gtk.ListStore libPathStore = new Gtk.ListStore (typeof(string));
private Gtk.ListStore includePathStore = new Gtk.ListStore (typeof(string));
static string[,] quickPathInsertMenu = new string[,] {
{GettextCatalog.GetString ("_Project Directory"), "${ProjectDir}"},
{GettextCatalog.GetString ("_Root Solution Directory"), "${CombineDir}"},
};
public CodeGenerationPanel ()
{
this.Build ();
Gtk.CellRendererText textRenderer = new Gtk.CellRendererText ();
libTreeView.Model = libStore;
libTreeView.HeadersVisible = false;
libTreeView.AppendColumn ("Library", textRenderer, "text", 0);
libPathTreeView.Model = libPathStore;
libPathTreeView.HeadersVisible = false;
libPathTreeView.AppendColumn ("Library", textRenderer, "text", 0);
includePathTreeView.Model = includePathStore;
includePathTreeView.HeadersVisible = false;
includePathTreeView.AppendColumn ("Include", textRenderer, "text", 0);
new MenuButtonEntry (libPathEntry, quickInsertLibButton, quickPathInsertMenu);
new MenuButtonEntry (includePathEntry, quickInsertIncludeButton, quickPathInsertMenu);
}
public void Load (CProjectConfiguration config)
{
configuration = config;
switch (configuration.WarningLevel)
{
case WarningLevel.None:
noWarningRadio.Active = true;
break;
case WarningLevel.Normal:
normalWarningRadio.Active = true;
break;
case WarningLevel.All:
allWarningRadio.Active = true;
break;
}
warningsAsErrorsCheckBox.Active = configuration.WarningsAsErrors;
optimizationSpinButton.Value = configuration.OptimizationLevel;
switch (configuration.CompileTarget)
{
case CBinding.CompileTarget.Bin:
targetComboBox.Active = 0;
break;
case CBinding.CompileTarget.StaticLibrary:
targetComboBox.Active = 1;
break;
case CBinding.CompileTarget.SharedLibrary:
targetComboBox.Active = 2;
break;
}
extraCompilerTextView.Buffer.Text = configuration.ExtraCompilerArguments;
extraLinkerTextView.Buffer.Text = configuration.ExtraLinkerArguments;
defineSymbolsTextEntry.Text = configuration.DefineSymbols;
libStore.Clear ();
foreach (string lib in configuration.Libs)
libStore.AppendValues (lib);
libPathStore.Clear ();
foreach (string libPath in configuration.LibPaths)
libPathStore.AppendValues (libPath);
includePathStore.Clear ();
foreach (string includePath in configuration.Includes)
includePathStore.AppendValues (includePath);
}
private void OnIncludePathAdded (object sender, EventArgs e)
{
if (includePathEntry.Text.Length > 0) {
includePathStore.AppendValues (includePathEntry.Text);
includePathEntry.Text = string.Empty;
}
}
private void OnIncludePathRemoved (object sender, EventArgs e)
{
Gtk.TreeIter iter;
includePathTreeView.Selection.GetSelected (out iter);
includePathStore.Remove (ref iter);
}
private void OnLibPathAdded (object sender, EventArgs e)
{
if (libPathEntry.Text.Length > 0) {
libPathStore.AppendValues (libPathEntry.Text);
libPathEntry.Text = string.Empty;
}
}
private void OnLibPathRemoved (object sender, EventArgs e)
{
Gtk.TreeIter iter;
libPathTreeView.Selection.GetSelected (out iter);
libPathStore.Remove (ref iter);
}
private void OnLibAdded (object sender, EventArgs e)
{
if (libAddEntry.Text.Length > 0) {
libStore.AppendValues (libAddEntry.Text);
libAddEntry.Text = string.Empty;
}
}
private void OnLibRemoved (object sender, EventArgs e)
{
Gtk.TreeIter iter;
libTreeView.Selection.GetSelected (out iter);
libStore.Remove (ref iter);
}
// TODO: This is platform specific... the C Binding should have a global list of 'standard' library dirs...
internal const string DEFAULT_LIB_DIR = "/usr/lib";
internal const string DEFAULT_INCLUDE_DIR = "/usr/lib";
internal const string STATIC_LIB_FILTER = "*.a";
internal const string DYNAMIC_LIB_FILTER = "*.so";
private void OnBrowseButtonClick (object sender, EventArgs e)
{
var dialog = new MonoDevelop.Components.SelectFileDialog (GettextCatalog.GetString ("Add Library")) {
TransientFor = (Gtk.Window) Toplevel,
CurrentFolder = DEFAULT_LIB_DIR,
};
dialog.AddFilter (GettextCatalog.GetString ("Static Library"), STATIC_LIB_FILTER);
dialog.AddFilter (GettextCatalog.GetString ("Dynamic Library"), DYNAMIC_LIB_FILTER);
dialog.AddAllFilesFilter ();
if (dialog.Run ())
libAddEntry.Text = dialog.SelectedFile;
}
private void OnIncludePathBrowseButtonClick (object sender, EventArgs e)
{
var dialog = new MonoDevelop.Components.SelectFolderDialog (GettextCatalog.GetString ("Add Path")) {
TransientFor = (Gtk.Window) Toplevel,
CurrentFolder = DEFAULT_INCLUDE_DIR,
};
if (dialog.Run ())
includePathEntry.Text = dialog.SelectedFile;
}
private void OnLibPathBrowseButtonClick (object sender, EventArgs e)
{
var dialog = new MonoDevelop.Components.SelectFolderDialog (GettextCatalog.GetString ("Add Path")) {
TransientFor = (Gtk.Window) Toplevel,
CurrentFolder = DEFAULT_LIB_DIR,
};
if (dialog.Run ())
libPathEntry.Text = dialog.SelectedFile;
}
public bool Store ()
{
if (configuration == null)
return false;
string line;
Gtk.TreeIter iter;
if (noWarningRadio.Active)
configuration.WarningLevel = WarningLevel.None;
else if (normalWarningRadio.Active)
configuration.WarningLevel = WarningLevel.Normal;
else
configuration.WarningLevel = WarningLevel.All;
configuration.WarningsAsErrors = warningsAsErrorsCheckBox.Active;
configuration.OptimizationLevel = (int)optimizationSpinButton.Value;
switch (targetComboBox.ActiveText)
{
case "Executable":
configuration.CompileTarget = CBinding.CompileTarget.Bin;
break;
case "Static Library":
configuration.CompileTarget = CBinding.CompileTarget.StaticLibrary;
break;
case "Shared Object":
configuration.CompileTarget = CBinding.CompileTarget.SharedLibrary;
break;
}
configuration.ExtraCompilerArguments = extraCompilerTextView.Buffer.Text;
configuration.ExtraLinkerArguments = extraLinkerTextView.Buffer.Text;
configuration.DefineSymbols = defineSymbolsTextEntry.Text;
libStore.GetIterFirst (out iter);
configuration.Libs.Clear ();
while (libStore.IterIsValid (iter)) {
line = (string)libStore.GetValue (iter, 0);
configuration.Libs.Add (line);
libStore.IterNext (ref iter);
}
libPathStore.GetIterFirst (out iter);
configuration.LibPaths.Clear ();
while (libPathStore.IterIsValid (iter)) {
line = (string)libPathStore.GetValue (iter, 0);
configuration.LibPaths.Add (line);
libPathStore.IterNext (ref iter);
}
includePathStore.GetIterFirst (out iter);
configuration.Includes.Clear ();
while (includePathStore.IterIsValid (iter)) {
line = (string)includePathStore.GetValue (iter, 0);
configuration.Includes.Add (line);
includePathStore.IterNext (ref iter);
}
return true;
}
protected virtual void OnLibAddEntryChanged (object sender, EventArgs e)
{
if (string.IsNullOrEmpty (libAddEntry.Text))
addLibButton.Sensitive = false;
else
addLibButton.Sensitive = true;
}
protected virtual void OnLibTreeViewCursorChanged (object sender, System.EventArgs e)
{
removeLibButton.Sensitive = true;
}
protected virtual void OnRemoveLibButtonClicked (object sender, System.EventArgs e)
{
removeLibButton.Sensitive = false;
}
protected virtual void OnIncludePathEntryChanged (object sender, System.EventArgs e)
{
if (string.IsNullOrEmpty (includePathEntry.Text))
includePathAddButton.Sensitive = false;
else
includePathAddButton.Sensitive = true;
}
protected virtual void OnLibPathEntryChanged (object sender, System.EventArgs e)
{
if (string.IsNullOrEmpty (libPathEntry.Text))
libPathAddButton.Sensitive = false;
else
libPathAddButton.Sensitive = true;
}
protected virtual void OnIncludePathTreeViewCursorChanged (object sender, System.EventArgs e)
{
includePathRemoveButton.Sensitive = true;
}
protected virtual void OnIncludePathRemoveButtonClicked (object sender, System.EventArgs e)
{
includePathRemoveButton.Sensitive = false;
}
protected virtual void OnLibPathTreeViewCursorChanged (object sender, System.EventArgs e)
{
libPathRemoveButton.Sensitive = true;
}
protected virtual void OnLibPathRemoveButtonClicked (object sender, System.EventArgs e)
{
libPathRemoveButton.Sensitive = false;
}
protected virtual void OnLibAddEntryActivated (object sender, System.EventArgs e)
{
OnLibAdded (this, new EventArgs ());
}
protected virtual void OnIncludePathEntryActivated (object sender, System.EventArgs e)
{
OnIncludePathAdded (this, new EventArgs ());
}
protected virtual void OnLibPathEntryActivated (object sender, System.EventArgs e)
{
OnLibPathAdded (this, new EventArgs ());
}
}
public class CodeGenerationPanelBinding : MultiConfigItemOptionsPanel
{
private CodeGenerationPanel panel;
public override Gtk.Widget CreatePanelWidget ()
{
return panel = new CodeGenerationPanel ();
}
public override void LoadConfigData ()
{
panel.Load ((CProjectConfiguration) CurrentConfiguration);
}
public override void ApplyChanges ()
{
panel.Store ();
}
}
}
|