Exemple #1
0
        public IdeTab(Control parent, IdePanel panel)
        {
            _tabButton              = new RadioButton();
            _tabButton.Text         = panel.Label;
            _tabButton.AutoSize     = true;
            _tabButton.Appearance   = Appearance.Button;
            _tabButton.AutoEllipsis = true;
            _tabButton.FlatStyle    = FlatStyle.Flat;
            _tabButton.FlatAppearance.BorderSize         = 0;
            _tabButton.FlatAppearance.MouseOverBackColor = SystemColors.ButtonHighlight;
            _tabButton.ForeColor       = parent.ForeColor;
            _tabButton.BackColor       = parent.BackColor;
            _tabButton.Margin          = Padding.Empty;
            _tabButton.Height          = parent.Height;
            _tabButton.CheckedChanged += (s, a) => { if (Selected && WasSelected != null)
                                                     {
                                                         WasSelected();
                                                     }
            };
            _tabButton.MouseDown += (s, a) => { if (a.Button == MouseButtons.Left)
                                                {
                                                    Selected = true;
                                                }
            };
            panel.LabelChanged += text => _tabButton.Text = text;

            Panel = panel;
        }
Exemple #2
0
        public IdeTab InsertTab(int indexValue, IdePanel panel)
        {
            var tab = CreateTabButton(panel);

            _tabPanel.Controls.SetChildIndex(tab.Button, indexValue);
            return(tab);
        }
Exemple #3
0
		public void HidePanel(IdePanel panel)
		{
			Control parent = panel;
			while (parent != null)
			{
				if (parent is IdeGroupedPanel groupedPanel)
				{
					RemovePanelFromGroupedPanel(panel, groupedPanel);
					OnPanelStatusChanged(panel, false);
					return;
				}
				parent = parent.Parent;
			}

			var panelForm = panel.FindForm();
			if (panelForm != null && !(panelForm is MainForm))
			{
				_memorizedPanelPositions.Remove(panel);
				panelForm.Visible = false;
				OnPanelStatusChanged(panel, false);
				return;
			}

			RemovePanelFromSplitContainer(panel);
			OnPanelStatusChanged(panel, false);
		}
Exemple #4
0
        protected bool MouseMoved(Point location)
        {
            if (_dragging == null)
            {
                return(false);
            }

            var delta = new Point(Cursor.Position.X - _dragOffset.X, Cursor.Position.Y - _dragOffset.Y);

            if (Math.Abs(delta.X) > DragTreshold || Math.Abs(delta.Y) > DragTreshold)
            {
                var draggingPanel = _dragging;
                _dragging = null;
                var form = FindForm() as IIdeLayoutParent;
                if (form != null)
                {
                    form.LayoutHandler.ReleasePanel(draggingPanel, PointToScreen(delta));
                }
                else
                {
                    return(false);
                }
                draggingPanel.Header.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));                 // Forces form drag immediately
            }

            return(false);
        }
Exemple #5
0
		private void JoinPanels(IdePanel existingPanel, IdePanel newPanel, int newIndex = 1)
		{
			var parent = existingPanel.Parent;
			var groupedPanel = new IdeGroupedPanel {Dock = DockStyle.Fill};
			groupedPanel.AddPanel(newPanel);
			groupedPanel.AddPanel(existingPanel, false, newIndex > 0 ? 0 : 1);
			parent.Controls.Add(groupedPanel);
		}
Exemple #6
0
 public void SetChildPanel(IdePanel panel)
 {
     if (Controls.Count >= 0)
     {
         Controls.Clear();
     }
     panel.Dock = DockStyle.Fill;
     Controls.Add(panel);
 }
Exemple #7
0
        public void ShowPanel(IdePanel panel)
        {
            var tab = Tabs.FirstOrDefault(t => t.Panel == panel);

            if (tab != null)
            {
                tab.Selected = true;
            }
        }
Exemple #8
0
		protected void CreateFloatPanel(IdePanel panel, Point? location = null, Size? size = null)
		{
			var floatPanel = new FloatPanel(this);
			floatPanel.SuspendLayout();
			floatPanel.SetChildPanel(panel);
			floatPanel.Show(_form);

			if (location.HasValue) floatPanel.Location = location.Value;
			if (size.HasValue) floatPanel.Size = size.Value;
			floatPanel.ResumeLayout();
		}
Exemple #9
0
        private IdeTab CreateTabButton(IdePanel panel)
        {
            var tab = new IdeTab(this, panel);

            SuspendLayout();
            _tabPanel.Controls.Add(tab.Button);
            _label.Visible    = false;
            _tabPanel.Visible = true;
            ResumeLayout();
            return(tab);
        }
Exemple #10
0
		private void RemovePanelFromGroupedPanel(IdePanel panel, IdeGroupedPanel groupedPanel)
		{
			var sibling = groupedPanel.Panels.FirstOrDefault(p => p != panel);
			if (sibling != null)
			{
				_memorizedPanelPositions[panel] = new PanelPosition
				{
					Index = groupedPanel.Tabs.FindIndex(t => t.Panel == panel),
					Sibling = sibling
				};
			}
			groupedPanel.RemovePanel(panel);
		}
Exemple #11
0
		private bool CheckGroupDock(IdePanel idePanel)
		{
			if (idePanel == null) return false;
			var headerBounds = idePanel.RectangleToScreen(idePanel.Header.Bounds);
			if (!headerBounds.Contains(Cursor.Position)) return false;
			
			DockSuggestion = new DockSuggestion
			{
				Bounds = headerBounds,
				JoinPanel = idePanel
			};
			return true;
		}
Exemple #12
0
		public void ReleasePanel(IdePanel panel, Point windowLocation)
		{
			var windowSize = panel.Size;
			
			if (panel.Parent is IdeGroupedPanel groupedPanel)
				groupedPanel.RemovePanel(panel);
			else
				RemovePanelFromSplitContainer(panel);

			_form.SuspendLayout();
			CreateFloatPanel(panel, windowLocation, windowSize);
			_form.ResumeLayout();
		}
Exemple #13
0
		private void AddPanelToGroupedPanel(IdePanel sibling, IdePanel idePanel, int index)
		{
			// TODO: Method for identifying specific parent controls
			var parent = sibling.Parent;
			while (parent != null)
			{
				if (parent is IdeGroupedPanel groupedPanel)
				{
					groupedPanel.AddPanel(idePanel, true, index);
					return;
				}
				parent = parent.Parent;
			}
			// Sibling isn't in a groupedpanel anymore, so join panels in a new one
			JoinPanels(sibling, idePanel, index);
		}
Exemple #14
0
        public void AddPanel(IdePanel panel, bool selectTab = false, int?index = null)
        {
            if (panel is IdeGroupedPanel groupedPanel)
            {
                foreach (var newTab in groupedPanel.Tabs)
                {
                    AddPanel(newTab.Panel, selectTab && newTab.Selected);
                }
                groupedPanel.Dispose();
                return;
            }
            panel.ShowHeader  = false;
            panel.GroupParent = this;

            if (index.HasValue && index.Value >= Tabs.Count)
            {
                index = null;
            }

            var tab = index.HasValue
                                ? Header.InsertTab(index.Value, panel)
                                : Header.AddTab(panel);

            panel.Dock = DockStyle.Fill;

            tab.WasSelected += () => SelectTab(tab);
            if (index.HasValue)
            {
                Tabs.Insert(index.Value, tab);
            }
            else
            {
                Tabs.Add(tab);
            }
            if (selectTab || Tabs.Count == 1)
            {
                tab.Selected = true;
            }
            else
            {
                panel.Visible = false;
            }

            Controls.Add(panel);
            Controls.SetChildIndex(panel, 0);
            RefreshLabel();
        }
Exemple #15
0
        protected bool LeftMouseDown(Point location)
        {
            if (!Visible || Parent == null)
            {
                return(false);
            }
            var control = OsFeatures.GlobalMouseHandler.GetCurrentControl();

            if (control != null)
            {
                while (control != null && control != this)
                {
                    control = control.Parent;
                }
                if (control == null)
                {
                    return(false);
                }
            }
            if (_closeButton.Bounds.Contains(PointToClient(location)))
            {
                return(false);
            }
            if (!Bounds.Contains(Parent.PointToClient(location)))
            {
                return(false);
            }

            if ((FindForm() is MainForm))
            {
                _dragging = Parent as IdePanel;
            }
            _dragOffset = location;
            if (Parent is IdeGroupedPanel groupedPanel)
            {
                foreach (var tab in groupedPanel.Tabs)
                {
                    if (tab.Button.Bounds.Contains(_tabPanel.PointToClient(location)))
                    {
                        _dragging = tab.Panel;
                    }
                }
            }

            return(false);
        }
Exemple #16
0
		private void RemovePanelFromSplitContainer(IdePanel panel)
		{
			var multiSplitPanel = panel.Parent as MultiSplitPanel;
			if (multiSplitPanel == null) multiSplitPanel = panel.Parent.Parent as MultiSplitPanel;
			if (multiSplitPanel != null)
			{
				var splitContainer = multiSplitPanel.Parent as MultiSplitContainer;
				_memorizedPanelPositions[panel] = new PanelPosition
					{
						SplitContainer = splitContainer,
						Index = splitContainer.Panels.IndexOf(multiSplitPanel)
					};
				splitContainer.RemovePanel(multiSplitPanel);
				if (splitContainer.Splits.Count == 0)
				{
					// TODO: Last panel removed, hide it but keep the dock suggestion available
				}
			}
		}
Exemple #17
0
 private void AddPanelNamesToGroup(Dictionary <Control, string> moduleNames, IdePanel parent, List <string> groupPanels)
 {
     if (parent == null)
     {
         return;
     }
     if (parent is IdeGroupedPanel groupedPanel)
     {
         foreach (var childPanel in groupedPanel.Panels)
         {
             if (moduleNames.ContainsKey(childPanel.Child))
             {
                 groupPanels.Add(moduleNames[childPanel.Child]);
             }
         }
     }
     else if (moduleNames.ContainsKey(parent.Child))
     {
         groupPanels.Add(moduleNames[parent.Child]);
     }
 }
Exemple #18
0
        public void RemovePanel(IdePanel panel)
        {
            var tab = Tabs.FirstOrDefault(t => t.Panel == panel);

            if (tab == null)
            {
                return;
            }
            if (Tabs.Count == 1)
            {
                throw new Exception("Can't remove the last tab in a grouped panel");
            }
            Controls.Remove(tab.Panel);
            Tabs.Remove(tab);
            tab.Panel.Visible     = true;
            tab.Panel.ShowHeader  = true;
            tab.Panel.GroupParent = null;

            if (Tabs.Count == 1)             // Only one tab remaining, so remove grouped panel
            {
                var lastPanel = Tabs[0].Panel;
                var myParent  = Parent;
                // Remove myself before adding child panel to avoid confusing floatpanels
                myParent.Controls.Remove(this);
                myParent.Controls.Add(lastPanel);
                lastPanel.Visible     = true;
                lastPanel.ShowHeader  = true;
                lastPanel.GroupParent = null;
                Dispose();
                return;
            }
            if (tab.Selected)
            {
                Tabs.First(t => t != tab).Selected = true;
            }
            Header.RemoveTab(tab);
            RefreshLabel();
        }
Exemple #19
0
		private void ShowPanel(IdePanel panel, IdePanel locationReference)
		{
			var panelForm = panel.FindForm();
			if (panelForm != null && !(panelForm is MainForm))
			{
				panelForm.Visible = true;
				OnPanelStatusChanged(panel, true);
				return;
			}

			if (!_memorizedPanelPositions.ContainsKey(locationReference))
			{
				// Panel was never visible in the first place, show as new form
				CreateFloatPanel(panel);
				OnPanelStatusChanged(panel, true);
				return;
			}

			var position = _memorizedPanelPositions[locationReference];
			_form.SuspendLayout();
			if (position.Sibling != null)
			{
				var siblingForm = position.Sibling.FindForm();
				if (siblingForm != null && siblingForm.Visible) AddPanelToGroupedPanel(position.Sibling, panel, position.Index);
				else
				{
					// Panel that was sibling when panel was hidden is no longer visible, so use its old position as reference
					ShowPanel(panel, position.Sibling);
					return;
				}
			}
			else
				AddPanelToSplitContainer(position.SplitContainer, panel, Math.Min(position.Index, position.SplitContainer.Panels.Count));
			_form.ResumeLayout();
			OnPanelStatusChanged(panel, true);
		}
Exemple #20
0
 public IdeTabPage(IdePanel child) : base()
 {
     _child      = child;
     _child.Dock = DockStyle.Fill;
     Controls.Add(child);
 }
Exemple #21
0
		public void ShowPanel(IdePanel panel)
		{
			ShowPanel(panel, panel);
		}
Exemple #22
0
		protected virtual void OnPanelStatusChanged(IdePanel panel, bool visible)
		{
			if (PanelStatusChanged != null) PanelStatusChanged(panel, visible);
		}
Exemple #23
0
 public IdeTab AddTab(IdePanel panel)
 {
     return(CreateTabButton(panel));
 }
Exemple #24
0
		private void AddPanelToSplitContainer(MultiSplitContainer multiSplitParent, IdePanel panel, int index)
		{
			var splitPanel = multiSplitParent.AddPanel(index);
			splitPanel.Add(panel);
		}