kurakinvit
9/30/2015 - 8:20 AM

Макросы для расширения VS2013 - Macros forVisual Studio 2013

Макросы для расширения VS2013 - Macros forVisual Studio 2013

// Creates a standard copyright header

var date = new Date();

var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getYear();

var hours = date.getHours();
var minutes = date.getMinutes();

// Add a zero if single digit
if (day <= 9) day = "0" + day;
if (month <= 9) month = "0" + month;
if (minutes <= 9) minutes = "0" + minutes;
if (hours <= 9) hours = "0" + hours;

//Macro.InsertText(month + "/" + day + "/" + year + ", " + hours + ":" + minutes);

var doc = dte.ActiveDocument;

// Helper function to create a header
var MakeDivider = function () {
	doc.Selection.Insert("//-----------------------------------------------------------------------", 1);
	doc.Selection.NewLine();
}

var filename = doc.Name;

if (dte.UndoContext.IsOpen)
	dte.UndoContext.Close();

dte.UndoContext.Open("Insert Header");

// Go to start of document
doc.Selection.StartOfDocument(false);

// Start header
MakeDivider();

// Insert header content
doc.Selection.Insert("// <copyright file=\"", 1);
doc.Selection.Insert(filename, 1);
doc.Selection.Insert("\" author=\"Kurakin Vitaliy\">\n", 1);
doc.Selection.Insert("//     " + day + "." + month + "." + year + ", " + hours + ":" + minutes + "\n", 1);
doc.Selection.Insert("// </copyright>\n", 1);

// Close header
MakeDivider();

doc.Selection.NewLine();

dte.UndoContext.Close();