notify before a context menu is to be displayed on the Document Explorer treeview

This commit is contained in:
Michael Becker 2020-06-19 16:42:35 -04:00
parent 1eed5e83c2
commit 03565555f7
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
5 changed files with 74 additions and 0 deletions

View File

@ -19,6 +19,8 @@
// 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.Controls;
namespace UniversalEditor.UserInterface
{
public class EditorDocumentExplorer
@ -31,5 +33,24 @@ namespace UniversalEditor.UserInterface
}
public EditorDocumentExplorerNode.EditorDocumentExplorerNodeCollection Nodes { get; private set; } = null;
public EditorDocumentExplorerNode SelectedNode
{
get
{
ListView lv = ((MainWindow)HostApplication.CurrentWindow).DocumentExplorerPanel.ListView;
if (lv.SelectedRows.Count > 0)
{
return lv.SelectedRows[0].GetExtraData<EditorDocumentExplorerNode>("node");
}
return null;
}
}
public event EditorDocumentExplorerBeforeContextMenuEventHandler BeforeContextMenu;
internal void FireBeforeContextMenu(EditorDocumentExplorerBeforeContextMenuEventArgs e)
{
BeforeContextMenu?.Invoke(this, e);
}
}
}

View File

@ -0,0 +1,35 @@
//
// EditorDocumentExplorerBeforeContextMenuEvent.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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;
namespace UniversalEditor.UserInterface
{
public class EditorDocumentExplorerBeforeContextMenuEventArgs : EventArgs
{
public EditorDocumentExplorerNode Node { get; private set; }
public string ContextMenuCommandID { get; set; } = null;
public EditorDocumentExplorerBeforeContextMenuEventArgs(EditorDocumentExplorerNode node)
{
Node = node;
}
}
public delegate void EditorDocumentExplorerBeforeContextMenuEventHandler(object sender, EditorDocumentExplorerBeforeContextMenuEventArgs e);
}

View File

@ -40,6 +40,7 @@ namespace UniversalEditor.UserInterface
private SolutionExplorerPanel pnlSolutionExplorer = new SolutionExplorerPanel();
private PropertyListPanel pnlPropertyList = new PropertyListPanel();
private DocumentExplorerPanel pnlDocumentExplorer = new DocumentExplorerPanel();
public DocumentExplorerPanel DocumentExplorerPanel { get { return pnlDocumentExplorer; } }
private RibbonTab LoadRibbonBar(CommandBar cb)
{

View File

@ -8,12 +8,15 @@ namespace UniversalEditor.UserInterface.Panels
public class DocumentExplorerPanel : Panel
{
private ListView lv = null;
public ListView ListView { get { return lv; } }
private DefaultTreeModel tm = null;
public DocumentExplorerPanel()
{
Layout = new BoxLayout(Orientation.Vertical);
lv = new ListView();
lv.BeforeContextMenu += lv_BeforeContextMenu;
lv.SelectionChanged += lv_SelectionChanged;
tm = new DefaultTreeModel(new Type[] { typeof(string) });
@ -24,6 +27,19 @@ namespace UniversalEditor.UserInterface.Panels
Controls.Add(lv, new BoxLayout.Constraints(true, true));
}
private void lv_BeforeContextMenu(object sender, EventArgs e)
{
if (lv.SelectedRows.Count == 0)
return;
EditorDocumentExplorerNode node = lv.SelectedRows[0].GetExtraData<EditorDocumentExplorerNode>("node");
EditorDocumentExplorerBeforeContextMenuEventArgs ee = new EditorDocumentExplorerBeforeContextMenuEventArgs(node);
CurrentEditor.DocumentExplorer.FireBeforeContextMenu(ee);
lv.ContextMenuCommandID = ee.ContextMenuCommandID;
}
private void lv_SelectionChanged(object sender, EventArgs e)
{
if (lv.SelectedRows.Count == 0)

View File

@ -132,6 +132,7 @@
<Compile Include="EditorDocumentExplorerNode.cs" />
<Compile Include="EditorDocumentExplorerSelectionChangedEvent.cs" />
<Compile Include="Editors\Markup\MarkupEditor.cs" />
<Compile Include="EditorDocumentExplorerBeforeContextMenuEvent.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">