Skip to content

Commit

Permalink
Improved the demo with a tree view for the configuration, for this I …
Browse files Browse the repository at this point in the history
…added the interfaces IConfig & IConfigScreen and implementations for these interfaces, this still is work in progress.

[release]
  • Loading branch information
Lakritzator committed Jul 20, 2016
1 parent 799d529 commit fa9c2ff
Show file tree
Hide file tree
Showing 32 changed files with 939 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,18 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.0.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Languages\IAddonTranslations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\NotSelectableConfigViewModel.cs" />
<Compile Include="ViewModels\AddonSettingsViewModel.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@

#endregion

namespace Dapplo.CaliburnMicro.Demo.Languages
namespace Dapplo.CaliburnMicro.Demo.Addon.Languages
{
[Language("Addon1")]
public interface IAddonTranslations : ILanguage, INotifyPropertyChanged
{
[DefaultValue("Blub")]
string Addon { get; }

[DefaultValue("Can't touch me")]
string NotSelectableAddon { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@

using System.ComponentModel.Composition;
using Caliburn.Micro;
using Dapplo.CaliburnMicro.Demo.Interfaces;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.CaliburnMicro.Demo.Addon.Languages;
using Dapplo.CaliburnMicro.Demo.Languages;
using Dapplo.CaliburnMicro.Demo.UseCases.Configuration;
using Dapplo.Utils.Extensions;

#endregion

namespace Dapplo.CaliburnMicro.Demo.Addon.ViewModels
{
[Export(typeof(ISettingsControl))]
public class AddonSettingsViewModel : Screen, ISettingsControl, IPartImportsSatisfiedNotification
[Export(typeof(IConfigScreen))]
public sealed class AddonSettingsViewModel : ConfigScreen, IPartImportsSatisfiedNotification
{
[Import]
public IAddonTranslations AddonTranslations { get; set; }
Expand All @@ -51,7 +53,10 @@ public void OnImportsSatisfied()

public void DoSomething()
{
EventAggregator.PublishOnUIThread("Addon clicked");
EventAggregator.PublishOnUIThread("Addon button clicked");
}

public override int ParentId { get; } = (int)ConfigIds.Addons;
public override int Id { get; } = (int) (ConfigIds.Addons + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Dapplo - building blocks for desktop applications
// Copyright (C) 2016 Dapplo
//
// For more information see: http://dapplo.net/
// Dapplo repositories are hosted on GitHub: https://github.com/dapplo
//
// This file is part of Dapplo.CaliburnMicro
//
// Dapplo.CaliburnMicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Dapplo.CaliburnMicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have a copy of the GNU Lesser General Public License
// along with Dapplo.CaliburnMicro. If not, see <http://www.gnu.org/licenses/lgpl.txt>.

#region using

using System.ComponentModel.Composition;
using Caliburn.Micro;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.CaliburnMicro.Demo.Addon.Languages;
using Dapplo.CaliburnMicro.Demo.Languages;
using Dapplo.CaliburnMicro.Demo.UseCases.Configuration;
using Dapplo.Utils.Extensions;

#endregion

namespace Dapplo.CaliburnMicro.Demo.Addon.ViewModels
{
[Export(typeof(IConfigScreen))]
public sealed class NotSelectableConfigViewModel : ConfigScreen, IPartImportsSatisfiedNotification
{
[Import]
public IAddonTranslations AddonTranslations { get; set; }

public void OnImportsSatisfied()
{
IsEnabled = false;
// automatically update the DisplayName
AddonTranslations.OnPropertyChanged(e =>
{
DisplayName = AddonTranslations.NotSelectableAddon;
}, nameof(IAddonTranslations.NotSelectableAddon));
}

public override int ParentId { get; } = (int)ConfigIds.Addons;
public override int Id { get; } = (int)(ConfigIds.Addons + 2);
}
}
13 changes: 8 additions & 5 deletions Dapplo.CaliburnMicro.Demo/Dapplo.CaliburnMicro.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Interfaces\ISettingsControl.cs" />
<Compile Include="Languages\IConfigTranslations.cs" />
<Compile Include="Languages\IValidationErrors.cs" />
<Compile Include="Languages\IWizardTranslations.cs" />
<Compile Include="Languages\IContextMenuTranslations.cs" />
Expand All @@ -116,11 +116,14 @@
<Compile Include="Models\IDemoConfiguration.cs" />
<Compile Include="Models\IWizardModel.cs" />
<Compile Include="Startup.cs" />
<Compile Include="UseCases\Configuration\ConfigIds.cs" />
<Compile Include="UseCases\Configuration\ViewModels\AddonConfigNodeViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\UiConfigNodeViewModel.cs" />
<Compile Include="ViewModels\CredentialsViewModel.cs" />
<Compile Include="ViewModels\DummyViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\LanguageSettingsViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\LanguageConfigViewModel.cs" />
<Compile Include="ViewModels\NotificationExampleViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\SettingsViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\ConfigViewModel.cs" />
<Compile Include="ViewModels\TrayIconViewModel.cs" />
<Compile Include="UseCases\Wizard\ViewModels\WizardStep4ViewModel.cs" />
<Compile Include="UseCases\Wizard\ViewModels\WizardStep3ViewModel.cs" />
Expand Down Expand Up @@ -181,15 +184,15 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UseCases\Configuration\Views\LanguageSettingsView.xaml">
<Page Include="UseCases\Configuration\Views\LanguageConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\NotificationExampleView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UseCases\Configuration\Views\SettingsView.xaml">
<Page Include="UseCases\Configuration\Views\ConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

#region using

using Caliburn.Micro;
using System.ComponentModel;
using Dapplo.Config.Language;

#endregion

namespace Dapplo.CaliburnMicro.Demo.Interfaces
namespace Dapplo.CaliburnMicro.Demo.Languages
{
public interface ISettingsControl : IHaveDisplayName
[Language("Config")]
public interface IConfigTranslations : ILanguage, INotifyPropertyChanged
{
string Ui { get; }
string Addons { get; }
}
}
4 changes: 4 additions & 0 deletions Dapplo.CaliburnMicro.Demo/Languages/language-de-DE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<resource name="settings">Einstellungen</resource>
<resource name="change_language">Sprache ändern</resource>
</resources>
<resources prefix="config">
<resource name="ui">Benutzeroberfläche</resource>
<resource name="addons">Erweiterungen</resource>
</resources>
<resources prefix="credentials">
<resource name="username">Benutzername</resource>
<resource name="password">Paswort</resource>
Expand Down
4 changes: 4 additions & 0 deletions Dapplo.CaliburnMicro.Demo/Languages/language-en-US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<resource name="settings">Settings</resource>
<resource name="change_language">Change language</resource>
</resources>
<resources prefix="config">
<resource name="ui">User interface</resource>
<resource name="addons">Addons</resource>
</resources>
<resources prefix="credentials">
<resource name="username">Username</resource>
<resource name="password">Password</resource>
Expand Down
48 changes: 48 additions & 0 deletions Dapplo.CaliburnMicro.Demo/UseCases/Configuration/ConfigIds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#region Dapplo 2016 - GNU Lesser General Public License

// Dapplo - building blocks for .NET applications
// Copyright (C) 2016 Dapplo
//
// For more information see: http://dapplo.net/
// Dapplo repositories are hosted on GitHub: https://github.com/dapplo
//
// This file is part of Dapplo.CaliburnMicro
//
// Dapplo.CaliburnMicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Dapplo.CaliburnMicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have a copy of the GNU Lesser General Public License
// along with Dapplo.CaliburnMicro. If not, see <http://www.gnu.org/licenses/lgpl.txt>.

#endregion

namespace Dapplo.CaliburnMicro.Demo.UseCases.Configuration
{
/// <summary>
/// Used to make it possible to add a ConfigScreen to a well defined parent node
/// </summary>
public enum ConfigIds
{
/// <summary>
/// The root ID
/// </summary>
Root = 0,

/// <summary>
/// UI related config screens should have this as parent
/// </summary>
Ui = 100,

/// <summary>
/// Config screens from addons should have this as parent
/// </summary>
Addons = 200
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Dapplo - building blocks for desktop applications
// Copyright (C) 2016 Dapplo
//
// For more information see: http://dapplo.net/
// Dapplo repositories are hosted on GitHub: https://github.com/dapplo
//
// This file is part of Dapplo.CaliburnMicro
//
// Dapplo.CaliburnMicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Dapplo.CaliburnMicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have a copy of the GNU Lesser General Public License
// along with Dapplo.CaliburnMicro. If not, see <http://www.gnu.org/licenses/lgpl.txt>.

#region using

using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Caliburn.Micro;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.CaliburnMicro.Demo.Languages;
using Dapplo.CaliburnMicro.Demo.Models;
using Dapplo.Config.Language;
using Dapplo.Utils.Extensions;

#endregion

namespace Dapplo.CaliburnMicro.Demo.UseCases.Configuration.ViewModels
{
[Export(typeof(IConfigScreen))]
public sealed class AddonConfigNodeViewModel : ConfigScreen, IPartImportsSatisfiedNotification
{
[Import]
public IConfigTranslations ConfigTranslations { get; set; }

public void OnImportsSatisfied()
{
// automatically update the DisplayName
ConfigTranslations.OnPropertyChanged(pcEvent =>
{
DisplayName = ConfigTranslations.Addons;
}, nameof(IConfigTranslations.Addons));
CanActivate = false;
}

public override int Id { get; } = (int) ConfigIds.Addons;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Caliburn.Micro;
using Dapplo.CaliburnMicro.Demo.Interfaces;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.CaliburnMicro.Demo.Languages;
using Dapplo.CaliburnMicro.Demo.Models;
using Dapplo.CaliburnMicro.Demo.ViewModels;
Expand All @@ -43,12 +43,15 @@ namespace Dapplo.CaliburnMicro.Demo.UseCases.Configuration.ViewModels
/// It is a conductor where one item is active.
/// </summary>
[Export]
public class SettingsViewModel : Conductor<ISettingsControl>.Collection.OneActive, IPartImportsSatisfiedNotification
public class ConfigViewModel : Config<IConfigScreen>, IPartImportsSatisfiedNotification
{
private static readonly LogSource Log = new LogSource();

[Import]
private ICoreTranslations CoreTranslations { get; set; }
public ICoreTranslations CoreTranslations { get; set; }

[Import]
public IConfigTranslations ConfigTranslations { get; set; }

[Import]
private CredentialsViewModel CredentialsVm { get; set; }
Expand All @@ -66,7 +69,7 @@ public class SettingsViewModel : Conductor<ISettingsControl>.Collection.OneActiv
/// Get all settings controls, these are the items that are displayed.
/// </summary>
[ImportMany]
private IEnumerable<ISettingsControl> SettingsControls { get; set; }
public override IEnumerable<IConfigScreen> ConfigScreens { get; set; }

/// <summary>
/// Used to show a "normal" dialog
Expand All @@ -85,7 +88,7 @@ public class SettingsViewModel : Conductor<ISettingsControl>.Collection.OneActiv
/// And will make sure that the selected item is made visible.
/// </summary>
/// <param name="view"></param>
public void ActivateChildView(ISettingsControl view)
public void ActivateChildView(IConfigScreen view)
{
ActivateItem(view);
}
Expand All @@ -108,14 +111,6 @@ public async Task Dialog()
await Dialogcoordinator.ShowMessageAsync(this, "Message from VM", "MVVM based dialogs!");
}

protected override void OnActivate()
{
base.OnActivate();
// Add all the imported settings controls
// TODO: Sort them for a tree view, somehow...
Items.AddRange(SettingsControls);
}

public void OnImportsSatisfied()
{
// automatically update the DisplayName
Expand Down
Loading

0 comments on commit fa9c2ff

Please sign in to comment.