Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion VdLabel/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ record DesktopConfig
public IReadOnlyList<WindowConfig> TargetWindows { get; init; } = [];
}

record WindowConfig(WindowMatchType MatchType, WindowPatternType PatternType, string Pattern);
record WindowConfig(WindowMatchType MatchType, WindowPatternType PatternType, string Pattern)
{
public string? TitlePattern { get; init; }
public WindowPatternType TitlePatternType { get; init; }
}

enum WindowMatchType
{
Expand Down
17 changes: 16 additions & 1 deletion VdLabel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ public async Task FindWindow(WindowConfigViewModel config)
WindowMatchType.Path => info.Path,
_ => throw new NotSupportedException(),
};
if (config.MatchType != WindowMatchType.Title && string.IsNullOrEmpty(config.TitlePattern))
{
config.TitlePattern = info.Title;
}
}

public DesktopConfig GetSaveConfig()
Expand All @@ -344,16 +348,27 @@ public DesktopConfig GetSaveConfig()
Utf8Command = this.Utf8Command,
Command = this.Command,
ImagePath = this.ImagePath,
TargetWindows = this.TargetWindows.Select(c => new WindowConfig(c.MatchType, c.PatternType, c.Pattern)).ToArray(),
TargetWindows = this.TargetWindows.Select(c => new WindowConfig(c.MatchType, c.PatternType, c.Pattern)
{
TitlePattern = c.TitlePattern,
TitlePatternType = c.TitlePatternType,
}).ToArray(),
};
}

partial class WindowConfigViewModel(WindowConfig? config = null) : ObservableObject
{
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsTitlePatternVisible))]
private WindowMatchType matchType = config?.MatchType ?? default;
[ObservableProperty]
private WindowPatternType patternType = config?.PatternType ?? default;
[ObservableProperty]
private string pattern = config?.Pattern ?? string.Empty;
[ObservableProperty]
private WindowPatternType titlePatternType = config?.TitlePatternType ?? WindowPatternType.Wildcard;
[ObservableProperty]
private string? titlePattern = config?.TitlePattern;

public bool IsTitlePatternVisible => this.MatchType != WindowMatchType.Title;
}
20 changes: 20 additions & 0 deletions VdLabel/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ComboBox
Grid.Row="0"
Expand Down Expand Up @@ -460,6 +461,25 @@
Grid.ColumnSpan="4"
Margin="0,4"
Text="{Binding Pattern, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<DockPanel
Grid.Row="2"
Grid.ColumnSpan="4"
Margin="0,2"
Visibility="{Binding IsTitlePatternVisible, Converter={StaticResource b2vConv}}">
<Label
Content="{x:Static p:Resources.TitlePattern}"
DockPanel.Dock="Left"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<ComboBox
DockPanel.Dock="Right"
Margin="4,0"
ItemsSource="{Binding DataContext.PatternTypes, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
SelectedItem="{Binding TitlePatternType, Mode=TwoWay}" />
<ui:TextBox
PlaceholderText="{x:Static p:Resources.TitlePattern}"
Text="{Binding TitlePattern, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DockPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
9 changes: 9 additions & 0 deletions VdLabel/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions VdLabel/Properties/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<data name="TargetWindow" xml:space="preserve">
<value>Target Window</value>
</data>
<data name="TitlePattern" xml:space="preserve">
<value>Title Pattern</value>
</data>
<data name="Add" xml:space="preserve">
<value>Add</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions VdLabel/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
<data name="TargetWindow" xml:space="preserve">
<value>対象ウィンドウ</value>
</data>
<data name="TitlePattern" xml:space="preserve">
<value>タイトルパターン</value>
</data>
<data name="Add" xml:space="preserve">
<value>追加</value>
</data>
Expand Down
8 changes: 5 additions & 3 deletions VdLabel/WindowMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WindowMonitor(ILogger<WindowMonitor> logger, IConfigStore configStore) : B
private bool needReload = true;
private TargetWindow[] targetWindows = [];

private record TargetWindow(Guid DesktopId, WindowMatchType MatchType, Regex Regex);
private record TargetWindow(Guid DesktopId, WindowMatchType MatchType, Regex Regex, Regex? TitleRegex);

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Expand Down Expand Up @@ -54,7 +54,8 @@ static Regex ToRegex(WindowPatternType patternType, string pattern)
var config = await this.configStore.Load().ConfigureAwait(false);
this.targetWindows = config.DesktopConfigs
.SelectMany(c => c.TargetWindows.Select(p => (c.Id, p)))
.Select(c => new TargetWindow(c.Id, c.p.MatchType, ToRegex(c.p.PatternType, c.p.Pattern)))
.Select(c => new TargetWindow(c.Id, c.p.MatchType, ToRegex(c.p.PatternType, c.p.Pattern),
c.p.TitlePattern is { } tp ? ToRegex(c.p.TitlePatternType, tp) : null))
.ToArray();
this.checkedWindows.Clear();
this.logger.LogDebug("ターゲットプロセス再読み込み");
Expand Down Expand Up @@ -119,7 +120,8 @@ private void CheckWindows()
return true;
}

if (this.targetWindows.FirstOrDefault(t => t.Regex.IsMatch(GetCheckText(t.MatchType, path, commandLine, windowTitle))) is not { } target)
if (this.targetWindows.FirstOrDefault(t => t.Regex.IsMatch(GetCheckText(t.MatchType, path, commandLine, windowTitle))
&& (t.TitleRegex is null || t.TitleRegex.IsMatch(windowTitle))) is not { } target)
{
// ウィンドウがターゲットでない場合はチェック済みとする
this.checkedWindows[hWnd] = windowTitle;
Expand Down