Matt Hamilton avatar Matt Hamilton committed 384f865

Prompt if you type a character or creator name that doesn't exist in your collection when adding an appearance or credit.

Comments (0)

Files changed (5)

Comicster/Comicster.csproj

     <PublisherName>Comicster</PublisherName>
     <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     <WebPage>publish.htm</WebPage>
-    <ApplicationRevision>45</ApplicationRevision>
+    <ApplicationRevision>46</ApplicationRevision>
     <ApplicationVersion>4.0.0.%2a</ApplicationVersion>
     <UseApplicationTrust>false</UseApplicationTrust>
     <PublishWizardCompleted>true</PublishWizardCompleted>

Comicster/ViewModels/CollectionViewModel.cs

             if (issue == null) return;
 
             var c = new Credit();
-            var message = new CreditEditorViewModel(this, c) { Title = String.Format("New Credit in '{0}'", issue.TitleAndNumber) };
+            var message = new CreditEditorViewModel(MessengerInstance, this, c) { Title = String.Format("New Credit in '{0}'", issue.TitleAndNumber) };
             message.Submitting += (m, a) =>
             {
                 if (issue.Credits.Any(app => app.Creator == c.Creator))
             if (issue == null) return;
 
             var appearance = new Appearance();
-            var message = new AppearanceEditorViewModel(this, appearance) { Title = String.Format("New Appearance in '{0}'", issue.TitleAndNumber) };
+            var message = new AppearanceEditorViewModel(MessengerInstance, this, appearance) { Title = String.Format("New Appearance in '{0}'", issue.TitleAndNumber) };
             message.Submitting += (m, a) =>
             {
                 if (issue.Appearances.Any(app => app.Character == appearance.Character))

Comicster/ViewModels/Editors/AppearanceEditorViewModel.cs

 using GalaSoft.MvvmLight;
 using System.Collections.Generic;
 using System.Linq;
+using GalaSoft.MvvmLight.Messaging;
 
 namespace Comicster.ViewModels
 {
     public class AppearanceEditorViewModel : EditorViewModel
     {
-        public AppearanceEditorViewModel(CollectionViewModel host, Appearance appearance)
-            : base(host, new AppearanceViewModel(appearance))
+        public AppearanceEditorViewModel(IMessenger messenger, CollectionViewModel host, Appearance appearance)
+            : base(host, new AppearanceViewModel(messenger, appearance))
         {
             Image = "/Images/character_16.png";
             Title = "Appearance Properties";
 
     public class AppearanceViewModel : ViewModelBase, IEditableObject
     {
-        public AppearanceViewModel(Appearance appearance)
+        public AppearanceViewModel(IMessenger messenger, Appearance appearance)
+            : base(messenger)
         {
             _appearance = appearance;
             if (_appearance.Character != null)
             // if it's only a partial match.
             if (_appearance.Character == null || _appearance.Character.Name != CharacterName)
             {
-                _appearance.Character = new Character { Name = CharacterName };
-                collection.Characters.Add(_appearance.Character);
+                // we have a new character - let's prompt the user so they don't accidentally add
+                // a typoed character name to their collection.
+
+                MessengerInstance.Send(new DialogMessage("Are you sure you want to add '" + CharacterName + "' to your collection?", response =>
+                    {
+                        if (response != System.Windows.MessageBoxResult.Yes)
+                        {
+                            e.Cancel = true;
+                            return;
+                        }
+
+                        Appearance.Character = new Character { Name = CharacterName };
+                        collection.Characters.Add(_appearance.Character);
+                    })
+                {
+                    Button = System.Windows.MessageBoxButton.YesNo,
+                    Caption = "Unknown Character",
+                    DefaultResult = System.Windows.MessageBoxResult.No,
+                    Icon = System.Windows.MessageBoxImage.Question,
+                });
             }
         }
 

Comicster/ViewModels/Editors/CreditEditorViewModel.cs

 using System.Collections.Generic;
 using System.ComponentModel;
 using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Messaging;
 
 namespace Comicster.ViewModels
 {
     public class CreditEditorViewModel : EditorViewModel
     {
-        public CreditEditorViewModel(CollectionViewModel host, Credit credit)
-            : base(host, new CreditViewModel(credit))
+        public CreditEditorViewModel(IMessenger messenger, CollectionViewModel host, Credit credit)
+            : base(messenger, host, new CreditViewModel(messenger, credit))
         {
             Image = "/Images/creator_16.png";
             Title = "Credit Properties";
 
     public class CreditViewModel : ViewModelBase, IEditableObject
     {
-        public CreditViewModel(Credit credit)
+        public CreditViewModel(IMessenger messenger, Credit credit)
+            : base(messenger)
         {
             _credit = credit;
             if (_credit.Creator != null)
             // if it's only a partial match.
             if (Creator == null || Creator.Name != CreatorName)
             {
-                Creator = new Creator { Name = CreatorName };
-                collection.Creators.Add(Creator);
+                // we have a new creator - let's prompt the user so they don't accidentally add
+                // a typoed creator name to their collection.
+
+                MessengerInstance.Send(new DialogMessage("Are you sure you want to add '" + CreatorName + "' to your collection?", response =>
+                {
+                    if (response != System.Windows.MessageBoxResult.Yes)
+                    {
+                        e.Cancel = true;
+                        return;
+                    }
+
+                    Creator = new Creator { Name = CreatorName };
+                    collection.Creators.Add(Creator);
+                })
+                {
+                    Button = System.Windows.MessageBoxButton.YesNo,
+                    Caption = "Unknown Character",
+                    DefaultResult = System.Windows.MessageBoxResult.No,
+                    Icon = System.Windows.MessageBoxImage.Question,
+                });
             }
         }
 

Comicster/ViewModels/Editors/IssueEditorViewModel.cs

             };
 
             Credits = new ObservableCollection<CreditViewModel>(
-                issue.Credits.Select(c => new CreditViewModel(c)));
+                issue.Credits.Select(c => new CreditViewModel(messenger, c)));
 
             Appearances = new ObservableCollection<AppearanceViewModel>(
-                issue.Appearances.Select(a => new AppearanceViewModel(a)));
+                issue.Appearances.Select(a => new AppearanceViewModel(messenger, a)));
 
             AddCreditCommand = new RelayCommand(AddCredit);
             RemoveCreditCommand = new RelayCommand<CreditViewModel>(RemoveCredit);
 
         void AddCredit()
         {
-            Credits.Add(new CreditViewModel(new Credit()));
+            Credits.Add(new CreditViewModel(MessengerInstance, new Credit()));
         }
 
         void RemoveCredit(CreditViewModel c)
 
         void AddAppearance()
         {
-            Appearances.Add(new AppearanceViewModel(new Appearance()));
+            Appearances.Add(new AppearanceViewModel(MessengerInstance, new Appearance()));
         }
 
         void RemoveAppearance(AppearanceViewModel a)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.