private ISplittableViewManager GetSplittableViewManager()
        {
            IContentReplaceableView v = AsControlReplaceableView();

            if (v == null)
            {
                return(null);
            }
            else
            {
                return((ISplittableViewManager)v.ViewManager.GetAdapter(typeof(ISplittableViewManager)));
            }
        }
Example #2
0
        private static CommandResult CmdSplitVertical(ICommandTarget target)
        {
            IContentReplaceableView view = CommandTargetUtil.AsContentReplaceableViewOrLastActivatedView(target);

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

            ISplittableViewManager svm = (ISplittableViewManager)view.ViewManager.GetAdapter(typeof(ISplittableViewManager));

            return(svm.SplitVertical(view, null));
        }
Example #3
0
        private static bool CanSplitUnify(ICommandTarget target)
        {
            IContentReplaceableView view = CommandTargetUtil.AsContentReplaceableViewOrLastActivatedView(target);

            if (view == null)
            {
                return(false);
            }

            ISplittableViewManager svm = (ISplittableViewManager)view.ViewManager.GetAdapter(typeof(ISplittableViewManager));

            return(svm.CanUnify(view));
        }
Example #4
0
        private static TerminalControl CastOrCreateTerminalControl(IPoderosaView view)
        {
            TerminalControl c = CastTerminalControl(view);

            if (c != null)
            {
                return(c);        //キャストできればそれでOK。でなければ作る
            }
            Debug.WriteLine("Creating New TerminalControl");
            IContentReplaceableView rv = (IContentReplaceableView)view.GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         tc = new TerminalControl();

            rv.ReplaceContent(new TerminalView(view.ParentForm, tc));
            return(tc);
        }
Example #5
0
        public void DetachView()
        {
            Debug.Assert(_currentView != null);
            IContentReplaceableView rv           = (IContentReplaceableView)_currentView.GetAdapter(typeof(IContentReplaceableView));
            IPoderosaView           internalview = rv == null ? _currentView : rv.GetCurrentContent(); //ContentReplaceableViewのときは中身を使用

            _sessionHost.Session.InternalDetachView(_document, internalview);

            if (rv != null && rv.AsControl().Visible)
            {
                rv.AssureEmptyViewClass();
            }

            _currentView = null;
        }
Example #6
0
        //ビューからのコントロールの取得
        private static TerminalControl CastTerminalControl(IPoderosaView view)
        {
            IContentReplaceableView rv = (IContentReplaceableView)view.GetAdapter(typeof(IContentReplaceableView));

            Debug.Assert(rv != null); //現状では分割方式でしか動作していないのでここまでは必ず成功
            IPoderosaView content = rv.GetCurrentContent();

            if (content is TerminalView)
            {
                return(((TerminalView)content).TerminalControl);
            }
            else
            {
                return(null);
            }
        }
Example #7
0
 private static string ViewName(IPoderosaView view)
 {
     if (view == null)
     {
         return("null");
     }
     else
     {
         IContentReplaceableView rv = (IContentReplaceableView)view.GetAdapter(typeof(IContentReplaceableView));
         if (rv != null)
         {
             return(rv.GetCurrentContent().GetType().Name);
         }
         else
         {
             return(view.GetType().Name);
         }
     }
 }
Example #8
0
        public static ITerminalSession InvokeOpenSessionOrNull(ICommandTarget target, TerminalParam param)
        {
            ITerminalParameter tp = param.ConvertToTerminalParameter();
            ITerminalSettings  ts = CreateTerminalSettings(param);

            IViewManager pm = CommandTargetUtil.AsWindow(target).ViewManager;
            //独立ウィンドウにポップアップさせるようなことは考えていない
            IContentReplaceableView rv = (IContentReplaceableView)pm.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         tc = (TerminalControl)rv.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (tc != null)   //ターミナルコントロールがないときは無理に設定しにいかない
            {
                RenderProfile rp = ts.UsingDefaultRenderProfile ? MacroPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile() : ts.RenderProfile;
                Size          sz = tc.CalcTerminalSize(rp);
                tp.SetTerminalSize(sz.Width, sz.Height);
            }


            return((ITerminalSession)MacroPlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(OpenSessionOrNull), tp, ts));
        }
        private static IPoderosaView ToPoderosaView(ICommandTarget target)
        {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
            IPoderosaView       view;

            if (window != null)
            {
                view = window.ViewManager.GetCandidateViewForNewDocument();
            }
            else
            {
                view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
                Debug.Assert(view != null);
            }

            IContentReplaceableView rv = (IContentReplaceableView)view.GetAdapter(typeof(IContentReplaceableView));

            if (rv != null)
            {
                view = rv.AssureViewClass(typeof(TerminalView));
            }
            return(view);
        }
Example #10
0
 public bool CanSplit(IContentReplaceableView view)
 {
     return(_paneDivision.CountLimit >= _paneDivision.PaneCount);
 }
Example #11
0
 public CommandResult UnifyAll(out IContentReplaceableView next)
 {
     PaneDivision.IPane nextfocus = null;
     UnifyAll(out nextfocus);
     next = (IContentReplaceableView)nextfocus;
     return CommandResult.Succeeded;
 }
Example #12
0
 public CommandResult Unify(IContentReplaceableView view, out IContentReplaceableView next)
 {
     PaneDivision.IPane nextfocus = null;
     bool r = Unify((PaneDivision.IPane)view.GetAdapter(typeof(PaneDivision.IPane)), out nextfocus);
     next = r ? (IContentReplaceableView)nextfocus : null; //TODO ���傢�܂�
     return r ? CommandResult.Succeeded : CommandResult.Failed;
 }
Example #13
0
 public CommandResult SplitVertical(IContentReplaceableView view, IViewFactory factory)
 {
     if (factory == null)
         factory = _defaultViewFactory;
     SplitVertical((PaneDivision.IPane)view.GetAdapter(typeof(PaneDivision.IPane)), factory);
     return CommandResult.Succeeded;
 }
Example #14
0
 public bool CanUnify(IContentReplaceableView view)
 {
     return _paneDivision.PaneCount > 1;
 }
Example #15
0
 public bool CanSplit(IContentReplaceableView view)
 {
     return _paneDivision.CountLimit >= _paneDivision.PaneCount;
 }
Example #16
0
 public bool CanUnify(IContentReplaceableView view)
 {
     return(_paneDivision.PaneCount > 1);
 }
Example #17
0
        public static CommandResult OpenShortcutFile(ICommandTarget target, string filename)
        {
            IPoderosaMainWindow window = CommandTargetUtil.AsWindow(target);

            if (window == null)
            {
                window = (IPoderosaMainWindow)CommandTargetUtil.AsViewOrLastActivatedView(target).ParentForm.GetAdapter(typeof(IPoderosaMainWindow));
            }
            if (window == null)
            {
                return(CommandResult.Ignored);
            }

            if (!File.Exists(filename))
            {
                window.Warning(String.Format("{0} is not a file", filename));
                return(CommandResult.Failed);
            }

            ShortcutFileContent f = null;

            try {
                f = ShortcutFileContent.LoadFromXML(filename);
            }
            catch (Exception ex) {
                //変なファイルをドロップしたなどで例外は簡単に起こりうる
                window.Warning(String.Format("Failed to read {0}\n{1}", filename, ex.Message));
                return(CommandResult.Failed);
            }

            try {
                //独立ウィンドウにポップアップさせるようなことは考えていない
                IContentReplaceableView rv = (IContentReplaceableView)target.GetAdapter(typeof(IContentReplaceableView));
                if (rv == null)
                {
                    rv = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
                }

                TerminalControl tc = (TerminalControl)rv.GetCurrentContent().GetAdapter(typeof(TerminalControl));
                if (tc != null) //ターミナルコントロールがないときは無理に設定しにいかない
                {
                    Size sz;
                    if (f.TerminalSettings.UsingDefaultRenderProfile)
                    {
                        using (RenderProfile profile = TerminalSessionsPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile())
                            sz = tc.CalcTerminalSize(profile);
                    }
                    else
                    {
                        sz = tc.CalcTerminalSize(f.TerminalSettings.RenderProfile);
                    }
                    //RenderProfile rp = f.TerminalSettings.UsingDefaultRenderProfile? TerminalSessionsPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile() : f.TerminalSettings.RenderProfile;
                    //Size sz = tc.CalcTerminalSize(rp);
                    f.TerminalParameter.SetTerminalSize(sz.Width, sz.Height);
                }

                ITerminalSession s = TerminalSessionsPlugin.Instance.TerminalSessionStartCommand.StartTerminalSession(target, f.TerminalParameter, f.TerminalSettings);
                return(s != null? CommandResult.Succeeded : CommandResult.Failed);
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
                return(CommandResult.Failed);
            }
        }
        /// <summary>
        /// 接続
        /// </summary>
        public void Connect()
        {
            ITCPParameter tcp = null;

            // プロトコル
            if (_prof.Protocol == ConnectionMethod.Telnet)
            {
                // Telnet
                tcp             = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
                tcp.Destination = _prof.HostName;
                tcp.Port        = _prof.Port;
                ITelnetParameter telnetParameter = null;
                telnetParameter = (ITelnetParameter)tcp.GetAdapter(typeof(ITelnetParameter));
                if (telnetParameter != null)
                {
                    telnetParameter.TelnetNewLine = _prof.TelnetNewLine;
                }
            }
            else if ((_prof.Protocol == ConnectionMethod.SSH1) || (_prof.Protocol == ConnectionMethod.SSH2))
            {
                // SSH
                ISSHLoginParameter ssh = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                tcp                      = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                tcp.Destination          = _prof.HostName;
                tcp.Port                 = _prof.Port;
                ssh.Method               = (_prof.Protocol == ConnectionMethod.SSH1) ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                ssh.Account              = _prof.UserName;
                ssh.AuthenticationType   = ConvertAuth(_prof.AuthType);
                ssh.PasswordOrPassphrase = _prof.Password;
                ssh.IdentityFileName     = _prof.KeyFile;
                ssh.LetUserInputPassword = (_prof.AutoLogin == true) ? false : true;
            }

            // TerminalSettings(表示プロファイル/改行コード/文字コード)
            ITerminalSettings terminalSettings = ConnectProfilePlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(_prof.HostName, null);

            terminalSettings.BeginUpdate();
            terminalSettings.RenderProfile = _prof.RenderProfile;
            terminalSettings.TransmitNL    = _prof.NewLine;
            terminalSettings.Encoding      = _prof.CharCode;
            terminalSettings.LocalEcho     = false;
            terminalSettings.EndUpdate();

            // TerminalParameter
            ITerminalParameter terminalParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));

            // ターミナルサイズ(これを行わないとPoderosa起動直後のOnReceptionが何故か機能しない, 行わない場合は2回目以降の接続時は正常)
            IViewManager            viewManager            = CommandTargetUtil.AsWindow(ConnectProfilePlugin.Instance.WindowManager.ActiveWindow).ViewManager;
            IContentReplaceableView contentReplaceableView = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         terminalControl        = (TerminalControl)contentReplaceableView.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (terminalControl != null)
            {
                Size size = terminalControl.CalcTerminalSize(terminalSettings.RenderProfile);
                terminalParam.SetTerminalSize(size.Width, size.Height);
            }

            // 接続(セッションオープン)
            _terminalSession = (ITerminalSession)ConnectProfilePlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(InvokeOpenSessionOrNull), terminalParam, terminalSettings);

            // 自動ログイン/SU/実行コマンド
            if (_terminalSession != null)
            {
                // 受信データオブジェクト作成(ユーザからのキーボード入力が不可)
                ReceptionData pool = new ReceptionData();
                _terminalSession.Terminal.StartModalTerminalTask(pool);

                // Telnet自動ログイン
                if ((_prof.AutoLogin == true) && (_prof.Protocol == ConnectionMethod.Telnet))
                {
                    if (TelnetAutoLogin() != true)
                    {
                        return;
                    }
                }

                // SU
                if ((_prof.AutoLogin == true) && (_prof.SUUserName != ""))
                {
                    if (SUSwitch() != true)
                    {
                        return;
                    }
                }

                // 実行コマンド
                if ((_prof.AutoLogin == true) && (_prof.ExecCommand != ""))
                {
                    if (ExecCommand() != true)
                    {
                        return;
                    }
                }

                // 受信データオブジェクト定義解除(ユーザからのキーボード入力を許可)
                _terminalSession.Terminal.EndModalTerminalTask();
            }
        }
Example #19
0
        /// <summary>
        /// Called when <see cref="IProtocolService.AsyncSSHConnect"/> is able to successfully establish the SSH connection.  Creates a new
        /// <see cref="IPoderosaMainWindow"/> instance and points the newly created connection to a new document instance within that window.  We then steal
        /// the <see cref="IContentReplaceableView"/> terminal window from Poderosa and set its parent to ourself, thus displaying the terminal within this
        /// control.
        /// </summary>
        /// <param name="result">Newly-created SSH connection.</param>
        public void SuccessfullyExit(ITerminalConnection result)
        {
            ICoreServices  coreServices  = (ICoreServices)_poderosaWorld.GetAdapter(typeof(ICoreServices));
            IWindowManager windowManager = coreServices.WindowManager;

            // Wire up the event handlers on the newly-created connection.
            (result as ICloseableTerminalConnection).ConnectionClosed += TerminalControl_ConnectionClosed;
            (result as ICloseableTerminalConnection).ConnectionLost   += TerminalControl_ConnectionLost;

            // We run all of this logic within an Invoke() to avoid trying to do this on the wrong GUI thread
            windowManager.MainWindows.First().AsForm().Invoke(
                new Action(
                    () =>
            {
                // Create a new Poderosa window to contain the connection terminal
                IPoderosaMainWindow window       = windowManager.CreateNewWindow(new MainWindowArgument(ClientRectangle, FormWindowState.Normal, "", "", 1));
                IViewManager viewManager         = window.ViewManager;
                Sessions.TerminalSession session = new Sessions.TerminalSession(result, _settings);

                // Create a new connection window within the Poderosa window, which we will later steal
                IContentReplaceableView view = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
                coreServices.SessionManager.StartNewSession(session, view);

                session.TerminalControl.HideSizeTip = true;

                Form containerForm = view.ParentForm.AsForm();

                // Hide all of the toolbar and statusbar chrome in the connection window and display only the terminal itself (it's a little
                // clumsy, I know)
                foreach (Control control in containerForm.Controls)
                {
                    if (control is MenuStrip || control.GetType().Name == "PoderosaStatusBar")
                    {
                        control.Visible = false;
                    }

                    else if (control.GetType().Name == "PoderosaToolStripContainer")
                    {
                        foreach (ToolStripPanel child in control.Controls.OfType <ToolStripPanel>())
                        {
                            child.Visible = false;
                        }

                        foreach (ToolStripContentPanel child in control.Controls.OfType <ToolStripContentPanel>())
                        {
                            foreach (Control grandChild in child.Controls)
                            {
                                if (grandChild.GetType().Name != "TerminalControl")
                                {
                                    grandChild.Visible = false;
                                }
                            }
                        }
                    }
                }

                // Steal the terminal view and display it within this control
                containerForm.TopLevel        = false;
                containerForm.FormBorderStyle = FormBorderStyle.None;
                containerForm.Width           = Width;
                containerForm.Height          = Height;
                containerForm.Dock            = DockStyle.Fill;
                containerForm.Parent          = this;

                view.AsControl().Focus();
            }));

            // Invoke the Connected event
            if (Connected != null)
            {
                Connected(this, new EventArgs());
            }
        }