Example #1
0
        public void ApplySplitInfo(string format)
        {
            try {
                //現状を獲得
                IPoderosaView[]     previous_views = GetAllViews();
                IPoderosaDocument[] documents      = new IPoderosaDocument[previous_views.Length]; //分割適用後アクティブになるやつ
                for (int i = 0; i < previous_views.Length; i++)
                {
                    documents[i] = previous_views[i].Document;
                }
                IPoderosaView[] new_views;

                SessionManagerPlugin sm = SessionManagerPlugin.Instance;

                if (format.Length > 0)
                {
                    Form container = _parent.AsForm();
                    container.SuspendLayout();
                    Control old_root = this.RootControl;
                    _paneDivision.ApplySplitInfo(old_root.Parent, old_root, format,
                                                 delegate(string label) {
                        return(CreateNewPane(_defaultViewFactory, DockStyle.Fill));
                    });                          //とりあえずデフォルトファクトリで作成
                    container.ResumeLayout(true);
                    _singlePane = null;          //成功裏に終わったときのみ
                    new_views   = GetAllViews(); //新しいのを取得
                }
                else
                {
                    IContentReplaceableView view;
                    UnifyAll(out view);
                    new_views = new IPoderosaView[] { view };
                }

                //既存ドキュメントに再適用
                foreach (DocumentHost dh in sm.GetAllDocumentHosts())
                {
                    int index = CollectionUtil.ArrayIndexOf(previous_views, dh.LastAttachedView);
                    if (index != -1)
                    {
                        IPoderosaView new_view = index < new_views.Length ? new_views[index] : new_views[0]; //個数が減ったら先頭に
                        dh.AlternateView(new_view);
                    }
                }

                //もともとActiveだったやつを再適用
                for (int i = 0; i < documents.Length; i++)
                {
                    if (documents[i] != null)
                    {
                        sm.AttachDocumentAndView(documents[i], sm.FindDocumentHost(documents[i]).LastAttachedView); //LastAttachedViewはこの上のループで適用済み
                    }
                }
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
            }
        }