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

Added an Option for errors and messages, which use MessageBox to write to Output Window #284

Merged
merged 3 commits into from
Dec 9, 2013
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override bool Execute(uint commandId, uint nCmdexecopt, IntPtr pvaIn,
}
else
{
MessageBox.Show("The file already exist", "Web Essentials", MessageBoxButton.OK, MessageBoxImage.Warning);
Logger.ShowMessage("The file already exists.");
}
}

Expand Down
18 changes: 17 additions & 1 deletion EditorExtensions/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio;
using System.Windows.Forms;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System;

Expand Down Expand Up @@ -35,6 +36,21 @@ public static void Log(Exception ex)
}
}

public static void ShowMessage(string message, string title = "Web Essentials",
MessageBoxButtons messageBoxButtons = MessageBoxButtons.OK,
MessageBoxIcon messageBoxIcon = MessageBoxIcon.Warning,
MessageBoxDefaultButton messageBoxDefaultButton = MessageBoxDefaultButton.Button1)
{
if (WESettings.GetBoolean(WESettings.Keys.AllMessagesToOutputWindow))
{
Log(String.Format("{0}: {1}", title, message));
}
else
{
MessageBox.Show(message, title, messageBoxButtons, messageBoxIcon, messageBoxDefaultButton);
}
}

private static bool EnsurePane()
{
if (pane == null)
Expand Down
13 changes: 7 additions & 6 deletions EditorExtensions/MenuItems/BundleFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static void CreateBundlefile(string extension)

if (File.Exists(bundlePath))
{
MessageBox.Show("The bundle file already exists.", "Web Essentials", MessageBoxButton.OK, MessageBoxImage.Warning);
Logger.ShowMessage("The bundle file already exists.");
}
else
{
Expand Down Expand Up @@ -273,7 +273,7 @@ private static void WriteBundleFile(string filePath, XmlDocument doc)

if (outputAttr != null && (outputAttr.InnerText.Contains("/") || outputAttr.InnerText.Contains("\\")))
{
MessageBox.Show("The 'output' attribute should contain a file name without a path; '" + outputAttr.InnerText + "' is not valid", "Web Essentials");
Logger.ShowMessage(String.Format("The 'output' attribute should contain a file name without a path; '{0}' is not valid", outputAttr.InnerText));
return;
}

Expand All @@ -300,9 +300,10 @@ private static void WriteBundleFile(string filePath, XmlDocument doc)
}
else
{
string error = string.Format("Bundle error: The file '{0}' doesn't exist", node.InnerText);
_dte.ItemOperations.OpenFile(filePath);
MessageBox.Show(error, "Web Essentials");

Logger.ShowMessage(String.Format("Bundle error: The file '{0}' doesn't exist", node.InnerText));

return;
}
}
Expand Down Expand Up @@ -347,7 +348,7 @@ private static void WriteBundleFile(string filePath, XmlDocument doc)
using (StreamWriter writer = new StreamWriter(bundlePath, false, new UTF8Encoding(true)))
{
writer.Write(sb.ToString().Trim());
Logger.Log("Updating bundle: " + Path.GetFileName(bundlePath));
Logger.Log("Web Essentials: Updating bundle: " + Path.GetFileName(bundlePath));
}
MarginBase.AddFileToProject(filePath, bundlePath);
}
Expand Down Expand Up @@ -392,4 +393,4 @@ private static void WriteMinFile(string filePath, string bundlePath, string cont
}
}
}
}
}
3 changes: 2 additions & 1 deletion EditorExtensions/MenuItems/ReferenceJs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;

Expand Down Expand Up @@ -74,7 +75,7 @@ private void Execute()
}
catch (IOException)
{
System.Windows.Forms.MessageBox.Show("Can't write to the folder");
Logger.ShowMessage("Can't write to the folder: " + _referencesJsPath);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions EditorExtensions/Options/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public override void SaveSettingsToStorage()
Settings.SetValue(WESettings.Keys.KeepImportantComments, KeepImportantComments);
Settings.SetValue(WESettings.Keys.EnableEnterFormat, EnableEnterFormat);
Settings.SetValue(WESettings.Keys.EnableBrowserLinkMenu, EnableBrowserLinkMenu);
Settings.SetValue(WESettings.Keys.AllMessagesToOutputWindow, AllMessagesToOutputWindow);

Settings.Save();
}
Expand All @@ -24,6 +25,7 @@ public override void LoadSettingsFromStorage()
KeepImportantComments = WESettings.GetBoolean(WESettings.Keys.KeepImportantComments);
EnableEnterFormat = WESettings.GetBoolean(WESettings.Keys.EnableEnterFormat);
EnableBrowserLinkMenu = WESettings.GetBoolean(WESettings.Keys.EnableBrowserLinkMenu);
AllMessagesToOutputWindow = WESettings.GetBoolean(WESettings.Keys.AllMessagesToOutputWindow);
}

// MISC
Expand All @@ -41,5 +43,10 @@ public override void LoadSettingsFromStorage()
[Description("Enable the menu that shows up in the browser. Requires restart.")]
[Category("Browser Link")]
public bool EnableBrowserLinkMenu { get; set; }

[LocDisplayName("Redirect Messages to Output Window")]
[Description("Redirect messages/notifications to output window.")]
[Category("Messages")]
public bool AllMessagesToOutputWindow { get; set; }
}
}
1 change: 1 addition & 0 deletions EditorExtensions/Options/WebEssentialsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class Keys
public const string KeepImportantComments = "KeepImportantComments";
public const string EnableEnterFormat = "EnableEnterFormat";
public const string EnableBrowserLinkMenu = "EnableBrowserLinkMenu";
public const string AllMessagesToOutputWindow = "AllMessagesToOutputWindow";

// LESS
public const string GenerateCssFileFromLess = "LessGenerateCssFile";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Microsoft.CSS.Core;
Expand Down Expand Up @@ -65,7 +64,7 @@ public static bool TrySaveFile(string base64, string filePath)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
Logger.ShowMessage(ex.Message, "Web Essentials " + ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.VisualStudio.Text;
using System;
using System.IO;
using System.Windows.Forms;
using System.Windows.Media.Imaging;

namespace MadsKristensen.EditorExtensions
Expand Down Expand Up @@ -47,13 +46,14 @@ private void ApplyChanges(string filePath)
}
else
{
MessageBox.Show("'" + _path + "' could not be resolved.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Information);
Logger.ShowMessage(String.Format("'{0}' could not be resolved.", _path), "Web Essentials: File not found");
}
}

private void InsertEmbedString(ITextSnapshot snapshot, string dataUri)
{
EditorExtensionsPackage.DTE.UndoContext.Open(DisplayText);
// it's not used anywhere...
Declaration dec = _url.FindType<Declaration>();

_span.TextBuffer.Replace(_span.GetSpan(snapshot), dataUri);
Expand Down