示例#1
0
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            ISelectionService selectionService = (ISelectionService)this.GetService(typeof(ISelectionService));

            if (selectionService != null)
            {
                selectionService.SelectionChanged += this.OnSelectionChanged;
            }

            //MessageBox.Show(this.Component.ToString());

            if (this.Control is TabView)
            {
                TabView view = this.Control as TabView;

                view.ControlAdded += TabViewControlAdded;
            }

            this.Verbs.Add(new DesignerVerb("+ Add Tab", (object sender, EventArgs e) =>
            {
                AddTab();
            }));

            this.Verbs.Add(new DesignerVerb("- Remove Tab", (object sender, EventArgs e) =>
            {
                RemoveTab();
            }));

            this.Verbs.Add(new DesignerVerb("\x25B2 Move Back", (object sender, EventArgs e) =>
            {
                TabPanel currentTab = this.Control is TabView ? (Control as TabView).SelectedTab : null;
                MoveTab(currentTab, GetNearbyTab(currentTab, true));
            }));

            this.Verbs.Add(new DesignerVerb("\x25BC Move Forward", (object sender, EventArgs e) =>
            {
                TabPanel currentTab = this.Control is TabView ? (Control as TabView).SelectedTab : null;
                MoveTab(currentTab, GetNearbyTab(currentTab, false));
            }));
        }
示例#2
0
        protected virtual void MoveTab(TabPanel from, TabPanel to)
        {
            if (!(this.Control is TabView))
            {
                return;
            }

            if (from == null || to == null ||
                !this.Control.Controls.Contains(from) ||
                !this.Control.Controls.Contains(to))
            {
                return;
            }

            IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            TabView       tabView      = this.Control as TabView;

            if (designerHost == null)
            {
                return;
            }

            using (DesignerTransaction transaction = designerHost.CreateTransaction($"Add tab to \"{tabView.Name}\""))
            {
                try
                {
                    PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)];

                    this.RaiseComponentChanging(controlsProperty);
                    this.Control.Controls.SetChildIndex(from, Control.Controls.GetChildIndex(to));
                    this.RaiseComponentChanged(controlsProperty, null, null);

                    tabView.UpdateLayout();
                    tabView.Refresh();
                    transaction.Commit();
                }
                catch
                {
                    transaction.Cancel();
                }
            }
        }
示例#3
0
        protected virtual void RemoveTab()
        {
            if (!(this.Control is TabView))
            {
                return;
            }

            IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            TabView       tabView      = this.Control as TabView;
            TabPanel      tabPanel     = null;

            if (tabView.SelectedTab != null)
            {
                tabPanel = tabView.SelectedTab;
            }

            if (designerHost == null || tabPanel == null)
            {
                return;
            }

            using (DesignerTransaction transaction = designerHost.CreateTransaction($"Remove tab from \"{tabView.Name}\""))
            {
                try
                {
                    PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)];

                    this.RaiseComponentChanging(controlsProperty);
                    designerHost.DestroyComponent(tabPanel);
                    this.RaiseComponentChanged(controlsProperty, null, null);

                    tabView.UpdateLayout();
                    tabView.Refresh();
                    transaction.Commit();
                }
                catch
                {
                    transaction.Cancel();
                }
            }
        }
示例#4
0
        protected virtual void AddTab()
        {
            if (!(this.Control is TabView))
            {
                return;
            }

            IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            TabView       tabView      = this.Control as TabView;

            if (designerHost == null)
            {
                return;
            }

            using (DesignerTransaction transaction = designerHost.CreateTransaction($"Add tab to \"{tabView.Name}\""))
            {
                try
                {
                    TabPanel           tab = (TabPanel)designerHost.CreateComponent(typeof(TabPanel));
                    PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)];
                    PropertyDescriptor tabTextProperty  = TypeDescriptor.GetProperties(tab)[nameof(tab.Text)];

                    this.RaiseComponentChanging(controlsProperty);
                    tabView.Controls.Add(tab);
                    this.RaiseComponentChanged(controlsProperty, null, null);

                    tabTextProperty.SetValue(tab, tab.Name);
                    tabView.ShowTab(tab);

                    tabView.UpdateLayout();
                    tabView.Refresh();
                    transaction.Commit();
                }
                catch
                {
                    transaction.Cancel();
                }
            }
        }