Skip to content
Browse files

Bugfix and streamlining of dialog + user cancellation

  • Loading branch information...
1 parent db5d400 commit 53cfc05a98fdccbb94f558ab9cbc9c8b1e4cdbcd @flq committed
View
5 Thawmadoce.RfSitesPublishing/EnterIdViewModel.cs
@@ -1,14 +1,15 @@
using System;
using Thawmadoce.Extensibility;
+using Thawmadoce.Frame;
namespace Thawmadoce.RfSitesPublishing
{
- public class EnterIdArgs
+ public class EnterIdArgs : IUserCancelled
{
public string Id { get; set; }
-
public string Server { get; set; }
public string Token { get; set; }
+ public bool UserCancelled { get; set; }
}
public class EnterIdViewModel : INeedRemoteControl
View
3 Thawmadoce.RfSitesPublishing/PublishingViewModel.cs
@@ -81,7 +81,8 @@ public void IdToUpdate()
if (CurrentServer == null) return;
var idArgs = new EnterIdArgs();
idArgs = _interaction.Dialog<EnterIdViewModel>().Run(idArgs);
- if (idArgs == null) return;
+ if (idArgs.UserCancelled)
+ return;
idArgs.Server = CurrentServer.Address;
idArgs.Token = CurrentServer.Token;
_publisher.Publish(new LoadContentTaskMsg(idArgs));
View
2 Thawmadoce/Editor/EnterLinkView.xaml
@@ -16,7 +16,7 @@
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal" FlowDirection="RightToLeft" >
<Button x:Name="OK" IsDefault="True" Margin="10" Padding="10,2">OK</Button>
- <Button x:Name="Cancel" IsCancel="True" Margin="10" Padding="10,2">Cancel</Button>
+ <Button IsCancel="True" Margin="10" Padding="10,2">Cancel</Button>
</StackPanel>
</Grid>
</UserControl>
View
17 Thawmadoce/Editor/EnterLinkViewModel.cs
@@ -1,19 +1,21 @@
using System;
using System.Windows;
using Caliburn.Micro;
+using Thawmadoce.Extensibility;
using Thawmadoce.Frame;
namespace Thawmadoce.Editor
{
- public class LinkArgs
+ public class LinkArgs : IUserCancelled
{
public string Link { get; set; }
- public bool UserCanceled { get; set; }
+ public bool UserCancelled { get; set; }
}
- public class EnterLinkViewModel : AbstractViewModel, IHaveDisplayName
+ public class EnterLinkViewModel : AbstractViewModel, IHaveDisplayName, INeedRemoteControl
{
private readonly LinkArgs _args;
+ private IDialogRemoteControl _remoteControl;
public EnterLinkViewModel(LinkArgs args)
{
@@ -32,16 +34,21 @@ public string Link
public void Cancel()
{
- _args.UserCanceled = true;
+ _args.UserCancelled = true;
}
public void OK()
{
- Deactivate(true);
+ _remoteControl.CloseDialog();
}
public string DisplayName { get; set; }
+ void INeedRemoteControl.Accept(IDialogRemoteControl remoteControl)
+ {
+ _remoteControl = remoteControl;
+ }
+
private static string GetLink()
{
var txt = Clipboard.GetText();
View
2 Thawmadoce/Editor/SelectionCommands/SelectionToLink.cs
@@ -16,7 +16,7 @@ public SelectionToLink(TextContext selectionText, IUserInteraction userInteracti
protected override TextContext Execute()
{
var args = _userInteraction.Dialog<EnterLinkViewModel>().Run(new LinkArgs());
- if (args.UserCanceled)
+ if (args.UserCancelled)
return TextContext;
var nextRefId = TextContext.NextReferenceId;
TextContext.ReplaceSelection("[{0}][{1}]", TextContext.CurrentSelection, nextRefId);
View
7 Thawmadoce/Frame/IUserInteraction.cs
@@ -8,6 +8,11 @@ public interface IUserInteraction
public interface IDialogStarter
{
void Run();
- I Run<I>(I arguments);
+ I Run<I>(I arguments) where I : IUserCancelled;
+ }
+
+ public interface IUserCancelled
+ {
+ bool UserCancelled { get; set; }
}
}
View
5 Thawmadoce/Frame/UserInteraction.cs
@@ -35,11 +35,12 @@ public void Run()
_mgr.ShowDialog(vm);
}
- public I Run<I>(I arguments)
+ public I Run<I>(I arguments) where I : IUserCancelled
{
var vm = _container.With(arguments).GetInstance<VM>();
var result = _mgr.ShowDialog(vm);
- return result.HasValue && result.Value ? arguments : default(I);
+ arguments.UserCancelled = result.HasValue && !result.Value;
+ return arguments;
}
}
}

0 comments on commit 53cfc05

Please sign in to comment.
Something went wrong with that request. Please try again.