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

Add context menu item to copy tweet address without focusing date link

Closes 
This commit is contained in:
chylex 2016-05-09 20:00:36 +02:00
parent 39816eae76
commit 9a29d4ff18
6 changed files with 82 additions and 23 deletions

View File

@ -29,6 +29,7 @@ protected override bool ShowWithoutActivation{
}
public bool FreezeTimer { get; set; }
public string CurrentUrl { get; private set; }
public FormNotification(Form owner, TweetDeckBridge bridge, bool autoHide){
InitializeComponent();
@ -133,9 +134,7 @@ public void ShowNotificationForSettings(bool reset){
}
if (reset){
browser.LoadHtml(TweetNotification.ExampleTweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
ResetTimerValue(TweetNotification.ExampleTweet.GetDisplayDuration(Program.UserConfig.NotificationDuration));
LoadTweet(TweetNotification.ExampleTweet);
timerProgress.Start();
}
@ -165,15 +164,22 @@ private void LoadNextNotification(){
browser.Load("about:blank"); // required, otherwise shit breaks
}
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
ResetTimerValue(tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration));
LoadTweet(tweet);
timerProgress.Stop();
timerProgress.Start();
UpdateTitle();
}
private void LoadTweet(TweetNotification tweet){
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
progressBarTimer.Value = 0;
CurrentUrl = tweet.Url;
}
private void MoveToVisibleLocation(){
bool needsReactivating = Location.X == -32000;
@ -230,10 +236,5 @@ private void MoveToVisibleLocation(){
private void UpdateTitle(){
Text = tweetQueue.Count > 0 ? Program.BrandName+" ("+tweetQueue.Count+" more left)" : Program.BrandName;
}
private void ResetTimerValue(int newTimeLeft){
totalTime = timeLeft = newTimeLeft;
progressBarTimer.Value = 0;
}
}
}

View File

@ -1,4 +1,5 @@
using CefSharp;
using System.Windows.Forms;
using TweetDck.Core.Controls;
namespace TweetDck.Core.Handling{
@ -6,6 +7,7 @@ class ContextMenuBrowser : ContextMenuBase{
private const int MenuSettings = 26600;
private const int MenuAbout = 26601;
private const int MenuMute = 26602;
private const int MenuCopyTweetUrl = 26603;
private readonly FormBrowser form;
@ -18,8 +20,13 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br
model.Remove(CefMenuCommand.Forward);
model.Remove(CefMenuCommand.Print);
model.Remove(CefMenuCommand.ViewSource);
RemoveSeparatorIfLast(model);
if (!string.IsNullOrEmpty(TweetDeckBridge.LastHighlightedTweet)){
model.AddItem((CefMenuCommand)MenuCopyTweetUrl,"Copy tweet address");
model.AddSeparator();
}
base.OnBeforeContextMenu(browserControl,browser,frame,parameters,model);
if (model.Count > 0){
@ -60,6 +67,10 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b
});
return true;
case MenuCopyTweetUrl:
Clipboard.SetText(TweetDeckBridge.LastHighlightedTweet,TextDataFormat.UnicodeText);
return true;
}
return false;

View File

@ -1,10 +1,12 @@
using CefSharp;
using System.Windows.Forms;
using CefSharp;
using TweetDck.Core.Controls;
namespace TweetDck.Core.Handling{
class ContextMenuNotification : ContextMenuBase{
private const int MenuSkipTweet = 26600;
private const int MenuFreeze = 26601;
private const int MenuCopyTweetUrl = 26602;
private readonly FormNotification form;
private readonly bool enableCustomMenu;
@ -22,6 +24,11 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br
model.AddCheckItem((CefMenuCommand)MenuFreeze,"Freeze");
model.SetChecked((CefMenuCommand)MenuFreeze,form.FreezeTimer);
model.AddSeparator();
if (!string.IsNullOrEmpty(form.CurrentUrl)){
model.AddItem((CefMenuCommand)MenuCopyTweetUrl,"Copy tweet address");
model.AddSeparator();
}
}
base.OnBeforeContextMenu(browserControl,browser,frame,parameters,model);
@ -41,6 +48,10 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b
case MenuFreeze:
form.InvokeSafe(() => form.FreezeTimer = !form.FreezeTimer);
return true;
case MenuCopyTweetUrl:
Clipboard.SetText(form.CurrentUrl,TextDataFormat.UnicodeText);
return true;
}
return false;

View File

@ -9,6 +9,7 @@
namespace TweetDck.Core.Handling{
class TweetDeckBridge{
public static string LastRightClickedLink = string.Empty;
public static string LastHighlightedTweet = string.Empty;
public static string ClipboardImagePath = string.Empty;
private readonly FormBrowser form;
@ -66,18 +67,20 @@ public void LoadNotificationHeadContents(string headContents){
}
public void SetLastRightClickedLink(string link){
form.InvokeSafe(() => {
LastRightClickedLink = link;
});
form.InvokeSafe(() => LastRightClickedLink = link);
}
public void SetLastHighlightedTweet(string link){
form.InvokeSafe(() => LastHighlightedTweet = link);
}
public void OpenSettingsMenu(){
form.InvokeSafe(form.OpenSettings);
}
public void OnTweetPopup(string tweetHtml, int tweetCharacters){
public void OnTweetPopup(string tweetHtml, string tweetUrl, int tweetCharacters){
form.InvokeSafe(() => {
form.OnTweetPopup(new TweetNotification(tweetHtml,tweetCharacters));
form.OnTweetPopup(new TweetNotification(tweetHtml,tweetUrl,tweetCharacters));
});
}

View File

@ -26,7 +26,7 @@ public static TweetNotification ExampleTweet{
build.Append(@"<div class='tweet-body'><p class='js-tweet-text tweet-text with-linebreaks'>This is an example tweet, which lets you test the location and duration of popup notifications.</p></div>");
build.Append(@"</div></div></article>");
return new TweetNotification(build.ToString(),95);
return new TweetNotification(build.ToString(),"",95);
}
}
@ -46,11 +46,19 @@ public enum Duration{
Short, Medium, Long, VeryLong
}
public string Url{
get{
return url;
}
}
private readonly string html;
private readonly string url;
private readonly int characters;
public TweetNotification(string html, int characters){
public TweetNotification(string html, string url, int characters){
this.html = html;
this.url = url;
this.characters = characters;
}

View File

@ -81,7 +81,8 @@
}));
html.css("border","0");
var url = html.find("time").first().children("a").first().attr("href") || "";
var body = html.find(".tweet-body").first();
body.children("div.js-quote-detail").each(function(){
@ -91,8 +92,8 @@
});
body.children("footer").remove();
$TD.onTweetPopup(html.html(),tweet.text.length); // TODO column
$TD.onTweetPopup(html.html(),url,tweet.text.length); // TODO column
}
else if (column.model.getHasSound()){
$TD.onTweetSound(); // TODO disable original
@ -293,6 +294,30 @@
}
});
//
// Block: Copy tweet address.
//
(function(){
var lastTweet = "";
var updateHighlightedTweet = function(link){
if (lastTweet != link){
$TD.setLastHighlightedTweet(link);
lastTweet = link;
}
};
$(document.body).delegate("article.js-stream-item","mouseenter mouseleave",function(e){
if (e.type === "mouseenter"){
var link = $(this).find("time").first().children("a").first();
updateHighlightedTweet(link.length > 0 ? link.attr("href") : "");
}
else if (e.type === "mouseleave"){
updateHighlightedTweet("");
}
});
})();
//
// Block: Paste images when tweeting.
//