Skip to content

Commit 6342ffc

Browse files
committed
Add 1 Miscellaneous Tools
1 parent f33f17f commit 6342ffc

13 files changed

+224
-14
lines changed

GlobalResDictionary.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,4 @@
12181218
</Style.Triggers>
12191219
</Style>
12201220
<!--#endregion-->
1221-
1222-
<converter:ListTextBoxWidthConverter x:Key="LTBWConverter" />
12231221
</ResourceDictionary>

MainWindow.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Width="600"
1212
Background="#1E1E1E"
1313
KeyDown="Window_KeyDown">
14-
<Window.Resources>
14+
<Window.Resources>
1515
<ResourceDictionary>
1616
<ResourceDictionary.MergedDictionaries>
1717
<ResourceDictionary Source="GlobalResDictionary.xaml" />
@@ -35,6 +35,12 @@
3535
Foreground="White">
3636
<view:PresetManager />
3737
</TabItem>
38+
<TabItem Style="{StaticResource TabItemStyle1}"
39+
Header="Misc.Tools"
40+
Background="Transparent"
41+
Foreground="White">
42+
<view:MiscellaneousTools />
43+
</TabItem>
3844
<TabItem Style="{StaticResource TabItemStyle1}"
3945
Header="Danbooru Tags Wiki"
4046
Background="Transparent"
@@ -45,7 +51,6 @@
4551
Header="Settings"
4652
Background="Transparent"
4753
Foreground="White">
48-
4954
</TabItem>
5055
</TabControl>
5156
</Grid>

MainWindow.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public partial class MainWindow : Window
1414
public MainWindow()
1515
{
1616
InitializeComponent();
17-
1817
}
1918

2019
private void Window_KeyDown(object sender, KeyEventArgs e)
@@ -35,6 +34,9 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
3534
case Key.D4:
3635
MainTab.SelectedIndex = 3;
3736
break;
37+
case Key.D5:
38+
MainTab.SelectedIndex = 4;
39+
break;
3840
default:
3941
break;
4042
}

Model/MiscToolReplaceCharModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Windows.Controls;
5+
6+
namespace SDPromptTool.Model
7+
{
8+
public class MiscToolReplaceCharModel
9+
{
10+
public string ReplaceFrom { get; set; }
11+
public string ReplaceTo { get; set; }
12+
public string TextBefore { get; set; }
13+
public TextBox TextAfter { get; set; }
14+
}
15+
}

View/MiscellaneousTools.xaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<UserControl x:Class="SDPromptTool.View.MiscellaneousTools"
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:SDPromptTool.View"
7+
xmlns:viewmodel="clr-namespace:SDPromptTool.ViewModel"
8+
d:DataContext="{d:DesignInstance Type=viewmodel:MainViewModel}"
9+
xmlns:converter="clr-namespace:SDPromptTool.ViewModel.Converter"
10+
mc:Ignorable="d"
11+
d:DesignHeight="420"
12+
d:DesignWidth="580">
13+
<UserControl.Resources>
14+
<converter:MiscToolReplaceCharConverter x:Key="MTRCConverter" />
15+
</UserControl.Resources>
16+
<d:UserControl.Resources>
17+
<ResourceDictionary>
18+
<ResourceDictionary.MergedDictionaries>
19+
<ResourceDictionary Source="/GlobalResDictionary.xaml" />
20+
</ResourceDictionary.MergedDictionaries>
21+
</ResourceDictionary>
22+
</d:UserControl.Resources>
23+
<Grid Margin="5">
24+
<Grid.RowDefinitions>
25+
<RowDefinition />
26+
<RowDefinition />
27+
</Grid.RowDefinitions>
28+
<Grid.ColumnDefinitions>
29+
<ColumnDefinition />
30+
<ColumnDefinition />
31+
</Grid.ColumnDefinitions>
32+
<Grid Margin="0,0,5,5"
33+
Grid.Row="0"
34+
Grid.Column="0">
35+
<Grid.RowDefinitions>
36+
<RowDefinition Height="25" />
37+
<RowDefinition Height="*" />
38+
<RowDefinition Height="*" />
39+
</Grid.RowDefinitions>
40+
<StackPanel Grid.Row="0"
41+
Orientation="Horizontal">
42+
<Label Content="Replace"
43+
FontSize="14"
44+
Foreground="White"
45+
Margin="0,-2,0,0" />
46+
<TextBox Style="{DynamicResource UniTextBoxStyle}"
47+
Name="ReplaceFrom"
48+
FontSize="14"
49+
Text="{}{}"
50+
VerticalContentAlignment="Center"
51+
Height="20"
52+
Width="25"
53+
Margin="0,0,0,2"
54+
Padding="0,-3,0,0" />
55+
<Label Content="with"
56+
FontSize="14"
57+
Foreground="White"
58+
Margin="0,-2,0,0" />
59+
<TextBox Style="{DynamicResource UniTextBoxStyle}"
60+
Name="ReplaceTo"
61+
FontSize="14"
62+
Text="()"
63+
VerticalContentAlignment="Center"
64+
Height="20"
65+
Width="25"
66+
Margin="0,0,0,2"
67+
Padding="0,-3,0,0" />
68+
<Button Style="{DynamicResource UniBtnStyle}"
69+
Content="🔰"
70+
Height="20"
71+
Width="20"
72+
Margin="20,0,0,2"
73+
ToolTip="It's character-based.&#x0a;By default, it will replace all '{' with '(' and all '}' with ')'."
74+
Command="{Binding MiscTools.ReplaceCharCommand}">
75+
<Button.CommandParameter>
76+
<MultiBinding Converter="{StaticResource MTRCConverter}">
77+
<Binding ElementName="ReplaceFrom"
78+
Path="Text" />
79+
<Binding ElementName="ReplaceTo"
80+
Path="Text" />
81+
<Binding ElementName="TextBefore"
82+
Path="Text" />
83+
<Binding ElementName="TextAfter" />
84+
</MultiBinding>
85+
</Button.CommandParameter>
86+
</Button>
87+
</StackPanel>
88+
<TextBox Name="TextBefore"
89+
Grid.Row="1"
90+
AcceptsReturn="True"
91+
Style="{DynamicResource UniTextBoxStyle}"
92+
Margin="0,0,0,2" />
93+
<TextBox Name="TextAfter"
94+
Grid.Row="2"
95+
AcceptsReturn="True"
96+
Style="{DynamicResource UniTextBoxStyle}"
97+
Margin="0,2,0,0" />
98+
</Grid>
99+
</Grid>
100+
</UserControl>

View/MiscellaneousTools.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Shapes;
13+
14+
namespace SDPromptTool.View
15+
{
16+
/// <summary>
17+
/// MiscellaneousTools.xaml 的交互逻辑
18+
/// </summary>
19+
public partial class MiscellaneousTools : UserControl
20+
{
21+
public MiscellaneousTools()
22+
{
23+
InitializeComponent();
24+
DataContext = MainWindow.MainVM;
25+
}
26+
}
27+
}

View/PresetManager.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
d:DataContext="{d:DesignInstance Type=viewmodel:MainViewModel}"
99
mc:Ignorable="d"
1010
d:DesignHeight="420"
11-
d:DesignWidth="580">
12-
<UserControl.Resources>
11+
d:DesignWidth="580"
12+
KeyDown="UserControl_KeyDown">
13+
<d:UserControl.Resources>
1314
<ResourceDictionary>
1415
<ResourceDictionary.MergedDictionaries>
1516
<ResourceDictionary Source="/GlobalResDictionary.xaml" />
1617
</ResourceDictionary.MergedDictionaries>
1718
</ResourceDictionary>
18-
</UserControl.Resources>
19+
</d:UserControl.Resources>
1920
<Grid>
2021
<Grid.ColumnDefinitions>
2122
<ColumnDefinition Width="2*" />

View/PresetManager.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void PSavedTimer_Tick(object sender, EventArgs e)
118118
PSavedTimer.Stop();
119119
Storyboard storyboard = new Storyboard();
120120
//Slowly make it white again.
121-
storyboard.Children.Add(initColorAnimation(PSaveBtn, Colors.Lime, Colors.White, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 2), "Foreground.(SolidColorBrush.Color)"));
121+
storyboard.Children.Add(InitColorAnimation(PSaveBtn, Colors.Lime, Colors.White, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 2), "Foreground.(SolidColorBrush.Color)"));
122122
storyboard.Begin();
123123
}
124124
private async void NSaveBtn_Click(object sender, RoutedEventArgs e)
@@ -138,7 +138,7 @@ private void NSavedTimer_Tick(object sender, EventArgs e)
138138
{
139139
NSavedTimer.Stop();
140140
Storyboard storyboard = new Storyboard();
141-
storyboard.Children.Add(initColorAnimation(NSaveBtn, Colors.Lime, Colors.White, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 2), "Foreground.(SolidColorBrush.Color)"));
141+
storyboard.Children.Add(InitColorAnimation(NSaveBtn, Colors.Lime, Colors.White, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 2), "Foreground.(SolidColorBrush.Color)"));
142142
storyboard.Begin();
143143
}
144144
#endregion
@@ -188,7 +188,7 @@ private void NListChanged(object sender, SelectionChangedEventArgs e)
188188
{ }
189189
}
190190

191-
private ColorAnimation initColorAnimation(UIElement uIElement, Color from, Color to, TimeSpan beginTime, TimeSpan duration, string propertyPath)
191+
private ColorAnimation InitColorAnimation(UIElement uIElement, Color from, Color to, TimeSpan beginTime, TimeSpan duration, string propertyPath)
192192
{
193193
ColorAnimation colorAnimation = new ColorAnimation { From = from, To = to, BeginTime = beginTime, Duration = duration };
194194
Storyboard.SetTarget(colorAnimation, uIElement);
@@ -207,5 +207,10 @@ private void NList_MouseUp(object sender, MouseButtonEventArgs e)
207207
if (e.ChangedButton == MouseButton.Right)
208208
((ListBox)((Grid)Content).Children[3]).SelectedIndex = -1;
209209
}
210+
211+
private void UserControl_KeyDown(object sender, KeyEventArgs e)
212+
{
213+
if (Keyboard.IsKeyDown(Key.LeftCtrl));
214+
}
210215
}
211216
}

View/PromptSelector.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
xmlns:local="clr-namespace:SDPromptTool.View"
88
xmlns:viewmodel="clr-namespace:SDPromptTool.ViewModel"
99
d:DataContext="{d:DesignInstance Type=viewmodel:MainViewModel}"
10+
xmlns:converter="clr-namespace:SDPromptTool.ViewModel.Converter"
1011
mc:Ignorable="d"
1112
d:DesignHeight="420"
1213
d:DesignWidth="580">
13-
<UserControl.Resources>
14+
<d:UserControl.Resources>
1415
<ResourceDictionary>
1516
<ResourceDictionary.MergedDictionaries>
1617
<ResourceDictionary Source="/GlobalResDictionary.xaml" />
1718
</ResourceDictionary.MergedDictionaries>
1819
</ResourceDictionary>
20+
</d:UserControl.Resources>
21+
<UserControl.Resources>
22+
<converter:ListTextBoxWidthConverter x:Key="LTBWConverter" />
1923
</UserControl.Resources>
2024
<Grid>
2125
<Grid.ColumnDefinitions>
@@ -294,7 +298,7 @@
294298
Content="Search!"
295299
IsEnabled="{Binding PSVM.IsNotSearching, Mode=OneWay}"
296300
IsEnabledChanged="SearchBtn_IsEnabledChanged"
297-
Command="{Binding PSVM.RefreshTagCommand}"/>
301+
Command="{Binding PSVM.RefreshTagCommand}" />
298302
</Grid>
299303
<ListBox DockPanel.Dock="Bottom"
300304
x:Name="TagList"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using SDPromptTool.Model;
2+
using System;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
6+
namespace SDPromptTool.ViewModel.Converter
7+
{
8+
public class MiscToolReplaceCharConverter : IMultiValueConverter
9+
{
10+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => new MiscToolReplaceCharModel
11+
{
12+
ReplaceFrom = (string)values[0],
13+
ReplaceTo = (string)values[1],
14+
TextBefore = (string)values[2],
15+
TextAfter = (System.Windows.Controls.TextBox)values[3]
16+
};
17+
18+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
19+
{
20+
throw new NotImplementedException();
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)