Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevitPluginTemplate: Скорректирован стиль шаблонов плагинов #109

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/templates/RevitPluginTemplate/Models/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;

Expand All @@ -24,4 +24,4 @@ internal class RevitSettings : ProjectSettings {
public override string ProjectName { get; set; }
public string SaveProperty { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

Expand All @@ -10,8 +10,7 @@ public RevitRepository(UIApplication uiApplication) {

public UIApplication UIApplication { get; }
public UIDocument ActiveUIDocument => UIApplication.ActiveUIDocument;

public Application Application => UIApplication.Application;
public Document Document => ActiveUIDocument.Document;
}
}
}
24 changes: 12 additions & 12 deletions .github/templates/RevitPluginTemplate/RevitPluginTemplateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -33,29 +33,29 @@ public RevitPluginTemplateCommand() {
}

protected override void Execute(UIApplication uiApplication) {
using(IKernel kernel = uiApplication.CreatePlatformServices()) {
using(IKernel kernel = uiApplication.CreatePlatformServices()) {
kernel.Bind<RevitRepository>()
.ToSelf()
.InSingletonScope();
kernel.Bind<PluginConfig>()

kernel.Bind<PluginConfig>()
.ToMethod(c => PluginConfig.GetPluginConfig());
kernel.Bind<MainViewModel>().ToSelf();
kernel.Bind<MainWindow>().ToSelf()
.WithPropertyValue(nameof(Window.DataContext),

kernel.Bind<MainViewModel>().ToSelf();
kernel.Bind<MainWindow>().ToSelf()
.WithPropertyValue(nameof(Window.DataContext),
c => c.Kernel.Get<MainViewModel>())
.WithPropertyValue(nameof(PlatformWindow.LocalizationService),
c => c.Kernel.Get<ILocalizationService>());

string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;

kernel.UseXtraLocalization(
$"/{assemblyName};component/Localization/Language.xaml",
CultureInfo.GetCultureInfo("ru-RU"));
Notification(kernel.Get<MainWindow>());
}

Notification(kernel.Get<MainWindow>());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Windows.Input;
using System.Windows.Input;

using dosymep.SimpleServices;
using dosymep.WPF.Commands;
Expand All @@ -16,10 +16,10 @@ internal class MainViewModel : BaseViewModel {
private string _saveProperty;

public MainViewModel(
PluginConfig pluginConfig,
RevitRepository revitRepository,
PluginConfig pluginConfig,
RevitRepository revitRepository,
ILocalizationService localizationService) {

_pluginConfig = pluginConfig;
_revitRepository = revitRepository;
_localizationService = localizationService;
Expand Down Expand Up @@ -48,10 +48,10 @@ private void LoadView() {
private void AcceptView() {
SaveConfig();
}

private bool CanAcceptView() {
if(string.IsNullOrEmpty(SaveProperty)) {
ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck");
ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck");
return false;
}

Expand All @@ -67,7 +67,7 @@ private void LoadConfig() {

private void SaveConfig() {
RevitSettings setting = _pluginConfig.GetSettings(_revitRepository.Document)
?? _pluginConfig.AddSettings(_revitRepository.Document);
?? _pluginConfig.AddSettings(_revitRepository.Document);

setting.SaveProperty = SaveProperty;
_pluginConfig.SaveProjectConfig();
Expand Down
27 changes: 13 additions & 14 deletions .github/templates/RevitPluginTemplate/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:base="clr-namespace:dosymep.WPF.Views"
xmlns:local="clr-namespace:RevitPluginTemplate.Views"
xmlns:vms="clr-namespace:RevitPluginTemplate.ViewModels"

xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"

mc:Ignorable="d"
WindowStartupLocation="CenterOwner"

Title="{DynamicResource MainWindow.Title}"
Height="450" Width="800"

Height="450"
Width="800"
d:DataContext="{d:DesignInstance vms:MainViewModel, IsDesignTimeCreatable=False}">

<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand EventName="Loaded" Command="{Binding LoadViewCommand}"/>
<dxmvvm:EventToCommand
EventName="Loaded"
Command="{Binding LoadViewCommand}" />
</dxmvvm:Interaction.Behaviors>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>

<dxe:TextEdit
Grid.Row="0"
Width="200"
VerticalAlignment="Center"
HorizontalAlignment="Center"

Text="{Binding SaveProperty,
UpdateSourceTrigger=PropertyChanged}" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Windows;
using System.Windows;

namespace RevitPluginTemplate.Views {
public partial class MainWindow {
Expand All @@ -8,7 +8,7 @@ public MainWindow() {

public override string PluginName => nameof(RevitPluginTemplate);
public override string ProjectConfigName => nameof(MainWindow);

private void ButtonOk_Click(object sender, RoutedEventArgs e) {
DialogResult = true;
}
Expand All @@ -17,4 +17,4 @@ private void ButtonCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false;
}
}
}
}
9 changes: 4 additions & 5 deletions src/RevitPlugins/Models/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.ProjectConfigs;
using dosymep.Serializers;

using pyRevitLabs.Json;

namespace RevitPlugins.Models
{
namespace RevitPlugins.Models {
public class PluginConfig : ProjectConfig<RevitSettings> {
[JsonIgnore] public override string ProjectConfigPath { get; set; }

Expand All @@ -20,9 +19,9 @@ public static PluginConfig GetPluginConfig() {
.Build<PluginConfig>();
}
}

public class RevitSettings : ProjectSettings {
public string SaveProperty { get; set; }
public override string ProjectName { get; set; }
}
}
}
5 changes: 2 additions & 3 deletions src/RevitPlugins/Models/RevitRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

Expand All @@ -10,8 +10,7 @@ public RevitRepository(UIApplication uiApplication) {

public UIApplication UIApplication { get; }
public UIDocument ActiveUIDocument => UIApplication.ActiveUIDocument;

public Application Application => UIApplication.Application;
public Document Document => ActiveUIDocument.Document;
}
}
}
2 changes: 1 addition & 1 deletion src/RevitPlugins/RevitPluginsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down
12 changes: 6 additions & 6 deletions src/RevitPlugins/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows.Input;

using Autodesk.Revit.UI;
Expand All @@ -20,10 +20,10 @@ internal class MainViewModel : BaseViewModel {
private string _saveProperty;

public MainViewModel(
PluginConfig pluginConfig,
RevitRepository revitRepository,
PluginConfig pluginConfig,
RevitRepository revitRepository,
ILocalizationService localizationService) {

_pluginConfig = pluginConfig;
_revitRepository = revitRepository;
_localizationService = localizationService;
Expand Down Expand Up @@ -52,7 +52,7 @@ private void LoadView() {
private void AcceptView() {
SaveConfig();
}

private bool CanAcceptView() {
if(string.IsNullOrEmpty(SaveProperty)) {
ErrorText = _localizationService.GetLocalizedString("MainWindow.HelloCheck");
Expand All @@ -71,7 +71,7 @@ private void LoadConfig() {

private void SaveConfig() {
var setting = _pluginConfig.GetSettings(_revitRepository.Document)
?? _pluginConfig.AddSettings(_revitRepository.Document);
?? _pluginConfig.AddSettings(_revitRepository.Document);

setting.SaveProperty = SaveProperty;
_pluginConfig.SaveProjectConfig();
Expand Down
17 changes: 8 additions & 9 deletions src/RevitPlugins/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:base="clr-namespace:dosymep.WPF.Views"
xmlns:local="clr-namespace:RevitPlugins.Views"
xmlns:vms="clr-namespace:RevitPlugins.ViewModels"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"

mc:Ignorable="d"
WindowStartupLocation="CenterOwner"

Title="{DynamicResource MainWindow.Title}"
Height="450" Width="800"

Height="450"
Width="800"
d:DataContext="{d:DesignInstance vms:MainViewModel, IsDesignTimeCreatable=False}">

<b:Interaction.Triggers>
<b:EventTrigger EventName="Loaded">
<b:EventTrigger
EventName="Loaded">
<b:InvokeCommandAction
Command="{Binding LoadViewCommand}" />
</b:EventTrigger>
</b:Interaction.Triggers>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="45" />
<RowDefinition
Height="*" />
<RowDefinition
Height="45" />
</Grid.RowDefinitions>

<TextBox
Grid.Row="0"
Width="200"
VerticalAlignment="Center"
HorizontalAlignment="Center"

Text="{Binding SaveProperty,
UpdateSourceTrigger=PropertyChanged}" />

Expand Down
6 changes: 3 additions & 3 deletions src/RevitPlugins/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Windows;
using System.Windows;

namespace RevitPlugins.Views {
public partial class MainWindow {
Expand All @@ -8,7 +8,7 @@ public MainWindow() {

public override string PluginName => nameof(RevitPlugins);
public override string ProjectConfigName => nameof(MainWindow);

private void ButtonOk_Click(object sender, RoutedEventArgs e) {
DialogResult = true;
}
Expand All @@ -17,4 +17,4 @@ private void ButtonCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false;
}
}
}
}
Loading