Skip to content
Open
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
15 changes: 14 additions & 1 deletion astyle-extension/AStyleExtension/AStyleExtensionPackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.ComponentModel.Design;
Expand Down Expand Up @@ -79,12 +80,24 @@ private Language GetLanguage(Document doc) {
private int OnBeforeDocumentSave(uint docCookie) {
bool csFormatOnSave = (bool)_props.Item("CsFormatOnSave").Value; ;
bool cppFormatOnSave = (bool)_props.Item("CppFormatOnSave").Value;
string cppIgnoredExtensions = (string)_props.Item("CppIgnoredFileExtensions").Value;

if (!cppFormatOnSave && !csFormatOnSave) {
return VSConstants.S_OK;
}

var doc = _dte.Documents.OfType<Document>().FirstOrDefault(x => x.FullName == _documentEventListener.GetDocumentName(docCookie));
var doc = _dte.Documents.OfType<Document>().FirstOrDefault(x => x.FullName == _documentEventListener.GetDocumentName(docCookie));
//check ignored extensions
if (!string.IsNullOrEmpty(cppIgnoredExtensions))
{
List<string> fileExtensionsList = new List<string>();
fileExtensionsList.AddRange(cppIgnoredExtensions.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
string ext = System.IO.Path.GetExtension(doc.FullName);
if (fileExtensionsList.Contains(ext))
{
return VSConstants.S_OK;
}
}
var language = GetLanguage(doc);

if (language == Language.CSharp && csFormatOnSave) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions astyle-extension/AStyleExtension/AStyleGeneralOptionsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class AStyleGeneralOptionsControl : UserControl {
private bool _isCSarpEnabled;
private bool _cppFormatOnSave;
private bool _csFormatOnSave;
private string _cppIgnoredExtensions;

public bool CppFormatOnSave {
get {
Expand Down Expand Up @@ -59,6 +60,16 @@ public bool IsCSarpEnabled {
}
}
}
public string CppIgnoredFileExtensions {
get
{
_cppIgnoredExtensions = txtIgnoredExtensions.Text;
return _cppIgnoredExtensions;
}
set {
_cppIgnoredExtensions = value;
txtIgnoredExtensions.Text = _cppIgnoredExtensions; }
}

public AStyleGeneralOptionsControl() {
InitializeComponent();
Expand Down Expand Up @@ -130,6 +141,7 @@ private void OnButtonExportClick(object sender, EventArgs e) {
CsCommandLine = CsOptions,
CppFormatOnSave = CppFormatOnSave,
CsFormatOnSave = CsFormatOnSave,
CppIgnoredFileExtensions = CppIgnoredFileExtensions,
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
};

Expand Down Expand Up @@ -177,6 +189,7 @@ private void OnButtonImportClick(object sender, EventArgs e) {

CppOptions = settings.CppCommandLine;
checkBoxCppFormatOnSave.Checked = settings.CppFormatOnSave;
CppIgnoredFileExtensions = settings.CppIgnoredFileExtensions;

if (IsCSarpEnabled) {
CsOptions = settings.CsCommandLine;
Expand Down
10 changes: 9 additions & 1 deletion astyle-extension/AStyleExtension/AStyleGeneralOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class AStyleGeneralOptionsPage : DialogPage {
public bool CppFormatOnSave { get; set; }
public bool CsFormatOnSave { get; set; }
public bool IsCSarpEnabled { get; set; }
public string CppIgnoredFileExtensions { get; set; }

public AStyleGeneralOptionsPage() {
IsCSarpEnabled = true;
Expand All @@ -26,6 +27,7 @@ protected override IWin32Window Window {

if (CppOptions != null) {
_control.CppOptions = CppOptions;

}

if (CsOptions != null) {
Expand All @@ -35,6 +37,10 @@ protected override IWin32Window Window {
_control.IsCSarpEnabled = IsCSarpEnabled;
_control.CppFormatOnSave = CppFormatOnSave;
_control.CsFormatOnSave = CsFormatOnSave;
if (!string.IsNullOrEmpty(CppIgnoredFileExtensions))
_control.CppIgnoredFileExtensions = CppIgnoredFileExtensions;
else
_control.CppIgnoredFileExtensions = "";

return _control;
}
Expand All @@ -46,6 +52,7 @@ protected override void OnDeactivate(CancelEventArgs e) {
CsOptions = _control.CsOptions;
CppFormatOnSave = _control.CppFormatOnSave;
CsFormatOnSave = _control.CsFormatOnSave;
CppIgnoredFileExtensions = _control.CppIgnoredFileExtensions;
}

base.OnDeactivate(e);
Expand All @@ -57,7 +64,7 @@ protected override void OnActivate(CancelEventArgs e) {
_control.CsOptions = CsOptions;
_control.CppFormatOnSave = CppFormatOnSave;
_control.CsFormatOnSave = CsFormatOnSave;

_control.CppIgnoredFileExtensions = CppIgnoredFileExtensions;
_control.ClearDetails();
}

Expand All @@ -70,6 +77,7 @@ protected override void OnApply(PageApplyEventArgs e) {
CsOptions = _control.CsOptions;
CppFormatOnSave = _control.CppFormatOnSave;
CsFormatOnSave = _control.CsFormatOnSave;
CppIgnoredFileExtensions = _control.CppIgnoredFileExtensions;
}

base.OnApply(e);
Expand Down
1 change: 1 addition & 0 deletions astyle-extension/AStyleExtension/AStyleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class AStyleSettings {
public string CppCommandLine { get; set; }
public string CsCommandLine { get; set; }
public string Version { get; set; }
public string CppIgnoredFileExtensions { get; set; }
}
}