ShareX/HelpersLib/Controls/TabToTreeView.cs

135 lines
3.9 KiB
C#
Raw Normal View History

#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (C) 2007-2014 ShareX Developers
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-06 15:06:33 +13:00
using System.ComponentModel;
using System.Windows.Forms;
namespace HelpersLib
{
public partial class TabToTreeView : UserControl
{
private TabControl mainTabControl;
2014-12-06 15:06:33 +13:00
[Browsable(false)]
public TabControl MainTabControl
{
get
{
return mainTabControl;
}
set
{
mainTabControl = value;
FillTreeView(tvMain.Nodes, mainTabControl);
tvMain.ExpandAll();
}
}
private int treeViewSize;
public int TreeViewSize
{
get
{
return treeViewSize;
}
set
{
treeViewSize = value;
scMain.SplitterDistance = treeViewSize;
}
}
public ImageList ImageList
{
get
{
return tvMain.ImageList;
}
set
{
tvMain.ImageList = value;
}
}
public TabToTreeView()
{
InitializeComponent();
TreeViewSize = 150;
}
2014-12-06 15:06:33 +13:00
private void FillTreeView(TreeNodeCollection nodeCollection, TabControl tab, TreeNode parent = null)
{
if (nodeCollection != null && tab != null)
{
foreach (TabPage tabPage in tab.TabPages)
{
2014-12-06 15:06:33 +13:00
if (parent != null && tabPage.Text == "{Parent}")
{
parent.Tag = tabPage;
continue;
}
TreeNode treeNode = new TreeNode(tabPage.Text);
if (!string.IsNullOrEmpty(tabPage.ImageKey))
{
treeNode.ImageKey = treeNode.SelectedImageKey = tabPage.ImageKey;
}
treeNode.Tag = tabPage;
nodeCollection.Add(treeNode);
foreach (Control control in tabPage.Controls)
{
if (control is TabControl)
{
2014-12-06 15:06:33 +13:00
FillTreeView(treeNode.Nodes, control as TabControl, treeNode);
break;
}
}
}
}
}
private void tvMain_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
{
e.Cancel = true;
}
private void tvMain_AfterSelect(object sender, TreeViewEventArgs e)
{
TabPage tabPage = e.Node.Tag as TabPage;
if (tabPage != null)
{
2014-12-06 15:06:33 +13:00
tvMain.BeginUpdate();
tcMain.Visible = true;
tcMain.TabPages.Clear();
tcMain.TabPages.Add(tabPage);
2014-12-06 15:06:33 +13:00
tvMain.Focus();
tvMain.EndUpdate();
}
}
}
}