Exemple #1
0
        public void AttachDocumentAndView(IPoderosaDocument document, IPoderosaView view)
        {
            view = AdjustToOuterView(view);
            DocumentHost dh = FindDocumentHost(document);

            Debug.Assert(dh != null, "the document must be registered by calling ISessionHost#RegisterDocument");

            if (view.Document == document)
            {
                Debug.Assert(dh.CurrentView == view);
                return; //何もしない
            }

            IPoderosaView previous_view = dh.CurrentView;                  //関連づけを指定するドキュメントがもともと見えていたビュー
            IPoderosaForm last_window   = ViewToForm(dh.LastAttachedView); //もともとの所有ウィンドウ。初めてのAttachではnullであることにちゅうい

            //現在の関連を一旦切る
            if (previous_view != null)
            {
                Debug.WriteLineIf(DebugOpt.DumpDocumentRelation, "Detach Prev View " + ViewName(previous_view));
                dh.DetachView();
            }
            Debug.Assert(dh.CurrentView == null);

            //接続先にドキュメントが存在していればそれを切り離す
            IPoderosaDocument existing_doc = view.Document;

            if (existing_doc != null)   //対象のビューに古いのがひっついていたら外す
            {
                DocumentHost eh = FindDocumentHost(existing_doc);
                Debug.Assert(eh.CurrentView == view);
                Debug.WriteLineIf(DebugOpt.DumpDocumentRelation, String.Format("Detach Destination View doc={0} view={1}", existing_doc.GetType().Name, ViewName(view)));
                eh.DetachView();
            }

            //新規の接続
            Debug.Assert(view.Document == null && dh.CurrentView == null); //Attach準備ができていること確認
            dh.AttachView(view);

            //移動することで新規に見えるようになるドキュメントを探索
            if (previous_view != null && previous_view != view)
            {
                DocumentHost new_visible_doc = ShowBackgroundDocument(previous_view);
                Debug.Assert(new_visible_doc != dh);
            }

            //ドキュメントを保有するウィンドウが変化したら通知。初回Attachではlast_mainwindow==nullであることに注意
            if (last_window != view.ParentForm)
            {
                if (last_window != null)
                {
                    NotifyRemove(last_window, document);
                }
                NotifyAdd(ViewToForm(view), document);
            }

            FireDocViewRelationChange();
        }
Exemple #2
0
        //viewの位置にある新規のドキュメントを見えるようにする。ドキュメントの表示位置を変えたとき、閉じたときに実行する
        private DocumentHost ShowBackgroundDocument(IPoderosaView view)
        {
            DocumentHost new_visible_doc = FindNewVisibleDoc(view);

            if (new_visible_doc != null)
            {
                new_visible_doc.AttachView(view);
            }
            return(new_visible_doc);
        }