Skip to content

Commit

Permalink
Resharper optimized version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slesa committed Feb 25, 2014
1 parent 37cca2b commit f85f158
Show file tree
Hide file tree
Showing 36 changed files with 417 additions and 533 deletions.
51 changes: 18 additions & 33 deletions sketches/wpf/caliburn/11_Screens/11_Screens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Settings\SettingsViewModel.cs" />
<Compile Include="Shell\ApplicationCloseStrategy.cs" />
<Compile Include="Shell\DialogConductorView.xaml.cs">
<DependentUpon>DialogConductorView.xaml</DependentUpon>
</Compile>
<Compile Include="Shell\DialogConductorViewModel.cs" />
<Compile Include="Shell\MessageBoxViewModel.cs" />
<Compile Include="Shell\ScreensBootstrapper.cs" />
<Compile Include="Shell\ShellViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Customers\AddressViewModel.cs" />
<Compile Include="Customers\CustomersWorkspaceViewModel.cs" />
<Compile Include="Customers\CustomerViewModel.cs" />
Expand All @@ -98,28 +87,24 @@
<Compile Include="Framework\MessageBoxOptions.cs" />
<Compile Include="Orders\OrdersWorkspaceViewModel.cs" />
<Compile Include="Orders\OrderViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
<Compile Include="Settings\SettingsViewModel.cs" />
<Compile Include="Shell\ApplicationCloseStrategy.cs" />
<Compile Include="Shell\DialogConductorView.xaml.cs">
<DependentUpon>DialogConductorView.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
<Compile Include="Shell\DialogConductorViewModel.cs" />
<Compile Include="Shell\MessageBoxViewModel.cs" />
<Compile Include="Shell\ScreensBootstrapper.cs" />
<Compile Include="Shell\ShellView.xaml.cs">
<DependentUpon>ShellView.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<Compile Include="Shell\ShellViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -188,14 +173,14 @@
</Page>
</ItemGroup>
<ItemGroup>
<Resource Include="Customers\Resources\Images\man1-48.png" />
<Resource Include="Resources\Images\backgroundshadow.png" />
<Resource Include="Resources\Images\backgroundtexture.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Orders\Resources\Images\shopping-cart-full48.png" />
<Resource Include="Customers\Resources\Images\man1-48.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Images\backgroundshadow.png" />
<Resource Include="Resources\Images\backgroundtexture.png" />
<Resource Include="Orders\Resources\Images\shopping-cart-full48.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Settings\Resources\Images\report48.png" />
Expand Down
1 change: 1 addition & 0 deletions sketches/wpf/caliburn/11_Screens/App.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Application x:Class="_11_Screens.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:Converters="clr-namespace:_11_Screens.Framework.Converters"
xmlns:Shell="clr-namespace:_11_Screens.Shell" >
<Application.Resources>
Expand Down
4 changes: 0 additions & 4 deletions sketches/wpf/caliburn/11_Screens/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ namespace _11_Screens
{
public partial class App : Application
{
public App()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace _11_Screens.Customers
{
public class AddressViewModel : Screen
{
public AddressViewModel() {
public AddressViewModel()
{
DisplayName = "Address";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace _11_Screens.Customers
[PartCreationPolicy(CreationPolicy.NonShared)]
public class CustomerViewModel : DocumentBase
{
public void Save() {
public void Save()
{
IsDirty = false;
Dialogs.ShowMessageBox("Your data has been successfully saved.", "Data Saved");
}

public void EditAddress() {
public void EditAddress()
{
Dialogs.ShowDialog(new AddressViewModel());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ namespace _11_Screens.Customers
[Export(typeof(IWorkspace))]
public class CustomersWorkspaceViewModel : DocumentWorkspace<CustomerViewModel>
{
readonly Func<CustomerViewModel> createCustomerViewModel;
static int count = 1;
readonly Func<CustomerViewModel> _createCustomerViewModel;
static int _count = 1;

[ImportingConstructor]
public CustomersWorkspaceViewModel(Func<CustomerViewModel> customerVMFactory) {
createCustomerViewModel = customerVMFactory;
public CustomersWorkspaceViewModel(Func<CustomerViewModel> customerVMFactory)
{
_createCustomerViewModel = customerVMFactory;
}

public override string IconName {
public override string IconName
{
get { return "Customers"; }
}

public override string Icon {
public override string Icon
{
get { return "../Customers/Resources/Images/man1-48.png"; }
}

public void New() {
var vm = createCustomerViewModel();
vm.DisplayName = "Customer " + count++;
public void New()
{
var vm = _createCustomerViewModel();
vm.DisplayName = "Customer " + _count++;
vm.IsDirty = true;
Edit(vm);
}
Expand Down
23 changes: 13 additions & 10 deletions sketches/wpf/caliburn/11_Screens/Framework/ApplicationCloseCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@
using System.ComponentModel.Composition;
using Caliburn.Micro;

namespace _11_Screens.Framework {
public class ApplicationCloseCheck : IResult {
readonly Action<IDialogManager, Action<bool>> closeCheck;
readonly IChild screen;
namespace _11_Screens.Framework
{
public class ApplicationCloseCheck : IResult
{
readonly Action<IDialogManager, Action<bool>> _closeCheck;
readonly IChild _screen;

public ApplicationCloseCheck(IChild screen, Action<IDialogManager, Action<bool>> closeCheck) {
this.screen = screen;
this.closeCheck = closeCheck;
public ApplicationCloseCheck(IChild screen, Action<IDialogManager, Action<bool>> closeCheck)
{
_screen = screen;
_closeCheck = closeCheck;
}

[Import]
public IShell Shell { get; set; }

public void Execute(ActionExecutionContext context)
{
var documentWorkspace = screen.Parent as IDocumentWorkspace;
var documentWorkspace = _screen.Parent as IDocumentWorkspace;
if (documentWorkspace != null)
documentWorkspace.Edit(screen);
documentWorkspace.Edit(_screen);

closeCheck(Shell.Dialogs, result => Completed(this, new ResultCompletionEventArgs { WasCancelled = !result }));
_closeCheck(Shell.Dialogs, result => Completed(this, new ResultCompletionEventArgs { WasCancelled = !result }));
}

public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Windows.Controls;

namespace _11_Screens.Framework.Controls {
public class CustomTransitionControl : ContentControl {
namespace _11_Screens.Framework.Controls
{
public class CustomTransitionControl : ContentControl
{
public event EventHandler ContentChanged = delegate { };

protected override void OnContentChanged(object oldContent, object newContent) {
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
ContentChanged(this, EventArgs.Empty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,88 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace _11_Screens.Framework.Controls {
namespace _11_Screens.Framework.Controls
{
/// <summary>
/// This class was borrowed from the SL4 JetPack Theme.
/// </summary>
public class TiledBackground : UserControl {
public class TiledBackground : UserControl
{
public static readonly DependencyProperty SourceUriProperty = DependencyProperty.Register(
"SourceUri",
typeof(Uri),
typeof(TiledBackground),
new PropertyMetadata(null, OnSourceUriChanged)
);

BitmapImage bitmap;
int lastHeight;
int lastWidth;
WriteableBitmap sourceBitmap;
readonly Image tiledImage = new Image();
BitmapImage _bitmap;
int _lastHeight;
int _lastWidth;
WriteableBitmap _sourceBitmap;
readonly Image _tiledImage = new Image();

public TiledBackground() {
tiledImage.Stretch = Stretch.None;
Content = tiledImage;
public TiledBackground()
{
_tiledImage.Stretch = Stretch.None;
Content = _tiledImage;
SizeChanged += TiledBackgroundSizeChanged;
}

/// <summary>
/// A description of the property.
/// </summary>
public Uri SourceUri {
public Uri SourceUri
{
get { return (Uri)GetValue(SourceUriProperty); }
set { SetValue(SourceUriProperty, value); }
}

void TiledBackgroundSizeChanged(object sender, SizeChangedEventArgs e) {
void TiledBackgroundSizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateTiledImage();
}

void UpdateTiledImage() {
if(sourceBitmap == null)
void UpdateTiledImage()
{
if(_sourceBitmap == null)
return;

var width = (int)Math.Ceiling(ActualWidth);
var height = (int)Math.Ceiling(ActualHeight);

// only regenerate the image if the width/height has grown
if(width < lastWidth && height < lastHeight)
if(width < _lastWidth && height < _lastHeight)
return;
lastWidth = width;
lastHeight = height;
_lastWidth = width;
_lastHeight = height;

var final = new WriteableBitmap(width, height, 96.0, 96.0, PixelFormats.Default, BitmapPalettes.Halftone256);

for(var x = 0; x < final.PixelWidth; x++) {
for(var y = 0; y < final.PixelHeight; y++) {
var tiledX = (x % sourceBitmap.PixelWidth);
var tiledY = (y % sourceBitmap.PixelHeight);
var tiledX = (x % _sourceBitmap.PixelWidth);
var tiledY = (y % _sourceBitmap.PixelHeight);
//final.Pixels[y * final.PixelWidth + x] = sourceBitmap.Pixels[tiledY * sourceBitmap.PixelWidth + tiledX];
}
}

tiledImage.Source = final;
_tiledImage.Source = final;
}

static void OnSourceUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
static void OnSourceUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((TiledBackground)d).OnSourceUriChanged(e);
}

protected virtual void OnSourceUriChanged(DependencyPropertyChangedEventArgs e) {
bitmap = new BitmapImage(e.NewValue as Uri) { CreateOptions = BitmapCreateOptions.None };
protected virtual void OnSourceUriChanged(DependencyPropertyChangedEventArgs e)
{
_bitmap = new BitmapImage(e.NewValue as Uri) { CreateOptions = BitmapCreateOptions.None };
//bitmap.ImageOpened += BitmapImageOpened;
}

void BitmapImageOpened(object sender, RoutedEventArgs e) {
sourceBitmap = new WriteableBitmap(bitmap);
void BitmapImageOpened(object sender, RoutedEventArgs e)
{
_sourceBitmap = new WriteableBitmap(_bitmap);
UpdateTiledImage();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ namespace _11_Screens.Framework.Converters
{
public class NullToCollapsedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Collapsed : Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Expand Down
22 changes: 13 additions & 9 deletions sketches/wpf/caliburn/11_Screens/Framework/DocumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
using System.ComponentModel.Composition;
using Caliburn.Micro;

namespace _11_Screens.Framework {
public class DocumentBase : Screen, IHaveShutdownTask {
bool isDirty;

public bool IsDirty {
get { return isDirty; }
namespace _11_Screens.Framework
{
public class DocumentBase : Screen, IHaveShutdownTask
{
bool _isDirty;
public bool IsDirty
{
get { return _isDirty; }
set {
isDirty = value;
_isDirty = value;
NotifyOfPropertyChange(() => IsDirty);
}
}
Expand All @@ -24,11 +26,13 @@ public override void CanClose(Action<bool> callback)
else callback(true);
}

public IResult GetShutdownTask() {
public IResult GetShutdownTask()
{
return IsDirty ? new ApplicationCloseCheck(this, DoCloseCheck) : null;
}

protected virtual void DoCloseCheck(IDialogManager dialogs, Action<bool> callback) {
protected virtual void DoCloseCheck(IDialogManager dialogs, Action<bool> callback)
{
dialogs.ShowMessageBox(
"You have unsaved data. Are you sure you want to close this document? All changes will be lost.",
"Unsaved Data",
Expand Down
Loading

0 comments on commit f85f158

Please sign in to comment.