start to move some common stuff out of UE and into MBS.Framework.UserInterface
This commit is contained in:
parent
9c7399461d
commit
41136a6a10
@ -1,83 +0,0 @@
|
||||
//
|
||||
// GenericBrowserPopup.Designer.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
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<TObj, TRef>
|
||||
where TObj : class, References<TRef>
|
||||
where TRef : class, ReferencedBy<TObj>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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<TObj, TRef> : CustomDialog
|
||||
public class GenericBrowserPopup<TObj, TRef> : SearchableDropdownListDialog
|
||||
where TObj : class, References<TRef>
|
||||
where TRef : class, ReferencedBy<TObj>
|
||||
{
|
||||
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<TRef> AvailableObjects { get; } = new Collection<TRef>();
|
||||
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<TreeModelRowColumn> columns = new List<TreeModelRowColumn>();
|
||||
|
||||
|
||||
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>("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>("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>("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>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,6 @@
|
||||
<Compile Include="Editors\PropertyList\PropertyListEditor.cs" />
|
||||
<Compile Include="Dialogs\DocumentPropertiesDialog.cs" />
|
||||
<Compile Include="Dialogs\GenericBrowserPopup.cs" />
|
||||
<Compile Include="Dialogs\GenericBrowserPopup.Designer.cs" />
|
||||
<Compile Include="Panels\StartPagePanel.cs" />
|
||||
<Compile Include="Dialogs\DocumentPropertiesDialogMode.cs" />
|
||||
<Compile Include="Dialogs\DocumentPropertiesDialogV2.cs" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user