diff --git a/GlazeWM.Bar/Components/ImageComponent.xaml b/GlazeWM.Bar/Components/ImageComponent.xaml
index fa3e37fda..04998e8be 100644
--- a/GlazeWM.Bar/Components/ImageComponent.xaml
+++ b/GlazeWM.Bar/Components/ImageComponent.xaml
@@ -6,5 +6,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GlazeWM.Bar.Components"
mc:Ignorable="d">
-
+
+
diff --git a/GlazeWM.Bar/Components/TextFileComponent.xaml b/GlazeWM.Bar/Components/TextFileComponent.xaml
index 9575773ff..0ad5f6adf 100644
--- a/GlazeWM.Bar/Components/TextFileComponent.xaml
+++ b/GlazeWM.Bar/Components/TextFileComponent.xaml
@@ -13,5 +13,9 @@
FontWeight="{Binding FontWeight}"
FontSize="{Binding FontSize}"
Text="{Binding Text}">
+
+
+
+
diff --git a/GlazeWM.Bar/Components/TextFileComponentViewModel.cs b/GlazeWM.Bar/Components/TextFileComponentViewModel.cs
index f4c0c22f4..9f3348da4 100644
--- a/GlazeWM.Bar/Components/TextFileComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/TextFileComponentViewModel.cs
@@ -6,6 +6,9 @@
using GlazeWM.Domain.UserConfigs.Events;
using GlazeWM.Infrastructure;
using GlazeWM.Infrastructure.Bussing;
+using GlazeWM.Domain.Containers;
+using System.Windows.Input;
+using GlazeWM.Bar.Common;
namespace GlazeWM.Bar.Components
{
@@ -13,9 +16,17 @@ public class TextFileComponentViewModel : ComponentViewModel
{
private readonly TextFileComponentConfig _baseConfig;
private readonly IDisposable _disposable;
+ private readonly Bus _bus = ServiceLocator.GetRequiredService();
+ private readonly ContainerService _containerService =
+ ServiceLocator.GetRequiredService();
+ private readonly CommandParsingService _commandParsingService =
+ ServiceLocator.GetRequiredService();
public string Text { get; set; } = "Loading...";
+ public ICommand LeftClickCommand => new RelayCommand(OnLeftClick);
+ public ICommand RightClickCommand => new RelayCommand(OnRightClick);
+
public FileSystemWatcher Watcher { get; }
public TextFileComponentViewModel(BarViewModel parentViewModel, TextFileComponentConfig baseConfig) : base(parentViewModel, baseConfig)
@@ -35,6 +46,32 @@ public TextFileComponentViewModel(BarViewModel parentViewModel, TextFileComponen
Update();
}
+ public void OnLeftClick()
+ {
+ InvokeCommand(_baseConfig.LeftClickCommand);
+ }
+
+ public void OnRightClick()
+ {
+ InvokeCommand(_baseConfig.RightClickCommand);
+ }
+
+ private void InvokeCommand(string commandString)
+ {
+ if (string.IsNullOrEmpty(commandString))
+ return;
+
+ var subjectContainer = _containerService.FocusedContainer;
+
+ var parsedCommand = _commandParsingService.ParseCommand(
+ commandString,
+ subjectContainer
+ );
+
+ // Use `dynamic` to resolve the command type at runtime and allow multiple dispatch.
+ _bus.Invoke((dynamic)parsedCommand);
+ }
+
protected override void Dispose(bool disposing)
{
if (disposing)
diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
index 0276c69f1..ab47daa71 100644
--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
@@ -195,10 +195,21 @@ windowRuleConfig.MatchProcessName is not null ||
)
.Where((commandString) => !string.IsNullOrEmpty(commandString));
+ var textFileComponentCommands = componentConfigs
+ .OfType()
+ .SelectMany(
+ (componentConfig) => new List {
+ componentConfig.LeftClickCommand,
+ componentConfig.RightClickCommand
+ }
+ )
+ .Where((commandString) => !string.IsNullOrEmpty(commandString));
+
var allCommandStrings = new List()
.Concat(keybindingsConfig.SelectMany((keybinding) => keybinding.CommandList))
.Concat(windowRulesConfig.SelectMany((windowRule) => windowRule.CommandList))
.Concat(textComponentCommands)
+ .Concat(textFileComponentCommands)
.Select((commandString) => CommandParsingService.FormatCommand(commandString));
foreach (var commandString in allCommandStrings)
diff --git a/GlazeWM.Domain/UserConfigs/TextFileComponentConfig.cs b/GlazeWM.Domain/UserConfigs/TextFileComponentConfig.cs
index 13ee20bcb..fc7c05ec6 100644
--- a/GlazeWM.Domain/UserConfigs/TextFileComponentConfig.cs
+++ b/GlazeWM.Domain/UserConfigs/TextFileComponentConfig.cs
@@ -3,5 +3,15 @@ namespace GlazeWM.Domain.UserConfigs
public class TextFileComponentConfig : BarComponentConfig
{
public string FilePath { get; set; }
+
+ ///
+ /// Command to invoke on left-click.
+ ///
+ public string LeftClickCommand { get; set; }
+
+ ///
+ /// Command to invoke on right-click.
+ ///
+ public string RightClickCommand { get; set; }
}
}