Skip to content

Commit

Permalink
修改jetbrains系软件下无效的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
silentmoooon committed Sep 14, 2017
1 parent 22d2f1d commit 72429a1
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 364 deletions.
4 changes: 2 additions & 2 deletions ClipOne/html/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ function tdEnter(event) {
var index = event.getAttribute('index') / 1;
selectTimeout = setTimeout(function () {
callbackObj.selectIndex(index);
}, 300);
}, 200);
if (clipObj[index].Type == "image") {
timeout = setTimeout(function () {

callbackObj.preview(index);
}, 600);
}, 500);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ClipOne/model/ClipType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ClipOne.model
{
[Flags]
enum ClipType
public enum ClipType
{
qq = 1 << 0,
html = 1 << 1,
Expand Down
1 change: 1 addition & 0 deletions ClipOne/service/CallbackObjectForJs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void DeleteClip(int id)

public void SelectIndex(int id)
{

window.selectedIndex = id;
}

Expand Down
268 changes: 267 additions & 1 deletion ClipOne/service/ClipService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ClipOne.model;
using ClipOne.util;
using ClipOne.view;
using HtmlAgilityPack;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
Expand All @@ -13,6 +15,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Xml;

namespace ClipOne.service
{
Expand Down Expand Up @@ -182,7 +185,270 @@ public static void ClearExpireImage( object lastSaveImg)
}

}
public static void HandClipText(ClipModel clip)
{
for (int i = 0; i < 3; i++)
{
try
{

string textStr = Clipboard.GetText();

if ((MainWindow.supportFormat&ClipType.html)!=0&& Clipboard.ContainsData(DataFormats.Html))
{
try
{
string htmlStr = Clipboard.GetData(DataFormats.Html).ToString();
//文字类型和html类型中"img"出现的次数一样则说明可以以text类型来解析
if (!string.IsNullOrEmpty(htmlStr) && textStr.GetOccurTimes("img") < htmlStr.Split("\r\n".ToCharArray())[16].GetOccurTimes("img"))
{

clip.ClipValue = htmlStr;
//html内容会固定出现在第16行。
clip.DisplayValue = htmlStr.Split("\r\n".ToCharArray())[16];
clip.Type = HTML_TYPE;
clip.Height = 165;
return;
}


}
catch { }
}

clip.ClipValue = textStr;
clip.DisplayValue = textStr.Replace("<", "&lt;").Replace(">", "&gt;");
clip.Type = TEXT_TYPE;

string[] array = clip.DisplayValue.Split('\n');

string tempStr = array[0];
if (array.Length > 0)
{
for (int j = 1; j < array.Length; j++)
{
if (j < 6)
{
tempStr += "<br>" + array[j];
}
else if (j == 6)
{
tempStr += "<br>...";
break;
}
}
}

clip.DisplayValue = tempStr;


if (array.Length > 5)

{
clip.Height = 6 * 22;
}
else if (array.Length > 1)
{
clip.Height = (array.Length) * 22;
}
else
{
clip.Height = 33;
}

return;

}
catch
{


}
}
}

public static void HandleClipFile(ClipModel clip)
{
for (int i = 0; i < 3; i++)
{
try
{
string[] files = (string[])Clipboard.GetData(DataFormats.FileDrop);

clip.Type = FILE_TYPE;
clip.ClipValue = string.Join(",", files);



//组装显示内容,按文件名分行
string displayStr = files.Length + " file";
if (files.Length > 1)
{
displayStr += "s";
}
int j = 0;
foreach (string str in files)
{
if (j < 5)
{
displayStr += "<br>" + Path.GetFileName(str);
}
else if (j == 5)
{
displayStr += "<br>...";
break;
}
j++;
}


clip.DisplayValue = displayStr;

if (files.Length >= 5)

{
clip.Height = 6 * 22;
}
else
{
clip.Height = (files.Length + 1) * 22;
}

break;
}
catch
{


}
}
}

public static void HandleClipHtml(ClipModel clip)
{
for (int i = 0; i < 3; i++)
{
try
{

string htmlStr = Clipboard.GetData(DataFormats.Html).ToString();



clip.ClipValue = htmlStr;
//html内容会固定出现在第16行。
clip.DisplayValue = htmlStr.Split("\r\n".ToCharArray())[16];
clip.Type = HTML_TYPE;
clip.Height = 165;

break;
}
catch
{

}
}
}

public static void HandleClipImage(ClipModel clip)
{
for (int i = 0; i < 3; i++)
{
try
{


BitmapSource bs = Clipboard.GetImage();

string path = SaveImage(bs);

clip.Type = IMAGE_TYPE;
clip.ClipValue = path;
clip.DisplayValue = path;
clip.Height = (int)bs.Height;
if (bs.Height > 165)
{
clip.Height = 165;
}
break;

}
catch
{


}
}
}

public static void HandleClipQQ(ClipModel clip)
{
for (int i = 0; i < 3; i++)
{
try
{

MemoryStream stream = (MemoryStream)Clipboard.GetData(QQ_RICH_TYPE);
byte[] b = stream.ToArray();
string xmlStr = System.Text.Encoding.UTF8.GetString(b);
xmlStr = xmlStr.Substring(0, xmlStr.IndexOf("</QQRichEditFormat>") + "</QQRichEditFormat>".Length);

string htmlStr = Clipboard.GetData(DataFormats.Html).ToString();

//qq的html内容会固定出现在第14行。
htmlStr = htmlStr.Split("\r\n".ToCharArray())[14];
if (htmlStr.Contains("\"file:///\""))
{

XmlDocument document = new XmlDocument();
document.LoadXml(xmlStr);
foreach (XmlNode node in document.DocumentElement.ChildNodes)
{
if (node.Name == "EditElement" && node.Attributes["type"].Value == "5") //图片类型
{
string filePath = node.Attributes["filepath"].Value;
if (!htmlStr.Contains(Path.GetFileName(filePath)))
{
htmlStr = htmlStr.ReplaceFirst("\"file:///\"", "\"file:///" + filePath.Replace("\\", "/") + "\"");
}
}
}

}
clip.Type = QQ_RICH_TYPE;
clip.ClipValue = xmlStr;

if (htmlStr.IndexOf("%") >= 0)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlStr);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//img"))
{
string src = node.GetAttributeValue("src", string.Empty);
if (src.IndexOf("%") >= 0)
{
src = src.Replace("%", "%25");
}
node.SetAttributeValue("src", src);
}
htmlStr = doc.DocumentNode.OuterHtml;
}
clip.DisplayValue = htmlStr;
clip.Height = 165;
break;



}
catch
{


}
}
}




}
}
2 changes: 1 addition & 1 deletion ClipOne/view/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<RowDefinition Name="row0" Height="auto" ></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Name="stack" Orientation="Horizontal" Grid.Row="0" Margin="0,0,0,0" Visibility="Collapsed" >
<StackPanel Name="searchStack" Orientation="Horizontal" Grid.Row="0" Margin="0,0,0,0" Visibility="Collapsed" >
<Label Name="lblSearch" HorizontalAlignment="Left" VerticalContentAlignment="Center" Margin="4,5,0,5" Padding="0,0,0,0" Width="40" Height="25" Content="查找:"></Label>
<TextBox Name="txtSearch" HorizontalAlignment="Left" VerticalContentAlignment="Center" Margin="1,5,0,5" BorderBrush="DarkGray" SelectionBrush="DarkGray" CaretBrush="DarkGray" Width="200" Height="25" TextChanged="TxtSearch_TextChanged" KeyDown="TxtSearch_KeyDown" />

Expand Down
Loading

0 comments on commit 72429a1

Please sign in to comment.