1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 03:15:49 +02:00

Allow dragging tweet links over columns to open them in detail view

Closes 
This commit is contained in:
chylex 2017-09-10 23:03:03 +02:00
parent 3f5ffc9e10
commit f17806f4e8
4 changed files with 61 additions and 0 deletions

View File

@ -85,6 +85,7 @@ public FormBrowser(UpdaterSettings updaterSettings){
this.browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
DialogHandler = new FileDialogHandler(),
DragHandler = new DragHandlerBrowser(),
MenuHandler = new ContextMenuBrowser(this),
JsDialogHandler = new JavaScriptDialogHandler(),
KeyboardHandler = new KeyboardHandlerBrowser(this),

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
using CefSharp;
namespace TweetDuck.Core.Handling{
sealed class DragHandlerBrowser : IDragHandler{
public bool OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData dragData, DragOperationsMask mask){
if (dragData.IsLink){
browserControl.ExecuteScriptAsync("window.TDGF_onGlobalDragStart", "link", dragData.LinkUrl);
}
else{
browserControl.ExecuteScriptAsync("window.TDGF_onGlobalDragStart", "unknown");
}
return false;
}
public void OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList<DraggableRegion> regions){}
}
}

View File

@ -683,6 +683,46 @@
};
})();
//
// Block: Allow drag & drop behavior for dropping links on columns to open their detail view.
//
(function(){
let tweetRegex = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?$/;
let isDraggingValid = false;
window.TDGF_onGlobalDragStart = function(type, data){
isDraggingValid = type === "link" && tweetRegex.test(data);
};
app.delegate("section.js-column", {
dragover: function(e){
e.originalEvent.dataTransfer.dropEffect = isDraggingValid ? "move" : "none";
e.preventDefault();
e.stopPropagation();
},
drop: function(e){
let match = tweetRegex.exec(e.originalEvent.dataTransfer.getData("URL"));
if (match.length === 2){
let column = TD.controller.columnManager.get($(this).attr("data-column"));
if (column){
TD.controller.clients.getPreferredClient().show(match[1], function(chirp){
TD.ui.updates.showDetailView(column, chirp, column.findChirp(chirp) || chirp);
$(document).trigger("uiGridClearSelection");
}, function(){
alert("error|Could not retrieve the requested tweet.");
});
}
}
e.preventDefault();
e.stopPropagation();
}
});
})();
//
// Block: Fix scheduled tweets not showing up sometimes.
//

View File

@ -88,6 +88,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Core\FormManager.cs" />
<Compile Include="Core\Handling\DragHandlerBrowser.cs" />
<Compile Include="Core\Handling\General\BrowserProcessHandler.cs" />
<Compile Include="Core\Handling\ContextMenuBase.cs" />
<Compile Include="Core\Handling\ContextMenuBrowser.cs" />