Exemple #1
0
        private void CleanupDocument(DocumentHost dh)
        {
            IPoderosaForm owner_window = ViewToForm(dh.LastAttachedView);
            IPoderosaView visible_view = dh.CurrentView;
            bool          was_active   = false;

            if (visible_view != null)
            {
                was_active = visible_view.AsControl().Focused;
                dh.DetachView();
                FireDocViewRelationChange();
            }

            if (owner_window != null)
            {
                NotifyRemove(owner_window, dh.Document);
            }

            dh.SessionHost.CloseDocument(dh.Document);
            _documentMap.Remove(dh.Document);

            //閉じたドキュメントのビューが見えていた場合は、その位置の別のドキュメントを見せる
            //TODO ウィンドウを閉じるときはこの処理は不要
            if (visible_view != null && visible_view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow)) != null)
            {
                ShowBackgroundDocument(visible_view);
                if (was_active && visible_view.Document != null)
                {
                    ActivateDocument(visible_view.Document, ActivateReason.InternalAction);
                }
            }
        }
Exemple #2
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 #3
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);
        }
Exemple #4
0
        public PrepareCloseResult CloseMultipleDocuments(ClosingContext context, IPoderosaDocument[] documents)
        {
            List <SessionHost> sessions = CreateSessionHostCollection();

            foreach (SessionHost sh in sessions)
            {
                sh.CMP_ClosingDocumentCount = 0; //カウントリセット
            }
            foreach (IPoderosaDocument doc in documents)
            {
                DocumentHost dh = FindDocumentHost(doc);
                dh.SessionHost.CMP_ClosingDocumentCount++;
            }
            //ここまでで、各SessionHostごとに何個のドキュメントを閉じようとしているかがカウントされた。
            //次にそれぞれについて処理をはじめる
            PrepareCloseResult result = PrepareCloseResult.TerminateSession;

            foreach (SessionHost sh in sessions)
            {
                if (sh.CMP_ClosingDocumentCount == 0)
                {
                    continue;                                        //影響なし
                }
                if (sh.CMP_ClosingDocumentCount == sh.DocumentCount) //セッションの全ドキュメントを閉じる場合
                {
                    PrepareCloseResult r = TerminateSession(sh.Session);
                    sh.CMP_PrepareCloseResult = r;
                    if (r == PrepareCloseResult.TerminateSession)
                    {
                        context.AddClosingSession(sh);
                    }
                    else if (r == PrepareCloseResult.Cancel)
                    {
                        result = PrepareCloseResult.Cancel; //一個でもキャンセルがあれば全体をキャンセルとする
                    }
                }
                else   //一部のドキュメントを閉じる。これが面倒
                       //TODO unsupported
                {
                    Debug.Assert(false, "unsupported");
                }
            }

            //それらについてセッションを閉じる
            foreach (SessionHost sh in context.ClosingSessions)
            {
                CleanupSession(sh);
            }

            return(result);
        }
Exemple #5
0
        /**
         * Activate処理のルート
         * NOTE 重複コールはここでブロックするようにする。
         * アクティブなドキュメントが変化するのは、
         *   - Viewをクリックしてフォーカスが変わるとき
         *   - タブをクリックしたとき
         *   - キーボードショートカット等、Poderosaのコードが発動するとき
         * の3つ。
         * そのうちのどれであるかを指定してここを呼ぶ。例えば、Focus移動のときは改めてFocus()を呼ばないなど内部で場合分けがなされる
         */
        public void ActivateDocument(IPoderosaDocument document, ActivateReason reason)
        {
            Debug.Assert(document != null);

            //ネストの防止 Focus系イベントハンドラがあるとどうしても呼ばれてしまうので
            if (_activateContext != null)
            {
                return;
            }

            try {
                _activateContext = new ActivateContext(document, reason);

                DocumentHost dh = FindDocumentHost(document);
                Debug.Assert(dh != null);

                if (dh.CurrentView != null)   //既に見えている場合
                {
                    if (reason != ActivateReason.ViewGotFocus)
                    {
                        SetFocusToView(dh.CurrentView); //ユーザのフォーカス指定だった場合はそれに任せる
                    }
                }
                else   //見えてはいなかった場合
                {
                    IPoderosaView view = dh.LastAttachedView;
                    Debug.Assert(view != null); //これを強制する仕組みをどこかにほしいかも。今はすべてのDocumentが最初にAttachDocumentAndViewされることを想定している
                    AttachDocumentAndView(document, view);
                    Debug.Assert(dh.CurrentView == view);
                    if (!view.AsControl().Focused)
                    {
                        view.AsControl().Focus();
                    }
                }

                Debug.Assert(dh.CurrentView.Document == document);


                //通知
                NotifyActivation(ViewToForm(dh.CurrentView), document, reason);
            }
            finally {
                _activateContext = null;
                if (DebugOpt.DumpDocumentRelation)
                {
                    DumpDocumentRelation();
                }
            }
        }
Exemple #6
0
        public IPoderosaForm GetParentFormFor(IPoderosaDocument document)
        {
            DocumentHost dh = _parent.FindDocumentHost(document);

            Debug.Assert(dh != null, "document must be alive");
            IPoderosaView view = dh.LastAttachedView;

            if (view != null)
            {
                return(view.ParentForm); //これが存在するならOK
            }
            else
            {
                return(WindowManagerPlugin.Instance.ActiveWindow); //ちょっと反則気味の取り方だが
            }
        }
Exemple #7
0
        public void RefreshDocumentStatus(IPoderosaDocument document)
        {
            DocumentHost dh = FindDocumentHost(document);

            Debug.Assert(dh != null);
            IPoderosaForm f = ViewToForm(dh.LastAttachedView);

            //ちょっと汚い分岐
            IPoderosaMainWindow mw = (IPoderosaMainWindow)f.GetAdapter(typeof(IPoderosaMainWindow));

            if (mw != null)
            {
                mw.DocumentTabFeature.Update(document);
            }
            else
            {
                ((IPoderosaPopupWindow)f.GetAdapter(typeof(IPoderosaPopupWindow))).UpdateStatus();
            }
        }
Exemple #8
0
        //ISessionManagerの終了系 細かいのはドキュメントあり
        public PrepareCloseResult CloseDocument(IPoderosaDocument document)
        {
            DocumentHost dh = FindDocumentHost(document);

            Debug.Assert(dh != null);
            SessionHost        sh = dh.SessionHost;
            PrepareCloseResult r  = sh.Session.PrepareCloseDocument(document);

            if (r == PrepareCloseResult.Cancel)
            {
                return(r);
            }

            CleanupDocument(dh);
            if (r == PrepareCloseResult.TerminateSession || sh.DocumentCount == 0)
            {
                CleanupSession(sh);
            }
            return(r);
        }
Exemple #9
0
        private void CleanupDocument(DocumentHost dh) {
            IPoderosaForm owner_window = ViewToForm(dh.LastAttachedView);
            IPoderosaView visible_view = dh.CurrentView;
            bool was_active = false;
            if (visible_view != null) {
                was_active = visible_view.AsControl().Focused;
                dh.DetachView();
                FireDocViewRelationChange();
            }

            if (owner_window != null) {
                NotifyRemove(owner_window, dh.Document);
            }

            dh.SessionHost.CloseDocument(dh.Document);
            _documentMap.Remove(dh.Document);

            //閉じたドキュメントのビューが見えていた場合は、その位置の別のドキュメントを見せる
            //TODO ウィンドウを閉じるときはこの処理は不要
            if (visible_view != null && visible_view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow)) != null) {
                ShowBackgroundDocument(visible_view);
                if (was_active && visible_view.Document != null)
                    ActivateDocument(visible_view.Document, ActivateReason.InternalAction);
            }
        }
Exemple #10
0
        private void CleanupDocument(DocumentHost dh)
        {
            IPoderosaForm owner_window = ViewToForm(dh.LastAttachedView);
            IPoderosaView visible_view = dh.CurrentView;
            bool was_active = false;
            if (visible_view != null) {
                was_active = visible_view.AsControl().Focused;
                dh.DetachView();
                FireDocViewRelationChange();
            }

            if (owner_window != null) {
                NotifyRemove(owner_window, dh.Document);
            }

            dh.SessionHost.CloseDocument(dh.Document);
            _documentMap.Remove(dh.Document);

            //�‚����h�L�������g�̃r���[�������Ă����ꍇ�́A���̈ʒu�̕ʂ̃h�L�������g�������
            //TODO �E�B���h�E��‚���Ƃ��͂��̏����͕s�v
            if (visible_view != null && visible_view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow)) != null) {
                ShowBackgroundDocument(visible_view);
                if (was_active && visible_view.Document != null)
                    ActivateDocument(visible_view.Document, ActivateReason.InternalAction);
            }
        }