示例#1
0
        private static CommandResult CmdCloseCurrentDocument(ICommandTarget target)
        {
            IPoderosaDocument document = CommandTargetUtil.AsDocumentOrViewOrLastActivatedDocument(target);

            if (document == null)
            {
                return(CommandResult.Ignored);
            }

            SessionManagerPlugin sm     = SessionManagerPlugin.Instance;
            IPoderosaView        view   = sm.FindDocumentHost(document).LastAttachedView;
            IPoderosaMainWindow  window = view == null ? null : (IPoderosaMainWindow)view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow));
            bool was_active             = window == null ? false : window.DocumentTabFeature.ActiveDocument == document;

            PrepareCloseResult result = sm.CloseDocument(document);

            if (result == PrepareCloseResult.Cancel)
            {
                return(CommandResult.Cancelled);
            }

            //同じビューに別のドキュメントが来ていればそれをアクティブに
            if (was_active)
            {
                IPoderosaDocument newdoc = view.Document;
                if (newdoc != null)
                {
                    sm.ActivateDocument(newdoc, ActivateReason.InternalAction);
                }
            }

            return(CommandResult.Succeeded);
        }
示例#2
0
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            base.OnClosing(e);
            try {
                if (SessionManagerPlugin.Instance == null)
                {
                    return; //単体テストではSessionなしで起動することもありだ
                }
                IPoderosaDocument doc = _view.Document;
                if (doc == null)
                {
                    return;
                }

                PrepareCloseResult r = SessionManagerPlugin.Instance.CloseDocument(doc);
                if (r == PrepareCloseResult.Cancel)
                {
                    _closeCancelled = true;
                    e.Cancel        = true;
                }
                else
                {
                    e.Cancel = false;
                }
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
                e.Cancel = false; //バグのためにウィンドウを閉じることもできない、というのはまずい
            }
        }
示例#3
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);
        }
示例#4
0
        private static CommandResult CmdCloseAll(ICommandTarget target)
        {
            IPoderosaMainWindow window = CommandTargetUtil.AsWindow(target);

            if (window == null)
            {
                return(CommandResult.Ignored);
            }

            IPoderosaDocument[] hosted_documents = SessionManagerPlugin.Instance.GetDocuments(window);
            PrepareCloseResult  r = SessionManagerPlugin.Instance.CloseMultipleDocuments(new ClosingContext(window), hosted_documents);

            return(r == PrepareCloseResult.Cancel ? CommandResult.Cancelled : CommandResult.Succeeded);
        }
示例#5
0
        public PrepareCloseResult TerminateSession(ISession session)
        {
            SessionHost        sh = FindSessionHost(session);
            PrepareCloseResult r  = sh.Session.PrepareCloseSession();

            Debug.Assert(r != PrepareCloseResult.ContinueSession, "sanity");
            if (r == PrepareCloseResult.Cancel)
            {
                return(r);
            }

            CleanupSession(sh);
            return(r);
        }
示例#6
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);
        }