diff --git a/EncouragePackage/EncourageIntellisenseController.cs b/EncouragePackage/EncourageIntellisenseController.cs
index 5d9be23..292c363 100644
--- a/EncouragePackage/EncourageIntellisenseController.cs
+++ b/EncouragePackage/EncourageIntellisenseController.cs
@@ -1,5 +1,4 @@
using System;
-using EnvDTE;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
@@ -27,7 +26,7 @@ public EncourageIntellisenseController(
void OnDocumentDirtyStateChanged(object sender, EventArgs e)
{
- if (!this.textDocument.IsDirty)
+ if (!textDocument.IsDirty)
{
DisplayEncouragement();
}
@@ -55,12 +54,10 @@ public void Detach(ITextView detacedTextView)
public void ConnectSubjectBuffer(ITextBuffer subjectBuffer)
{
-
}
public void DisconnectSubjectBuffer(ITextBuffer subjectBuffer)
{
-
}
}
-}
\ No newline at end of file
+}
diff --git a/EncouragePackage/EncourageIntellisenseControllerProvider.cs b/EncouragePackage/EncourageIntellisenseControllerProvider.cs
index 4376885..5be8f35 100644
--- a/EncouragePackage/EncourageIntellisenseControllerProvider.cs
+++ b/EncouragePackage/EncourageIntellisenseControllerProvider.cs
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
-using EnvDTE;
using Microsoft.VisualStudio.Language.Intellisense;
-using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
diff --git a/EncouragePackage/EncouragePackage.cs b/EncouragePackage/EncouragePackage.cs
index 87672f0..bbc479c 100644
--- a/EncouragePackage/EncouragePackage.cs
+++ b/EncouragePackage/EncouragePackage.cs
@@ -1,18 +1,16 @@
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+using Haack.Encourage.Options;
using Microsoft.VisualStudio.Shell;
namespace Haack.Encourage
{
///
/// This is the class that implements the package exposed by this assembly.
- ///
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
- /// to do it: it derives from the Package class that provides the implementation of the
- /// IVsPackage interface and uses the registration attributes defined in the framework to
+ /// to do it: it derives from the Package class that provides the implementation of the
+ /// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell.
///
// This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
@@ -22,31 +20,8 @@ namespace Haack.Encourage
// in the Help/About dialog of Visual Studio.
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidEncouragePackagePkgString)]
+ [ProvideOptionPage(typeof(OptionsDialogPage), "Encourage", "Encouragement List", 0, 0, supportsAutomation: true)]
public sealed class EncouragePackage : Package
{
- ///
- /// Default constructor of the package.
- /// Inside this method you can place any initialization code that does not require
- /// any Visual Studio service because at this point the package object is created but
- /// not sited yet inside Visual Studio environment. The place to do all the other
- /// initialization is the Initialize method.
- ///
- public EncouragePackage()
- {
- Debug.WriteLine("Entering constructor for: {0}", this);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Overridden Package Implementation
-
- ///
- /// Initialization of the package; this method is called right after the package is sited, so this is the place
- /// where you can put all the initialization code that rely on services provided by VisualStudio.
- ///
- protected override void Initialize()
- {
- Debug.WriteLine("Entering Initialize() of: {0}", this);
- base.Initialize();
- }
}
}
diff --git a/EncouragePackage/EncouragePackage.csproj b/EncouragePackage/EncouragePackage.csproj
index 516de99..13a2391 100644
--- a/EncouragePackage/EncouragePackage.csproj
+++ b/EncouragePackage/EncouragePackage.csproj
@@ -45,6 +45,10 @@
true
+
+ False
+ ..\References\Vs2012\Microsoft.VisualStudio.ComponentModelHost.dll
+
@@ -71,6 +75,7 @@
+
@@ -129,14 +134,20 @@
-
+
+
+ Component
+
+
+ OptionsDialogPageControl.xaml
+
True
True
@@ -175,6 +186,12 @@
+
+
+ Designer
+ MSBuild:Compile
+
+
true
@@ -187,4 +204,4 @@
-->
-
+
\ No newline at end of file
diff --git a/EncouragePackage/EncourageSignatureHelpSource.cs b/EncouragePackage/EncourageSignatureHelpSource.cs
index f84808a..8f63986 100644
--- a/EncouragePackage/EncourageSignatureHelpSource.cs
+++ b/EncouragePackage/EncourageSignatureHelpSource.cs
@@ -17,12 +17,12 @@ sealed class Signature : ISignature
public ITrackingSpan ApplicableToSpan
{
- get { return this.trackingSpan; }
+ get { return trackingSpan; }
}
public string Content
{
- get { return this.content; }
+ get { return content; }
}
public IParameter CurrentParameter
@@ -34,17 +34,17 @@ public IParameter CurrentParameter
public string Documentation
{
- get { return this.documentation; }
+ get { return documentation; }
}
public ReadOnlyCollection Parameters
{
- get { return new ReadOnlyCollection(new IParameter[] { }); }
+ get { return new ReadOnlyCollection(new IParameter[] { }); }
}
public string PrettyPrintedContent
{
- get { return this.prettyPrintedContent; }
+ get { return prettyPrintedContent; }
}
internal Signature(ITrackingSpan trackingSpan, string content, string prettyPrintedContent, string documentation)
@@ -57,9 +57,9 @@ internal Signature(ITrackingSpan trackingSpan, string content, string prettyPrin
}
///
- /// This object needs to be added as a key to the property bag of an ITextView where
- /// encouragement should be applied. This prevents encouragement from being
- /// introduced in places like signature overload.
+ /// This object needs to be added as a key to the property bag of an ITextView where
+ /// encouragement should be applied. This prevents encouragement from being
+ /// introduced in places like signature overload.
///
internal static readonly object SessionKey = new object();
@@ -112,8 +112,11 @@ public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList encouragements = new List
- {
- "Nice Job!",
- "Way to go!",
- "Wow, nice change!",
- "So good!",
- "Bravo!",
- "You rock!",
- "Well done!",
- "I see what you did there!",
- "Genius work!",
- "Thumbs up!",
- "Coding win!",
- "FTW!",
- "Yep!",
- "Nnnnailed it!"
- };
-
- public string GetRandomEncouragement()
- {
- int randomIndex = random.Next(0, encouragements.Count);
- return encouragements[randomIndex];
- }
- }
-}
diff --git a/EncouragePackage/Encouragments.cs b/EncouragePackage/Encouragments.cs
new file mode 100644
index 0000000..e216ae1
--- /dev/null
+++ b/EncouragePackage/Encouragments.cs
@@ -0,0 +1,103 @@
+using Microsoft.VisualStudio.Settings;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Settings;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Diagnostics;
+
+namespace Haack.Encourage
+{
+ [Export(typeof(IEncouragements))]
+ public class Encouragements : IEncouragements
+ {
+ const string CollectionPath = "Encouragements";
+ const string PropertyName = "AllEncouragements";
+
+ static readonly Random random = new Random();
+ static readonly string[] defaultEncouragements = new[]
+ {
+ "Nice Job!",
+ "Way to go!",
+ "Wow, nice change!",
+ "So good!",
+ "Bravo!",
+ "You rock!",
+ "Well done!",
+ "I see what you did there!",
+ "Genius work!",
+ "Thumbs up!",
+ "Coding win!",
+ "FTW!",
+ "Yep!",
+ "Nnnnailed it!"
+ };
+
+ readonly List encouragements = new List(defaultEncouragements);
+ readonly WritableSettingsStore writableSettingsStore;
+
+ public IEnumerable AllEncouragements
+ {
+ get { return encouragements; }
+ set
+ {
+ encouragements.Clear();
+ encouragements.AddRange(value);
+ if (encouragements.Count == 0)
+ {
+ encouragements.AddRange(defaultEncouragements);
+ }
+ SaveSettings();
+ }
+ }
+
+ [ImportingConstructor]
+ public Encouragements(SVsServiceProvider vsServiceProvider)
+ {
+ var shellSettingsManager = new ShellSettingsManager(vsServiceProvider);
+ writableSettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
+
+ LoadSettings();
+ }
+
+ public string GetRandomEncouragement()
+ {
+ int randomIndex = random.Next(0, encouragements.Count);
+ return encouragements[randomIndex];
+ }
+
+ void LoadSettings()
+ {
+ try
+ {
+ if (writableSettingsStore.PropertyExists(CollectionPath, PropertyName))
+ {
+ string value = writableSettingsStore.GetString(CollectionPath, PropertyName);
+ AllEncouragements = value.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+ }
+ }
+ catch (Exception ex)
+ {
+ Debug.Fail(ex.Message);
+ }
+ }
+
+ void SaveSettings()
+ {
+ try
+ {
+ if (!writableSettingsStore.CollectionExists(CollectionPath))
+ {
+ writableSettingsStore.CreateCollection(CollectionPath);
+ }
+
+ string value = string.Join(Environment.NewLine, encouragements);
+ writableSettingsStore.SetString(CollectionPath, PropertyName, value);
+ }
+ catch (Exception ex)
+ {
+ Debug.Fail(ex.Message);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/EncouragePackage/IEncouragements.cs b/EncouragePackage/IEncouragements.cs
index 6f8589c..fd4f4cc 100644
--- a/EncouragePackage/IEncouragements.cs
+++ b/EncouragePackage/IEncouragements.cs
@@ -1,7 +1,10 @@
-namespace Haack.Encourage
+using System.Collections.Generic;
+namespace Haack.Encourage
{
public interface IEncouragements
{
+ IEnumerable AllEncouragements { get; set; }
+
string GetRandomEncouragement();
}
}
\ No newline at end of file
diff --git a/EncouragePackage/Options/OptionsDialogPage.cs b/EncouragePackage/Options/OptionsDialogPage.cs
new file mode 100644
index 0000000..beaf83a
--- /dev/null
+++ b/EncouragePackage/Options/OptionsDialogPage.cs
@@ -0,0 +1,48 @@
+using System;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Windows;
+using Microsoft.VisualStudio.ComponentModelHost;
+using Microsoft.VisualStudio.Shell;
+
+namespace Haack.Encourage.Options
+{
+ [ClassInterface(ClassInterfaceType.AutoDual)]
+ [CLSCompliant(false)]
+ [ComVisible(true)]
+ [Guid("1D9ECCF3-5D2F-4112-9B25-264596873DC9")]
+ public class OptionsDialogPage : UIElementDialogPage
+ {
+ OptionsDialogPageControl optionsDialogControl;
+
+ protected override UIElement Child
+ {
+ get { return optionsDialogControl ?? (optionsDialogControl = new OptionsDialogPageControl()); }
+ }
+
+ protected override void OnActivate(CancelEventArgs e)
+ {
+ base.OnActivate(e);
+
+ var encouraments = GetEncouragements();
+ optionsDialogControl.Encouragements = string.Join(Environment.NewLine, encouraments.AllEncouragements);
+ }
+
+ protected override void OnApply(PageApplyEventArgs args)
+ {
+ if (args.ApplyBehavior == ApplyKind.Apply)
+ {
+ string[] userEncouragments = optionsDialogControl.Encouragements.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+ GetEncouragements().AllEncouragements = userEncouragments;
+ }
+
+ base.OnApply(args);
+ }
+
+ IEncouragements GetEncouragements()
+ {
+ var componentModel = (IComponentModel)(Site.GetService(typeof(SComponentModel)));
+ return componentModel.DefaultExportProvider.GetExportedValue();
+ }
+ }
+}
diff --git a/EncouragePackage/Options/OptionsDialogPageControl.xaml b/EncouragePackage/Options/OptionsDialogPageControl.xaml
new file mode 100644
index 0000000..7a48e2f
--- /dev/null
+++ b/EncouragePackage/Options/OptionsDialogPageControl.xaml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/EncouragePackage/Options/OptionsDialogPageControl.xaml.cs b/EncouragePackage/Options/OptionsDialogPageControl.xaml.cs
new file mode 100644
index 0000000..9cf4be6
--- /dev/null
+++ b/EncouragePackage/Options/OptionsDialogPageControl.xaml.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using Microsoft.VisualStudio.Shell;
+
+namespace Haack.Encourage.Options
+{
+ ///
+ /// Interaction logic for OptionsDialogPageControl.xaml
+ ///
+ public partial class OptionsDialogPageControl : UserControl
+ {
+ public OptionsDialogPageControl()
+ {
+ InitializeComponent();
+
+ encouragements.AddHandler(UIElementDialogPage.DialogKeyPendingEvent, new RoutedEventHandler(OnDialogKeyPendingEvent));
+ }
+
+ void OnDialogKeyPendingEvent(object sender, RoutedEventArgs e)
+ {
+ var args = e as DialogKeyEventArgs;
+ if (args != null && args.Key == Key.Enter)
+ {
+ e.Handled = true;
+ }
+ }
+
+ public string Encouragements
+ {
+ get { return encouragements.Text; }
+ set { encouragements.Text = value; }
+ }
+ }
+}
diff --git a/EncouragePackage/app.config b/EncouragePackage/app.config
new file mode 100644
index 0000000..3430dc5
--- /dev/null
+++ b/EncouragePackage/app.config
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+Nice Job!
+Way to go!
+Wow, nice change!
+So good!
+Bravo!
+You rock!
+Well done!
+I see what you did there!
+Genius work!
+Thumbs up!
+Coding win!
+FTW!
+Yep!
+Nnnnailed it!
+
+
+
+
\ No newline at end of file
diff --git a/References/Vs2012/Microsoft.VisualStudio.ComponentModelHost.dll b/References/Vs2012/Microsoft.VisualStudio.ComponentModelHost.dll
new file mode 100644
index 0000000..6760100
Binary files /dev/null and b/References/Vs2012/Microsoft.VisualStudio.ComponentModelHost.dll differ