Exemplo n.º 1
0
        public bool RemoveSpecifiedTab(string tabName, bool confirm)
        {
            int idx;

            for (idx = 0; idx < ListTab.TabPages.Count; idx++)
            {
                if (ListTab.TabPages[idx].Text == tabName)
                {
                    break;
                }
            }

            if (_statuses.IsDefaultTab(tabName))
            {
                return(false);
            }

            if (confirm)
            {
                string tmp    = string.Format(R.RemoveSpecifiedTabText1, Environment.NewLine);
                var    result = MessageBox.Show(tmp, string.Format("{0} {1}", tabName, R.RemoveSpecifiedTabText2), MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Cancel)
                {
                    return(false);
                }
            }

            SetListProperty(); // 他のタブに列幅等を反映

            TabUsageType tabType = _statuses.Tabs[tabName].TabType;

            // オブジェクトインスタンスの削除
            SplitContainer1.Panel1.SuspendLayout();
            SplitContainer1.Panel2.SuspendLayout();
            SplitContainer1.SuspendLayout();
            ListTab.SuspendLayout();
            SuspendLayout();

            TabPage tabPage    = ListTab.TabPages[idx];
            var     listCustom = (DetailsListView)tabPage.Tag;

            tabPage.Tag = null;
            tabPage.SuspendLayout();

            if (ReferenceEquals(ListTab.SelectedTab, ListTab.TabPages[idx]))
            {
                ListTab.SelectTab(_prevSelectedTab != null && ListTab.TabPages.Contains(_prevSelectedTab) ? _prevSelectedTab : ListTab.TabPages[0]);
            }

            ListTab.Controls.Remove(tabPage);

            if (tabType == TabUsageType.PublicSearch)
            {
                Control pnl = tabPage.Controls["panelSearch"];
                foreach (Control ctrl in pnl.Controls)
                {
                    if (ctrl.Name == "buttonSearch")
                    {
                        ctrl.Click -= SearchButton_Click;
                    }

                    ctrl.Enter -= SearchControls_Enter;
                    ctrl.Leave -= SearchControls_Leave;
                    pnl.Controls.Remove(ctrl);
                    ctrl.Dispose();
                }

                tabPage.Controls.Remove(pnl);
            }

            tabPage.Controls.Remove(listCustom);
            listCustom.Columns.Clear();
            listCustom.ContextMenuStrip = null;

            listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
            listCustom.MouseDoubleClick     -= MyList_MouseDoubleClick;
            listCustom.ColumnClick          -= MyList_ColumnClick;
            listCustom.DrawColumnHeader     -= MyList_DrawColumnHeader;
            listCustom.DragDrop             -= TweenMain_DragDrop;
            listCustom.DragOver             -= TweenMain_DragOver;
            listCustom.DrawItem             -= MyList_DrawItem;
            listCustom.MouseClick           -= MyList_MouseClick;
            listCustom.ColumnReordered      -= MyList_ColumnReordered;
            listCustom.ColumnWidthChanged   -= MyList_ColumnWidthChanged;
            listCustom.CacheVirtualItems    -= MyList_CacheVirtualItems;
            listCustom.RetrieveVirtualItem  -= MyList_RetrieveVirtualItem;
            listCustom.DrawSubItem          -= MyList_DrawSubItem;
            listCustom.HScrolled            -= MyList_HScrolled;

            _tabDialog.RemoveTab(tabName);

            listCustom.SmallImageList     = null;
            listCustom.ListViewItemSorter = null;

            // キャッシュのクリア
            if (_curTab.Equals(tabPage))
            {
                _curTab       = null;
                _curItemIndex = -1;
                _curList      = null;
                _curPost      = null;
            }

            _itemCache      = null;
            _itemCacheIndex = -1;
            _postCache      = null;

            tabPage.ResumeLayout(false);

            SplitContainer1.Panel1.ResumeLayout(false);
            SplitContainer1.Panel2.ResumeLayout(false);
            SplitContainer1.ResumeLayout(false);
            ListTab.ResumeLayout(false);
            ResumeLayout(false);
            PerformLayout();

            tabPage.Dispose();
            listCustom.Dispose();
            _statuses.RemoveTab(tabName);

            foreach (TabPage tp in ListTab.TabPages)
            {
                var lst = (DetailsListView)tp.Tag;
                lst.VirtualListSize = _statuses.Tabs[tp.Text].AllCount;
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool AddNewTab(string tabName, bool startup, TabUsageType tabType, ListElement listInfo = null)
        {
            // 重複チェック
            if (ListTab.TabPages.Cast <TabPage>().Any(tb => tb.Text == tabName))
            {
                return(false);
            }

            // 新規タブ名チェック
            if (tabName == R.AddNewTabText1)
            {
                return(false);
            }

            // タブタイプ重複チェック
            if (!startup)
            {
                if (tabType == TabUsageType.DirectMessage ||
                    tabType == TabUsageType.Favorites ||
                    tabType == TabUsageType.Home ||
                    tabType == TabUsageType.Mentions ||
                    tabType == TabUsageType.Related)
                {
                    if (_statuses.GetTabByType(tabType) != null)
                    {
                        return(false);
                    }
                }
            }

            var tabPage = new TabPage();

            int cnt = ListTab.TabPages.Count;

            //// ToDo:Create and set controls follow tabtypes

            SplitContainer1.Panel1.SuspendLayout();
            SplitContainer1.Panel2.SuspendLayout();
            SplitContainer1.SuspendLayout();
            ListTab.SuspendLayout();
            SuspendLayout();

            tabPage.SuspendLayout();

            // UserTimeline関連
            Label label = null;

            if (tabType == TabUsageType.UserTimeline || tabType == TabUsageType.Lists)
            {
                label = new Label
                {
                    Dock      = DockStyle.Top,
                    Name      = "labelUser",
                    Text      = tabType == TabUsageType.Lists ? listInfo.ToString() : _statuses.Tabs[tabName].User + "'s Timeline",
                    TextAlign = ContentAlignment.MiddleLeft
                };
                using (var tmpComboBox = new ComboBox())
                {
                    label.Height = tmpComboBox.Height;
                }
            }

            ListTab.Controls.Add(tabPage);
            var listCustom = CreateDetailListView(tabName, startup);

            listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
            listCustom.MouseDoubleClick     += MyList_MouseDoubleClick;
            listCustom.ColumnClick          += MyList_ColumnClick;
            listCustom.DrawColumnHeader     += MyList_DrawColumnHeader;
            listCustom.DragDrop             += TweenMain_DragDrop;
            listCustom.DragOver             += TweenMain_DragOver;
            listCustom.DrawItem             += MyList_DrawItem;
            listCustom.MouseClick           += MyList_MouseClick;
            listCustom.ColumnReordered      += MyList_ColumnReordered;
            listCustom.ColumnWidthChanged   += MyList_ColumnWidthChanged;
            listCustom.CacheVirtualItems    += MyList_CacheVirtualItems;
            listCustom.RetrieveVirtualItem  += MyList_RetrieveVirtualItem;
            listCustom.DrawSubItem          += MyList_DrawSubItem;
            listCustom.HScrolled            += MyList_HScrolled;
            tabPage.Controls.Add(listCustom);

            if (_statuses.IsDistributableTab(tabName))
            {
                _tabDialog.AddTab(tabName);
            }

            // 検索関連の準備
            Panel pnl = null;

            if (tabType == TabUsageType.PublicSearch)
            {
                pnl = CreateSearchPanel(tabName);
                tabPage.Controls.Add(pnl);
            }

            if (tabType == TabUsageType.UserTimeline || tabType == TabUsageType.Lists)
            {
                tabPage.Controls.Add(label);
            }

            tabPage.Location = new Point(4, 4);
            tabPage.Name     = string.Format("CTab{0}", cnt);
            tabPage.Size     = new Size(380, 260);
            tabPage.TabIndex = 2 + cnt;
            tabPage.Text     = tabName;
            tabPage.UseVisualStyleBackColor = true;

            if (tabType == TabUsageType.PublicSearch)
            {
                pnl.ResumeLayout(false);
            }

            tabPage.ResumeLayout(false);

            SplitContainer1.Panel1.ResumeLayout(false);
            SplitContainer1.Panel2.ResumeLayout(false);
            SplitContainer1.ResumeLayout(false);
            ListTab.ResumeLayout(false);
            ResumeLayout(false);
            PerformLayout();
            tabPage.Tag = listCustom;
            return(true);
        }