Skip to content

Commit 46d7e02

Browse files
committed
Add Status Bar
1 parent 27b112e commit 46d7e02

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using mToolkitPlatformComponentLibrary.Pipelines;
2+
using mToolkitPlatformDesktopLauncher.UserControls;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Xml.Linq;
9+
10+
namespace mToolkitPlatformDesktopLauncher.Pipelines
11+
{
12+
/// <summary>
13+
/// Represents a pipeline for processing status bar messages.
14+
/// </summary>
15+
public class StatusbarPipeline : mPipeline<XElement>
16+
{
17+
/// <summary>
18+
/// Gets or sets the current FancyStatusbar instance.
19+
/// </summary>
20+
public static FancyStatusbar Current { get; set; }
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="StatusbarPipeline"/> class.
24+
/// </summary>
25+
public StatusbarPipeline() : base("Statusbar")
26+
{
27+
}
28+
29+
/// <summary>
30+
/// Processes an incoming message for the pipeline.
31+
/// </summary>
32+
/// <param name="message">The message to process.</param>
33+
protected override void AcceptMessage(mPipeMessage message)
34+
{
35+
XElement messageElement = (XElement)message.Message;
36+
37+
string text = messageElement.Element("text")?.Value ?? string.Empty;
38+
string additional = messageElement.Element("additional")?.Value ?? string.Empty;
39+
string type = messageElement.Element("type")?.Value ?? string.Empty;
40+
string timing = messageElement.Element("timing")?.Value ?? string.Empty;
41+
42+
if (!string.IsNullOrEmpty(text) && Current != null)
43+
{
44+
int timingValue = string.IsNullOrEmpty(timing) ? -1 : int.Parse(timing);
45+
Current.Update(text, additional, type, timingValue);
46+
}
47+
}
48+
}
49+
}

mToolkit Platform Desktop Application/Properties/Settings.Designer.cs

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="mToolkitPlatformDesktopLauncher.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="WindowLeft" Type="System.Double" Scope="User">
6+
<Value Profile="(Default)">800</Value>
7+
</Setting>
8+
<Setting Name="WindowTop" Type="System.Double" Scope="User">
9+
<Value Profile="(Default)">600</Value>
10+
</Setting>
11+
<Setting Name="WindowWidth" Type="System.Double" Scope="User">
12+
<Value Profile="(Default)">800</Value>
13+
</Setting>
14+
<Setting Name="WindowHeight" Type="System.Double" Scope="User">
15+
<Value Profile="(Default)">600</Value>
16+
</Setting>
17+
</Settings>
18+
</SettingsFile>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<UserControl x:Class="mToolkitPlatformDesktopLauncher.UserControls.FancyStatusbar"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:mToolkitPlatformDesktopLauncher.UserControls"
7+
mc:Ignorable="d"
8+
d:DesignHeight="20" d:DesignWidth="800">
9+
<Grid>
10+
<StatusBar MouseDoubleClick="StatusBar_MouseDoubleClick">
11+
<StatusBarItem>
12+
<TextBlock Name="StatusText" Text="Abc" FontFamily="Arial" FontSize="10" />
13+
</StatusBarItem>
14+
</StatusBar>
15+
</Grid>
16+
</UserControl>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using mToolkitPlatformDesktopLauncher.Pipelines;
2+
using System;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Input;
8+
using System.Windows.Media;
9+
10+
namespace mToolkitPlatformDesktopLauncher.UserControls
11+
{
12+
/// <summary>
13+
/// Represents a custom fancy status bar control.
14+
/// </summary>
15+
public partial class FancyStatusbar : UserControl
16+
{
17+
private string? _additional;
18+
private int _updated;
19+
20+
/// <summary>
21+
/// Initializes a new instance of the FancyStatusbar class.
22+
/// </summary>
23+
public FancyStatusbar()
24+
{
25+
InitializeComponent();
26+
StatusbarPipeline.Current = this;
27+
StatusText.Text = string.Empty;
28+
_updated = DateTime.Now.Millisecond;
29+
}
30+
31+
/// <summary>
32+
/// Updates the status bar text, color, and optional additional information.
33+
/// </summary>
34+
/// <param name="text">The status text to display.</param>
35+
/// <param name="additional">Optional additional information.</param>
36+
/// <param name="type">Optional status type (e.g. "error", "success").</param>
37+
/// <param name="timing">Optional time in milliseconds to display the status before resetting.</param>
38+
public void Update(string text, string? additional, string? type, int? timing = -1)
39+
{
40+
StatusText.Text = text;
41+
_additional = additional;
42+
SetForegroundColor(type);
43+
44+
int now = DateTime.Now.Millisecond;
45+
_updated = now;
46+
47+
if (timing != -1 && timing != null)
48+
{
49+
ResetStatusTextAfterDelay(now, timing.Value);
50+
}
51+
}
52+
53+
private void SetForegroundColor(string? type)
54+
{
55+
StatusText.Foreground = Brushes.Black;
56+
57+
switch (type?.ToLower())
58+
{
59+
case "error":
60+
StatusText.Foreground = Brushes.Red;
61+
break;
62+
case "success":
63+
StatusText.Foreground = Brushes.Green;
64+
break;
65+
}
66+
}
67+
68+
private async void ResetStatusTextAfterDelay(int now, int delay)
69+
{
70+
await Task.Delay(delay);
71+
72+
if (_updated == now)
73+
{
74+
StatusText.Dispatcher.Invoke(() => StatusText.Text = "");
75+
}
76+
}
77+
78+
/// <summary>
79+
/// Handles the MouseDoubleClick event on the status bar.
80+
/// </summary>
81+
/// <param name="sender">The sender of the event.</param>
82+
/// <param name="e">The MouseButtonEventArgs for the event.</param>
83+
private void StatusBar_MouseDoubleClick(object sender, MouseButtonEventArgs e)
84+
{
85+
if (_additional != null)
86+
{
87+
MessageBox.Show(_additional);
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)