Browse Source

first attempt to fix focus problems in inline refactor dialogs

pull/1/head
Siegfried Pammer 16 years ago
parent
commit
f9ef8ccf21
  1. 14
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/AbstractInlineRefactorDialog.cs
  2. 23
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs

14
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/AbstractInlineRefactorDialog.cs

@ -9,9 +9,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Snippets; using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
@ -37,9 +38,16 @@ namespace SharpRefactoring.Gui
this.editor = editor; this.editor = editor;
this.context = context; this.context = context;
this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), editor.Document.Text, editor.Caret.Offset); this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), editor.Document.Text, anchor.Offset);
this.Background = SystemColors.ControlBrush; this.Background = SystemColors.ControlBrush;
FocusFirstElement();
}
protected virtual void FocusFirstElement()
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate { this.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); }));
} }
protected abstract string GenerateCode(LanguageProperties language, IClass currentClass); protected abstract string GenerateCode(LanguageProperties language, IClass currentClass);
@ -55,7 +63,7 @@ namespace SharpRefactoring.Gui
if (parseInfo != null) { if (parseInfo != null) {
LanguageProperties language = parseInfo.CompilationUnit.Language; LanguageProperties language = parseInfo.CompilationUnit.Language;
IClass current = parseInfo.CompilationUnit.GetInnermostClass(editor.Caret.Line, editor.Caret.Column); IClass current = parseInfo.CompilationUnit.GetInnermostClass(anchor.Line, anchor.Column);
// Generate code could modify the document. // Generate code could modify the document.
// So read anchor.Offset after code generation. // So read anchor.Offset after code generation.

23
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/InsertCtorDialog.xaml.cs

@ -11,7 +11,10 @@ using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Snippets; using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
@ -37,6 +40,8 @@ namespace SharpRefactoring.Gui
// "Add check for null" is checked for every item by default // "Add check for null" is checked for every item by default
//Select(w => { if(w.IsNullable) w.AddCheckForNull = true; return w; }). //Select(w => { if(w.IsNullable) w.AddCheckForNull = true; return w; }).
.ToList(); .ToList();
FocusFirstElement();
} }
IEnumerable<CtorParamWrapper> CreateCtorParams(IEnumerable<IField> fields, IEnumerable<IProperty> properties) IEnumerable<CtorParamWrapper> CreateCtorParams(IEnumerable<IField> fields, IEnumerable<IProperty> properties)
@ -165,6 +170,24 @@ namespace SharpRefactoring.Gui
varList.ItemsSource = paramList.OrderBy(p => p.Index); varList.ItemsSource = paramList.OrderBy(p => p.Index);
varList.SelectedIndex = selection + 1; varList.SelectedIndex = selection + 1;
} }
protected override void FocusFirstElement()
{
Dispatcher.BeginInvoke((Action)TryFocusAndSelectItem, DispatcherPriority.Background);
}
void TryFocusAndSelectItem()
{
object ctorParamWrapper = varList.Items.GetItemAt(0);
if (ctorParamWrapper != null) {
ListBoxItem item = (ListBoxItem)varList.ItemContainerGenerator.ContainerFromItem(ctorParamWrapper);
item.Focus();
varList.ScrollIntoView(item);
varList.SelectedItem = item;
Keyboard.Focus(item);
}
}
} }
[ValueConversion(typeof(int), typeof(bool))] [ValueConversion(typeof(int), typeof(bool))]

Loading…
Cancel
Save