public override void Setup() { Win.Title = this.GetName(); Win.Y = 1; // menu Win.Height = Dim.Fill(1); // status bar Top.LayoutSubviews(); var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { miWrap = new MenuItem("_Word Wrap", "", () => WordWrap()) { CheckType = MenuItemCheckStyle.Checked }, new MenuItem("_Quit", "", () => Quit()), }) }); Top.Add(menu); textView = new SqlTextView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(1), }; textView.Init(); textView.Text = "SELECT TOP 100 * \nfrom\n MyDb.dbo.Biochemistry;"; Win.Add(textView); var statusBar = new StatusBar(new StatusItem [] { new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Quit()), }); Top.Add(statusBar); }
public ConsoleGuiSqlEditor(IBasicActivateItems activator, IViewSQLAndResultsCollection collection) { this.Activator = activator; this._collection = collection; Modal = true; ColorScheme = ConsoleMainWindow.ColorScheme; // Tabs (query and results) TabView = new TabView() { Width = Dim.Fill(), Height = Dim.Fill(), Y = 1 }; textView = new SqlTextView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), Text = _orignalSql = collection.GetSql().Replace("\r\n", "\n").Replace("\t", " ") }; textView.AllowsTab = false; TabView.AddTab(queryTab = new Tab("Query", textView), true); tableView = new TableView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; tableView.Style.AlwaysShowHeaders = true; tableView.CellActivated += TableView_CellActivated; TabView.AddTab(resultTab = new Tab("Results", tableView), false); Add(TabView); // Buttons on top of control _btnRunOrCancel = new Button("Run") { X = 0, Y = 0, }; _btnRunOrCancel.Clicked += () => RunOrCancel(); Add(_btnRunOrCancel); var resetSql = new Button("Reset Sq_l") { X = Pos.Right(_btnRunOrCancel) + 1 }; resetSql.Clicked += () => ResetSql(); Add(resetSql); var clearSql = new Button("Clear S_ql") { X = Pos.Right(resetSql) + 1, }; clearSql.Clicked += () => ClearSql(); Add(clearSql); var lblTimeout = new Label("Timeout:") { X = Pos.Right(clearSql) + 1, }; Add(lblTimeout); var tbTimeout = new TextField(_timeout.ToString()) { X = Pos.Right(lblTimeout), Width = 5 }; tbTimeout.TextChanged += TbTimeout_TextChanged; Add(tbTimeout); var btnSave = new Button("Save") { X = Pos.Right(tbTimeout) + 1, }; btnSave.Clicked += () => Save(); Add(btnSave); var btnClose = new Button("Clos_e") { X = Pos.Right(btnSave) + 1, }; btnClose.Clicked += () => { Application.RequestStop(); }; Add(btnClose); var auto = new AutoCompleteProvider(collection.GetQuerySyntaxHelper()); collection.AdjustAutocomplete(auto); var bits = auto.Items.SelectMany(auto.GetBits).OrderBy(a => a).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList(); textView.Autocomplete.AllSuggestions = bits; textView.Autocomplete.MaxWidth = 40; }