Skip to content

Commit

Permalink
Merge pull request #47 from doki-theme/sqlBkFix
Browse files Browse the repository at this point in the history
Restored themed XAML view background.
  • Loading branch information
Unthrottled authored May 2, 2022
2 parents 2551cd2 + 67f8e14 commit 22619f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
---

# 78.0-1.0.2 [Themed XAML Views]

- Restored the original intended background color of the `XAML` view. ([#22](https://github.com/doki-theme/doki-theme-visualstudio/issues/21))

# 78.0-1.0.1 [Themed Tab Layout]

- Themed the tab layout title to match the rest of the IDE.
Expand Down
13 changes: 10 additions & 3 deletions doki-theme-visualstudio/UITools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ public class UITools {
Func<DependencyObject, bool> predicate
) {
while (true) {
var parent = childDependencyObject is Visual || childDependencyObject is Visual3D
? VisualTreeHelper.GetParent(childDependencyObject)
: LogicalTreeHelper.GetParent(childDependencyObject);
var parent = GetParent(childDependencyObject);
if (parent == null) return null;

if (predicate(parent)) return parent;
childDependencyObject = parent;
}
}

public static DependencyObject? GetParent(
DependencyObject childDependencyObject
) {
var parent = childDependencyObject is Visual || childDependencyObject is Visual3D
? VisualTreeHelper.GetParent(childDependencyObject)
: LogicalTreeHelper.GetParent(childDependencyObject);
return parent;
}

public static void TraverseParentTree(
DependencyObject childDependencyObject,
Action<DependencyObject> predicate
Expand Down
23 changes: 19 additions & 4 deletions doki-theme-visualstudio/WallpaperAdornment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
using Microsoft.VisualStudio.PlatformUI;

namespace doki_theme_visualstudio {
// Wallpaper works by attaching a background image to the
Expand Down Expand Up @@ -202,7 +203,6 @@ private void DoStupidShit() {
});
}
}

private void MakeThingsAboveWallpaperTransparent() {
UITools.FindParent(_editorCanvas, parent => {
if (parent.GetType().FullName
Expand All @@ -228,16 +228,31 @@ private void SetBackgroundToTransparent(DependencyObject dependencyObject) {

private DependencyObject? GetEditorView() {
return UITools.FindParent(_editorCanvas,
o => o.GetType().FullName.Equals(EditorViewClassName,
StringComparison.OrdinalIgnoreCase));
o => o.GetType().FullName.Equals(EditorViewClassName));
}

// Wallpapers work by setting all of the children (children are higher z-index than parents)
// above the parent editor window to transparent. Then set the background color
// of the parent editor window to the text editor color. After that, find the first child
// whose background can be an image, then draw the Image on that.
// Fixes: https://github.com/doki-theme/doki-theme-visualstudio/issues/21
private void DrawWallpaper() {
if (_image == null) return;
ThreadHelper.JoinableTaskFactory.Run(async () => {
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var editorView = GetEditorView();
editorView?.SetValue(Panel.BackgroundProperty, _image);
if (editorView != null) {
var textEditorBackground = VSColorTheme.GetThemedColor(EnvironmentColors.SystemWindowColorKey);
editorView.SetValue(Panel.BackgroundProperty, new SolidColorBrush(Color.FromRgb(
textEditorBackground.R,
textEditorBackground.G,
textEditorBackground.B)));
var brushedChild = UITools.FindChild(editorView, childGuy => {
var property = childGuy.GetType().GetProperty("Background");
return property?.GetValue(childGuy) is Brush && !childGuy.GetType().FullName.Contains("SplitterGrip");
});
brushedChild?.SetValue(Panel.BackgroundProperty, _image);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion doki-theme-visualstudio/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="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="78.1.1" Language="en-US" Publisher="Unthrottled" />
<Identity Id="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="78.1.2" Language="en-US" Publisher="Unthrottled" />
<DisplayName>The Doki Theme</DisplayName>
<Description xml:space="preserve">Cute anime character themes!</Description>
<MoreInfo>https://github.com/doki-theme/doki-theme-visualstudio#the-doki-theme-visual-studio</MoreInfo>
Expand Down

0 comments on commit 22619f9

Please sign in to comment.