private void OnDragDrop(object sender, DragEventArgs dragEventArgs, ICombineableFactory commandFactory) { //point they are dragged over var editor = ((Scintilla)sender); if (editor.ReadOnly) { return; } var clientPoint = editor.PointToClient(new Point(dragEventArgs.X, dragEventArgs.Y)); //get where the mouse is hovering over int pos = editor.CharPositionFromPoint(clientPoint.X, clientPoint.Y); var command = commandFactory.Create(dragEventArgs); if (command == null) { return; } //if it has a Form give it focus var form = editor.FindForm(); if (form != null) { form.Activate(); editor.Focus(); } editor.InsertText(pos, command.GetSqlString()); }
private void OnDragEnter(object sender, DragEventArgs dragEventArgs, ICombineableFactory commandFactory) { var command = commandFactory.Create(dragEventArgs); if (command != null) { dragEventArgs.Effect = DragDropEffects.Copy; } }
public SetSQLDialog(string originalSQL, ICombineableFactory commandFactory) { InitializeComponent(); _designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime); if (_designMode) //dont add the QueryEditor if we are in design time (visual studio) because it breaks { return; } QueryEditor = new ScintillaTextEditorFactory().Create(commandFactory); QueryEditor.Text = originalSQL; panel1.Controls.Add(QueryEditor); }
public DragDropProvider(ICombineableFactory commandFactory, ICommandExecutionFactory commandExecutionFactory, TreeListView treeView) { _commandFactory = commandFactory; _commandExecutionFactory = commandExecutionFactory; _treeView = treeView; _treeView.IsSimpleDragSource = false; _treeView.DragSource = this; _treeView.IsSimpleDropSink = true; ((SimpleDropSink)_treeView.DropSink).CanDrop += DragDropProvider_CanDrop; ((SimpleDropSink)_treeView.DropSink).Dropped += DragDropProvider_Dropped; _treeView.ModelCanDrop += ModelCanDrop; _treeView.ModelDropped += ModelDropped; }
/// <summary> /// Creates a new SQL (default) Scintilla editor with highlighting /// </summary> /// <param name="commandFactory">Unless your control is going to be 100% ReadOnly then you should supply an <see cref="ICombineableFactory"/> to allow dragging and /// dropping components into the window. The <see cref="ICombineableFactory"/> will decide whether the given object can be translated into an <see cref="ICombineToMakeCommand"/> and hence into a unique bit of SQL /// to add to the editor</param> /// <param name="language">Determines highlighting, options include mssql,csharp or null</param> /// <param name="syntaxHelper"></param> /// <param name="spellCheck"></param> /// <param name="lineNumbers"></param> /// <param name="currentDirectory"></param> /// <returns></returns> public Scintilla Create(ICombineableFactory commandFactory = null, SyntaxLanguage language = SyntaxLanguage.SQL, IQuerySyntaxHelper syntaxHelper = null, bool spellCheck = false, bool lineNumbers = true, string currentDirectory = null) { var toReturn = new Scintilla(); toReturn.Dock = DockStyle.Fill; toReturn.HScrollBar = true; toReturn.VScrollBar = true; if (lineNumbers) { toReturn.Margins[0].Width = 40; //allows display of line numbers } else { foreach (var margin in toReturn.Margins) { margin.Width = 0; } } toReturn.ClearCmdKey(Keys.Control | Keys.S); //prevent Ctrl+S displaying ascii code toReturn.ClearCmdKey(Keys.Control | Keys.R); //prevent Ctrl+R displaying ascii code toReturn.ClearCmdKey(Keys.Control | Keys.W); //prevent Ctrl+W displaying ascii code switch (language) { case SyntaxLanguage.SQL: SetSQLHighlighting(toReturn, syntaxHelper); break; case SyntaxLanguage.CSharp: SetCSharpHighlighting(toReturn); break; case SyntaxLanguage.XML: SetLexerEnumHighlighting(toReturn, Lexer.Xml); break; case SyntaxLanguage.LogFile: SetLexerEnumHighlighting(toReturn, Lexer.Verilog); break; } if (commandFactory != null) { toReturn.AllowDrop = true; toReturn.DragEnter += (s, e) => OnDragEnter(s, e, commandFactory); toReturn.DragDrop += (s, e) => OnDragDrop(s, e, commandFactory); } toReturn.WrapMode = (WrapMode)UserSettings.WrapMode; var scintillaMenu = new ScintillaMenu(toReturn, spellCheck); toReturn.ContextMenuStrip = scintillaMenu; try { if (spellCheck) { string aff; string dic; if (currentDirectory == null) { aff = "en_us.aff"; dic = "en_us.dic"; } else { aff = Path.Combine(currentDirectory, "en_us.aff"); dic = Path.Combine(currentDirectory, "en_us.dic"); } var hunspell = new Hunspell(aff, dic); DateTime lastCheckedSpelling = DateTime.MinValue; toReturn.KeyPress += (s, e) => { if (DateTime.Now.Subtract(lastCheckedSpelling) > TimeSpan.FromSeconds(10)) { lastCheckedSpelling = DateTime.Now; CheckSpelling((Scintilla)s, hunspell); } }; toReturn.Leave += (s, e) => CheckSpelling((Scintilla)s, hunspell); toReturn.Disposed += (s, e) => scintilla_Disposed(s, e, hunspell); scintillaMenu.Hunspell = hunspell; } } catch (Exception e) { if (!DictionaryExceptionShown) { ExceptionViewer.Show("Could not load dictionary", e); DictionaryExceptionShown = true; } } return(toReturn); }
/// <summary> /// Creates a new SQL (default) Scintilla editor with highlighting /// </summary> /// <param name="commandFactory">Unless your control is going to be 100% ReadOnly then you should supply an <see cref="ICombineableFactory"/> to allow dragging and /// dropping components into the window. The <see cref="ICombineableFactory"/> will decide whether the given object can be translated into an <see cref="ICombineToMakeCommand"/> and hence into a unique bit of SQL /// to add to the editor</param> /// <param name="language">Determines highlighting, options include mssql,csharp or null</param> /// <param name="syntaxHelper"></param> /// <param name="spellCheck"></param> /// <param name="lineNumbers"></param> /// <param name="currentDirectory"></param> /// <returns></returns> public Scintilla Create(ICombineableFactory commandFactory = null, string language = "mssql", IQuerySyntaxHelper syntaxHelper = null, bool spellCheck = false, bool lineNumbers = true, string currentDirectory = null) { var toReturn = new Scintilla(); toReturn.Dock = DockStyle.Fill; toReturn.HScrollBar = true; toReturn.VScrollBar = true; if (lineNumbers) { toReturn.Margins[0].Width = 40; //allows display of line numbers } else { foreach (var margin in toReturn.Margins) { margin.Width = 0; } } toReturn.ClearCmdKey(Keys.Control | Keys.S); //prevent Ctrl+S displaying ascii code toReturn.ClearCmdKey(Keys.Control | Keys.R); //prevent Ctrl+R displaying ascii code toReturn.ClearCmdKey(Keys.Control | Keys.W); //prevent Ctrl+W displaying ascii code if (language == "mssql") { SetSQLHighlighting(toReturn, syntaxHelper); } if (language == "csharp") { SetCSharpHighlighting(toReturn); } if (language == "xml") { SetLexerEnumHighlighting(toReturn, Lexer.Xml); } if (commandFactory != null) { toReturn.AllowDrop = true; toReturn.DragEnter += (s, e) => OnDragEnter(s, e, commandFactory); toReturn.DragDrop += (s, e) => OnDragDrop(s, e, commandFactory); } toReturn.WrapMode = (WrapMode)UserSettings.WrapMode; var scintillaMenu = new ScintillaMenu(toReturn); toReturn.ContextMenuStrip = scintillaMenu; try { if (spellCheck) { string aff; string dic; if (currentDirectory == null) { aff = "en_us.aff"; dic = "en_us.dic"; } else { aff = Path.Combine(currentDirectory, "en_us.aff"); dic = Path.Combine(currentDirectory, "en_us.dic"); } var hunspell = new Hunspell(aff, dic); toReturn.TextChanged += (s, e) => scintilla_TextChanged(s, e, hunspell); toReturn.Disposed += (s, e) => scintilla_Disposed(s, e, hunspell); scintillaMenu.Hunspell = hunspell; } } catch (Exception e) { if (!DictionaryExceptionShown) { ExceptionViewer.Show("Could not load dictionary", e); DictionaryExceptionShown = true; } } return(toReturn); }