mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-28 18:15:47 +02:00
Add triggers for Settings and About menus (via context menu and JS injection)
This commit is contained in:
parent
d89c51a1d3
commit
9d8cda9b6d
@ -24,7 +24,7 @@ public FormBrowser(){
|
|||||||
|
|
||||||
bridge = new TweetDeckBridge(this);
|
bridge = new TweetDeckBridge(this);
|
||||||
|
|
||||||
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/");
|
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){ MenuHandler = new ContextMenuHandler(this) };
|
||||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||||
browser.RegisterJsObject("$TD",bridge);
|
browser.RegisterJsObject("$TD",bridge);
|
||||||
|
|
||||||
@ -78,5 +78,15 @@ private void FormBrowser_WindowStateChanged(object sender, EventArgs e){
|
|||||||
Config.IsMaximized = WindowState != FormWindowState.Normal;
|
Config.IsMaximized = WindowState != FormWindowState.Normal;
|
||||||
FormBrowser_ResizeEnd(sender,e);
|
FormBrowser_ResizeEnd(sender,e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// callback handlers
|
||||||
|
|
||||||
|
public void OpenSettings(){
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenAbout(){
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
Core/Handling/ContextMenuHandler.cs
Normal file
51
Core/Handling/ContextMenuHandler.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using CefSharp;
|
||||||
|
|
||||||
|
namespace TweetDick.Core.Handling{
|
||||||
|
class ContextMenuHandler : IContextMenuHandler{
|
||||||
|
private const int MenuSettings = 26500;
|
||||||
|
private const int MenuAbout = 26501;
|
||||||
|
|
||||||
|
private readonly FormBrowser form;
|
||||||
|
|
||||||
|
public ContextMenuHandler(FormBrowser form){
|
||||||
|
this.form = form;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
||||||
|
model.Remove(CefMenuCommand.Back);
|
||||||
|
model.Remove(CefMenuCommand.Forward);
|
||||||
|
model.Remove(CefMenuCommand.Print);
|
||||||
|
model.Remove(CefMenuCommand.ViewSource);
|
||||||
|
|
||||||
|
if (model.Count > 0 && model.GetTypeAt(model.Count-1) == MenuItemType.Separator){
|
||||||
|
model.RemoveAt(model.Count-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.AddItem(CefMenuCommand.Reload,"Reload");
|
||||||
|
model.AddSeparator();
|
||||||
|
model.AddItem((CefMenuCommand)MenuSettings,"Settings");
|
||||||
|
model.AddSeparator();
|
||||||
|
model.AddItem((CefMenuCommand)MenuAbout,"About TweetDick");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags){
|
||||||
|
switch((int)commandId){
|
||||||
|
case MenuSettings:
|
||||||
|
form.OpenSettings();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MenuAbout:
|
||||||
|
form.OpenAbout();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame){}
|
||||||
|
|
||||||
|
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
using System.Windows.Forms;
|
namespace TweetDick.Core.Handling{
|
||||||
|
|
||||||
namespace TweetDick.Core.Handling{
|
|
||||||
class TweetDeckBridge{
|
class TweetDeckBridge{
|
||||||
private readonly FormBrowser form;
|
private readonly FormBrowser form;
|
||||||
|
|
||||||
@ -9,7 +7,7 @@ public TweetDeckBridge(FormBrowser form){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSettingsMenu(){
|
public void OpenSettingsMenu(){
|
||||||
MessageBox.Show("Settings");
|
form.OpenSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(string data){
|
public void Log(string data){
|
||||||
|
@ -8,6 +8,27 @@
|
|||||||
// Function: Initializes TweetDick events. Called after the website app is loaded.
|
// Function: Initializes TweetDick events. Called after the website app is loaded.
|
||||||
//
|
//
|
||||||
var initializeTweetDick = function(){
|
var initializeTweetDick = function(){
|
||||||
|
$("[data-action='settings-menu']").click(function(){
|
||||||
|
setTimeout(function(){
|
||||||
|
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-tweetdick><a href="#" data-action>TweetDick</a></li><li class="drp-h-divider"></li>');
|
||||||
|
|
||||||
|
var tweetDickBtn = menu.children("[data-tweetdick]");
|
||||||
|
|
||||||
|
tweetDickBtn.on("click","a",function(){
|
||||||
|
$TD.openSettingsMenu();
|
||||||
|
});
|
||||||
|
|
||||||
|
tweetDickBtn.hover(function(){
|
||||||
|
$(this).addClass("is-selected");
|
||||||
|
},function(){
|
||||||
|
$(this).removeClass("is-selected");
|
||||||
|
});
|
||||||
|
},0);
|
||||||
|
});
|
||||||
|
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Configuration\UserConfig.cs" />
|
<Compile Include="Configuration\UserConfig.cs" />
|
||||||
|
<Compile Include="Core\Handling\ContextMenuHandler.cs" />
|
||||||
<Compile Include="Core\FormBrowser.cs">
|
<Compile Include="Core\FormBrowser.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
Reference in New Issue
Block a user