Permalink
Browse files

Code: General fixes.

* Removes unused usings.
* Eliminates unnecessary branches.
* Renames `NodeExecutorBase`'s override methods.
  • Loading branch information...
1 parent cf6644b commit 75609c5dc84641f518b645fdc8e9f322135fd88e @am11 am11 committed Jun 25, 2015
@@ -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
@@ -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;
@@ -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;
@@ -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>
@@ -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;
@@ -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)
@@ -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("-", "_");
- }
}
}
@@ -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;
@@ -134,8 +128,6 @@ private static string GetMimeType(Bitmap bitmap)
ProjectHelpers.AddFileToActiveProject(fileName);
}
-
-
protected override bool IsEnabled()
{
return true;
@@ -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
);
@@ -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("://"))
@@ -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"))
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
@@ -89,7 +90,7 @@ private static void Horizontal(Dictionary<string, Image> images, List<SpriteFrag
{
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;
}
@@ -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;
@@ -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
@@ -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("\\", "/")
);
}
@@ -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))
@@ -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;
}
@@ -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.
@@ -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));
@@ -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)
{
}
}
@@ -449,7 +452,7 @@ public InternetExplorerFeatureControlSecurityException(string message, Exception
/// </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";
@@ -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);
@@ -514,7 +517,7 @@ private enum BrowserEmulationVersion
/// 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
)
{
@@ -530,11 +533,11 @@ private enum BrowserEmulationVersion
// 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)
{
@@ -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;
}
@@ -696,7 +699,7 @@ public JavaScriptToManagedConnector()
{
}
- public JavaScriptToManagedConnector(Action<object,object,object> errorHandler)
+ public JavaScriptToManagedConnector(Action<object, object, object> errorHandler)
{
_errorHandler = errorHandler;
}
@@ -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;
@@ -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;
}
@@ -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")]
@@ -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; }
Oops, something went wrong.

0 comments on commit 75609c5

Please sign in to comment.