Skip to content

Commit

Permalink
Bug fixes, organization and a new feature (dim modes)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alpzy committed Jul 11, 2020
1 parent 23405df commit 92affc9
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 174 deletions.
26 changes: 0 additions & 26 deletions Focus Dimmer/Classifier/DimFormatDefinition.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Focus_Dimmer.Classifier
namespace Focus_Dimmer.Classifiers
{
internal static class DimFormatClassifierTypeDefinition
internal static class DimGrayFormatClassifierTypeDefinition
{
[Export(typeof(ClassificationTypeDefinition))]
[Name("Alpzy/DimFormatDefinition")]
[Name("Alpzy/DimGray")]
private static ClassificationTypeDefinition typeDefinition;
}
}
21 changes: 21 additions & 0 deletions Focus Dimmer/Classifiers/DimGray/DimGrayFormatDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;
using System.ComponentModel.Composition;
using System.Windows.Media;

namespace Focus_Dimmer.Classifiers
{
[Export(typeof(EditorFormatDefinition))]
[Name("Alpzy/DimGray")]
[ClassificationType(ClassificationTypeNames = "Alpzy/DimGray")]
[UserVisible(true)]
[Order(After = Priority.High)]
class DimGrayFormatDefinition : ClassificationFormatDefinition
{
public DimGrayFormatDefinition()
{
this.DisplayName = "DimGray Classifier"; // Human readable version of the name
this.ForegroundColor = Colors.DimGray;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Focus_Dimmer.Classifiers
{
internal static class TransparentFormatClassifierTypeDefinition
{
[Export(typeof(ClassificationTypeDefinition))]
[Name("Alpzy/Transparent")]
private static ClassificationTypeDefinition typeDefinition;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;
using System.ComponentModel.Composition;

namespace Focus_Dimmer.Classifiers
{
[Export(typeof(EditorFormatDefinition))]
[Name("Alpzy/Transparent")]
[ClassificationType(ClassificationTypeNames = "Alpzy/Transparent")]
[UserVisible(true)]
[Order(After = Priority.High)]
class TransparentFormatDefinition : ClassificationFormatDefinition
{
public TransparentFormatDefinition()
{
this.DisplayName = "Transparent Classifier"; // Human readable version of the name
this.ForegroundOpacity = 0.25;
}
}
}
55 changes: 55 additions & 0 deletions Focus Dimmer/Commands/ToggleModeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.ComponentModel.Design;
using Focus_Dimmer.Enums;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace Focus_Dimmer.Commands
{
public sealed class ToggleModeCommand
{
public const int CommandId = 0x0101;

public static readonly Guid CommandSet = new Guid("7cef4032-34d2-4bfd-9b60-b1ae5e3f0305");

private readonly AsyncPackage package;

public EventHandler toggled;

private ToggleModeCommand(AsyncPackage package, OleMenuCommandService commandService)
{
this.package = package ?? throw new ArgumentNullException(nameof(package));
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.onToggled, menuCommandID);
commandService.AddCommand(menuItem);
}

public static ToggleModeCommand Instance
{
get;
private set;
}

private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
{
get
{
return this.package;
}
}

public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new ToggleModeCommand(package, commandService);
}

private void onToggled(object sender, EventArgs e)
{
FocusDimmer.Mode = FocusDimmer.Mode == Modes.DimGray ? Modes.Transparent : Modes.DimGray;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.ComponentModel.Design;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;

namespace Focus_Dimmer
namespace Focus_Dimmer.Commands
{
public sealed class ToggleOnOffCommand
{
Expand Down Expand Up @@ -45,8 +40,6 @@ private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider

public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in ToggleOnOffCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Expand Down
14 changes: 14 additions & 0 deletions Focus Dimmer/Enums/Modes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Focus_Dimmer.Enums
{
public enum Modes : int
{
DimGray = 0,
Transparent = 1
}
}
12 changes: 9 additions & 3 deletions Focus Dimmer/Focus Dimmer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Classifier\DimFormatDefinition.cs" />
<Compile Include="Classifiers\DimGray\DimGrayFormatDefinition.cs" />
<Compile Include="Classifiers\Transparent\TransparentFormatClassifierTypeDefinition.cs" />
<Compile Include="Classifiers\Transparent\TransparentFormatDefinition.cs" />
<Compile Include="Commands\ToggleModeCommand.cs" />
<Compile Include="Enums\Modes.cs" />
<Compile Include="Tagger\DimTagger.cs" />
<Compile Include="Tagger\DimTaggerProvider.cs" />
<Compile Include="Classifier\DimFormatClassifierTypeDefinition.cs" />
<Compile Include="Classifiers\DimGray\DimGrayFormatClassifierTypeDefinition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FocusDimmer.cs" />
<Compile Include="ToggleOnOffCommand.cs" />
<Compile Include="Commands\ToggleOnOffCommand.cs" />
<Compile Include="Utils\CodeBlockUtils.cs" />
<Compile Include="Utils\TagUtils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
Expand Down
10 changes: 8 additions & 2 deletions Focus Dimmer/FocusDimmer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Focus_Dimmer.Commands;
using Focus_Dimmer.Enums;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

Expand All @@ -14,16 +16,20 @@ public sealed class FocusDimmer : AsyncPackage
public const string PackageGuidString = "43eb844c-abc7-4dca-842c-1309721e4bdc";

private static bool isOn = false;
private static Modes mode = Modes.DimGray;

public static bool IsOn { get{ return isOn; } set{ isOn = value; Toggled?.Invoke(new Object(), new EventArgs()); } }
public static bool IsOn { get { return isOn; } set{ isOn = value; ToggledOnOff?.Invoke(new Object(), new EventArgs()); } }
public static Modes Mode { get { return mode; } set { mode = value; ToggledMode?.Invoke(new Object(), new EventArgs()); } }

public static event EventHandler Toggled;
public static event EventHandler ToggledOnOff;
public static event EventHandler ToggledMode;

#region Package Members
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
await ToggleOnOffCommand.InitializeAsync(this);
await ToggleModeCommand.InitializeAsync(this);
}

#endregion
Expand Down
23 changes: 15 additions & 8 deletions Focus Dimmer/FocusDimmer.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,40 @@
<Commands package="guidFocus_DimmerPackage">

<Groups>
<Group guid="guidFocus_DimmerPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Group guid="guidFocus_DimmerPackageCmdSet" id="FocusDimmerMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>
</Groups>

<Buttons>
<Button guid="guidFocus_DimmerPackageCmdSet" id="ToggleOnOffCommandId" priority="0x0100" type="Button">
<Parent guid="guidFocus_DimmerPackageCmdSet" id="MyMenuGroup" />
<Button guid="guidFocus_DimmerPackageCmdSet" id="ToggleOnOffCommandID" priority="0x0100" type="Button">
<Parent guid="guidFocus_DimmerPackageCmdSet" id="FocusDimmerMenuGroup" />
<Icon guid="guidImages" id="power" />
<Strings>
<ButtonText>Toggle Focus Dimmer</ButtonText>
<ButtonText>Toggle Focus Dimmer On/Off</ButtonText>
</Strings>
</Button>
<Button guid="guidFocus_DimmerPackageCmdSet" id="ToggleModeCommandID" priority="0x0100" type="Button">
<Parent guid="guidFocus_DimmerPackageCmdSet" id="FocusDimmerMenuGroup" />
<Strings>
<ButtonText>Toggle Focus Dimmer Mode</ButtonText>
</Strings>
</Button>
</Buttons>
<Bitmaps>

<Bitmap guid="guidImages" href="Resources\powerIcon.png" usedList="power"/>
</Bitmaps>
</Commands>
<KeyBindings>
<KeyBinding guid="guidFocus_DimmerPackageCmdSet" id="ToggleOnOffCommandId" editor="guidVSStd97" key1="L" mod1="ALT"/>
<KeyBinding guid="guidFocus_DimmerPackageCmdSet" id="ToggleOnOffCommandID" editor="guidVSStd97" key1="L" mod1="ALT"/>
<KeyBinding guid="guidFocus_DimmerPackageCmdSet" id="ToggleModeCommandID" editor="guidVSStd97" key1="M" mod1="ALT"/>
</KeyBindings>
<Symbols>
<GuidSymbol name="guidFocus_DimmerPackage" value="{43eb844c-abc7-4dca-842c-1309721e4bdc}" />
<GuidSymbol name="guidFocus_DimmerPackageCmdSet" value="{7cef4032-34d2-4bfd-9b60-b1ae5e3f0305}">
<IDSymbol name="MyMenuGroup" value="0x1020" />
<IDSymbol name="ToggleOnOffCommandId" value="0x0100" />
<IDSymbol name="FocusDimmerMenuGroup" value="0x1020" />
<IDSymbol name="ToggleOnOffCommandID" value="0x0100" />
<IDSymbol name="ToggleModeCommandID" value="0x0101" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{40f7c6da-49be-45c3-a044-721baeaffabc}" >
Expand Down
Loading

0 comments on commit 92affc9

Please sign in to comment.