예제 #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
        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);
            }
        }
예제 #3
0
        public void MouseMiddleButton(TabKey key)
        {
            IPoderosaDocument    doc = KeyToDocument(key);
            SessionManagerPlugin sm  = SessionManagerPlugin.Instance;

            bool          was_active = _tabBarTable.ActiveTabKey == key;
            IPoderosaView view       = sm.FindDocumentHost(doc).LastAttachedView;

            sm.CloseDocument(doc);

            //アクティブなやつを閉じたらば
            if (was_active && view != null && view.Document != null)
            {
                sm.ActivateDocument(view.Document, ActivateReason.InternalAction);
            }
        }