45
47
public partial class AddViewDialog : Gtk.Dialog
47
AspMvcProject project;
48
IList<string> loadedTemplateList;
50
Gtk.ListStore primaryPlaceholderStore = new Gtk.ListStore (typeof (String));
51
System.CodeDom.Compiler.CodeDomProvider provider;
52
DropDownBox dataClassCombo;
49
AspMvcProject project;
50
IDictionary<string, IList<string>> loadedTemplateList;
51
IDictionary<string, Gtk.ListStore> templateStore;
52
Gtk.ListStore dataClassStore;
55
Gtk.ListStore primaryPlaceholderStore = new Gtk.ListStore (typeof (String));
56
System.CodeDom.Compiler.CodeDomProvider provider;
53
57
TypeDataProvider classDataProvider;
55
59
public AddViewDialog (AspMvcProject project)
57
61
this.project = project;
60
dataClassCombo = new DropDownBox ();
63
Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h);
64
dataClassCombo.DefaultIconHeight = Math.Max (h, 16);
65
dataClassCombo.DefaultIconWidth = Math.Max (w, 16);
66
dataClassAlignment.Add (dataClassCombo);
67
dataClassAlignment.QueueResize ();
68
dataClassCombo.ShowAll ();
70
provider = project.LanguageBinding.GetCodeDomProvider ();
64
provider = project.LanguageBinding.GetCodeDomProvider ();
66
var viewEngines = GetProperViewEngines ();
67
loadedTemplateList = new Dictionary<string, IList<string>> ();
68
foreach (var engine in viewEngines) {
69
viewEngineCombo.AppendText (engine);
70
loadedTemplateList[engine] = project.GetCodeTemplates ("AddView", engine);
73
viewEngineCombo.Active = 0;
74
InitializeTemplateStore (loadedTemplateList);
72
76
ContentPlaceHolders = new List<string> ();
73
77
string siteMaster = project.VirtualToLocalPath ("~/Views/Shared/Site.master", null);
74
78
if (project.Files.GetFile (siteMaster) != null)
75
79
masterEntry.Text = "~/Views/Shared/Site.master";
77
loadedTemplateList = project.GetCodeTemplates ("AddView");
78
bool foundEmptyTemplate = false;
79
int templateIndex = 0;
80
foreach (string file in loadedTemplateList) {
81
string name = PP.GetFileNameWithoutExtension (file);
82
templateCombo.AppendText (name);
83
if (!foundEmptyTemplate){
84
if (name == "Empty") {
85
templateCombo.Active = templateIndex;
86
foundEmptyTemplate = true;
92
if (!foundEmptyTemplate)
93
throw new Exception ("The Empty.tt template is missing.");
95
81
primaryPlaceholderCombo.Model = primaryPlaceholderStore;
97
83
UpdateTypePanelSensitivity (null, null);
98
84
UpdateMasterPanelSensitivity (null, null);
88
IEnumerable<string> GetProperViewEngines ()
91
if (MvcVersion.CompareTo ("2.0.0.0") > 0)
95
void InitializeTemplateStore (IDictionary<string, IList<string>> tempList)
97
templateStore = new Dictionary<string, Gtk.ListStore> ();
99
foreach (var engine in tempList.Keys) {
100
bool foundEmptyTemplate = false;
101
templateStore[engine] = new Gtk.ListStore (typeof (string));
103
foreach (string file in tempList[engine]) {
104
string name = PP.GetFileNameWithoutExtension (file);
105
if (!foundEmptyTemplate) {
106
if (name == "Empty") {
107
templateStore[engine].InsertWithValues (0, name);
108
foundEmptyTemplate = true;
110
templateStore[engine].AppendValues (name);
114
if (!foundEmptyTemplate)
115
throw new Exception ("The Empty.tt template is missing.");
118
UpdateTemplateList ();
121
void UpdateTemplateList ()
123
templateCombo.Model = templateStore[ActiveViewEngine];
124
oldEngine = ActiveViewEngine;
125
templateCombo.Active = 0;
102
128
protected virtual void Validate (object sender, EventArgs e)
114
140
bool canHaveMaster = !IsPartialView;
115
141
masterCheck.Sensitive = canHaveMaster;
116
masterPanel.Sensitive = canHaveMaster && HasMaster;
142
masterPanel.Sensitive = canHaveMaster && HasMaster;
143
placeholderBox.Sensitive = masterPanel.Sensitive && ActiveViewEngine != "Razor";
117
144
MasterChanged (null, null);
121
148
protected virtual void UpdateTypePanelSensitivity (object sender, EventArgs e)
123
//FIXME: need to fix the class list widget
124
bool enabled = typePanel.Sensitive = false; // stronglyTypedCheck.Active;
126
if (enabled && classDataProvider == null) {
127
dataClassCombo.DataProvider = classDataProvider = new TypeDataProvider (project);
128
if (classDataProvider.List.Count > 0)
129
dataClassCombo.SetItem (0);
150
bool enabled = typePanel.Sensitive = stronglyTypedCheck.Active;
152
if (enabled && classDataProvider == null) {
153
classDataProvider = new TypeDataProvider (project);
154
dataClassStore = new Gtk.ListStore (typeof (string));
155
foreach (var item in classDataProvider.TypeNamesList)
156
dataClassStore.AppendValues (item);
157
dataClassCombo.Model = dataClassStore;
158
if (classDataProvider.TypeNamesList.Count > 0)
159
dataClassCombo.Active = 0;
141
171
public bool IsValid ()
143
173
if (!IsValidIdentifier (ViewName))
146
if (!IsPartialView && HasMaster) {
147
if (String.IsNullOrEmpty (MasterFile) || !System.IO.File.Exists (project.VirtualToLocalPath (oldMaster, null)))
149
//PrimaryPlaceHolder can be empty
176
if (!IsPartialView && HasMaster && ActiveViewEngine != "Razor") {
177
if (String.IsNullOrEmpty (MasterFile) || !System.IO.File.Exists (project.VirtualToLocalPath (oldMaster, null)))
179
//PrimaryPlaceHolder can be empty
180
//Layout Page can be empty in Razor Views - it's usually set in _ViewStart.cshtml file
152
if (IsStronglyTyped && (ViewDataType == null))
183
if (IsStronglyTyped && String.IsNullOrEmpty(ViewDataTypeString))
163
194
protected virtual void ShowMasterSelectionDialog (object sender, System.EventArgs e)
165
var dialog = new MonoDevelop.Ide.Projects.ProjectFileSelectorDialog (project, null, "*.master") {
166
Title = MonoDevelop.Core.GettextCatalog.GetString ("Select a Master Page..."),
196
string pattern, title;
197
if (ActiveViewEngine == "Razor") {
198
pattern = "*.cshtml";
199
title = MonoDevelop.Core.GettextCatalog.GetString ("Select a Layout file...");
201
pattern = "*.master";
202
title = MonoDevelop.Core.GettextCatalog.GetString ("Select a Master Page...");
204
var dialog = new MonoDevelop.Ide.Projects.ProjectFileSelectorDialog (project, null, pattern)
170
210
if (MessageService.RunCustomDialog (dialog) == (int) Gtk.ResponseType.Ok)
196
236
if (pd != null) {
198
var visitor = new ContentPlaceHolderVisitor ();
199
pd.RootNode.AcceptVisit (visitor);
200
ContentPlaceHolders.AddRange (visitor.PlaceHolders);
238
ContentPlaceHolders.AddRange (pd.XDocument.GetAllPlaceholderIds ());
202
240
for (int i = 0; i < ContentPlaceHolders.Count; i++) {
203
241
string placeholder = ContentPlaceHolders[i];
204
242
primaryPlaceholderStore.AppendValues (placeholder);
206
244
if (placeholder.Contains ("main") || placeholder.Contains ("Main")
207
|| placeholder.Contains ("content") || placeholder.Contains ("Main"))
245
|| placeholder.Contains ("content") || placeholder.Contains ("Content"))
208
246
primaryPlaceholderCombo.Active = i;
210
248
} catch (Exception ex) {
256
protected virtual void ViewEngineChanged (object sender, EventArgs e)
258
if (String.IsNullOrEmpty (oldEngine))
260
if (oldEngine != ActiveViewEngine) {
261
UpdateTemplateList ();
262
UpdateMasterPanelSensitivity (null, null);
266
protected virtual void DataClassChanged (object sender, EventArgs e)
218
271
#region Public properties
220
public IType ViewDataType {
273
public Type ViewDataType {
275
return dataClassCombo.Active >= 0 ? (Type)classDataProvider.TypesList[dataClassCombo.Active] : System.Type.GetType(dataClassCombo.ActiveText, false);
279
public string ViewDataTypeString {
222
return (IType)dataClassCombo.CurrentItem;
281
return dataClassCombo.ActiveText;
267
326
public bool IsStronglyTyped {
268
327
get { return stronglyTypedCheck.Active; }
273
class TypeDataProvider : DropDownBoxListWindow.IListDataProvider
277
public List<ITypeDefinition> List { get; private set; }
279
public TypeDataProvider (MonoDevelop.Projects.DotNetProject project)
281
var ctx = TypeSystemService.GetCompilation (project);
282
List = new List<ITypeDefinition> (ctx.MainAssembly.GetAllTypeDefinitions ());
283
this.ambience = AmbienceService.GetAmbience (project.LanguageName);
286
public int IconCount { get { return List.Count; } }
290
//called when the list is shown
293
public string GetMarkup (int n)
295
return ambience.GetString ((IEntity)List[n], OutputFlags.IncludeGenerics | OutputFlags.UseFullName | OutputFlags.IncludeMarkup);
298
public Gdk.Pixbuf GetIcon (int n)
300
return ImageService.GetPixbuf (List[n].GetStockIcon (),Gtk.IconSize.Menu);
303
public object GetTag (int n)
308
public void ActivateItem (int n)
330
public string ActiveViewEngine {
331
get { return viewEngineCombo.ActiveText; }
334
public string MvcVersion {
336
return project.GetAspNetMvcVersion ();
342
class TypeDataProvider
344
public List<ITypeDefinition> TypesList { get; private set; }
345
public List<string> TypeNamesList { get; private set; }
348
public TypeDataProvider (MonoDevelop.Projects.DotNetProject project)
350
TypeNamesList = new List<string> ();
351
var ctx = TypeSystemService.GetCompilation (project);
352
TypesList = new List<ITypeDefinition> (ctx.MainAssembly.GetAllTypeDefinitions ());
353
this.ambience = AmbienceService.GetAmbience (project.LanguageName);
354
foreach (var typeDef in TypesList) {
355
TypeNamesList.Add (ambience.GetString ((IEntity)typeDef, OutputFlags.IncludeGenerics | OutputFlags.UseFullName | OutputFlags.IncludeMarkup));