Skip to content

Commit 08fcf65

Browse files
committed
Send a message to remove the plugin from the list
1 parent 97d0a15 commit 08fcf65

File tree

7 files changed

+102
-1
lines changed

7 files changed

+102
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<UserControl x:Class="LiveWriterPluginManager.Controls.Messages.InformationControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:LiveWriterPluginManager.Controls.Messages"
7+
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="300">
10+
<Border Padding="10">
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="3*" />
14+
<RowDefinition Height="Auto" />
15+
</Grid.RowDefinitions>
16+
17+
18+
<TextBlock Grid.Row="0"
19+
VerticalAlignment="Top"
20+
TextWrapping="Wrap"
21+
Text="{Binding Message}"
22+
Margin="10,0,0,0" />
23+
24+
<Button Grid.Row="1"
25+
HorizontalAlignment="Center"
26+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"
27+
Content="Ok"
28+
IsDefault="True"
29+
Style="{DynamicResource MaterialDesignFlatButton}"
30+
Margin="0,10,0,0" />
31+
</Grid>
32+
</Border>
33+
</UserControl>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Windows;
2+
3+
namespace LiveWriterPluginManager.Controls.Messages
4+
{
5+
/// <summary>
6+
/// Interaction logic for InformationControl.xaml
7+
/// </summary>
8+
public partial class InformationControl
9+
{
10+
public InformationControl()
11+
{
12+
InitializeComponent();
13+
14+
DataContext = this;
15+
}
16+
17+
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
18+
"Message", typeof (string), typeof (InformationControl), new PropertyMetadata(default(string)));
19+
20+
public string Message
21+
{
22+
get { return (string) GetValue(MessageProperty); }
23+
set { SetValue(MessageProperty, value); }
24+
}
25+
}
26+
}

LiveWriterPluginManager/Helpers/AppHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace LiveWriterPluginManager.Helpers
1111
{
1212
public static class AppHelper
1313
{
14+
public const string RemovePluginMsg = "RemovePluginMsg";
15+
1416
static AppHelper()
1517
{
1618
LocalAppDataFolder = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "OpenLiveWriter");

LiveWriterPluginManager/LiveWriterPluginManager.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@
170170
<Compile Include="Controls\Messages\ErrorControl.xaml.cs">
171171
<DependentUpon>ErrorControl.xaml</DependentUpon>
172172
</Compile>
173+
<Compile Include="Controls\Messages\InformationControl.xaml.cs">
174+
<DependentUpon>InformationControl.xaml</DependentUpon>
175+
</Compile>
173176
<Compile Include="Controls\Messages\QuestionControl.xaml.cs">
174177
<DependentUpon>QuestionControl.xaml</DependentUpon>
175178
</Compile>
@@ -200,6 +203,10 @@
200203
<SubType>Designer</SubType>
201204
<Generator>MSBuild:Compile</Generator>
202205
</Page>
206+
<Page Include="Controls\Messages\InformationControl.xaml">
207+
<SubType>Designer</SubType>
208+
<Generator>MSBuild:Compile</Generator>
209+
</Page>
203210
<Page Include="Controls\Messages\QuestionControl.xaml">
204211
<SubType>Designer</SubType>
205212
<Generator>MSBuild:Compile</Generator>

LiveWriterPluginManager/Services/MessageService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IMessageService
88
{
99
Task<bool> ShowQuestionAsync(string question, string positive, string negative);
1010
Task ShowErrorAsync(string errorMessage);
11+
Task ShowMessageAsync(string message);
1112
}
1213

1314
public class MessageService : IMessageService
@@ -33,5 +34,15 @@ public Task ShowErrorAsync(string errorMessage)
3334

3435
return DialogHost.Show(errorControl);
3536
}
37+
38+
public Task ShowMessageAsync(string message)
39+
{
40+
var infoControl = new InformationControl
41+
{
42+
Message = message
43+
};
44+
45+
return DialogHost.Show(infoControl);
46+
}
3647
}
3748
}

LiveWriterPluginManager/ViewModel/PluginViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GalaSoft.MvvmLight;
22
using GalaSoft.MvvmLight.Command;
3+
using GalaSoft.MvvmLight.Messaging;
34
using LiveWriterPluginManager.Helpers;
45
using LiveWriterPluginManager.Model;
56
using LiveWriterPluginManager.Services;
@@ -37,7 +38,17 @@ public RelayCommand DeletePluginCommand
3738
var removePlugin = await _messageService.ShowQuestionAsync("Are you sure you wish to remove this plugin?", "Yes", "No, ignore me");
3839
if (removePlugin)
3940
{
40-
_liveWriterService.DeletePlugin(Plugin);
41+
try
42+
{
43+
_liveWriterService.DeletePlugin(Plugin);
44+
Messenger.Default.Send(new NotificationMessage(this, AppHelper.RemovePluginMsg));
45+
46+
await _messageService.ShowMessageAsync("Plugin deleted.");
47+
}
48+
catch
49+
{
50+
51+
}
4152
}
4253
});
4354
}

LiveWriterPluginManager/ViewModel/RemovePluginViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Threading.Tasks;
44
using GalaSoft.MvvmLight;
55
using GalaSoft.MvvmLight.Command;
6+
using GalaSoft.MvvmLight.Messaging;
7+
using LiveWriterPluginManager.Helpers;
68
using LiveWriterPluginManager.Services;
79

810
namespace LiveWriterPluginManager.ViewModel
@@ -17,6 +19,15 @@ public RemovePluginViewModel(ILiveWriterService liveWriterService, IMessageServi
1719
{
1820
_liveWriterService = liveWriterService;
1921
_messageService = messageService;
22+
23+
Messenger.Default.Register<NotificationMessage>(this, m =>
24+
{
25+
if (m.Notification.Equals(AppHelper.RemovePluginMsg))
26+
{
27+
var plugin = m.Sender as PluginViewModel;
28+
Plugins.Remove(plugin);
29+
}
30+
});
2031
}
2132

2233
public ObservableCollection<PluginViewModel> Plugins { get; set; } = new ObservableCollection<PluginViewModel>();

0 commit comments

Comments
 (0)