Skip to content

Commit a441bb9

Browse files
committed
WpfWorkbench.OnDrop: don't show dialogs during the drop event; use Dispatcher.BeginInvoke instead.
1 parent 07fb789 commit a441bb9

File tree

3 files changed

+67
-59
lines changed

3 files changed

+67
-59
lines changed

src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,7 @@ public ResolveResult ResolveMemberAccess(ResolveResult target, string identifier
16941694
case NameLookupMode.Type:
16951695
case NameLookupMode.TypeInUsingDeclaration:
16961696
case NameLookupMode.BaseTypeReference:
1697-
result = lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType);
1698-
break;
1697+
return lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType);
16991698
default:
17001699
throw new NotSupportedException("Invalid value for NameLookupMode");
17011700
}

src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFi
648648

649649
static FileOperationResult ObservedSaveHandleError(Exception e, NamedFileOperationDelegate saveFileAs, FileName fileName, string message, FileErrorPolicy policy)
650650
{
651+
message = message + Environment.NewLine + Environment.NewLine + e.Message;
651652
var messageService = ServiceSingleton.GetRequiredService<IMessageService>();
652653
switch (policy) {
653654
case FileErrorPolicy.Inform:
@@ -693,6 +694,7 @@ public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, F
693694

694695
static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy)
695696
{
697+
message = message + Environment.NewLine + Environment.NewLine + e.Message;
696698
var messageService = ServiceSingleton.GetRequiredService<IMessageService>();
697699
switch (policy) {
698700
case FileErrorPolicy.Inform:

src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected override void OnSourceInitialized(EventArgs e)
107107
// Set WindowState after PresentationSource is initialized, because now bounds and location are properly set.
108108
this.WindowState = lastNonMinimizedWindowState;
109109
}
110-
110+
111111
void SetBounds(Rect bounds)
112112
{
113113
this.Left = bounds.Left;
@@ -174,7 +174,7 @@ void ExecuteCommand(ICommand command, object caller)
174174
// keep a reference to the event handler to prevent it from being garbage collected
175175
// (CommandManager.RequerySuggested only keeps weak references to the event handlers)
176176
EventHandler requerySuggestedEventHandler;
177-
177+
178178
void CommandManager_RequerySuggested(object sender, EventArgs e)
179179
{
180180
UpdateMenu();
@@ -270,9 +270,9 @@ public ICollection<IViewContent> PrimaryViewContents {
270270
get {
271271
SD.MainThread.VerifyAccess();
272272
return (from window in WorkbenchWindowCollection
273-
where window.ViewContents.Count > 0
274-
select window.ViewContents[0]
275-
).ToList().AsReadOnly();
273+
where window.ViewContents.Count > 0
274+
select window.ViewContents[0]
275+
).ToList().AsReadOnly();
276276
}
277277
}
278278

@@ -319,7 +319,7 @@ private set {
319319
}
320320
}
321321
}
322-
322+
323323
void WorkbenchWindowActiveViewContentChanged(object sender, EventArgs e)
324324
{
325325
if (workbenchLayout != null) {
@@ -671,22 +671,29 @@ protected override void OnDrop(DragEventArgs e)
671671
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
672672
if (files == null)
673673
return;
674-
foreach (string file in files) {
675-
if (File.Exists(file)) {
676-
var fileName = FileName.Create(file);
677-
if (SD.ProjectService.IsSolutionOrProjectFile(fileName)) {
678-
SD.ProjectService.OpenSolutionOrProject(fileName);
679-
} else {
680-
SD.FileService.OpenFile(fileName);
681-
}
682-
}
683-
}
674+
// Handle opening the files outside the drop event, so that the drag source doesn't think
675+
// the operation is still in progress while we're showing a "file cannot be opened" error message.
676+
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<string[]>(HandleDrop), files);
684677
}
685678
} catch (Exception ex) {
686679
MessageService.ShowException(ex);
687680
}
688681
}
689682

683+
void HandleDrop(string[] files)
684+
{
685+
foreach (string file in files) {
686+
if (File.Exists(file)) {
687+
var fileName = FileName.Create(file);
688+
if (SD.ProjectService.IsSolutionOrProjectFile(fileName)) {
689+
SD.ProjectService.OpenSolutionOrProject(fileName);
690+
} else {
691+
SD.FileService.OpenFile(fileName);
692+
}
693+
}
694+
}
695+
}
696+
690697
void InitFocusTrackingEvents()
691698
{
692699
#if DEBUG
@@ -700,7 +707,7 @@ internal static void FocusDebug(string format, params object[] args)
700707
{
701708
#if DEBUG
702709
if (enableFocusDebugOutput)
703-
LoggingService.DebugFormatted(format, args);
710+
LoggingService.DebugFormatted(format, args);
704711
#endif
705712
}
706713

@@ -709,55 +716,55 @@ internal static void FocusDebug(string format, params object[] args)
709716

710717
void WpfWorkbench_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
711718
{
712-
FocusDebug("GotKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
719+
FocusDebug("GotKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
713720
}
714721

715722
void WpfWorkbench_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
716723
{
717-
FocusDebug("LostKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
724+
FocusDebug("LostKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
718725
}
719726

720727
protected override void OnPreviewKeyDown(KeyEventArgs e)
721728
{
722-
base.OnPreviewKeyDown(e);
723-
if (!e.Handled && e.Key == Key.D && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
724-
enableFocusDebugOutput = !enableFocusDebugOutput;
729+
base.OnPreviewKeyDown(e);
730+
if (!e.Handled && e.Key == Key.D && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
731+
enableFocusDebugOutput = !enableFocusDebugOutput;
725732

726-
StringWriter output = new StringWriter();
727-
output.WriteLine("Keyboard.FocusedElement = " + GetElementName(Keyboard.FocusedElement));
728-
output.WriteLine("ActiveContent = " + GetElementName(this.ActiveContent));
729-
output.WriteLine("ActiveViewContent = " + GetElementName(this.ActiveViewContent));
730-
output.WriteLine("ActiveWorkbenchWindow = " + GetElementName(this.ActiveWorkbenchWindow));
731-
((AvalonDockLayout)workbenchLayout).WriteState(output);
732-
LoggingService.Debug(output.ToString());
733-
e.Handled = true;
734-
}
735-
if (!e.Handled && e.Key == Key.F && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
736-
if (TextOptions.GetTextFormattingMode(this) == TextFormattingMode.Display)
737-
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
738-
else
739-
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
740-
SD.StatusBar.SetMessage("TextFormattingMode=" + TextOptions.GetTextFormattingMode(this));
741-
}
742-
if (!e.Handled && e.Key == Key.R && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
743-
switch (TextOptions.GetTextRenderingMode(this)) {
744-
case TextRenderingMode.Auto:
745-
case TextRenderingMode.ClearType:
746-
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Grayscale);
747-
break;
748-
case TextRenderingMode.Grayscale:
749-
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased);
750-
break;
751-
default:
752-
TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);
753-
break;
754-
}
755-
SD.StatusBar.SetMessage("TextRenderingMode=" + TextOptions.GetTextRenderingMode(this));
756-
}
757-
if (!e.Handled && e.Key == Key.G && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
758-
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
759-
SD.StatusBar.SetMessage("Total memory = " + (GC.GetTotalMemory(true) / 1024 / 1024f).ToString("f1") + " MB");
760-
}
733+
StringWriter output = new StringWriter();
734+
output.WriteLine("Keyboard.FocusedElement = " + GetElementName(Keyboard.FocusedElement));
735+
output.WriteLine("ActiveContent = " + GetElementName(this.ActiveContent));
736+
output.WriteLine("ActiveViewContent = " + GetElementName(this.ActiveViewContent));
737+
output.WriteLine("ActiveWorkbenchWindow = " + GetElementName(this.ActiveWorkbenchWindow));
738+
((AvalonDockLayout)workbenchLayout).WriteState(output);
739+
LoggingService.Debug(output.ToString());
740+
e.Handled = true;
741+
}
742+
if (!e.Handled && e.Key == Key.F && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
743+
if (TextOptions.GetTextFormattingMode(this) == TextFormattingMode.Display)
744+
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
745+
else
746+
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
747+
SD.StatusBar.SetMessage("TextFormattingMode=" + TextOptions.GetTextFormattingMode(this));
748+
}
749+
if (!e.Handled && e.Key == Key.R && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
750+
switch (TextOptions.GetTextRenderingMode(this)) {
751+
case TextRenderingMode.Auto:
752+
case TextRenderingMode.ClearType:
753+
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Grayscale);
754+
break;
755+
case TextRenderingMode.Grayscale:
756+
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased);
757+
break;
758+
default:
759+
TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);
760+
break;
761+
}
762+
SD.StatusBar.SetMessage("TextRenderingMode=" + TextOptions.GetTextRenderingMode(this));
763+
}
764+
if (!e.Handled && e.Key == Key.G && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
765+
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
766+
SD.StatusBar.SetMessage("Total memory = " + (GC.GetTotalMemory(true) / 1024 / 1024f).ToString("f1") + " MB");
767+
}
761768
}
762769
#endif
763770

0 commit comments

Comments
 (0)