Skip to content

Commit

Permalink
Code: General fixes.
Browse files Browse the repository at this point in the history
* Removes unused usings.
* Eliminates unnecessary branches.
* Renames `NodeExecutorBase`'s override methods.
  • Loading branch information
am11 committed Jun 25, 2015
1 parent cf6644b commit 75609c5
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 103 deletions.
3 changes: 0 additions & 3 deletions BuildTasks.Tester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Framework;

namespace WebEssentials.BuildTasks.Tester
Expand Down
4 changes: 0 additions & 4 deletions BuildTasks/NodeInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Newtonsoft.Json;
Expand Down
3 changes: 0 additions & 3 deletions EditorExtensions/CSS/DragDrop/FontDrop.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Windows.Forms;
using MadsKristensen.EditorExtensions.Images;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using Microsoft.VisualStudio.Utilities;
Expand Down
5 changes: 3 additions & 2 deletions EditorExtensions/CustomDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@
</Words>
<Acronyms>
<CasingExceptions>
<Acronym>XHTML</Acronym>
<Acronym>BOM</Acronym>
<Acronym>CSS</Acronym>
<Acronym>JSON</Acronym>
<Acronym>JSONLD</Acronym>
<Acronym>BOM</Acronym>
<Acronym>XHTML</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
7 changes: 1 addition & 6 deletions EditorExtensions/HTML/DragDrop/HtmlImageDrop.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Web;
using MadsKristensen.EditorExtensions.Css;
using MadsKristensen.EditorExtensions.Images;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using Microsoft.VisualStudio.Utilities;
Expand All @@ -32,7 +27,7 @@ namespace MadsKristensen.EditorExtensions.Html
// but apparently visual studio get confused by content type inheritance or does not
// handle it correcly.
[Order(Before = "DefaultFileDropHandler")]
[Order(Before = "HtmlViewFileDropHandlerProvider")]
[Order(Before = "HtmlViewFileDropHandlerProvider")]
public class MarkdownImageDropHandlerProvider : IDropHandlerProvider
{
public IDropHandler GetAssociatedDropHandler(IWpfTextView wpfTextView)
Expand Down
7 changes: 1 addition & 6 deletions EditorExtensions/Handlebars/Compilers/HandlebarsCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ protected override string GetPath(string sourceFileName, string targetFileName)
parameters.Add("service", ServiceName);
parameters.Add("sourceFileName", sourceFileName);
parameters.Add("targetFileName", targetFileName);
parameters.Add("compiledTemplateName", CleanTemplateNameForJs(Path.GetFileNameWithoutExtension(sourceFileName)));
parameters.Add("compiledTemplateName", Path.GetFileNameWithoutExtension(sourceFileName).Replace("-", "_"));

return parameters.FlattenParameters();
}

private string CleanTemplateNameForJs(string templateName)
{
return templateName.Replace("-", "_");
}
}
}
8 changes: 0 additions & 8 deletions EditorExtensions/Images/Commands/PasteImageCommandTarget.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Windows.Forms;
using MadsKristensen.EditorExtensions.Markdown;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using Microsoft.VisualStudio.Text.Projection;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.Web.Editor;

Expand Down Expand Up @@ -134,8 +128,6 @@ private static async void SaveClipboardImageToFile(IDataObject data, string file
ProjectHelpers.AddFileToActiveProject(fileName);
}



protected override bool IsEnabled()
{
return true;
Expand Down
12 changes: 6 additions & 6 deletions EditorExtensions/Images/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private static string GetFormat(IWpfTextView textView)
foreach (ITextBuffer buffer in buffers)
{
var point = textView.BufferGraph.MapDownToBuffer(
snapshotPoint,
PointTrackingMode.Negative,
buffer,
snapshotPoint,
PointTrackingMode.Negative,
buffer,
PositionAffinity.Predecessor
);

Expand All @@ -86,8 +86,8 @@ private static string GetRelativeEncodedUrl(string fileName)
if (activeDocument == null)
return null;

var baseFolder = activeDocument.FullName;
var baseFolder = activeDocument.FullName;

var result = FileHelpers.RelativePath(baseFolder, fileName);

if (result.Contains("://"))
Expand Down Expand Up @@ -149,7 +149,7 @@ public static bool InsertLinkToImageFile(this IWpfTextView textView, string abso

string format = GetFormat(textView);
int position = textView.Caret.Position.BufferPosition.Position;

string text = string.Format(CultureInfo.InvariantCulture, format, relative, Path.GetFileName(absoluteImageFilePath));

using (WebEssentialsPackage.UndoContext("Insert Image"))
Expand Down
3 changes: 2 additions & 1 deletion EditorExtensions/Images/Sprite/SpriteGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -89,7 +90,7 @@ private static Dictionary<string, Image> GetImages(SpriteDocument sprite)
{
if (!System.IO.File.Exists(file))
{
Logger.Log(string.Format("The image file {0} for sprite {1} was not found", file, sprite.FileName));
Logger.Log(string.Format(CultureInfo.CurrentCulture, "The image file {0} for sprite {1} was not found", file, sprite.FileName));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
using Newtonsoft.Json.Linq;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
Expand All @@ -11,6 +7,10 @@
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
using Newtonsoft.Json.Linq;
using Intel = Microsoft.VisualStudio.Language.Intellisense;

namespace MadsKristensen.EditorExtensions.JavaScript
Expand Down
45 changes: 24 additions & 21 deletions EditorExtensions/Markdown/Margin/MarkdownMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public static IEnumerable<string> GetExistingFilesInFolders(string fileName, par
/// <returns></returns>
private static string ConvertLocalDirectoryPathToUrl(string absoluteOrRelativePath, bool ensureTrailingSlash = true)
{
if (ensureTrailingSlash && !absoluteOrRelativePath.EndsWith("\\"))
if (ensureTrailingSlash && !absoluteOrRelativePath.EndsWith("\\", StringComparison.Ordinal))
absoluteOrRelativePath = absoluteOrRelativePath + "\\";

return string.Format(
CultureInfo.InvariantCulture,
"file:///{0}",
"file:///{0}",
absoluteOrRelativePath.Replace("\\", "/")
);
}
Expand Down Expand Up @@ -298,15 +298,15 @@ protected override FrameworkElement CreatePreviewControl()
_browser.HorizontalAlignment = HorizontalAlignment.Stretch;

// This can be done only once
_browser.ObjectForScripting = new JavaScriptToManagedConnector((errorMsg, document, line) =>
_browser.ObjectForScripting = new JavaScriptToManagedConnector((errorMsg, document, line) =>
{
// Unfortunatly, when the error is in a file other than the main document the errorMsg
// and line are not available.
// Instead they always contain : line:"0" errorMsg:"script Error"
// This is another IE "feature" to "protect" you :).
Log("Error in ({0}:{1}): {2}", document, line, errorMsg);
});

_browser.Navigated += (sender, ev) =>
{
if (!ShouldHandleNavigationEvent(ev))
Expand All @@ -315,16 +315,16 @@ protected override FrameworkElement CreatePreviewControl()
var browser = sender as WebBrowser;
InjectJavascriptErrorsRedirection(browser);
};
_browser.LoadCompleted += (sender,ev) =>

_browser.LoadCompleted += (sender, ev) =>
{
if (!ShouldHandleNavigationEvent(ev))
if (!ShouldHandleNavigationEvent(ev))
return;
var browser = sender as WebBrowser;
RestoreDocumentVerticalPosition(browser);
};

return _browser;
}

Expand Down Expand Up @@ -376,7 +376,7 @@ private static bool ShouldHandleNavigationEvent(System.Windows.Navigation.Naviga
// If the user click on a link in the preview window, @event.Uri is null.
return @event.Uri == null;
}

/// <summary>
/// Hook the the DOM onerror event and redirect it to the managed host that
/// will then write it to the visual studio output pane.
Expand Down Expand Up @@ -405,7 +405,7 @@ private static void InjectJavascriptErrorsRedirection(WebBrowser browser)
}
}
}

private static void Log(string format, params object[] args)
{
Logger.Log(string.Format(CultureInfo.InvariantCulture, "[markdown]: " + format, args));
Expand All @@ -428,17 +428,20 @@ public InternetExplorerFeatureControlSecurityException()
{
}

public InternetExplorerFeatureControlSecurityException(string message) : base(message)
public InternetExplorerFeatureControlSecurityException(string message)
: base(message)
{
}

public InternetExplorerFeatureControlSecurityException(string message, Exception inner) : base(message, inner)
public InternetExplorerFeatureControlSecurityException(string message, Exception inner)
: base(message, inner)
{
}

protected InternetExplorerFeatureControlSecurityException(
SerializationInfo info,
StreamingContext context) : base(info, context)
StreamingContext context)
: base(info, context)
{
}
}
Expand All @@ -449,7 +452,7 @@ protected InternetExplorerFeatureControlSecurityException(
/// </summary>
internal class InternetExplorerBrowserFeatureControl
{

private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer";
private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
private const string BlockCrossProtocolFileNavigation = InternetExplorerRootKey + @"\MAIN\FeatureControl\FEATURE_BLOCK_CROSS_PROTOCOL_FILE_NAVIGATION";
Expand Down Expand Up @@ -482,7 +485,7 @@ private enum BrowserEmulationVersion
/// The RegistryKey instance that can be used to access
/// the registry sub key
/// </returns>
private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.RegistryKey key,
private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.RegistryKey key,
string subkeyName, bool writable)
{
var subKey = key.OpenSubKey(subkeyName, writable);
Expand Down Expand Up @@ -514,7 +517,7 @@ private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.Regis
/// execute this operation.
/// </exception>
private static T UseRegistryKey<T>(
Microsoft.Win32.RegistryKey key, string subkeyName,
Microsoft.Win32.RegistryKey key, string subkeyName,
bool writable, Func<Microsoft.Win32.RegistryKey, T> useKey
)
{
Expand All @@ -530,11 +533,11 @@ private static T UseRegistryKey<T>(
// The user does not have the permissions required to read from the registry key.
throw new InternetExplorerFeatureControlSecurityException(
string.Format(
CultureInfo.CurrentCulture,
CultureInfo.CurrentCulture,
"The current user does not have the rights to open the registry key: '{0}\\{1}'", key, subkeyName),
se
);

}
catch (UnauthorizedAccessException uaEx)
{
Expand Down Expand Up @@ -562,7 +565,7 @@ private static int GetInternetExplorerMajorVersion()
if (separator != -1)
{
if (!int.TryParse(version.Substring(0, separator), out result))
{
{
// Make CodeAnalisys happy :)
result = 0;
}
Expand Down Expand Up @@ -696,7 +699,7 @@ public JavaScriptToManagedConnector()
{
}

public JavaScriptToManagedConnector(Action<object,object,object> errorHandler)
public JavaScriptToManagedConnector(Action<object, object, object> errorHandler)
{
_errorHandler = errorHandler;
}
Expand Down
2 changes: 1 addition & 1 deletion EditorExtensions/Markdown/MenuItems/Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void HasStylesheet(object sender, System.EventArgs e)
menuCommand.Enabled = !File.Exists(MarkdownMargin.GetCustomSolutionStylesheetFilePath());
}


private void HasHtmlTemplate(object sender, System.EventArgs e)
{
OleMenuCommand menuCommand = sender as OleMenuCommand;
Expand Down
9 changes: 3 additions & 6 deletions EditorExtensions/SCSS/Compilers/ScssCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,15 @@ protected override string PostProcessResult(string result, string targetFileName
tree: new CssParser().Parse(result, true),
targetFile: targetFileName,
oldBasePath: sourceFileName);

Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");
}
catch (Exception ex)
{
Logger.Log(ServiceName + ": An error occurred while normalizing generated paths in " + sourceFileName + "\r\n" + ex);
return result;
}
}
else
{
Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");
}

Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");

return result;
}
Expand Down
7 changes: 1 addition & 6 deletions EditorExtensions/Settings/WESettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ void OnEnableChainCompilationChanged(EventArgs e)
}
}

public abstract class CssChainableCompilationSettings<T> : ChainableCompilationSettings<T>, ICssChainableCompilerSettings where T : CssChainableCompilationSettings<T>
public abstract class CssChainableCompilationSettings<T> : ChainableCompilationSettings<T>, IChainableCompilerSettings where T : CssChainableCompilationSettings<T>
{
[Category("Compilation")]
[DisplayName("Adjust Relative Paths")]
Expand Down Expand Up @@ -796,11 +796,6 @@ public interface IChainableCompilerSettings : ICompilerInvocationSettings
event EventHandler EnableChainCompilationChanged;
}

public interface ICssChainableCompilerSettings : IChainableCompilerSettings
{
bool AdjustRelativePaths { get; }
}

public interface IMinifierSettings
{
bool AutoMinify { get; set; }
Expand Down
Loading

0 comments on commit 75609c5

Please sign in to comment.