1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-06 05:34:05 +02:00

Add link expanding and tooltip support to popup notifications

This commit is contained in:
chylex 2016-05-12 15:10:22 +02:00
parent 4c44da7f4a
commit 7238e17b86
6 changed files with 96 additions and 9 deletions

View File

@ -229,7 +229,12 @@ public void OnTweetSound(){
}
public void DisplayTooltip(string text){
public void DisplayTooltip(string text, bool showInNotification){
if (showInNotification){
notification.DisplayTooltip(text);
return;
}
if (string.IsNullOrEmpty(text)){
toolTip.Hide(this);
}

View File

@ -29,6 +29,7 @@ private void InitializeComponent() {
this.panelBrowser = new System.Windows.Forms.Panel();
this.timerProgress = new System.Windows.Forms.Timer(this.components);
this.progressBarTimer = new TweetDck.Core.Controls.FlatProgressBar();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// panelBrowser
@ -87,5 +88,6 @@ private void InitializeComponent() {
private System.Windows.Forms.Panel panelBrowser;
private Controls.FlatProgressBar progressBarTimer;
private System.Windows.Forms.Timer timerProgress;
private System.Windows.Forms.ToolTip toolTip;
}
}

View File

@ -249,5 +249,16 @@ private void MoveToVisibleLocation(){
private void UpdateTitle(){
Text = tweetQueue.Count > 0 ? Program.BrandName+" ("+tweetQueue.Count+" more left)" : Program.BrandName;
}
public void DisplayTooltip(string text){
if (string.IsNullOrEmpty(text)){
toolTip.Hide(this);
}
else{
Point position = PointToClient(Cursor.Position);
position.Offset(20,5);
toolTip.Show(text,this,position);
}
}
}
}

View File

@ -101,9 +101,9 @@ public void OnUpdateDismissed(string versionTag){
});
}
public void DisplayTooltip(string text){
public void DisplayTooltip(string text, bool showInNotification){
form.InvokeSafe(() => {
form.DisplayTooltip(text);
form.DisplayTooltip(text,showInNotification);
});
}

View File

@ -202,11 +202,11 @@
})();
//
// Block: Expand shortened links on hover.
// Block: Expand shortened links on hover or display tooltip.
//
(function(){
var cutStart = function(str, search){
return _.startsWith(str,search) ? str.substr(search.length) : str;
return str.startsWith(search) ? str.substr(search.length) : str;
};
var prevMouseX = -1, prevMouseY = -1;
@ -233,7 +233,7 @@
}
else{
tooltipTimer = window.setTimeout(function(){
$TD.displayTooltip(me.attr("data-full-url"));
$TD.displayTooltip(me.attr("data-full-url"),false);
tooltipDisplayed = true;
},400);
}
@ -246,15 +246,16 @@
me.text(prevText);
}
}
else{
if (tooltipDisplayed){
window.clearTimeout(tooltipTimer);
tooltipDisplayed = false;
$TD.displayTooltip(null);
$TD.displayTooltip(null,false);
}
}
else if (e.type === "mousemove"){
if (tooltipDisplayed && (prevMouseX != e.clientX || prevMouseY != e.clientY)){
$TD.displayTooltip(me.attr("data-full-url"));
$TD.displayTooltip(me.attr("data-full-url"),false);
prevMouseX = e.clientX;
prevMouseY = e.clientY;
}

View File

@ -27,4 +27,72 @@
addEventListener(links,"contextmenu",function(e){
$TD.setLastRightClickedLink(e.currentTarget.getAttribute("data-full-url") || "");
});
//
// Block: Expand shortened links on hover or display tooltip.
//
(function(){
var cutStart = function(str, search){
return str.startsWith(search) ? str.substr(search.length) : str;
};
var prevMouseX = -1, prevMouseY = -1;
var tooltipTimer, tooltipDisplayed;
addEventListener(links,"mouseenter",function(e){
var url = e.currentTarget.getAttribute("data-full-url");
if (!url)return;
var text = e.currentTarget.textContent;
if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis
return;
}
if ($TD.expandLinksOnHover){
var expanded = url;
expanded = cutStart(expanded,"https://");
expanded = cutStart(expanded,"http://");
expanded = cutStart(expanded,"www.");
e.currentTarget.setAttribute("td-prev-text",text);
e.currentTarget.innerHTML = expanded;
}
else{
tooltipTimer = window.setTimeout(function(){
$TD.displayTooltip(url,true);
tooltipDisplayed = true;
},400);
}
});
addEventListener(links,"mouseleave",function(e){
if (!e.currentTarget.hasAttribute("data-full-url"))return;
if ($TD.expandLinksOnHover){
var prevText = e.currentTarget.getAttribute("td-prev-text");
if (prevText){
e.currentTarget.innerHTML = prevText;
}
}
if (tooltipDisplayed){
window.clearTimeout(tooltipTimer);
tooltipDisplayed = false;
$TD.displayTooltip(null,true);
}
});
addEventListener(links,"mousemove",function(e){
if (tooltipDisplayed && (prevMouseX != e.clientX || prevMouseY != e.clientY)){
var url = e.currentTarget.getAttribute("data-full-url");
if (!url)return;
$TD.displayTooltip(url,true);
prevMouseX = e.clientX;
prevMouseY = e.clientY;
}
});
})();
})($TD);