From 6b318f84aba42c3d079361a2f143f879dc02a1ad Mon Sep 17 00:00:00 2001 From: silentmoon Date: Tue, 20 Nov 2018 14:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=BA=E9=99=B7bug:=20=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=90=AF=E5=8A=A8=E5=90=8E=E7=B2=98=E8=B4=B4=E4=B8=8D?= =?UTF-8?q?=E4=B8=8A=20=20=E9=9A=94=E5=87=A0=E5=88=86=E9=92=9F=E4=B8=8D?= =?UTF-8?q?=E7=94=A8=E5=8F=88=E7=B2=98=E8=B4=B4=E4=B8=8D=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClipOne/ClipOne.csproj | 2 +- ClipOne/html/js/main.js | 593 ++++++++++++++++---------------- ClipOne/packages.config | 2 +- ClipOne/service/ClipService.cs | 2 +- ClipOne/view/MainWindow.xaml | 2 +- ClipOne/view/MainWindow.xaml.cs | 45 +-- 6 files changed, 318 insertions(+), 328 deletions(-) diff --git a/ClipOne/ClipOne.csproj b/ClipOne/ClipOne.csproj index 88da7c7..ac91978 100644 --- a/ClipOne/ClipOne.csproj +++ b/ClipOne/ClipOne.csproj @@ -104,7 +104,7 @@ ..\packages\HtmlAgilityPack.1.8.8\lib\Net45\HtmlAgilityPack.dll - ..\packages\Microsoft.Toolkit.Win32.UI.Controls.4.0.1\lib\net462\Microsoft.Toolkit.Win32.UI.Controls.dll + ..\packages\Microsoft.Toolkit.Win32.UI.Controls.4.0.3\lib\net462\Microsoft.Toolkit.Win32.UI.Controls.dll ..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll diff --git a/ClipOne/html/js/main.js b/ClipOne/html/js/main.js index aae4695..c4af879 100644 --- a/ClipOne/html/js/main.js +++ b/ClipOne/html/js/main.js @@ -9,52 +9,53 @@ var lastSelectedIndex = -1; var storeInterval; var clearImageInterval; var maxRecords = 100; -var searchValue = ''; - +var searchValue = ""; + + //屏蔽鼠标选择操作 -document.onselectstart = function () { - event.returnValue = false; -} -//屏蔽右键菜单 -document.oncontextmenu = function (e) { - e.preventDefault(); +document.onselectstart = function() { + event.returnValue = false; + } + //屏蔽右键菜单 +document.oncontextmenu = function(e) { + e.preventDefault(); }; -$(document).ready(function () { +$(document).ready(function() { $(".content").niceScroll(".table_main", { cursorborder: "", cursoropacitymin: 0, cursoropacitymax: 0.7, cursorwidth: "2px", cursorcolor: "#808080" }); - + //删除操作 - $("#delete").on("click", function () { - $("#tr" + deleteId).parent().addClass("tr_hover"); - clipObj.splice(deleteId, 1); - - $("#rightMenu").css("display", "none"); - displayData(); + $("#delete").on("click", function() { + $("#tr" + deleteId).parent().addClass("tr_hover"); + clipObj.splice(deleteId, 1); + + $("#rightMenu").css("display", "none"); + displayData(); }); - + //查找 - $("#searchInput").on("input", function (event) { - - var value = $("#searchInput").val().toLowerCase(); - searchValue = value; - displayData(); + $("#searchInput").on("input", function(event) { + + var value = $("#searchInput").val().toLowerCase(); + searchValue = value; + displayData(); }); - - - $("body").on("keydown", keyDown); - $("body").on("keyup", keyUp); - var str = window.localStorage.getItem("data"); - if (str != null) { - clipObj = JSON.parse(str); - } + + $("body").on("keydown", keyDown); + $("body").on("keyup", keyUp); + + var str = window.localStorage.getItem("data"); + if (str != null) { + clipObj = JSON.parse(str); + } maxRecords = window.localStorage.getItem("recordCount"); if (maxRecords == null) { @@ -62,138 +63,131 @@ $(document).ready(function () { } storeInterval = setInterval(saveData, 120000); - clearImageInterval=setInterval(clearImage,2*3600*1000); + clearImageInterval = setInterval(clearImage, 2 * 3600 * 1000); displayData(); }); -function clearImage(){ - var images=[]; - for(var i=0;i 0) { - showSearch(); - } else { - hideSearch(); - - } - return; - } - - else if (!searchMode) { - - if (event.shiftKey) { //多条操作 - isShiftPressed = true; - var key = -1; - if (event.keyCode >= 49 && event.keyCode <= 57) { //数字键 - key = event.keyCode - 49; - } else if (event.keyCode >= 65 && event.keyCode <= 90) { //字母键 - key = event.keyCode - 56; - } else { - return; - } - - if (lastSelectedIndex == -1) { - lastSelectedIndex = key; - } else { - pasteValueByRange(lastSelectedIndex, key); - } - } - else if (event.keyCode >= 49 && event.keyCode <= 57) { //数字键 - pasteValue(event.keyCode - 49); - } else if (event.keyCode >= 65 && event.keyCode <= 90) { //字母键 - pasteValue(event.keyCode - 56); - } else if (event.keyCode == 32) { //空格直接粘贴第0项 - event.preventDefault(); - pasteValue(0); - } - - - } + } else if (event.ctrlKey && event.keyCode == 70) { //ctrl+f + if (!searchMode && clipObj.length > 0) { + showSearch(); + } else { + hideSearch(); + + } + return; + } else if (!searchMode) { + + if (event.shiftKey) { //多条操作 + isShiftPressed = true; + var key = -1; + if (event.keyCode >= 49 && event.keyCode <= 57) { //数字键 + key = event.keyCode - 49; + } else if (event.keyCode >= 65 && event.keyCode <= 90) { //字母键 + key = event.keyCode - 56; + } else { + return; + } + + if (lastSelectedIndex == -1) { + lastSelectedIndex = key; + } else { + pasteValueByRange(lastSelectedIndex, key); + } + } else if (event.keyCode >= 49 && event.keyCode <= 57) { //数字键 + pasteValue(event.keyCode - 49); + + } else if (event.keyCode >= 65 && event.keyCode <= 90) { //字母键 + + pasteValue(event.keyCode - 56); + + } else if (event.keyCode == 32) { //空格直接粘贴第0项 + event.preventDefault(); + pasteValue(0); + } + + + } } function keyUp(event) { - if (event.key == "Shift") { - lastSelectedIndex = -1; - isShiftPressed = false; - $(".tr_hover").removeClass("tr_hover"); - } + if (event.key == "Shift") { + lastSelectedIndex = -1; + isShiftPressed = false; + $(".tr_hover").removeClass("tr_hover"); + } } //显示搜索框 function showSearch() { - $("#searchDiv").css("display", "block"); + $("#searchDiv").css("display", "block"); $("#searchInput")[0].focus(); - - searchMode = true; + + searchMode = true; } //隐藏搜索框 function hideSearch() { - $("#searchDiv").css("display", "none"); - searchMode=false; + $("#searchDiv").css("display", "none"); + searchMode = false; if ($("#searchInput").val() != "") { - window.external.notify("testhide:" ); - $("#searchInput").val(""); - searchValue = ""; - displayData(); - } - - + $("#searchInput").val(""); + searchValue = ""; + displayData(); + } + + } //选中时高亮 function trSelect(event) { - $("#rightMenu").css("display", "none"); - var index = event.getAttribute('index') / 1; - selectIndex = index; - - if (!isShiftPressed) { - selectItem(index); - } - //if (clipObj[index].Type == "image") { - // previewTimeout = setTimeout(function () { - // preview(clipObj[index].ClipValue); - // }, 500); - //} + $("#rightMenu").css("display", "none"); + var index = event.getAttribute('index') / 1; + selectIndex = index; + + if (!isShiftPressed) { + $(".tr_hover").removeClass("tr_hover"); + $("#tr" + index).addClass("tr_hover"); + } + } //反选 function trUnselect(event) { - if (previewTimeout) { - clearTimeout(previewTimeout); - previewTimeout = undefined; - hidePreview(); - } + if (previewTimeout) { + clearTimeout(previewTimeout); + previewTimeout = undefined; + hidePreview(); + } } @@ -201,185 +195,170 @@ function trUnselect(event) { //显示右键菜单 function showMenu(e) { - document.getElementById("rightMenu").style.left = e.pageX + 'px'; - document.getElementById("rightMenu").style.top = e.pageY + 'px'; - document.getElementById("rightMenu").style.display = "block"; + document.getElementById("rightMenu").style.left = e.pageX + 'px'; + document.getElementById("rightMenu").style.top = e.pageY + 'px'; + document.getElementById("rightMenu").style.display = "block"; } //隐藏右键菜单 function hideMenu() { - document.getElementById("rightMenu").style.display = "none"; + document.getElementById("rightMenu").style.display = "none"; } //滚动到顶部 function scrollTop() { - $(".content").scrollTop(0); + $(".content").scrollTop(0); } + function scrollDown() { - var div = $(".content"); - var tr = $("#tr" + selectIndex); - if (tr.offset().top + tr.height() > div.height()) { - div.scrollTop(tr.height() + div.scrollTop()); - } + var div = $(".content"); + var tr = $("#tr" + selectIndex); + if (tr.offset().top + tr.height() > div.height()) { + div.scrollTop(tr.height() + div.scrollTop()); + } } + function scrollUp() { - var div = $(".content"); - var tr = $("#tr" + selectIndex); - if (tr.offset().top < 0) { - div.scrollTop(div.scrollTop() - tr.height()); - } + var div = $(".content"); + var tr = $("#tr" + selectIndex); + if (tr.offset().top < 0) { + div.scrollTop(div.scrollTop() - tr.height()); + } } //数字转换成字母 function num2key(num) { - return String.fromCharCode(55 + num); + return String.fromCharCode(55 + num); } -//选中某项 -function selectItem(index) { - - $(".tr_hover").removeClass("tr_hover"); - $("#tr" + index).addClass("tr_hover"); -} //显示记录 function displayData() { - var tbody = ""; + var tbody = ""; var matchCount = -1; - + for (var i = 0; i < clipObj.length; i++) { if (clipObj[i] == null) { clipObj.splice(i, 1); i--; } - var trs = ""; - var num = ""; - - if (searchValue == "" || clipObj[i].Type == searchValue || clipObj[i].ClipValue.toLowerCase().indexOf(searchValue) >= 0) { - matchCount++; - if (matchCount < 9) { - num = "" + (matchCount + 1) + ""; - } else if (matchCount < 35) { - num = "" + num2key((matchCount + 1)) + ""; - } else { - num = "" + (matchCount + 1); - } - if (clipObj[i].Type == "image") { - - trs = " " + num + " "; - } else { - trs = " " + clipObj[i].DisplayValue + " " + num + " "; - - } - } - tbody += trs; - } - - $(".myTable").html(tbody); - if (matchCount == -1) { - tbody = " 无记录 "; - $(".myTable").html(tbody); - - } else { - if (searchValue != "") { - selectIndex = 0; - - } else { - selectIndex = 1; - } - - $("#tr" + selectIndex).addClass("tr_hover"); - - $("#tr" + selectIndex).one("mouseout", function () { - $("#tr" + selectIndex).removeClass("tr_hover"); - - }); + var trs = ""; + var num = ""; + + if (searchValue == "" || clipObj[i].Type == searchValue || clipObj[i].ClipValue.toLowerCase().indexOf(searchValue) >= 0) { + matchCount++; + if (matchCount < 9) { + num = "" + (matchCount + 1) + ""; + } else if (matchCount < 35) { + num = "" + num2key((matchCount + 1)) + ""; + } else { + num = "" + (matchCount + 1); + } + if (clipObj[i].Type == "image") { + + trs = " " + num + " "; + } else { + trs = " " + clipObj[i].DisplayValue + " " + num + " "; + + } + } + tbody += trs; + } + + $(".myTable").html(tbody); + if (matchCount == -1) { + tbody = " 无记录 "; + $(".myTable").html(tbody); + } - - $(".content").getNiceScroll().resize(); + + $(".content").getNiceScroll().resize(); changeWindowHeight($("body").height()); } //粘贴选择项 function mouseup(e) { - var event = window.event; - if (event.button == 0) { - if (isShiftPressed) { //多条 - if (lastSelectedIndex == -1) { - $("#tr1").removeClass("tr_hover"); - $("#" + e.id).addClass("tr_hover"); - lastSelectedIndex = e.getAttribute('index') / 1; - } else { - pasteValueByRange(lastSelectedIndex, e.getAttribute('index') / 1); - } - } else { //单条 - $("#tr1").removeClass("tr_hover"); - $("#" + e.id).addClass("tr_hover"); - pasteValue(e.getAttribute('index') / 1); - } - } else if (event.button == 2) { //弹出右键菜单 - if (isShiftPressed) { - pasteValueByRange(0, e.getAttribute('index') / 1); - } else { - deleteNode = e; - deleteId = e.getAttribute('index'); - showMenu(event); - } - } + var event = window.event; + if (event.button == 0) { + if (isShiftPressed) { //多条 + if (lastSelectedIndex == -1) { + $("#tr1").removeClass("tr_hover"); + $("#" + e.id).addClass("tr_hover"); + lastSelectedIndex = e.getAttribute('index') / 1; + } else { + pasteValueByRange(lastSelectedIndex, e.getAttribute('index') / 1); + } + } else { //单条 + + + $("#tr1").removeClass("tr_hover"); + $("#" + e.id).addClass("tr_hover"); + + pasteValue(e.getAttribute('index') / 1); + } + } else if (event.button == 2) { //弹出右键菜单 + if (isShiftPressed) { + pasteValueByRange(0, e.getAttribute('index') / 1); + } else { + deleteNode = e; + deleteId = e.getAttribute('index'); + showMenu(event); + } + } } - - - + + + //设置保存最大记录数 function setMaxRecords(records) { - maxRecords = records; - window.localStorage.setItem("recordCount", maxRecords); + maxRecords = records; + window.localStorage.setItem("recordCount", maxRecords); } //增加条目 function addData(data) { - - data = decodeURIComponent(data.replace(/\+/g, '%20')); + + data = decodeURIComponent(data.replace(/\+/g, '%20')); var obj = JSON.parse(data); - + if (obj == null) { return; } - - if (obj.Type == "text") { - for (var i = 0; i < clipObj.length; i++) { - if (clipObj[i].ClipValue == obj.ClipValue) { - clipObj.splice(i, 1); - break; - } - } - } - + + if (obj.Type == "text") { + for (var i = 0; i < clipObj.length; i++) { + if (clipObj[i].ClipValue == obj.ClipValue) { + clipObj.splice(i, 1); + break; + } + } + } + clipObj.splice(0, 0, obj); - - if (clipObj.length > maxRecords) { - setTimeout(function () { - - var clip = clipObj.splice(maxRecords, 1)[0]; - if (clip.Type == "image") { - deleteImage(clip.ClipValue); - } - - }, 0); - } + + if (clipObj.length > maxRecords) { + setTimeout(function() { + + var clip = clipObj.splice(maxRecords, 1)[0]; + if (clip.Type == "image") { + deleteImage(clip.ClipValue); + } + + }, 0); + } displayData(); - - + + } - + //显示记录 function showRecord() { @@ -393,30 +372,30 @@ function showRecord() { if ($("#searchInput").val() != "") { $("#searchInput").val(""); searchValue = ""; - - } - // displayData(); - if (clipObj.length != 0) { - - if (searchValue != "") { - selectIndex = 0; - - } else { - selectIndex = 1; - } - $(".tr_hover").removeClass("tr_hover"); - $("#tr" + selectIndex).addClass("tr_hover"); - - $("#tr" + selectIndex).one("mouseout", function () { - $("#tr" + selectIndex).removeClass("tr_hover"); - - }); - } - $("#searchText").show(); + + } + + if (clipObj.length != 0) { + + if (searchValue != "") { + selectIndex = 0; + + } else { + selectIndex = 1; + } + $(".tr_hover").removeClass("tr_hover"); + $("#tr" + selectIndex).addClass("tr_hover"); + + //$("#tr" + selectIndex).one("mouseout", function () { + // $("#tr" + selectIndex).removeClass("tr_hover"); + + //}); + } + $("#searchText").show(); $("#searchText")[0].focus(); $("#searchText").hide(); - - + + } @@ -425,69 +404,75 @@ function showRecord() { //粘贴单条 function pasteValue(index) { - obj = clipObj.splice(index, 1)[0]; - clipObj.splice(0, 0, obj); - + + //$("body").off("keydown"); + + obj = clipObj.splice(index, 1)[0]; window.external.notify("PasteValue:" + encodeURIComponent(JSON.stringify(obj))); - - displayData(); + clipObj.splice(0, 0, obj); + + //setTimeout(function() { $("body").on("keydown", keyDown); }, 1000); + + displayData(); + + } //粘贴多条 function pasteValueByRange(startIndex, endIndex) { - var clipList = []; - if (endIndex > startIndex) { - for (var i = startIndex; i <= endIndex; i++) { - var result = clipObj.splice(i, 1)[0]; - clipObj.splice(0, 0, result); - clipList.push(result); - } - } else if (endIndex < startIndex) { - for (var i = startIndex; i >= endIndex; i--) { - var result = clipObj.splice(i, 1)[0]; - clipObj.splice(0, 0, result); - clipList.push(result); - } - } else { - pasteValue(startIndex); - return; + var clipList = []; + if (endIndex > startIndex) { + for (var i = startIndex; i <= endIndex; i++) { + var result = clipObj.splice(i, 1)[0]; + clipObj.splice(0, 0, result); + clipList.push(result); + } + } else if (endIndex < startIndex) { + for (var i = startIndex; i >= endIndex; i--) { + var result = clipObj.splice(i, 1)[0]; + clipObj.splice(0, 0, result); + clipList.push(result); + } + } else { + pasteValue(startIndex); + return; } - - window.external.notify("PasteValueList:" + encodeURIComponent(JSON.stringify(clipList))); - + // $("body").off("keydown"); + window.external.notify("PasteValueList:" + encodeURIComponent(JSON.stringify(clipList))); + //setTimeout(function() { $("body").on("keydown", keyDown); }, 1000); displayData(); } //删除 function deleteImage(path) { - window.external.notify("DeleteImage:" + path); + window.external.notify("DeleteImage:" + path); } //调整高度 function changeWindowHeight(height) { - window.external.notify("ChangeWindowHeight:" + height); + window.external.notify("ChangeWindowHeight:" + height); } - -function hideUi(){ - //scrollTop(); + +function hideUi() { + //scrollTop(); } //获取所有记录,用来持久化 function getAllClip() { - return encodeURIComponent(JSON.stringify(clipObj)); + return encodeURIComponent(JSON.stringify(clipObj)); } function saveData() { - window.localStorage.setItem("data", JSON.stringify(clipObj)); + window.localStorage.setItem("data", JSON.stringify(clipObj)); } + function saveRecordCount() { - window.localStorage.setItem("recordCount", maxRecords); -} -function clear() { - clipObj = []; - window.localStorage.clear(); - displayData(); + window.localStorage.setItem("recordCount", maxRecords); } - +function clear() { + clipObj = []; + window.localStorage.clear(); + displayData(); +} \ No newline at end of file diff --git a/ClipOne/packages.config b/ClipOne/packages.config index 3082187..2f8be9f 100644 --- a/ClipOne/packages.config +++ b/ClipOne/packages.config @@ -1,7 +1,7 @@  - + diff --git a/ClipOne/service/ClipService.cs b/ClipOne/service/ClipService.cs index 9f9e824..b4722b6 100644 --- a/ClipOne/service/ClipService.cs +++ b/ClipOne/service/ClipService.cs @@ -160,7 +160,7 @@ public static void SetValueToClipboard(ClipModel result) } catch (Exception e){ - //Console.WriteLine(e.StackTrace); + File.AppendAllText("C:/Users/xiecan/test.txt", e.Message + "\n"); } } } diff --git a/ClipOne/view/MainWindow.xaml b/ClipOne/view/MainWindow.xaml index 6fb3e2c..87405d6 100644 --- a/ClipOne/view/MainWindow.xaml +++ b/ClipOne/view/MainWindow.xaml @@ -9,7 +9,7 @@ xmlns:local="clr-namespace:ClipOne.view" xmlns:WPF="clr-namespace:Microsoft.Toolkit.Win32.UI.Controls.WPF;assembly=Microsoft.Toolkit.Win32.UI.Controls" mc:Ignorable="d" - Title="MainWindow" Height="100" Width="461" Closing="Window_Closing" Loaded="Window_Loaded" Deactivated="Window_Deactivated" AllowsTransparency="True" WindowStyle="None" Background="Transparent" ResizeMode="NoResize" Topmost="True" ShowInTaskbar="False" Left="-10000" ShowActivated="False" MaxHeight="620" SourceInitialized="Window_SourceInitialized" > + Title="MainWindow" Height="100" Width="461" Closing="Window_Closing" Loaded="Window_Loaded" Deactivated="Window_Deactivated" AllowsTransparency="True" WindowStyle="None" Background="Transparent" ResizeMode="NoResize" Topmost="False" ShowInTaskbar="False" Left="-10000" ShowActivated="False" MaxHeight="620" SourceInitialized="Window_SourceInitialized" > diff --git a/ClipOne/view/MainWindow.xaml.cs b/ClipOne/view/MainWindow.xaml.cs index 2318925..8dd7982 100644 --- a/ClipOne/view/MainWindow.xaml.cs +++ b/ClipOne/view/MainWindow.xaml.cs @@ -146,13 +146,13 @@ public MainWindow() InitializeComponent(); System.IO.Directory.SetCurrentDirectory(System.Windows.Forms.Application.StartupPath); - + } private void Window_Loaded(object sender, RoutedEventArgs e) { - + if (!Directory.Exists(cacheDir)) { @@ -184,13 +184,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) } - - - - - - - + /// /// /加载设置项 @@ -260,8 +254,9 @@ private void WebView1_ScriptNotify(object sender, Microsoft.Toolkit.Win32.UI.Con if (args[0] == "PasteValue") { - + PasteValue(args[1]); + } else if (args[0] == "PasteValueList") @@ -288,6 +283,11 @@ private void WebView1_ScriptNotify(object sender, Microsoft.Toolkit.Win32.UI.Con { DiyHide(); } + //else if (args[0].StartsWith("test")) + //{ + // File.AppendAllText("C:/Users/xiecan/test.txt", args[0] + " " + args[1] + "\n"); + //} + } private void ClearImage(object images) @@ -722,9 +722,8 @@ public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bo { activeHwnd = WinAPIHelper.GetForegroundWindow(); - - this.Topmost = true; - this.Activate(); + // File.AppendAllText("C:/Users/xiecan/test.txt", activeHwnd + "--\n"); + WinAPIHelper.POINT point = new WinAPIHelper.POINT(); @@ -754,7 +753,9 @@ public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bo } - + this.Show(); + this.Topmost = true; + this.Activate(); ShowWindowAndList(); @@ -876,7 +877,7 @@ private void SetValueToClip(ClipModel result) ClipService.SetValueToClipboard(result); Thread.Sleep(100); - + //File.AppendAllText("C:/Users/xiecan/test.txt", result.DisplayValue + "\n"); System.Windows.Forms.SendKeys.SendWait("^v"); } @@ -894,10 +895,12 @@ private void Window_Deactivated(object sender, EventArgs e) /// private void WindowLostFocusHandle() { - - DiyHide(); - + this.Topmost = false; + if (this.Visibility == Visibility.Visible) { + this.Hide(); + } + // this.Left = HideLeftValue; } @@ -988,14 +991,16 @@ private void DiyHide() { this.Topmost = false; - + this.Hide(); if (activeHwnd != IntPtr.Zero) { WinAPIHelper.SetForegroundWindow(activeHwnd); + // File.AppendAllText("C:/Users/xiecan/test.txt", activeHwnd+"\n"); } - this.Left = HideLeftValue; + + }