Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
[Ide] Bring back Drop support to the main IDE window
Browse files Browse the repository at this point in the history
Fixes issue #4403
(partially reverts 67b943d)
  • Loading branch information
sevoku committed May 11, 2018
1 parent 17145c0 commit 14c5ef1
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ public DefaultWorkbench()
IdeApp.CommandService.SetRootWindow (this);
DockNotebook.NotebookChanged += NotebookPagesChanged;

Drag.DestSet (this, DestDefaults.All, targetEntryTypes, Gdk.DragAction.Copy);

Accessible.SetIsMainWindow (true);
}

Expand Down Expand Up @@ -1510,6 +1512,50 @@ object ICommandRouter.GetNextCommandTarget ()
}

#endregion

#region DnD

enum TargetList
{
UriList = 100
}

static TargetEntry [] targetEntryTypes = { new TargetEntry ("text/uri-list", 0, (uint)TargetList.UriList) };


protected override bool OnDragMotion (Gdk.DragContext context, int x, int y, uint time_)
{
// Bring this window to the front. Otherwise, the drop may end being done in another window that overlaps this one
if (!Platform.IsWindows)
Present ();
return base.OnDragMotion (context, x, y, time_);
}

protected override void OnDragDataReceived (Gdk.DragContext context, int x, int y, SelectionData selection_data, uint info, uint time_)
{
if (info != (uint)TargetList.UriList)
return;
string fullData = System.Text.Encoding.UTF8.GetString (selection_data.Data);

foreach (string individualFile in fullData.Split ('\n')) {
string file = individualFile.Trim ();
if (file.StartsWith ("file://", StringComparison.Ordinal)) {
var filePath = new FilePath (file);

try {
if (Services.ProjectService.IsWorkspaceItemFile (filePath))
IdeApp.Workspace.OpenWorkspaceItem (filePath);
else
IdeApp.Workbench.OpenDocument (filePath, null);
} catch (Exception e) {
LoggingService.LogError ($"unable to open file {filePath}", e);
}
}
}
base.OnDragDataReceived (context, x, y, selection_data, info, time_);
}

#endregion
}

class PadActivationHandler: CommandHandler
Expand Down

0 comments on commit 14c5ef1

Please sign in to comment.