Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #41 from kamilskoracki/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Kraviecc authored May 29, 2019
2 parents a94f9fb + 0104990 commit 0b7d02c
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 290 deletions.
1 change: 1 addition & 0 deletions CocoJumper.Base/CocoJumper.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="EventModels\SearchEvent.cs" />
<Compile Include="EventModels\SearchResultEvent.cs" />
<Compile Include="EventModels\StartNewSearchEvent.cs" />
<Compile Include="Exception\NotFoundException.cs" />
<Compile Include="Exception\InvalidStateException.cs" />
<Compile Include="Logic\ICocoJumperLogic.cs" />
<Compile Include="Logic\TaggerCommon.cs" />
Expand Down
9 changes: 9 additions & 0 deletions CocoJumper.Base/Exception/NotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CocoJumper.Base.Exception
{
public class NotFoundException : System.Exception
{
public NotFoundException(string message) : base(message)
{
}
}
}
2 changes: 1 addition & 1 deletion CocoJumper.Base/Logic/ICocoJumperLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CocoJumper.Base.Logic
{
public interface ICocoJumperLogic : IDisposable
{
void ActivateSearching(bool isSingle, bool isHighlight);
void ActivateSearching(bool isSingle, bool isHighlight, bool isWord);
CocoJumperKeyboardActionResult KeyboardAction(char? key, KeyEventType eventType);
}
}
4 changes: 2 additions & 2 deletions CocoJumper.Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
3 changes: 3 additions & 0 deletions CocoJumper/CocoJumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@
<Compile Include="CodeHighlighterTag\CodeHighlighterTaggerProvider.cs" />
<Compile Include="CodeMarkerTag\CodeMarkerTagger.cs" />
<Compile Include="CodeMarkerTag\CodeMarkerTaggerProvider.cs" />
<Compile Include="Commands\CocoJumperBaseCommand.cs" />
<Compile Include="Commands\CocoJumperMultiSearchCommand.cs" />
<Compile Include="Commands\CocoJumperCommandPackage.cs" />
<Compile Include="Commands\CocoJumperOptions.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Commands\CocoJumperSingleSearchCommand.cs" />
<Compile Include="Commands\CocoJumperSingleSearchHighlightCommand.cs" />
<Compile Include="Commands\CocoJumperWordSearchCommand.cs" />
<Compile Include="Controls\SearcherWithMarker.xaml.cs">
<DependentUpon>SearcherWithMarker.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -109,6 +111,7 @@
<ItemGroup>
<Content Include="Commands\Resources\CocoJumperSingleSearchCommand.png" />
<Content Include="Commands\Resources\CocoJumperSingleSearchHighlightCommand.png" />
<Content Include="Commands\Resources\CocoJumperWordSearchCommand.png" />
<VSCTCompile Include="Commands\CocoJumperCommandPackage.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
Expand Down
23 changes: 15 additions & 8 deletions CocoJumper/CodeMarkerTag/CodeMarkerTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ private void OnSearch(SearchResultEvent e)

foreach (SearchEvent eSearchEvent in e.SearchEvents)
{
if (_taggers.ContainsKey(eSearchEvent.StartPosition))
TagSpan<IntraTextAdornmentTag> tagger = new TagSpan<IntraTextAdornmentTag>(
span: new SnapshotSpan(_buffer.CurrentSnapshot, new Span(eSearchEvent.StartPosition, 0)),
tag: new IntraTextAdornmentTag(new LetterWithMarker(eSearchEvent.Letters, lineHeight), null,
PositionAffinity.Predecessor));
bool taggerExist = _taggers.ContainsKey(eSearchEvent.StartPosition);

if (eSearchEvent.StartPosition == 0
&& taggerExist)
{
_taggers[eSearchEvent.StartPosition] = tagger;
continue;
}

_taggers.Add(eSearchEvent.StartPosition,
new TagSpan<IntraTextAdornmentTag>(
span: new SnapshotSpan(_buffer.CurrentSnapshot, new Span(eSearchEvent.StartPosition, 0)),
tag: new IntraTextAdornmentTag(new LetterWithMarker(eSearchEvent.Letters, lineHeight), null,
PositionAffinity.Predecessor)
)
);
if (taggerExist)
continue;

_taggers.Add(eSearchEvent.StartPosition, tagger);
}

IEnumerable<int> keysToRemove =
Expand Down
114 changes: 114 additions & 0 deletions CocoJumper/Commands/CocoJumperBaseCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using CocoJumper.Base.Enum;
using CocoJumper.Base.Events;
using CocoJumper.Base.Exception;
using CocoJumper.Base.Logic;
using CocoJumper.Events;
using CocoJumper.Extensions;
using CocoJumper.Listeners;
using CocoJumper.Logic;
using CocoJumper.Provider;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System;
using System.ComponentModel.Design;
using System.Threading.Tasks;

namespace CocoJumper.Commands
{
internal abstract class CocoJumperBaseCommand
{
protected ICocoJumperLogic Logic;
private readonly IVsEditorAdaptersFactoryService _editorAdaptersFactoryService;
private readonly AsyncPackage _package;
private readonly IVsTextManager _vsTextManager;
private InputListener _inputListener;

protected CocoJumperBaseCommand(AsyncPackage package,
OleMenuCommandService commandService,
IVsTextManager textManager,
IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
IEventAggregator eventAggregator,
Guid commandSet,
int commandId)
{
_package = package ?? throw new ArgumentNullException(nameof(package));

_vsTextManager = textManager ?? throw new ArgumentNullException(nameof(textManager));
_editorAdaptersFactoryService = editorAdaptersFactoryService ?? throw new ArgumentNullException(nameof(editorAdaptersFactoryService));

eventAggregator.AddListener(new DelegateListener<ExitEvent>(OnExit), true);

commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
CommandID menuCommandID = new CommandID(commandSet, commandId);
MenuCommand menuItem = new MenuCommand(Execute, menuCommandID);
commandService.AddCommand(menuItem);
}

protected IAsyncServiceProvider ServiceProvider
{
get { return _package; }
}

protected static async
Task<(OleMenuCommandService commandService,
IVsTextManager vsTextManager,
IVsEditorAdaptersFactoryService editor,
IEventAggregator eventAggregator)> GetServicesAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
IVsTextManager vsTextManager = await package.GetServiceAsync(typeof(SVsTextManager)) as IVsTextManager;
IComponentModel componentModel = await package.GetServiceAsync(typeof(SComponentModel)) as IComponentModel
?? throw new NotFoundException($"{nameof(IComponentModel)} not found.");
IVsEditorAdaptersFactoryService editor = componentModel.GetService<IVsEditorAdaptersFactoryService>();
IEventAggregator eventAggregator = componentModel.GetService<IEventAggregator>();

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

return (commandService, vsTextManager, editor, eventAggregator);
}

protected void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
IVsTextView textView = _vsTextManager.GetActiveView();
IWpfTextView wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(textView);
CocoJumperCommandPackage cocoJumperCommandPackage = (CocoJumperCommandPackage)_package;

CleanupLogicAndInputListener();
WpfViewProvider renderer = new WpfViewProvider(wpfTextView);

Logic = new CocoJumperLogic(renderer, cocoJumperCommandPackage);
_inputListener = new InputListener(textView);
_inputListener.KeyPressEvent += OnKeyboardAction;

ExecutePostAction();
}

protected abstract void ExecutePostAction();

protected void OnExit(ExitEvent e)
{
CleanupLogicAndInputListener();
}

protected void OnKeyboardAction(object oSender, char? key, KeyEventType eventType)
{
Logic = Logic ?? throw new Exception($"{nameof(OnKeyboardAction)} in {nameof(CocoJumperBaseCommand)}, {nameof(Logic)} is null");
if (Logic.KeyboardAction(key, eventType) == CocoJumperKeyboardActionResult.Finished)
{
CleanupLogicAndInputListener();
}
}

private void CleanupLogicAndInputListener()
{
Logic?.Dispose();
_inputListener?.Dispose();
Logic = null;
_inputListener = null;
}
}
}
52 changes: 27 additions & 25 deletions CocoJumper/Commands/CocoJumperCommandPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,85 @@ namespace CocoJumper.Commands
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideOptionPage(typeof(CocoJumperOptions), "Environment\\Keyboard", "CocoJumper", 0, 0, true, ProvidesLocalizedCategoryName = false)]
[ProvideOptionPage(typeof(CocoJumperOptions), "Environment\\Keyboard", "CocoJumper",
0, 0, true, ProvidesLocalizedCategoryName = false)]
[Guid(PackageGuidString)]
public sealed class CocoJumperCommandPackage : AsyncPackage
{
public const string PackageGuidString = "cd8f3565-1f57-4c09-b5c1-01fe488ab080";

protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
MefProvider.ComponentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;
await CocoJumperMultiSearchCommand.InitializeAsync(this);
await CocoJumperSingleSearchCommand.InitializeAsync(this);
await CocoJumperSingleSearchHighlightCommand.InitializeAsync(this);
await base.InitializeAsync(cancellationToken, progress);
}

public int LimitResults
public int AutomaticallyExitInterval
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.LimitResults;
return page.AutomaticallyExitInterval;
}
}

public int TimerInterval
public bool DisableHighlightForMultiSearch
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.TimerInterval;
return page.DisableHighlightForMultiSearch;
}
}

public bool JumpAfterChoosedElement
public bool DisableHighlightForSingleHighlight
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.JumpAfterChoosedElement;
return page.DisableHighlightForSingleHighlight;
}
}

public int AutomaticallyExitInterval
public bool DisableHighlightForSingleSearch
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.AutomaticallyExitInterval;
return page.DisableHighlightForSingleSearch;
}
}

public bool DisableHighlightForMultiSearch
public bool JumpAfterChosenElement
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.DisableHighlightForMultiSearch;
return page.JumpAfterChosenElement;
}
}

public bool DisableHighlightForSingleHighlight
public int LimitResults
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.DisableHighlightForSingleHighlight;
return page.LimitResults;
}
}

public bool DisableHighlightForSingleSearch
public int TimerInterval
{
get
{
CocoJumperOptions page = (CocoJumperOptions)GetDialogPage(typeof(CocoJumperOptions));
return page.DisableHighlightForSingleSearch;
return page.TimerInterval;
}
}

protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
MefProvider.ComponentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;
await CocoJumperMultiSearchCommand.InitializeAsync(this);
await CocoJumperSingleSearchCommand.InitializeAsync(this);
await CocoJumperSingleSearchHighlightCommand.InitializeAsync(this);
await CocoJumperWordSearchCommand.InitializeAsync(this);
await base.InitializeAsync(cancellationToken, progress);
}
}
}
19 changes: 19 additions & 0 deletions CocoJumper/Commands/CocoJumperCommandPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
<ButtonText>CocoJumper - SingleSearchHighlight</ButtonText>
</Strings>
</Button>
<Button guid="guidCocoJumperCommandPackageCmdSet" id="cmdidCocoJumperWordSearchCommand" priority="0x0100" type="Button">
<Parent guid="guidCocoJumperCommandPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages3" id="bmpPic1" />
<Strings>
<ButtonText>CocoJumper - WordSearch</ButtonText>
</Strings>
</Button>
</Buttons>

<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
Expand All @@ -85,12 +92,14 @@
<Bitmap guid="guidImages" href="Resources\CocoJumperCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages1" href="Resources\CocoJumperSingleSearchCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages2" href="Resources\CocoJumperSingleSearchHighlightCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages3" href="Resources\CocoJumperWordSearchCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
</Bitmaps>
</Commands>
<KeyBindings>
<KeyBinding guid="guidCocoJumperCommandPackageCmdSet" id="CocoJumperCommandId" editor="guidVSStd97" mod1="CONTROL ALT" key1="VK_OEM_1" />
<KeyBinding guid="guidCocoJumperCommandPackageCmdSet" id="cmdidCocoJumperSingleSearchCommand" editor="guidVSStd97" mod1="CONTROL ALT" key1="VK_OEM_2" />
<KeyBinding guid="guidCocoJumperCommandPackageCmdSet" id="cmdidCocoJumperSingleSearchHighlightCommand" editor="guidVSStd97" mod1="CONTROL ALT SHIFT" key1="VK_OEM_2" />
<KeyBinding guid="guidCocoJumperCommandPackageCmdSet" id="cmdidCocoJumperWordSearchCommand" editor="guidVSStd97" mod1="CONTROL ALT" key1="VK_OEM_7" />
</KeyBindings>
<Symbols>
<!-- This is the package guid. -->
Expand All @@ -102,6 +111,7 @@
<IDSymbol name="CocoJumperCommandId" value="0x0100" />
<IDSymbol value="4129" name="cmdidCocoJumperSingleSearchCommand" />
<IDSymbol value="4130" name="cmdidCocoJumperSingleSearchHighlightCommand" />
<IDSymbol value="4131" name="cmdidCocoJumperWordSearchCommand" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{4c6fb194-1dd5-4e06-8779-d1f9ffde0979}">
Expand Down Expand Up @@ -130,5 +140,14 @@
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>

<GuidSymbol value="{a5e54357-e9de-40a1-95a1-5525f781bf5d}" name="guidImages3">
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>
</Symbols>
</CommandTable>
Loading

0 comments on commit 0b7d02c

Please sign in to comment.