Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: icsharpcode/SharpDevelop
...
head fork: icsharpcode/SharpDevelop
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
20 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectView.xaml
@@ -99,13 +99,13 @@
<Label
Grid.Row="5"
- IsEnabled="{Binding Path=IsStronglyTypedView}"
+ IsEnabled="{Binding Path=IsViewTemplateEnabled}"
Content="Template:"/>
<ComboBox
Grid.Row="5"
Grid.Column="1"
Margin="0, 2, 0, 0"
- IsEnabled="{Binding Path=IsStronglyTypedView}"
+ IsEnabled="{Binding Path=IsViewTemplateEnabled}"
ItemsSource="{Binding Path=ViewTemplates}"
ItemTemplate="{StaticResource ViewEngineTemplate}"
SelectedItem="{Binding Path=SelectedViewTemplate}"/>
@@ -113,39 +113,42 @@
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
+ IsEnabled="{Binding Path=IsContentPageEnabled}"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Master Page:"/>
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
+ IsEnabled="{Binding Path=IsContentPageEnabled}"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Layout:"/>
<CheckBox
Grid.Column="1"
Grid.Row="6"
Margin="0, 28, 0, 0"
+ IsEnabled="{Binding Path=IsContentPageEnabled}"
IsChecked="{Binding Path=IsContentPage}"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
- IsEnabled="{Binding Path=IsContentPage}"
+ IsEnabled="{Binding Path=IsContentPagePropertiesEnabled}"
Content="Master Page:"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
- IsEnabled="{Binding Path=IsContentPage}"
+ IsEnabled="{Binding Path=IsContentPagePropertiesEnabled}"
Content="Layout:"/>
<Grid
Grid.Row="7"
- Grid.Column="1">
+ Grid.Column="1"
+ IsEnabled="{Binding Path=IsContentPagePropertiesEnabled}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox
- IsEnabled="{Binding Path=IsContentPage}"
Text="{Binding Path=MasterPageFile}"/>
<StackPanel
Grid.Column="2"
@@ -153,7 +156,6 @@
<Button
Padding="9, 0, 9, 0"
Style="{x:Null}"
- IsEnabled="{Binding Path=IsContentPage}"
Content="..."
Command="{Binding Path=OpenSelectMasterPageViewCommand}"/>
</StackPanel>
@@ -162,13 +164,13 @@
<Label
Grid.Row="8"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
- IsEnabled="{Binding Path=IsContentPage}"
+ IsEnabled="{Binding Path=IsContentPagePropertiesEnabled}"
Content="Main Content ID:"/>
<TextBox
Grid.Row="8"
Grid.Column="1"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
- IsEnabled="{Binding Path=IsContentPage}"
+ IsEnabled="{Binding Path=IsContentPagePropertiesEnabled}"
Text="{Binding Path=PrimaryContentPlaceHolderId}"/>
<StackPanel
View
57 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs
@@ -24,9 +24,10 @@ public class AddMvcViewToProjectViewModel : ViewModelBase<AddMvcViewToProjectVie
bool isSelectMasterPageViewOpen;
MvcProjectFile selectedMasterPage;
string masterPageFile = String.Empty;
- List<MvcViewTextTemplate> viewTemplates;
+ List<MvcViewTextTemplate> viewTemplates = new List<MvcViewTextTemplate>();
MvcViewTextTemplate selectedViewTemplate;
MvcModelClassViewModelsForSelectedFolder modelClassesForSelectedFolder;
+ MvcModelClassViewModel selectedModelClass;
public AddMvcViewToProjectViewModel(ISelectedMvcFolder selectedViewFolder)
: this(
@@ -203,9 +204,18 @@ MvcViewTextTemplate GetEmptyViewTemplate()
set {
isContentPage = value;
OnPropertyChanged(viewModel => viewModel.IsContentPage);
+ OnPropertyChanged(viewModel => viewModel.IsContentPagePropertiesEnabled);
}
}
+ public bool IsContentPageEnabled {
+ get { return !IsPartialView; }
+ }
+
+ public bool IsContentPagePropertiesEnabled {
+ get { return IsContentPage && IsContentPageEnabled; }
+ }
+
public bool CanAddMvcView()
{
return viewFileName.HasValidViewName();
@@ -275,7 +285,11 @@ void AddMvcViewFileToProject()
public bool IsPartialView {
get { return viewFileName.IsPartialView; }
- set { viewFileName.IsPartialView = value; }
+ set {
+ viewFileName.IsPartialView = value;
+ OnPropertyChanged(viewModel => viewModel.IsContentPageEnabled);
+ OnPropertyChanged(viewModel => viewModel.IsContentPagePropertiesEnabled);
+ }
}
public bool IsStronglyTypedView {
@@ -287,15 +301,50 @@ void AddMvcViewFileToProject()
OnPropertyChanged(viewModel => viewModel.ModelClasses);
}
OnPropertyChanged(viewModel => viewModel.IsStronglyTypedView);
+ OnPropertyChanged(viewModel => viewModel.IsViewTemplateEnabled);
}
}
+ public bool IsViewTemplateEnabled {
+ get { return IsStronglyTypedView && (SelectedModelClass != null); }
+ }
+
public IEnumerable<MvcModelClassViewModel> ModelClasses {
get { return modelClassesForSelectedFolder.ModelClasses; }
}
- public MvcModelClassViewModel SelectedModelClass { get; set; }
- public string ModelClassName { get; set; }
+ public MvcModelClassViewModel SelectedModelClass {
+ get { return selectedModelClass; }
+ set {
+ selectedModelClass = value;
+ if (selectedModelClass == null) {
+ SelectDefaultViewTemplate();
+ }
+ OnPropertyChanged(viewModel => viewModel.SelectedModelClass);
+ OnPropertyChanged(viewModel => viewModel.IsViewTemplateEnabled);
+ }
+ }
+
+ string modelClassName;
+
+ public string ModelClassName {
+ get { return modelClassName; }
+ set {
+ modelClassName = value;
+ if (!ModelClassNameMatchesSelectedModelClassName()) {
+ SelectedModelClass = null;
+ }
+ }
+ }
+
+ bool ModelClassNameMatchesSelectedModelClassName()
+ {
+ if (selectedModelClass != null) {
+ return selectedModelClass.Name == modelClassName;
+ }
+ return false;
+ }
+
public string PrimaryContentPlaceHolderId { get; set; }
public string MasterPageFile {
View
6 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcModelClassViewModel.cs
@@ -19,7 +19,11 @@ public class MvcModelClassViewModel
void GetName()
{
- name = String.Format("{0} ({1})", mvcClass.Name, mvcClass.Namespace);
+ if (String.IsNullOrEmpty(mvcClass.Namespace)) {
+ name = mvcClass.Name;
+ } else {
+ name = String.Format("{0} ({1})", mvcClass.Name, mvcClass.Namespace);
+ }
}
public string Name {
View
240 src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/AddMvcViewToProjectViewModelTests.cs
@@ -1148,5 +1148,245 @@ public void SelectedViewEngine_RazorViewEngineSelected_SelectedViewTemplatePrope
Assert.IsTrue(fired);
}
+
+ [Test]
+ public void IsContentPageEnabled_IsPartialViewIsNotSelected_ReturnsTrue()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = false;
+ bool enabled = viewModel.IsContentPageEnabled;
+
+ Assert.IsTrue(enabled);
+ }
+
+ [Test]
+ public void IsContentPageEnabled_IsPartialViewIsSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = true;
+ bool enabled = viewModel.IsContentPageEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsPartialView_IsPartialViewChangedFromTrueToFalse_IsContentPageEnabledPropertyChangedEventIsFired()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = true;
+ MonitorPropertyChangedEvents();
+ viewModel.IsPartialView = false;
+ SelectRazorViewEngine();
+
+ bool fired = propertyChangedEvents.Contains("IsContentPageEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void IsContentPagePropertiesEnabled_IsPartialViewIsNotSelectedAndIsContentPageIsSelected_ReturnsTrue()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = false;
+ viewModel.IsContentPage = true;
+ bool enabled = viewModel.IsContentPagePropertiesEnabled;
+
+ Assert.IsTrue(enabled);
+ }
+
+ [Test]
+ public void IsContentPagePropertiesEnabled_IsPartialViewIsNotSelectedAndIsContentPageIsNotSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = false;
+ viewModel.IsContentPage = false;
+ bool enabled = viewModel.IsContentPagePropertiesEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsContentPagePropertiesEnabled_IsPartialViewIsSelectedAndIsContentPageIsSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = true;
+ viewModel.IsContentPage = true;
+ bool enabled = viewModel.IsContentPagePropertiesEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsPartialView_IsPartialViewChangedFromTrueToFalse_IsContentPagePropertiesEnabledPropertyChangedEventIsFired()
+ {
+ CreateViewModel();
+ viewModel.IsPartialView = true;
+ MonitorPropertyChangedEvents();
+ viewModel.IsPartialView = false;
+ SelectRazorViewEngine();
+
+ bool fired = propertyChangedEvents.Contains("IsContentPagePropertiesEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void IsPartialView_IsContentPageChangedFromTrueToFalse_IsContentPagePropertiesEnabledPropertyChangedEventIsFired()
+ {
+ CreateViewModel();
+ viewModel.IsContentPage = true;
+ MonitorPropertyChangedEvents();
+ viewModel.IsContentPage = false;
+ SelectRazorViewEngine();
+
+ bool fired = propertyChangedEvents.Contains("IsContentPagePropertiesEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void IsViewTemplateEnabled_ModelClassSelectedAndIsStronglyTypedViewIsNotSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ viewModel.IsStronglyTypedView = false;
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsViewTemplateEnabled_ModelClassSelectedAndIsStronglyTypedViewIsSelected_ReturnsTrue()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsTrue(enabled);
+ }
+
+ [Test]
+ public void IsViewTemplateEnabled_NoModelClassSelectedAndIsStronglyTypedViewIsSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = null;
+ viewModel.ModelClassName = "Test";
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsStronglyTypedView_IsStronglyTypedViewIsChangedFromTrueToFalse_IsViewTemplateEnabledPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ viewModel.IsStronglyTypedView = true;
+ MonitorPropertyChangedEvents();
+ viewModel.IsStronglyTypedView = false;
+
+ bool fired = propertyChangedEvents.Contains("IsViewTemplateEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void SelectedModelClass_SelectedModelClassChangedToNull_IsViewTemplateEnabledPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ MonitorPropertyChangedEvents();
+ viewModel.SelectedModelClass = null;
+
+ bool fired = propertyChangedEvents.Contains("IsViewTemplateEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedFromSelectedModelClass_SelectedModelClassChangedToNull()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ viewModel.ModelClassName = "Test";
+
+ MvcModelClassViewModel selectedModelClass = viewModel.SelectedModelClass;
+
+ Assert.IsNull(selectedModelClass);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedFromSelectedModelClass_SelectedModelClassPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ MonitorPropertyChangedEvents();
+ viewModel.ModelClassName = "Test";
+
+ bool fired = propertyChangedEvents.Contains("SelectedModelClass");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedToMatchSelectedModelClass_SelectedModelClassIsNotChangedToNull()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ MvcModelClassViewModel expectedModelClass = viewModel.ModelClasses.First();
+ viewModel.SelectedModelClass = expectedModelClass;
+ viewModel.ModelClassName = "MyModel (ICSharpCode.MyProject)";
+
+ MvcModelClassViewModel selectedModelClass = viewModel.SelectedModelClass;
+
+ Assert.AreEqual(expectedModelClass, selectedModelClass);
+ }
+
+ [Test]
+ public void ViewTemplates_NonEmptyViewTemplateSelectedWhenUserTypesInModelClassName_EmptyViewTemplateSelected()
+ {
+ fakeTextTemplateRepository = new FakeMvcTextTemplateRepository();
+
+ var templateB = new MvcViewTextTemplate(@"d:\templates\B.tt");
+ fakeTextTemplateRepository.ViewTextTemplates.Add(templateB);
+
+ var emptyTemplate = new MvcViewTextTemplate(@"d:\templates\Empty.tt");
+ fakeTextTemplateRepository.ViewTextTemplates.Add(emptyTemplate);
+
+ CreateViewModelWithViewFolderPath(@"d:\myproject\views", fakeTextTemplateRepository);
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+
+ viewModel.IsStronglyTypedView = true;
+ MvcModelClassViewModel expectedModelClass = viewModel.ModelClasses.First();
+ viewModel.SelectedModelClass = expectedModelClass;
+ viewModel.SelectedViewTemplate = templateB;
+ viewModel.ModelClassName = "test";
+
+ MvcViewTextTemplate template = viewModel.SelectedViewTemplate;
+
+ Assert.AreEqual(emptyTemplate, template);
+ }
}
}
View
9 src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcModelClassViewModelTests.cs
@@ -52,5 +52,14 @@ public void FullName_ClassHasNamespaceAndName_ReturnsFullyQualifiedClassName()
Assert.AreEqual("ICSharpCode.Tests.MyClass", name);
}
+
+ [Test]
+ public void Name_ClassNameButHasEmptyNamespace_ReturnsClassNameOnly()
+ {
+ CreateViewModel(String.Empty, "MyClass");
+ string text = viewModel.Name;
+
+ Assert.AreEqual("MyClass", text);
+ }
}
}

No commit comments for this range

Something went wrong with that request. Please try again.