Skip to content

Commit

Permalink
Merge pull request #11 from usysware/Bookmarks
Browse files Browse the repository at this point in the history
Bookmarks
  • Loading branch information
Sergey M authored Aug 17, 2020
2 parents d3a0a44 + 85fd273 commit a6fb65c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
20 changes: 14 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,32 @@ dotnet_style_predefined_type_for_member_access = true:warning
# accessibility modifiers must always be specified
dotnet_style_require_accessibility_modifiers = always:warning

# IDE0016 - null check style
# IDE0008: Use explicit type
csharp_style_var_elsewhere = false:none
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = false:none

# IDE0016: null check style
csharp_style_throw_expression = false:none

# IDE0018 - inline variables style
# IDE0018: inline variables style
csharp_style_inlined_variable_declaration = true:silent

# IDE0019 - pattern matching style
# IDE0019: pattern matching style
csharp_style_pattern_matching_over_as_with_null_check = false:none

# IDE0020 - pattern matching style
# IDE0020: pattern matching style
csharp_style_pattern_matching_over_is_with_cast_check = false:none

# IDE0029 - coalescing expressions check
# IDE0029: coalescing expressions check
dotnet_style_coalesce_expression = false:none

# IDE0054 - compound assignment expressions check
# IDE0054: compound assignment expressions check
dotnet_style_prefer_compound_assignment = false:none

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = none

# define "Constants" symbols specifications
dotnet_naming_symbols.constants.applicable_kinds = field
dotnet_naming_symbols.constants.applicable_accessibilities = public,private,protected,internal,protected_internal,local
Expand Down
29 changes: 26 additions & 3 deletions DPackRx/Features/Bookmarks/BookmarksGlyphFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ public class BookmarksGlyphFactory : IGlyphFactory
{
#region Fields

private const string IMAGE_RESOURCE = "pack://application:,,,/DPackRx;component/Features/Bookmarks/Images/{0}Bookmark{1}.png";
private readonly IWpfTextViewMargin _margin;

#endregion

public BookmarksGlyphFactory(IWpfTextViewMargin margin)
{
_margin = margin;
}

#region IGlyphFactory Members

public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag) // TODO: consider drawing bookmarks directly
Expand All @@ -27,13 +32,31 @@ public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag) // TODO: co
return null;

var bookmarkTag = (BookmarkTag)tag;
var prefix = bookmarkTag.Type == BookmarkType.Global ? "Global" : string.Empty;

var image = new Image { Width = 16, Height = 16 };
image.Source = new BitmapImage(new Uri(string.Format(IMAGE_RESOURCE, prefix, bookmarkTag.Number)));
image.Source = new BitmapImage(GetImageUri(bookmarkTag));
image.ToolTip = GetDisplayName(bookmarkTag);
return image;
}

#endregion

#region Private Methods

private Uri GetImageUri(BookmarkTag bookmarkTag)
{
var prefix = bookmarkTag.Type == BookmarkType.Global ? "Global" : string.Empty;
return new Uri($"pack://application:,,,/DPackRx;component/Features/Bookmarks/Images/{prefix}Bookmark{bookmarkTag.Number}.png");
}

private string GetDisplayName(BookmarkTag bookmarkTag)
{
if (bookmarkTag.Type == BookmarkType.Local)
return $"Bookmark {bookmarkTag.Number}";
else
return $"Global bookmark {bookmarkTag.Number}";
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BookmarksGlyphFactoryProvider : IGlyphFactoryProvider

public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
{
return new BookmarksGlyphFactory();
return new BookmarksGlyphFactory(margin);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions DPackRx/Features/Bookmarks/BookmarksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public bool SetBookmark(int number)
bookmark.Line = position.Line;
bookmark.Column = position.Column;

_shellStatusBarService.SetStatusBarText($"Set bookmark {number}");
_shellStatusBarService.SetStatusBarText($"Updated bookmark {number}");
_log.LogMessage($"Bookmark # {number} updated", LOG_CATEGORY);
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ public bool SetGlobalBookmark(int number)
bookmarks.Add(bookmark);
}

_shellStatusBarService.SetStatusBarText($"Set global bookmark {number}");
_shellStatusBarService.SetStatusBarText($"Updated global bookmark {number}");
_log.LogMessage($"Global bookmark # {number} updated", LOG_CATEGORY);
}
}
Expand Down
6 changes: 4 additions & 2 deletions DPackRx/Features/Bookmarks/BookmarksSimpleTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ private void DoChanged(int number, BookmarkType type)
{
_log?.LogMessage($"Removed changed {changedBookmark.Type} bookmark {changedBookmark.Number} tag", LOG_CATEGORY);

RemoveTagSpan(_bookmarkSpans[changedBookmark]);
if (!RemoveTagSpan(_bookmarkSpans[changedBookmark]))
_log?.LogMessage($"Failed to remove changed {changedBookmark.Type} bookmark {changedBookmark.Number} tag span", LOG_CATEGORY);
_bookmarkSpans.Remove(changedBookmark);
}
}
Expand Down Expand Up @@ -248,7 +249,8 @@ private void DoChanged(int number, BookmarkType type)
{
_log?.LogMessage($"Removed deleted {b.Type} bookmark {b.Number} tag", LOG_CATEGORY);

RemoveTagSpan(_bookmarkSpans[b]);
if (!RemoveTagSpan(_bookmarkSpans[b]))
_log?.LogMessage($"Failed to remove deleted {b.Type} bookmark {b.Number} tag span", LOG_CATEGORY);
_bookmarkSpans.Remove(b);
});
}
Expand Down
2 changes: 1 addition & 1 deletion DPackRx/Features/Bookmarks/BookmarksTaggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DPackRx.Features.Bookmarks
/// Creates bookmark tagger.
/// </summary>
[Export(typeof(ITaggerProvider))]
[ContentType("any")]
[ContentType("text")]
[Order(Before = Priority.Default)]
[TextViewRole(PredefinedTextViewRoles.Document)]
[TagType(typeof(BookmarkTag))]
Expand Down
2 changes: 1 addition & 1 deletion DPackRx/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="3D22E261-32E5-46CE-A4B0-B884FA49A9A2" Version="4.0.0.31" Language="en-US" Publisher="USysWare" />
<Identity Id="3D22E261-32E5-46CE-A4B0-B884FA49A9A2" Version="4.0.0.32" Language="en-US" Publisher="USysWare" />
<DisplayName>DPack Rx</DisplayName>
<Description xml:space="preserve">FREE tools collection designed to greatly increase developer's productivity, automate repetitive processes and expand upon some of Microsoft Visual Studio features. Visual Studio 2017 and 2019 are supported.</Description>
<MoreInfo>https://github.com/usysware/dpack</MoreInfo>
Expand Down

0 comments on commit a6fb65c

Please sign in to comment.