mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-14 01:25:38 -05:00
- Add support for filtering by category
- Break up main window into partials instead of using regions
This commit is contained in:
52
Application/MainWindow/DragDrop.cs
Normal file
52
Application/MainWindow/DragDrop.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
public partial class MainWindow
|
||||
{
|
||||
private readonly string[] _chromeExtensions = { "chrome-extension://ehojfdcmnajoklleckniaifaijfnkpbi/subscribe.html?", "chrome-extension://nlbjncdgjeocebhnmkbbbdekmmmcbfjd/subscribe.html?" };
|
||||
|
||||
private void HandleDragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
// Default to not allowed
|
||||
e.Effects = DragDropEffects.None;
|
||||
e.Handled = true;
|
||||
|
||||
// If there isn't any text in the data then it is not allowed
|
||||
if (!e.Data.GetDataPresent(DataFormats.Text))
|
||||
return;
|
||||
|
||||
// Get the data as a string
|
||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
||||
|
||||
// If the data doesn't look like a URI then it is not allowed
|
||||
if (!Uri.IsWellFormedUriString(data, UriKind.Absolute))
|
||||
return;
|
||||
|
||||
// Allowed
|
||||
e.Effects = DragDropEffects.Copy;
|
||||
}
|
||||
|
||||
private void HandleDragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
// Get the data as a string
|
||||
var data = (string) e.Data.GetData(DataFormats.Text);
|
||||
|
||||
// Check to see if the data starts with any known Chrome extension
|
||||
var chromeExtension = _chromeExtensions.FirstOrDefault(c => data.StartsWith(c));
|
||||
|
||||
// Remove the Chrome extension URL and decode the URL
|
||||
if (chromeExtension != null)
|
||||
{
|
||||
data = data.Substring(chromeExtension.Length);
|
||||
data = WebUtility.UrlDecode(data);
|
||||
}
|
||||
|
||||
// Handle the new feed but allow the drag/drop to complete
|
||||
Dispatcher.BeginInvoke(new NewFeedDelegate(HandleNewFeed), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user