Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 2a64332

Browse files
committed
add words count
1 parent 77f7270 commit 2a64332

File tree

3 files changed

+87
-51
lines changed

3 files changed

+87
-51
lines changed

src/ClipboardR.Panels/PreviewPanel.xaml

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@
66
xmlns:local="clr-namespace:ClipboardR.Panels"
77
mc:Ignorable="d">
88
<UserControl.Resources>
9-
<Image x:Key="CopyIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/copy.png" Height="30" Width="30" />
10-
<Image x:Key="PinIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pin.png" Height="30" Width="30" />
11-
<Image x:Key="PinedIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pined.png" Height="30" Width="30" />
12-
<Image x:Key="DeleteIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/delete.png" Height="30" Width="30" />
9+
<Image x:Key="CopyIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/copy.png" Height="30"
10+
Width="30" />
11+
<Image x:Key="PinIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pin.png" Height="30"
12+
Width="30" />
13+
<Image x:Key="PinedIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pined.png"
14+
Height="30" Width="30" />
15+
<Image x:Key="DeleteIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/delete.png"
16+
Height="30" Width="30" />
1317
<Image x:Key="SaveIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/save.png"></Image>
1418
</UserControl.Resources>
1519
<Grid
16-
MinWidth="300" MinHeight="100"
17-
MaxWidth="340" MaxHeight="500" HorizontalAlignment="Center">
20+
Width="Auto"
21+
Height="Auto"
22+
HorizontalAlignment="Center">
1823
<Grid.RowDefinitions>
1924
<RowDefinition Height="90*" />
2025
<RowDefinition Height="10*" />
2126
</Grid.RowDefinitions>
22-
<Grid.ColumnDefinitions>
23-
<ColumnDefinition Width="50*" />
24-
<ColumnDefinition Width="50*" />
25-
</Grid.ColumnDefinitions>
26-
<Image Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="1" Panel.ZIndex="0"
27-
x:Name="PreImage" Margin="3,3,3,3"
28-
HorizontalAlignment="Center" VerticalAlignment="Center"
29-
Visibility="Hidden"
30-
MaxWidth="320" MaxHeight="400" >
27+
<Image
28+
Grid.Row="0"
29+
Grid.Column="0"
30+
Panel.ZIndex="0"
31+
x:Name="PreImage" Margin="3,3,3,3"
32+
HorizontalAlignment="Center" VerticalAlignment="Center"
33+
Visibility="Hidden"
34+
MaxWidth="320" MaxHeight="400">
3135
<Image.ContextMenu>
3236
<ContextMenu>
3337
<MenuItem Header="Save" Click="ImSaveAs_Click">
@@ -38,46 +42,66 @@
3842
</ContextMenu>
3943
</Image.ContextMenu>
4044
</Image>
41-
<TextBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="1" IsUndoEnabled="False"
42-
x:Name="TxtBoxPre" HorizontalAlignment="Center"
43-
Panel.ZIndex="1" FontSize="14" TextAlignment="Left" Padding="5,5,5,5"
44-
MaxWidth="320" MaxHeight="400" Focusable="True"
45-
VerticalScrollBarVisibility="Auto" Text="&lt;UserControl x:Class=&quot;ClipboardR.Panels.PreviewPanel&quot;&#xD;&#xA; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&#xD;&#xA; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&#xD;&#xA; xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;&#xD;&#xA; xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;&#xD;&#xA; xmlns:local=&quot;clr-namespace:ClipboardR.Panels&quot;&#xD;&#xA; mc:Ignorable=&quot;d&quot;&gt;&#xD;&#xA; &lt;Grid HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot; &#xD;&#xA; Margin=&quot;5, 5, 5, 5&quot;&#xD;&#xA; MinWidth=&quot;410&quot; MinHeight=&quot;620&quot;&gt;&#xD;&#xA; &lt;Grid.RowDefinitions&gt;&#xD;&#xA; &lt;RowDefinition Height=&quot;90*&quot; /&gt;&#xD;&#xA; &lt;RowDefinition Height=&quot;10*&quot; /&gt;&#xD;&#xA; &lt;/Grid.RowDefinitions&gt;&#xD;&#xA; &lt;Grid.ColumnDefinitions&gt;&#xD;&#xA; &lt;ColumnDefinition Width=&quot;50*&quot; /&gt;&#xD;&#xA; &lt;ColumnDefinition Width=&quot;50*&quot; /&gt;&#xD;&#xA; &lt;/Grid.ColumnDefinitions&gt;&#xD;&#xA; &lt;Image x:Name=&quot;PreImage&quot; Margin=&quot;3,3,3,3&quot;&#xD;&#xA; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&#xD;&#xA; Grid.ColumnSpan=&quot;2&quot; Visibility=&quot;Hidden&quot; Panel.ZIndex=&quot;0&quot;&#xD;&#xA; MinWidth=&quot;410&quot; MinHeight=&quot;100&quot; &#xD;&#xA; MaxWidth=&quot;420&quot; MaxHeight=&quot;500&quot; /&gt;&#xD;&#xA; &lt;TextBox Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; Grid.ColumnSpan=&quot;2&quot; Grid.RowSpan=&quot;2&quot; &#xD;&#xA; x:Name=&quot;TxtBoxPre&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&#xD;&#xA; Panel.ZIndex=&quot;1&quot; FontSize=&quot;14&quot; TextAlignment=&quot;Left&quot; Padding=&quot;3,3,3,3&quot; &#xD;&#xA; MinWidth=&quot;410&quot; MinHeight=&quot;100&quot; MaxWidth=&quot;420&quot; MaxHeight=&quot;500&quot; Focusable=&quot;True&quot; &#xD;&#xA; VerticalScrollBarVisibility=&quot;Auto&quot; Text=&quot;finition Width=&amp;quot;50*&amp;quot; /&amp;gt;&amp;#xD;&amp;#xA; &amp;lt;/Grid.ColumnDefinitions&amp;gt;&amp;#xD;&amp;#xA; &amp;lt;Image x:Name=&amp;quot;PreImage&amp;quot; Margin=&amp;quot;3,3,3,3&amp;quot;&amp;#xD;&amp;#xA; HorizontalAlignment=&amp;quot;Center&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot;&amp;#xD;&amp;#xA; Grid.ColumnSpan=&amp;quot;2&amp;quot; Visibility=&amp;quot;Hidden&amp;quot; Panel.ZIndex=&amp;quot;0&amp;quot;&amp;#xD;&amp;#xA; MinWidth=&amp;quot;410&amp;quot; MinHeight=&amp;quot;100&amp;quot; &amp;#xD;&amp;#xA; MaxWidth=&amp;quot;420&amp;quot; MaxHeight=&amp;quot;500&amp;quot; /&amp;gt;&amp;#xD;&amp;#xA; &amp;lt;TextBox Grid.Row=&amp;quot;0&amp;quot; Grid.Column=&amp;quot;0&amp;quot; Grid.ColumnSpan=&amp;quot;2&amp;quot; Grid.RowSpan=&amp;quot;2&amp;quot; &amp;#xD;&amp;#xA; x:Name=&amp;quot;TxtBoxPre&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot;&amp;#xD;&amp;#xA; Panel.ZIndex=&amp;quot;1&amp;quot; FontSize=&amp;quot;14&amp;quot; TextAlignment=&amp;quot;Left&amp;quot; Padding=&amp;quot;3,3,3,3&amp;quot; &amp;#xD;&amp;#xA; MinWidth=&amp;quot;410&amp;quot; MinHeight=&amp;quot;100&amp;quot; MaxWidth=&amp;quot;420&amp;quot; MaxHeight=&amp;quot;500&amp;quot; Focusable=&amp;quot;True&amp;quot; &amp;#xD;&amp;#xA; VerticalScrollBarVisibility=&amp;quot;Auto&amp;quot; Text=&amp;quot;dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd&amp;amp;#xD;&amp;amp;#xA;&amp;quot; GotFocus=&amp;quot;TxtBoxPre_GotFocus&amp;quot; &amp;#xD;&amp;#xA; Margin=&amp;quot;3,3,3,3&amp;quot; HorizontalContentAlignment=&amp;quot;Left&amp;quot; &amp;#xD;&amp;#xA; TextChanged=&amp;quot;TxtBoxPre_TextChanged&amp;quot; IsReadOnly=&amp;quot;True&amp;quot; /&amp;gt;&amp;#xD;&amp;#xA; &amp;lt;Button Grid.Column=&amp;quot;0&amp;quot; Grid.Row=&amp;quot;1&amp;quot; &amp;#xD;&amp;#xA; x:Name=&amp;quot;BtnCopy&amp;quot; Content=&amp;quot;Copy&amp;quot; HorizontalAlignment&quot; GotFocus=&quot;TxtBoxPre_GotFocus&quot; &#xD;&#xA; Margin=&quot;3,3,3,3&quot; HorizontalContentAlignment=&quot;Left&quot; &#xD;&#xA; TextChanged=&quot;TxtBoxPre_TextChanged&quot; IsReadOnly=&quot;True&quot; /&gt;&#xD;&#xA; &lt;Button Grid.Column=&quot;0&quot; Grid.Row=&quot;1&quot; &#xD;&#xA; x:Name=&quot;BtnCopy&quot; Content=&quot;Copy&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&#xD;&#xA; MinWidth=&quot;50&quot; MinHeight=&quot;30&quot; MaxWidth=&quot;50&quot; MaxHeight=&quot;30&quot; &#xD;&#xA; Margin=&quot;5,5,5,5&quot; Click=&quot;BtnCopy_Click&quot; /&gt;&#xD;&#xA; &lt;Button Grid.Column=&quot;1&quot; Grid.Row=&quot;1&quot; &#xD;&#xA; x:Name=&quot;BtnDelete&quot; Content=&quot;Delete&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot; &#xD;&#xA; MinWidth=&quot;50&quot; MinHeight=&quot;30&quot; MaxWidth=&quot;50&quot; MaxHeight=&quot;30&quot; &#xD;&#xA; Margin=&quot;5,5,5,5&quot; Click=&quot;BtnDelete_Click&quot; /&gt;&#xD;&#xA; &lt;/Grid&gt;&#xD;&#xA;&lt;/UserControl&gt;"
46-
GotFocus="TxtBoxPre_GotFocus"
47-
Margin="5,5,5,5" HorizontalContentAlignment="Left"
48-
TextChanged="TxtBoxPre_TextChanged" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" MinWidth="320" UseLayoutRounding="False"/>
49-
<Grid Grid.Row="1" Grid.Column="0"
50-
ColumnSpan="2" MaxWidth="320" MaxHeight="50">
51-
<Grid.RowDefinitions>
52-
<RowDefinition Height="99*" />
53-
</Grid.RowDefinitions>
54-
<Grid.ColumnDefinitions>
55-
<ColumnDefinition Width="30*" />
56-
<ColumnDefinition Width="30*" />
57-
<ColumnDefinition Width="30*" />
58-
</Grid.ColumnDefinitions>
59-
<Button Grid.Row="0" Grid.Column="0"
45+
<TextBox
46+
Grid.Row="0"
47+
Grid.Column="0"
48+
x:Name="TxtBoxPre"
49+
IsUndoEnabled="True"
50+
HorizontalAlignment="Center"
51+
HorizontalContentAlignment="Left"
52+
MinWidth="320"
53+
Panel.ZIndex="1"
54+
Text=""
55+
TextAlignment="Left"
56+
FontSize="14"
57+
IsReadOnly="False"
58+
Margin="5,5,5,5"
59+
Padding="5,5,5,5"
60+
Focusable="True"
61+
VerticalScrollBarVisibility="Auto"
62+
HorizontalScrollBarVisibility="Auto"
63+
GotFocus="TxtBoxPre_GotFocus"
64+
TextChanged="TxtBoxPre_TextChanged"
65+
UseLayoutRounding="False" />
66+
<DockPanel
67+
Grid.Row="1"
68+
Grid.Column="0"
69+
HorizontalAlignment="Stretch">
70+
<TextBlock
71+
x:Name="TextBlockWordCount"
72+
DockPanel.Dock="Left"
73+
HorizontalAlignment="Center"
74+
VerticalAlignment="Center">
75+
</TextBlock>
76+
<StackPanel
77+
Orientation="Horizontal"
78+
HorizontalAlignment="Right"
79+
VerticalAlignment="Center"
80+
DockPanel.Dock="Right">
81+
<Button
6082
x:Name="BtnCopy" ToolTip="Copy to clipboard"
6183
HorizontalAlignment="Center" VerticalAlignment="Bottom"
6284
Width="33" Height="33" Padding="0, 0, 0, 0"
63-
Margin="5,5,5,5" Click="BtnCopy_Click" >
64-
<DynamicResource ResourceKey="CopyIcon"/>
65-
</Button>
66-
<Button Grid.Row="0" Grid.Column="1"
85+
Margin="5,5,5,5" Click="BtnCopy_Click">
86+
<DynamicResource ResourceKey="CopyIcon" />
87+
</Button>
88+
<Button
6789
x:Name="BtnPin" ToolTip="Pin on top"
6890
HorizontalAlignment="Center" VerticalAlignment="Bottom"
6991
Width="33" Height="33" Padding="0, 0, 0, 0"
70-
Margin="5,5,5,5" Click="BtnPin_Click" >
71-
<DynamicResource ResourceKey="PinIcon"/>
72-
</Button>
73-
<Button Grid.Row="0" Grid.Column="2"
74-
x:Name="BtnDelete" ToolTip="Delete this record"
75-
HorizontalAlignment="Center" VerticalAlignment="Bottom"
76-
Width="33" Height="33" Padding="0, 0, 0, 0"
77-
Margin="5,5,5,5" Click="BtnDelete_Click" >
78-
<DynamicResource ResourceKey="DeleteIcon"/>
79-
</Button>
80-
</Grid>
81-
92+
Margin="5,5,5,5" Click="BtnPin_Click">
93+
<DynamicResource ResourceKey="PinIcon" />
94+
</Button>
95+
<Button
96+
x:Name="BtnDelete" ToolTip="Delete this record"
97+
HorizontalAlignment="Center" VerticalAlignment="Bottom"
98+
Width="33" Height="33" Padding="0, 0, 0, 0"
99+
Margin="5,5,5,5" Click="BtnDelete_Click">
100+
<DynamicResource ResourceKey="DeleteIcon" />
101+
</Button>
102+
</StackPanel>
103+
104+
</DockPanel>
105+
82106
</Grid>
83107
</UserControl>

src/ClipboardR.Panels/PreviewPanel.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public partial class PreviewPanel : UserControl
2020
private Action<ClipboardData> CopyRecord { get; set; }
2121
private Action<ClipboardData> PinRecord { get; set; }
2222
private int OldScore { get; set; }
23+
private bool Ready { get; set; } = false;
24+
private const string WordsCountPrefix = "Words Count: ";
2325

2426
public PreviewPanel(
2527
ClipboardData clipboardData,
@@ -41,6 +43,7 @@ Action<ClipboardData> pinAction
4143

4244
SetContent();
4345
SetBtnIcon();
46+
Ready = true;
4447
}
4548

4649
public void SetContent()
@@ -72,6 +75,7 @@ public void SetText(string s = "")
7275
{
7376
TxtBoxPre.Clear();
7477
TxtBoxPre.Text = string.IsNullOrWhiteSpace(s) ? _clipboardData.Text : s;
78+
TextBlockWordCount.Text = WordsCountPrefix + TxtBoxPre.Text.Length;
7579
}
7680

7781
public void SetImage()
@@ -84,6 +88,9 @@ public void SetImage()
8488

8589
private void BtnCopy_Click(object sender, System.Windows.RoutedEventArgs e)
8690
{
91+
// if textbox is visible, it means the record is a text ot files, change the data to text
92+
if (TxtBoxPre.IsVisible)
93+
_clipboardData.Data = TxtBoxPre.Text;
8794
CopyRecord?.Invoke(_clipboardData);
8895
}
8996

@@ -103,7 +110,11 @@ private void TxtBoxPre_GotFocus(object sender, System.Windows.RoutedEventArgs e)
103110
tb.Dispatcher.BeginInvoke(new Action(() => tb.SelectAll()));
104111
}
105112

106-
private void TxtBoxPre_TextChanged(object sender, TextChangedEventArgs e) { }
113+
private void TxtBoxPre_TextChanged(object sender, TextChangedEventArgs e)
114+
{
115+
if (Ready)
116+
TextBlockWordCount.Text = WordsCountPrefix + TxtBoxPre.Text.Length;
117+
}
107118

108119
private void BtnPin_Click(object sender, RoutedEventArgs e)
109120
{

src/ClipboardR/Main.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ private Result ClipDataToResult(ClipboardData o)
214214
VirtualKeyCode.CONTROL,
215215
VirtualKeyCode.VK_V
216216
);
217+
_context.API.ChangeQuery(_context.CurrentPluginMetadata.ActionKeyword, true);
217218
return true;
218219
},
219220
};

0 commit comments

Comments
 (0)