Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TN8001 committed Jan 20, 2018
1 parent 1acf0f4 commit f3b4883
Show file tree
Hide file tree
Showing 32 changed files with 536 additions and 767 deletions.
3 changes: 1 addition & 2 deletions ClipboardIndicator.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.13
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClipboardIndicator", "ClipboardIndicator\ClipboardIndicator.csproj", "{869CFB0B-8104-417E-8F15-120F777F2F1B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{236F0040-FB7C-4A00-AC88-A1841C153BDF}"
ProjectSection(SolutionItems) = preProject
AppImage.png = AppImage.png
README.md = README.md
EndProjectSection
EndProject
Expand Down
86 changes: 23 additions & 63 deletions ClipboardIndicator/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
x:Class="ClipboardIndicator.About"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding AssemblyName, Mode=OneWay, StringFormat=\{0\} のバージョン情報}"
xmlns:utility="clr-namespace:ClipboardIndicator.Utility"
Title="{Binding Source={x:Static utility:ProductInfo.Name}, StringFormat=\{0\} のバージョン情報}"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
<DockPanel>
Expand All @@ -18,76 +19,35 @@
<TextBlock
FontSize="24"
FontWeight="Bold"
Text="{Binding AssemblyName}" />
Text="{x:Static utility:ProductInfo.Name}" />
</StackPanel>
</StackPanel>
<Button
Width="80"
Margin="0,0,10,10"
Margin="10"
HorizontalAlignment="Right"
Click="Button_Click"
Content="OK"
DockPanel.Dock="Bottom"
IsDefault="True" />
<Grid Grid.Column="1" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Margin="5,2" Text="名前:" />
<TextBlock
x:Name="xmlname"
Grid.Column="1"
Margin="5,2"
Text="{Binding AssemblyName}"
TextWrapping="Wrap" />
<TextBlock
Grid.Row="1"
Margin="5,2"
Text="作者:" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Margin="5,2"
Text="{Binding AssemblyCopyright}"
TextWrapping="Wrap" />
<TextBlock
Grid.Row="2"
Margin="5,2"
Text="バージョン:" />
<TextBlock
Grid.Row="2"
Grid.Column="1"
Margin="5,2"
Text="{Binding AssemblyVersion}"
TextWrapping="Wrap" />
<TextBlock
Grid.Row="3"
Margin="5,2,5,0"
Text="説明:" />
<TextBlock
Grid.Row="4"
Grid.ColumnSpan="2"
Margin="5,2,5,2"
TextWrapping="Wrap">
<Run Text="クリップボードに文字が入っているかを確認できます。" />
<LineBreak />
<Run Text="使い方の詳しい情報は" />
<Hyperlink
NavigateUri="https://github.com/TN8001/ClipboardIndicator/"
RequestNavigate="Hyperlink_RequestNavigate"
ToolTip="{Binding NavigateUri, RelativeSource={RelativeSource Self}}">
<Run Text="こちら" />
</Hyperlink>
<Run Text="をご覧ください。" />
</TextBlock>
</Grid>
<StackPanel Margin="5" Grid.IsSharedSizeScope="True">
<!--<HeaderedContentControl Content="{x:Static utility:ProductInfo.Name}" Header="名前:" />-->
<HeaderedContentControl Content="{x:Static utility:ProductInfo.Copyright}" Header="作者:" />
<HeaderedContentControl Content="{x:Static utility:ProductInfo.Version}" Header="バージョン:" />
<HeaderedContentControl Padding="5,2" Header="説明:">
<TextBlock TextWrapping="Wrap">
<Run Text="クリップボードに文字が入っているかを確認できます。" />
<LineBreak />
<Run Text="使い方の詳しい情報は" />
<Hyperlink
NavigateUri="https://github.com/TN8001/ClipboardIndicator/"
RequestNavigate="Hyperlink_RequestNavigate"
ToolTip="{Binding NavigateUri, RelativeSource={RelativeSource Self}}">
<Run Text="こちら" />
</Hyperlink>
<Run Text="をご覧ください。" />
</TextBlock>
</HeaderedContentControl>
</StackPanel>
</DockPanel>
</Window>
15 changes: 2 additions & 13 deletions ClipboardIndicator/About.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Diagnostics;
using System.Windows;
using System.Windows.Navigation;

namespace ClipboardIndicator
{
public partial class About : Window
{
private static Version v = Assembly.GetExecutingAssembly().GetName().Version;
public string AssemblyVersion { get; } = $"{v.Major}.{v.Minor}.{v.Build}";
public string AssemblyName { get; } = Assembly.GetEntryAssembly().GetName().Name;
public string AssemblyCopyright { get; } = ((AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCopyrightAttribute))).Copyright;

public About()
{
InitializeComponent();
DataContext = this;
}
public About() => InitializeComponent();

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Expand Down
39 changes: 31 additions & 8 deletions ClipboardIndicator/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
<Application x:Class="ClipboardViewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClipboardViewer"
StartupUri="MainWindow.xaml" ShutdownMode="OnMainWindowClose">
<Application.Resources>

</Application.Resources>
<Application
x:Class="ClipboardViewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnMainWindowClose"
StartupUri="MainWindow.xaml">
<Application.Resources>

<Style TargetType="HeaderedContentControl">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Padding" Value="5,2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HeaderedContentControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="a" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Text="{TemplateBinding Header}" />
<ContentPresenter
Grid.Column="1"
Margin="{TemplateBinding Padding}"
VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
36 changes: 14 additions & 22 deletions ClipboardIndicator/ClipboardIndicator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
<OutputType>WinExe</OutputType>
<RootNamespace>ClipboardIndicator</RootNamespace>
<AssemblyName>ClipboardIndicator</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -23,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,6 +34,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\App.ico</ApplicationIcon>
Expand Down Expand Up @@ -67,16 +70,23 @@
<Compile Include="About.xaml.cs">
<DependentUpon>About.xaml</DependentUpon>
</Compile>
<Compile Include="StartupPopup.cs" />
<Compile Include="Extensions\DependencyObjectExtensions.cs" />
<Compile Include="Models\ColorModel.cs" />
<Compile Include="Extensions\ConvertExtensions.cs" />
<Compile Include="Models\FontModel.cs" />
<Compile Include="Models\WindowModel.cs" />
<Compile Include="Controls\StartupPopup.cs" />
<Compile Include="Utility\ProductInfo.cs" />
<Compile Include="Utility\SerializeHelper.cs" />
<Compile Include="Utility\BoolInvertConverter.cs" />
<Compile Include="ClipboardService.cs" />
<Compile Include="DraggableButton.cs" />
<Compile Include="Controls\DraggableButton.cs" />
<Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SettingsModel.cs" />
<Compile Include="Models\SettingsModel.cs" />
<Compile Include="ViewModel.cs" />
<Compile Include="Extensions\WindowExtensions.cs" />
<Page Include="About.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -104,25 +114,7 @@
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>PublicSettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Pointing.png" />
Expand Down
50 changes: 20 additions & 30 deletions ClipboardIndicator/ClipboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

namespace ClipboardIndicator
{
public delegate void ClipboardCopiedEventHandler(string text);

public class ClipboardService
{
private const int WM_CLIPBOARDUPDATE = 0x031D;

[DllImport("user32.dll", SetLastError = true)]
private extern static void AddClipboardFormatListener(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)]
private extern static void RemoveClipboardFormatListener(IntPtr hwnd);

private const int WM_CLIPBOARDUPDATE = 0x031D;

public delegate void ClipboardCopiedEventHandler(string text);
public event ClipboardCopiedEventHandler ClipboardCopied;

private Window actualWindow;
Expand All @@ -34,17 +36,16 @@ public ClipboardService(Window window)
actualWindow.Closing += (s, e) => Unhook();
}

public async Task ClearAsync()
public void Clear()
{
//CLIPBRD_E_CANT_OPEN対策にリトライ処理
for(var i = 0; i < 5; i++)
for(var i = 0; i < 5; i++) //CLIPBRD_E_CANT_OPEN対策にリトライ処理
{
try
{
Clipboard.Clear();
return;
}
catch { }
await Task.Delay(100);
catch { Task.Delay(100).Wait(); }
}
}

Expand All @@ -54,7 +55,7 @@ private void Hook()
HwndSource.FromHwnd(handle).AddHook(WndProc);
AddClipboardFormatListener(handle);

var _ = OnClipboardCopied(); //#pragma warning disable CS4014
OnClipboardCopied();
}
private void Unhook()
{
Expand All @@ -65,50 +66,39 @@ private void Unhook()
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if(msg == WM_CLIPBOARDUPDATE)
{
var _ = OnClipboardCopied(); //#pragma warning disable CS4014
}
OnClipboardCopied();

return IntPtr.Zero;
}
private async Task OnClipboardCopied()
private void OnClipboardCopied()
{
var text = await GetTextAsync();
var text = GetText();
Debug.WriteLine($"ClipboardCopied:{text}");
ClipboardCopied(text);
}
private async Task<string> GetTextAsync()
private string GetText()
{
//CLIPBRD_E_CANT_OPEN対策にリトライ処理
for(var i = 0; i < 5; i++)
for(var i = 0; i < 5; i++) //CLIPBRD_E_CANT_OPEN対策にリトライ処理
{
try
{
return GetClipboardTextFirstLine();
}
catch { }
await Task.Delay(100);
catch { Task.Delay(100).Wait(); }
}

return "<!CANT_OPEN>";
}

private static string GetClipboardTextFirstLine()
private string GetClipboardTextFirstLine()
{
string text;
if(Clipboard.Contains​Text())
text = Clipboard.GetText()
return Clipboard.GetText()
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
.First();
else if(!Clipboard.GetDataObject().GetFormats().Any())
return "<Empty>";
else
{
if(!Clipboard.GetDataObject().GetFormats().Any())
text = "<Empty>";
else
text = "<Not Text Data>";
}

return text;
return "<Not Text Data>";
}
}
}
Expand Down
Loading

0 comments on commit f3b4883

Please sign in to comment.