Browse Source

WpfWorkbench.OnDrop: don't show dialogs during the drop event; use Dispatcher.BeginInvoke instead.

pull/403/head
Daniel Grunwald 12 years ago
parent
commit
a441bb9f9f
  1. 3
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpResolver.cs
  2. 2
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs
  3. 121
      src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

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

@ -1694,8 +1694,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
case NameLookupMode.Type: case NameLookupMode.Type:
case NameLookupMode.TypeInUsingDeclaration: case NameLookupMode.TypeInUsingDeclaration:
case NameLookupMode.BaseTypeReference: case NameLookupMode.BaseTypeReference:
result = lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType); return lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType);
break;
default: default:
throw new NotSupportedException("Invalid value for NameLookupMode"); throw new NotSupportedException("Invalid value for NameLookupMode");
} }

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

@ -648,6 +648,7 @@ namespace ICSharpCode.Core
static FileOperationResult ObservedSaveHandleError(Exception e, NamedFileOperationDelegate saveFileAs, FileName fileName, string message, FileErrorPolicy policy) static FileOperationResult ObservedSaveHandleError(Exception e, NamedFileOperationDelegate saveFileAs, FileName fileName, string message, FileErrorPolicy policy)
{ {
message = message + Environment.NewLine + Environment.NewLine + e.Message;
var messageService = ServiceSingleton.GetRequiredService<IMessageService>(); var messageService = ServiceSingleton.GetRequiredService<IMessageService>();
switch (policy) { switch (policy) {
case FileErrorPolicy.Inform: case FileErrorPolicy.Inform:
@ -693,6 +694,7 @@ namespace ICSharpCode.Core
static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy) static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy)
{ {
message = message + Environment.NewLine + Environment.NewLine + e.Message;
var messageService = ServiceSingleton.GetRequiredService<IMessageService>(); var messageService = ServiceSingleton.GetRequiredService<IMessageService>();
switch (policy) { switch (policy) {
case FileErrorPolicy.Inform: case FileErrorPolicy.Inform:

121
src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
// Set WindowState after PresentationSource is initialized, because now bounds and location are properly set. // Set WindowState after PresentationSource is initialized, because now bounds and location are properly set.
this.WindowState = lastNonMinimizedWindowState; this.WindowState = lastNonMinimizedWindowState;
} }
void SetBounds(Rect bounds) void SetBounds(Rect bounds)
{ {
this.Left = bounds.Left; this.Left = bounds.Left;
@ -174,7 +174,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
// keep a reference to the event handler to prevent it from being garbage collected // keep a reference to the event handler to prevent it from being garbage collected
// (CommandManager.RequerySuggested only keeps weak references to the event handlers) // (CommandManager.RequerySuggested only keeps weak references to the event handlers)
EventHandler requerySuggestedEventHandler; EventHandler requerySuggestedEventHandler;
void CommandManager_RequerySuggested(object sender, EventArgs e) void CommandManager_RequerySuggested(object sender, EventArgs e)
{ {
UpdateMenu(); UpdateMenu();
@ -270,9 +270,9 @@ namespace ICSharpCode.SharpDevelop.Workbench
get { get {
SD.MainThread.VerifyAccess(); SD.MainThread.VerifyAccess();
return (from window in WorkbenchWindowCollection return (from window in WorkbenchWindowCollection
where window.ViewContents.Count > 0 where window.ViewContents.Count > 0
select window.ViewContents[0] select window.ViewContents[0]
).ToList().AsReadOnly(); ).ToList().AsReadOnly();
} }
} }
@ -319,7 +319,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
} }
} }
} }
void WorkbenchWindowActiveViewContentChanged(object sender, EventArgs e) void WorkbenchWindowActiveViewContentChanged(object sender, EventArgs e)
{ {
if (workbenchLayout != null) { if (workbenchLayout != null) {
@ -671,22 +671,29 @@ namespace ICSharpCode.SharpDevelop.Workbench
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files == null) if (files == null)
return; return;
foreach (string file in files) { // Handle opening the files outside the drop event, so that the drag source doesn't think
if (File.Exists(file)) { // the operation is still in progress while we're showing a "file cannot be opened" error message.
var fileName = FileName.Create(file); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<string[]>(HandleDrop), files);
if (SD.ProjectService.IsSolutionOrProjectFile(fileName)) {
SD.ProjectService.OpenSolutionOrProject(fileName);
} else {
SD.FileService.OpenFile(fileName);
}
}
}
} }
} catch (Exception ex) { } catch (Exception ex) {
MessageService.ShowException(ex); MessageService.ShowException(ex);
} }
} }
void HandleDrop(string[] files)
{
foreach (string file in files) {
if (File.Exists(file)) {
var fileName = FileName.Create(file);
if (SD.ProjectService.IsSolutionOrProjectFile(fileName)) {
SD.ProjectService.OpenSolutionOrProject(fileName);
} else {
SD.FileService.OpenFile(fileName);
}
}
}
}
void InitFocusTrackingEvents() void InitFocusTrackingEvents()
{ {
#if DEBUG #if DEBUG
@ -700,7 +707,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
{ {
#if DEBUG #if DEBUG
if (enableFocusDebugOutput) if (enableFocusDebugOutput)
LoggingService.DebugFormatted(format, args); LoggingService.DebugFormatted(format, args);
#endif #endif
} }
@ -709,55 +716,55 @@ namespace ICSharpCode.SharpDevelop.Workbench
void WpfWorkbench_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) void WpfWorkbench_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{ {
FocusDebug("GotKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus); FocusDebug("GotKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
} }
void WpfWorkbench_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) void WpfWorkbench_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{ {
FocusDebug("LostKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus); FocusDebug("LostKeyboardFocus: oldFocus={0}, newFocus={1}", e.OldFocus, e.NewFocus);
} }
protected override void OnPreviewKeyDown(KeyEventArgs e) protected override void OnPreviewKeyDown(KeyEventArgs e)
{ {
base.OnPreviewKeyDown(e); base.OnPreviewKeyDown(e);
if (!e.Handled && e.Key == Key.D && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) { if (!e.Handled && e.Key == Key.D && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
enableFocusDebugOutput = !enableFocusDebugOutput; enableFocusDebugOutput = !enableFocusDebugOutput;
StringWriter output = new StringWriter(); StringWriter output = new StringWriter();
output.WriteLine("Keyboard.FocusedElement = " + GetElementName(Keyboard.FocusedElement)); output.WriteLine("Keyboard.FocusedElement = " + GetElementName(Keyboard.FocusedElement));
output.WriteLine("ActiveContent = " + GetElementName(this.ActiveContent)); output.WriteLine("ActiveContent = " + GetElementName(this.ActiveContent));
output.WriteLine("ActiveViewContent = " + GetElementName(this.ActiveViewContent)); output.WriteLine("ActiveViewContent = " + GetElementName(this.ActiveViewContent));
output.WriteLine("ActiveWorkbenchWindow = " + GetElementName(this.ActiveWorkbenchWindow)); output.WriteLine("ActiveWorkbenchWindow = " + GetElementName(this.ActiveWorkbenchWindow));
((AvalonDockLayout)workbenchLayout).WriteState(output); ((AvalonDockLayout)workbenchLayout).WriteState(output);
LoggingService.Debug(output.ToString()); LoggingService.Debug(output.ToString());
e.Handled = true; e.Handled = true;
} }
if (!e.Handled && e.Key == Key.F && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) { if (!e.Handled && e.Key == Key.F && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
if (TextOptions.GetTextFormattingMode(this) == TextFormattingMode.Display) if (TextOptions.GetTextFormattingMode(this) == TextFormattingMode.Display)
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal); TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
else else
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display); TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
SD.StatusBar.SetMessage("TextFormattingMode=" + TextOptions.GetTextFormattingMode(this)); SD.StatusBar.SetMessage("TextFormattingMode=" + TextOptions.GetTextFormattingMode(this));
} }
if (!e.Handled && e.Key == Key.R && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) { if (!e.Handled && e.Key == Key.R && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
switch (TextOptions.GetTextRenderingMode(this)) { switch (TextOptions.GetTextRenderingMode(this)) {
case TextRenderingMode.Auto: case TextRenderingMode.Auto:
case TextRenderingMode.ClearType: case TextRenderingMode.ClearType:
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Grayscale); TextOptions.SetTextRenderingMode(this, TextRenderingMode.Grayscale);
break; break;
case TextRenderingMode.Grayscale: case TextRenderingMode.Grayscale:
TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased); TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased);
break; break;
default: default:
TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType); TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);
break; break;
} }
SD.StatusBar.SetMessage("TextRenderingMode=" + TextOptions.GetTextRenderingMode(this)); SD.StatusBar.SetMessage("TextRenderingMode=" + TextOptions.GetTextRenderingMode(this));
} }
if (!e.Handled && e.Key == Key.G && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) { if (!e.Handled && e.Key == Key.G && e.KeyboardDevice.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)) {
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
SD.StatusBar.SetMessage("Total memory = " + (GC.GetTotalMemory(true) / 1024 / 1024f).ToString("f1") + " MB"); SD.StatusBar.SetMessage("Total memory = " + (GC.GetTotalMemory(true) / 1024 / 1024f).ToString("f1") + " MB");
} }
} }
#endif #endif

Loading…
Cancel
Save