From 41136a6a1058a1bc3d745a3de751d5d96c5bc420 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Fri, 20 Nov 2020 22:17:41 -0500 Subject: [PATCH] start to move some common stuff out of UE and into MBS.Framework.UserInterface --- .../Dialogs/GenericBrowserPopup.Designer.cs | 83 -------------- .../Dialogs/GenericBrowserPopup.cs | 108 +++--------------- .../UniversalEditor.UserInterface.csproj | 1 - 3 files changed, 17 insertions(+), 175 deletions(-) delete mode 100644 Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.Designer.cs diff --git a/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.Designer.cs b/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.Designer.cs deleted file mode 100644 index c7a77ee6..00000000 --- a/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.Designer.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// GenericBrowserPopup.Designer.cs -// -// Author: -// Michael Becker -// -// Copyright (c) 2019 -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -using System; -using MBS.Framework.UserInterface; -using MBS.Framework.UserInterface.Controls; -using MBS.Framework.UserInterface.Layouts; -using MBS.Framework.Drawing; -using MBS.Framework.UserInterface.Controls.ListView; - -namespace UniversalEditor.UserInterface.Dialogs -{ - partial class GenericBrowserPopup - where TObj : class, References - where TRef : class, ReferencedBy - { - private Button cmdReset = null; - private Button cmdNone = null; - private TextBox txtSearch = null; - private ListViewControl lv = null; - - private Container ctSearchAndShowAll = null; - private DefaultTreeModel tm = null; - - private void InitializeComponent() - { - this.Decorated = false; - this.Layout = new BoxLayout(Orientation.Vertical); - - - this.ctSearchAndShowAll = new Container(); - this.ctSearchAndShowAll.Layout = new BoxLayout(Orientation.Horizontal); - - this.txtSearch = new TextBox(); - this.txtSearch.Changed += txtSearch_Changed; - this.txtSearch.KeyDown += txtSearch_KeyDown; - this.ctSearchAndShowAll.Controls.Add(this.txtSearch, new BoxLayout.Constraints(true, true)); - - this.cmdReset = new Button(); - this.cmdReset.Text = "_Reset"; - this.cmdReset.Click += cmdReset_Click; - this.ctSearchAndShowAll.Controls.Add(this.cmdReset, new BoxLayout.Constraints(false, false)); - - this.cmdNone = new Button(); - this.cmdNone.Text = "_None"; - this.cmdNone.Click += cmdNone_Click; - this.ctSearchAndShowAll.Controls.Add(this.cmdNone, new BoxLayout.Constraints(false, false)); - - this.Controls.Add(ctSearchAndShowAll, new BoxLayout.Constraints(false, true)); - - this.tm = new DefaultTreeModel(new Type[] { typeof(string), typeof(string) }); - - this.lv = new ListViewControl(); - lv.Columns.Add(new ListViewColumnText(tm.Columns[0], "Name")); - lv.Columns.Add(new ListViewColumnText(tm.Columns[1], "Description")); - lv.RowActivated += this.lv_RowActivated; - this.lv.Model = tm; - this.Controls.Add(this.lv, new BoxLayout.Constraints(true, true)); - - this.MinimumSize = new Dimension2D (300, 200); - - StartPosition = WindowStartPosition.Manual; - } - - } -} diff --git a/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.cs b/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.cs index fa63a3fd..bbe66686 100644 --- a/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.cs +++ b/Libraries/UniversalEditor.UserInterface/Dialogs/GenericBrowserPopup.cs @@ -25,55 +25,22 @@ using System.Collections.ObjectModel; using MBS.Framework.UserInterface; using MBS.Framework.UserInterface.Controls; using MBS.Framework.UserInterface.Controls.ListView; +using MBS.Framework.UserInterface.Dialogs; using MBS.Framework.UserInterface.Input.Keyboard; namespace UniversalEditor.UserInterface.Dialogs { - public partial class GenericBrowserPopup : CustomDialog + public class GenericBrowserPopup : SearchableDropdownListDialog where TObj : class, References where TRef : class, ReferencedBy { - public GenericBrowserPopup() - { - this.InitializeComponent(); - } - - public event EventHandler SelectionChanged; - - private bool mvarAutoClose = true; - public bool AutoClose { get { return mvarAutoClose; } set { mvarAutoClose = value; } } - /* - protected override void OnDeactivate(EventArgs e) - { - base.OnDeactivate(e); - if (mvarAutoClose) this.Close(); - } - */ public Collection AvailableObjects { get; } = new Collection(); public TObj SelectedObject { get; set; } = default(TObj); - /* - protected override void OnShown(EventArgs e) + protected override void UpdateSearchInternal(string query) { - base.OnShown(e); - UpdateSearch(); - } - */ + base.UpdateSearchInternal(query); - protected override void OnCreated(EventArgs e) - { - base.OnCreated(e); - UpdateSearch(); - } - - private void txtSearch_Changed(object sender, EventArgs e) - { - UpdateSearch(); - } - - private void UpdateSearch() - { - tm.Rows.Clear(); foreach (TRef item in AvailableObjects) { bool itemShouldFilter = false; @@ -81,89 +48,48 @@ namespace UniversalEditor.UserInterface.Dialogs foreach (string detail in details) { if (detail == null) continue; - if (detail.ToLower().Trim().Contains(txtSearch.Text.ToLower().Trim())) + if (detail.ToLower().Trim().Contains(query.ToLower().Trim())) { itemShouldFilter = true; break; } } - if (String.IsNullOrEmpty(txtSearch.Text.Trim()) || itemShouldFilter) + if (String.IsNullOrEmpty(query.Trim()) || itemShouldFilter) { AddObjectToList(item); } } - - if (tm.Rows.Count == 1) - { - lv.SelectedRows.Clear(); - lv.SelectedRows.Add(tm.Rows[0]); - } - // lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } private void AddObjectToList(TRef itmr) { string[] details = itmr.GetDetails(); List columns = new List(); - + for (int i = 0; i < details.Length; i++) { string str = details[i]; if (String.IsNullOrEmpty(str)) str = String.Empty; - - columns.Add(new TreeModelRowColumn(tm.Columns[i], str)); + + columns.Add(CreateColumn(i, str)); } - TreeModelRow lvi = new TreeModelRow(columns.ToArray()); + TreeModelRow lvi = new TreeModelRow(columns.ToArray()); lvi.SetExtraData("TRef", itmr); - tm.Rows.Add(lvi); + AddRow(lvi); } - private void lv_RowActivated(object sender, ListViewRowActivatedEventArgs e) + protected override void SelectRow(TreeModelRow row) { - // if (lv.SelectedItems.Count != 1) return; - - SelectedObject = e.Row.GetExtraData("TRef")?.Create(); - SelectionChanged?.Invoke(this, e); - - DialogResult = DialogResult.OK; - Close(); - } - - private void txtSearch_KeyDown(object sender, KeyEventArgs e) - { - if (e.Key == KeyboardKey.Enter) + base.SelectRow(row); + if (row == null) { - e.Cancel = true; - if (lv.SelectedRows.Count != 1) return; - - SelectedObject = lv.SelectedRows[0].GetExtraData("TRef")?.Create(); - if (SelectionChanged != null) SelectionChanged(this, e); - - Close(); + SelectedObject = null; } - else if (e.Key == KeyboardKey.Escape) + else { - e.Cancel = true; - - // already handled by GTK? but what about other platforms - Close(); + SelectedObject = row.GetExtraData("TRef")?.Create(); } } - - public event EventHandler ResetList; - - private void cmdReset_Click(object sender, EventArgs e) - { - ResetList?.Invoke(this, e); - UpdateSearch(); - } - - private void cmdNone_Click(object sender, EventArgs e) - { - SelectedObject = null; - SelectionChanged?.Invoke(this, e); - Close(); - } } } diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index a890f830..c361d398 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -96,7 +96,6 @@ -