示例#1
0
文件: Completion.cs 项目: neiz/Wish
 public CommandResult OnPreviewKeyDown(WishArgs args)
 {
     switch (args.Key)
     {
         case Key.Enter:
             return new CommandResult { State = Common.State.Tabbing, FullyProcessed = true};
         case Key.Tab:
             return new CommandResult { State = Common.State.Tabbing, FullyProcessed = true};
         case Key.Oem5:
             return new CommandResult { State = Common.State.Tabbing, FullyProcessed = true};
         case Key.Escape:
             _wishModel.CloseCompletionWindow();
             break;
     }
     return new CommandResult {Handled = true, FullyProcessed = true};
 }
示例#2
0
文件: WishModel.cs 项目: neiz/Wish
 public CommandResult Complete(WishArgs wishArgs)
 {
     var command = _repl.Read(wishArgs.TextEditor.Text);
     var args = command.Arguments.ToList();
     string completionTarget;
     List<string> completions;
     if(args.Any())
     {
         var arg = args.Last();
         completionTarget = arg.PartialPath.CompletionTarget;
         completions = command.Complete().ToList();
     }
     else
     {
         completionTarget = command.Function.Name;
         completions = command.Function.Complete().ToList();
     }
     if(completions.Count() == 0) return new CommandResult { FullyProcessed = true, Handled = true };
     _completionWindow = new CompletionWindow(wishArgs.TextEditor.TextArea)
                                      {
                                          SizeToContent = SizeToContent.WidthAndHeight,
                                          MinWidth = 150
                                      };
     var completionData = _completionWindow.CompletionList.CompletionData;
     foreach (var completion in completions)
     {
         completionData.Add(new CompletionData(completionTarget, completion));
     }
     if (completionData.Count == 0) return new CommandResult { FullyProcessed = true, Handled = true };
     _completionWindow.Show();
     _completionWindow.Closed += delegate
                                     {
                                         wishArgs.OnClosed.Invoke();
                                         _completionWindow = null;
                                     };
     return new CommandResult{ FullyProcessed = true, Handled = false, State = Common.State.Tabbing  };
 }
示例#3
0
 protected override void OnPreviewKeyDown(KeyEventArgs e)
 {
     foreach (var inputBinding in from InputBinding inputBinding in InputBindings
                                  let keyGesture = inputBinding.Gesture as KeyGesture
                                  where (keyGesture != null && keyGesture.Key == e.Key) && keyGesture.Modifiers == Keyboard.Modifiers
                                  where inputBinding.Command != null
                                  select inputBinding)
     {
         inputBinding.Command.Execute(0);
         e.Handled = true;
     }
     foreach (var command in
         (from CommandBinding cb in CommandBindings select cb.Command)
             .OfType<RoutedCommand>()
             .Where(command => (from InputGesture inputGesture in command.InputGestures select inputGesture as KeyGesture)
                                 .Any(keyGesture => (keyGesture != null && keyGesture.Key == e.Key)
                                     && keyGesture.Modifiers == Keyboard.Modifiers)))
     {
         command.Execute(0, this);
         e.Handled = true;
     }
     if (e.KeyboardDevice.Modifiers.Any()) return;
     var args = new WishArgs
                {
                    TextEditor = textEditor,
                    OnClosed = StateNormal,
                    Execute = Execute,
                    Key = e.Key,
                    WorkingDirectory = Title
                };
     var result = _state.OnPreviewKeyDown(args);
     if(result.IsExit)
     {
         Exit();
         return;
     }
     e.Handled = result.Handled;
     _state = EnumToState(result.State);
     if (result.FullyProcessed) return;
     ProcessCommandResult(result);
 }
示例#4
0
 private void Process(string text)
 {
     textEditor.Text += text;
     var args = new WishArgs {Key = Key.Enter, WorkingDirectory = Title, TextEditor = textEditor};
     var result = _wishModel.Raise(args);
     var state = result.State;
     switch (state)
     {
         case Common.State.Normal:
             _state = new Normal(_wishModel);
             break;
         case Common.State.Tabbing:
             _state = new Completion(_wishModel);
             break;
     }
     ClearPopups();
     textEditor.Focus();
     ProcessCommandResult(result);
 }
示例#5
0
 private void ExecuteControlP(object sender, ExecutedRoutedEventArgs e)
 {
     var args = new WishArgs {Key = Key.Up, WorkingDirectory = Title, TextEditor = textEditor};
     var result = _wishModel.Raise(args);
     ClearPopups();
     textEditor.Focus();
     ProcessCommandResult(result);
 }
示例#6
0
 void Execute()
 {
     var args = new WishArgs {Key = Key.Enter, WorkingDirectory = Title, TextEditor = textEditor};
     var result = _wishModel.Raise(args);
     ClearPopups();
     textEditor.Focus();
     ProcessCommandResult(result);
 }
示例#7
0
文件: WishModel.cs 项目: neiz/Wish
 public CommandResult Raise(WishArgs wishArgs)
 {
     var text = wishArgs.TextEditor.Text;
     switch (wishArgs.Key)
     {
         case Key.Enter: return Execute(text, wishArgs.WorkingDirectory);
         case Key.Up: return _repl.Up(text);
         case Key.Down: return _repl.Down(text);
     }
     return new CommandResult { FullyProcessed = true };
 }
示例#8
0
文件: Normal.cs 项目: neiz/Wish
 public CommandResult OnPreviewKeyDown(WishArgs args)
 {
     return args.Key.Equals(Key.Tab)
                      ? _wishModel.Complete(args)
                      : _wishModel.Raise(args);
 }