Skip to content

Commit 7287a76

Browse files
committed
0.4
support automatically generating css support options everything in between
1 parent 78233cf commit 7287a76

19 files changed

+759
-42
lines changed

Key.snk

596 Bytes
Binary file not shown.

README.md

-15
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,3 @@ In the near future I am planning to add support for the following (assuming VS/W
1515
- Multiline comments
1616

1717

18-
### Release Notes
19-
20-
**v0.1**
21-
22-
- Basic Syntax Highlighting Support
23-
- Basic Outlining Support
24-
25-
**v0.2**
26-
27-
- Match Existing Color Settings
28-
29-
**v0.3**
30-
31-
- Support for Comment / Uncomment selection (<kbd>ctrl</kbd> + <kbd>K</kbd>, <kbd>C</kbd> / <kbd>U</kbd>)
32-
- Warnings for deprecated functionality

ReleaseNotes.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Release Notes
2+
3+
## 0.1
4+
5+
- Basic Syntax Highlighting Support
6+
- Basic Outlining Support
7+
8+
9+
## 0.2
10+
11+
- Match Existing Color Settings
12+
13+
14+
## 0.3
15+
16+
- Support for Comment / Uncomment selection (<kbd>ctrl</kbd> + <kbd>K</kbd>, <kbd>C</kbd> / <kbd>U</kbd>)
17+
- Warnings for deprecated functionality
18+
19+
20+
## 0.4
21+
22+
- Support generating css file on save (thanks to [NSass project](https://github.com/TBAPI-0KA/NSass))
23+
- Support including generated css in project automatically
24+
- Add options controlling css generation and project integration
25+
26+
By default, CSS files will be generated on save, added to the project nested under the .scss file if
27+
the css file was not already part of the project, and it will be configured as Content. You can
28+
disable each aspect individually, though some aspects don't matter if others are disabled.
3.76 KB
Binary file not shown.

SassyStudio.2012/Guids.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SassyStudio
8+
{
9+
static class Guids
10+
{
11+
public const string guidSassyStudioPkgString = "141b7a26-b79d-4ca0-9102-77e7cc7e0ec8";
12+
public const string guidSassyStudioCmdSetString = "9ba4ff19-dae9-47ba-af4a-2f13062e3990";
13+
14+
public static readonly Guid guidSassyStudioCmdSet = new Guid(guidSassyStudioCmdSetString);
15+
}
16+
}

SassyStudio.2012/InteropHelper.cs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Threading;
9+
using EnvDTE;
10+
using EnvDTE80;
11+
12+
namespace SassyStudio
13+
{
14+
static class InteropHelper
15+
{
16+
internal static void AddNestedFile(DTE2 dte, string parent, string child, BuildActionType type)
17+
{
18+
// ignore if child doesn't exist
19+
if (!File.Exists(child)) return;
20+
21+
// if we can't load parent or child already part of solution, don't attempt to change anything
22+
ProjectItem parentItem, childItem;
23+
if (!TryGetProjectItem(dte.Solution, parent, out parentItem) || TryGetProjectItem(dte.Solution, child, out childItem))
24+
return;
25+
26+
// add the the child item and save project
27+
childItem = parentItem.ProjectItems.AddFromFile(child);
28+
childItem.ContainingProject.Save();
29+
30+
// schedule call to change build action
31+
// this is a work around since it seems to ignore property changes until after file saved
32+
// and even after that it still ignores it, so async makes it better
33+
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => ChangeBuildActionType(dte, child, type)), DispatcherPriority.Background);
34+
}
35+
36+
private static void ChangeBuildActionType(DTE2 dte, string path, BuildActionType type)
37+
{
38+
ProjectItem item;
39+
if (TryGetProjectItem(dte.Solution, path, out item))
40+
{
41+
var vsBuildAction = (int)type;
42+
var vsType = type.ToString();
43+
44+
var actionProperty = item.Properties.Item("BuildAction");
45+
var typeProperty = item.Properties.Item("ItemType");
46+
47+
// stop if no changes
48+
if (vsBuildAction.Equals(actionProperty.Value) && vsType.Equals(typeProperty.Value))
49+
return;
50+
51+
Logger.Log("ProjectItem properties changing.");
52+
actionProperty.Value = vsBuildAction;
53+
typeProperty.Value = vsType;
54+
item.ContainingProject.Save();
55+
}
56+
}
57+
58+
static bool TryGetProjectItem(Solution solution, string path, out ProjectItem item)
59+
{
60+
item = solution.FindProjectItem(path);
61+
return item != null;
62+
}
63+
64+
internal enum BuildActionType : int
65+
{
66+
None = 0,
67+
Content = 2
68+
}
69+
}
70+
}

SassyStudio.2012/Logger.cs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.VisualStudio.Shell.Interop;
7+
8+
namespace SassyStudio
9+
{
10+
public static class Logger
11+
{
12+
static readonly Lazy<IVsOutputWindowPane> _Pane = new Lazy<IVsOutputWindowPane>(() => SassyStudioPackage.Instance.GetOutputPane(new Guid("f1574ced-8144-4889-b7fd-485703faac9c"), "Sassy Studio"));
13+
private static IVsOutputWindowPane Pane { get { return _Pane.Value; } }
14+
15+
16+
public static void Log(string message, bool activatePane = false)
17+
{
18+
if (string.IsNullOrEmpty(message))
19+
return;
20+
21+
try
22+
{
23+
var builder = new StringBuilder(message);
24+
builder.Insert(0, DateTime.Now.ToString("hh:mm:ss tt': '"));
25+
builder.AppendLine();
26+
Pane.OutputString(builder.ToString());
27+
if (activatePane)
28+
Pane.Activate();
29+
}
30+
catch
31+
{
32+
// woopsie
33+
}
34+
}
35+
36+
public static void Log(Exception ex, string message = null, bool activatePane = true)
37+
{
38+
var builder = new StringBuilder();
39+
if (!string.IsNullOrEmpty(message))
40+
builder.AppendLine(message);
41+
42+
if (ex != null)
43+
{
44+
builder
45+
.Append("[").Append(ex.GetType().Name).Append("]")
46+
.AppendLine(ex.Message);
47+
48+
if (!string.IsNullOrEmpty(ex.StackTrace))
49+
builder.AppendLine(ex.StackTrace);
50+
}
51+
52+
if (builder.Length > 0)
53+
Log(builder.ToString(), activatePane);
54+
}
55+
}
56+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Microsoft.VisualStudio.Shell;
8+
9+
namespace SassyStudio.Options
10+
{
11+
class ScssOptions : DialogPage
12+
{
13+
public override void LoadSettingsFromStorage()
14+
{
15+
// defaults
16+
GenerateCssOnSave = true;
17+
IncludeCssInProject = true;
18+
IncludeCssInProjectOutput = true;
19+
IncludeSourceComments = false;
20+
21+
base.LoadSettingsFromStorage();
22+
}
23+
24+
[LocDisplayName("Generate .css on save")]
25+
[Description("When enabled, a css file with the same name will be generated")]
26+
[Category("SCSS")]
27+
public bool GenerateCssOnSave { get; set; }
28+
29+
[LocDisplayName("Include .css in project")]
30+
[Description("When .css file is generated it will be added as nested file of .scss file")]
31+
[Category("SCSS")]
32+
public bool IncludeCssInProject { get; set; }
33+
34+
[LocDisplayName("Include .css in project output")]
35+
[Description("When enabled, the generated .css file will have it's Build Action set to Content")]
36+
[Category("SCSS")]
37+
public bool IncludeCssInProjectOutput { get; set; }
38+
39+
[LocDisplayName("Source Comments")]
40+
[Description("When enabled, comments will be added to the .css file specifying the file and line number where the values originated from.")]
41+
[Category("SCSS")]
42+
public bool IncludeSourceComments { get; set; }
43+
}
44+
}

SassyStudio.2012/Resources.Designer.cs

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)