• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thorstenalpers / CleanMyPosts / 15097829564

18 May 2025 04:20PM UTC coverage: 11.132%. First build
15097829564

push

github

thorstenalpers
Merge branch 'develop'

15 of 244 branches covered (6.15%)

Branch coverage included in aggregate %.

42 of 79 new or added lines in 12 files covered. (53.16%)

101 of 798 relevant lines covered (12.66%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/UI/Services/WindowManagerService.cs
1
using System.Windows;
2
using System.Windows.Controls;
3
using System.Windows.Navigation;
4
using CleanMyPosts.UI.Contracts.Services;
5
using CleanMyPosts.UI.Contracts.ViewModels;
6
using CleanMyPosts.UI.Contracts.Views;
7
using CleanMyPosts.UI.Helpers;
8
using MahApps.Metro.Controls;
9

10
namespace CleanMyPosts.UI.Services;
11

12
public class WindowManagerService(IServiceProvider serviceProvider, IPageService pageService) : IWindowManagerService
×
13
{
14
    private readonly IServiceProvider _serviceProvider = serviceProvider;
×
15
    private readonly IPageService _pageService = pageService;
×
16
    public Window MainWindow => Application.Current.MainWindow;
×
17

18
    public void OpenInNewWindow(string pageKey, object parameter = null)
19
    {
NEW
20
        var existingWindow = GetWindow(pageKey);
×
21
        if (existingWindow is not null)
×
22
        {
23
            existingWindow.Activate();
×
24
            return;
×
25
        }
26

27
        var frame = new Frame
×
28
        {
×
29
            Focusable = false,
×
30
            NavigationUIVisibility = NavigationUIVisibility.Hidden
×
31
        };
×
32

33
        var newWindow = new MetroWindow
×
34
        {
×
35
            Title = "CleanMyPosts",
×
36
            Style = Application.Current.FindResource("CustomMetroWindow") as Style,
×
37
            Content = frame
×
38
        };
×
39

40
        frame.Navigated += OnNavigated;
×
41
        newWindow.Closed += OnWindowClosed;
×
NEW
42
        frame.Navigate(_pageService.GetPage(pageKey), parameter);
×
43
        newWindow.Show();
×
44
    }
×
45

46
    public bool? OpenInDialog(string pageKey, object parameter = null)
47
    {
48
        if (_serviceProvider.GetService(typeof(IShellDialogWindow)) is not IShellDialogWindow shellWindow)
×
49
        {
50
            return null;
×
51
        }
52

53
        var frame = shellWindow.GetDialogFrame();
×
54
        frame.Navigated += OnNavigated;
×
55

56
        ((Window)shellWindow).Closed += OnWindowClosed;
×
NEW
57
        frame.Navigate(_pageService.GetPage(pageKey), parameter);
×
58

59
        return ((Window)shellWindow).ShowDialog();
×
60
    }
61

62
    public Window GetWindow(string pageKey)
63
    {
64
        foreach (Window window in Application.Current.Windows)
×
65
        {
66
            var dataContext = window.GetDataContext();
×
NEW
67
            if (dataContext?.GetType().FullName == pageKey)
×
68
            {
69
                return window;
×
70
            }
71
        }
72
        return null;
×
73
    }
×
74

75
    private static void OnNavigated(object sender, NavigationEventArgs e)
76
    {
77
        if (sender is Frame frame &&
×
78
            frame.GetDataContext() is INavigationAware navigationAware)
×
79
        {
80
            navigationAware.OnNavigatedTo(e.ExtraData);
×
81
        }
82
    }
×
83

84
    private void OnWindowClosed(object sender, EventArgs e)
85
    {
86
        if (sender is Window window && window.Content is Frame frame)
×
87
        {
88
            frame.Navigated -= OnNavigated;
×
89
            window.Closed -= OnWindowClosed;
×
90
        }
91
    }
×
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc