diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs index 808501cb..657d4819 100644 --- a/Core/Bridge/TweetDeckBridge.cs +++ b/Core/Bridge/TweetDeckBridge.cs @@ -53,12 +53,8 @@ public void SetNotificationQuotedTweet(string link){ notification.InvokeAsyncSafe(() => notification.CurrentQuotedTweetUrl = link); } - public void OpenSettingsMenu(){ - form.InvokeAsyncSafe(form.OpenSettings); - } - - public void OpenPluginsMenu(){ - form.InvokeAsyncSafe(form.OpenPlugins); + public void OpenContextMenu(){ + form.InvokeAsyncSafe(form.OpenContextMenu); } public void OnTweetPopup(string tweetHtml, string tweetUrl, int tweetCharacters){ diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 6403d2c7..282dde0c 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -33,6 +33,7 @@ private static UserConfig Config{ private readonly PluginManager plugins; private readonly UpdateHandler updates; private readonly FormNotificationTweet notification; + private readonly ContextMenu contextMenu; private FormSettings currentFormSettings; private FormAbout currentFormAbout; @@ -53,6 +54,8 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings) this.plugins.Reloaded += plugins_Reloaded; this.plugins.PluginChangedState += plugins_PluginChangedState; + this.contextMenu = ContextMenuBrowser.CreateMenu(this); + this.notification = new FormNotificationTweet(this, plugins, NotificationFlags.TopMost){ #if DEBUG CanMoveWindow = () => (ModifierKeys & Keys.Alt) == Keys.Alt @@ -85,6 +88,7 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings) Disposed += (sender, args) => { browser.Dispose(); + contextMenu.Dispose(); if (notificationScreenshotManager != null){ notificationScreenshotManager.Dispose(); @@ -308,8 +312,16 @@ public void UpdateProperties(PropertyBridge.Properties properties = PropertyBrid browser.ExecuteScriptAsync(PropertyBridge.GenerateScript(properties)); } + public void ReloadToTweetDeck(){ + browser.ExecuteScriptAsync("window.location.href = 'https://tweetdeck.twitter.com'"); + } + // callback handlers + public void OpenContextMenu(){ + contextMenu.Show(this, new Point(Cursor.Position.X, Cursor.Position.Y-22)); + } + public void OpenSettings(){ OpenSettings(0); } diff --git a/Core/Handling/ContextMenuBrowser.cs b/Core/Handling/ContextMenuBrowser.cs index b543bffa..4b948fcb 100644 --- a/Core/Handling/ContextMenuBrowser.cs +++ b/Core/Handling/ContextMenuBrowser.cs @@ -1,4 +1,5 @@ -using CefSharp; +using System.Windows.Forms; +using CefSharp; using TweetDck.Core.Bridge; using TweetDck.Core.Controls; using TweetDck.Core.Utils; @@ -17,6 +18,12 @@ class ContextMenuBrowser : ContextMenuBase{ private const int MenuCopyQuotedTweetUrl = 26613; private const int MenuScreenshotTweet = 26614; + private const string TitleReloadBrowser = "Reload browser"; + private const string TitleMuteNotifications = "Mute notifications"; + private const string TitleSettings = "Settings"; + private const string TitlePlugins = "Plugins"; + private const string TitleAboutProgram = "About "+Program.BrandName; + private readonly FormBrowser form; private string lastHighlightedTweet; @@ -66,14 +73,14 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br IMenuModel globalMenu = model.Count == 0 ? model : model.AddSubMenu((CefMenuCommand)MenuGlobal, Program.BrandName); - globalMenu.AddItem(CefMenuCommand.Reload, "Reload browser"); - globalMenu.AddCheckItem((CefMenuCommand)MenuMute, "Mute notifications"); + globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser); + globalMenu.AddCheckItem((CefMenuCommand)MenuMute, TitleMuteNotifications); globalMenu.SetChecked((CefMenuCommand)MenuMute, Program.UserConfig.MuteNotifications); globalMenu.AddSeparator(); - globalMenu.AddItem((CefMenuCommand)MenuSettings, "Settings"); - globalMenu.AddItem((CefMenuCommand)MenuPlugins, "Plugins"); - globalMenu.AddItem((CefMenuCommand)MenuAbout, "About "+Program.BrandName); + globalMenu.AddItem((CefMenuCommand)MenuSettings, TitleSettings); + globalMenu.AddItem((CefMenuCommand)MenuPlugins, TitlePlugins); + globalMenu.AddItem((CefMenuCommand)MenuAbout, TitleAboutProgram); #if DEBUG globalMenu.AddSeparator(); @@ -107,11 +114,7 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b return true; case MenuMute: - form.InvokeAsyncSafe(() => { - Program.UserConfig.MuteNotifications = !Program.UserConfig.MuteNotifications; - Program.UserConfig.Save(); - }); - + form.InvokeAsyncSafe(ToggleMuteNotifications); return true; case MenuOpenTweetUrl: @@ -137,5 +140,27 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b return false; } + + public static ContextMenu CreateMenu(FormBrowser form){ + ContextMenu menu = new ContextMenu(); + + menu.MenuItems.Add(TitleReloadBrowser, (sender, args) => form.ReloadToTweetDeck()); + menu.MenuItems.Add(TitleMuteNotifications, (sender, args) => ToggleMuteNotifications()); + menu.MenuItems.Add("-"); + menu.MenuItems.Add(TitleSettings, (sender, args) => form.OpenSettings()); + menu.MenuItems.Add(TitlePlugins, (sender, args) => form.OpenPlugins()); + menu.MenuItems.Add(TitleAboutProgram, (sender, args) => form.OpenAbout()); + + menu.Popup += (sender, args) => { + menu.MenuItems[1].Checked = Program.UserConfig.MuteNotifications; + }; + + return menu; + } + + private static void ToggleMuteNotifications(){ + Program.UserConfig.MuteNotifications = !Program.UserConfig.MuteNotifications; + Program.UserConfig.Save(); + } } } diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index cb185650..4572b26f 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -119,26 +119,15 @@ var menu = $(".js-dropdown-content").children("ul").first(); if (menu.length === 0)return; - menu.children(".drp-h-divider").last().after([ - '<li class="is-selectable" data-std><a href="#" data-action="td-settings">TweetDuck settings</a></li>', - '<li class="is-selectable" data-std><a href="#" data-action="td-plugins">TweetDuck plugins</a></li>', - '<li class="drp-h-divider"></li>' - ].join("")); + menu.children(".drp-h-divider").last().before('<li class="is-selectable" data-std><a href="#" data-action="tweetduck">TweetDuck</a></li>'); - var buttons = menu.children("[data-std]"); + var button = menu.children("[data-std]"); - buttons.on("click", "a", function(){ - var action = $(this).attr("data-action"); - - if (action === "td-settings"){ - $TD.openSettingsMenu(); - } - else if (action === "td-plugins"){ - $TD.openPluginsMenu(); - } + button.on("click", "a", function(){ + $TD.openContextMenu(); }); - buttons.hover(function(){ + button.hover(function(){ $(this).addClass("is-selected"); }, function(){ $(this).removeClass("is-selected");