Пример #1
0
        /// <exclude/>
        public static IContentReplaceableView AsContentReplaceableViewOrLastActivatedView(ICommandTarget target)
        {
            if (target == null)
            {
                return(null);
            }
            IContentReplaceableViewSite view = (IContentReplaceableViewSite)target.GetAdapter(typeof(IContentReplaceableViewSite));

            if (view != null)
            {
                return(view.CurrentContentReplaceableView); //成功
            }
            else
            {
                IContentReplaceableView view2 = (IContentReplaceableView)target.GetAdapter(typeof(IContentReplaceableView));
                if (view2 != null)
                {
                    return(view2);
                }
                else
                {
                    IPoderosaMainWindow window = AsWindow(target);
                    if (window != null)
                    {
                        return(window.LastActivatedView);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Пример #2
0
 //ちょっと恣意的だが、ビュー直接またはLastActivatedViewで
 public static IPoderosaView AsViewOrLastActivatedView(ICommandTarget target) {
     IPoderosaView view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
     if (view != null)
         return view; //成功
     else
         return AsLastActivatedView(target);
 }
Пример #3
0
            public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

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

                using (OpenSessionDialog dlg = new OpenSessionDialog(window)) {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        IContentReplaceableView view       = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
                        IPoderosaView           targetView = view.AssureViewClass(typeof(TerminalView));

                        ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                        TerminalSession ts = new TerminalSession(dlg.TerminalConnection, dlg.TerminalSettings);
                        sm.StartNewSession(ts, targetView);
                        sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                        IAutoExecMacroParameter autoExecParam = dlg.TerminalConnection.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                        if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null)
                        {
                            TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                        }
                        return(CommandResult.Succeeded);
                    }
                    return(CommandResult.Cancelled);
                }
            }
Пример #4
0
        //ドキュメント直接指定か、Viewか、ウィンドウの最後にアクティブになったドキュメント
        /// <summary>
        /// <ja>
        /// ドキュメントまたは最後にアクティブであったドキュメントに変換します。
        /// </ja>
        /// <en>
        /// It converts it at the document or the end into an active document.
        /// </en>
        /// </summary>
        /// <param name="target">
        /// <ja>対象となるターゲット。</ja>
        /// <en>It is a target that becomes an object. </en>
        /// </param>
        /// <returns>
        /// <ja>変換したインターフェイスです。変換できないときにはnullが戻ります。</ja>
        /// <en>It is a converted interface. Null returns when it is not possible to convert it. </en>
        /// </returns>
        /// <remarks>
        /// <ja>
        /// このメソッドは、まず、<paramref name="target"/>をIPoderosaDocumentに変換しようとし、変換できたならそのインターフェイスを返します。
        /// 変換できない場合には、<see cref="AsViewOrLastActivatedView">AsViewOrLastActivatedViewメソッド</see>を呼び出して得たビューの<see cref="IPoderosaView.Document">Documentプロパティ</see>
        /// からドキュメントを得ます。
        /// </ja>
        /// <en>
        /// If it tries to convert <paramref name="target"/> into IPoderosaDocument first of all, and it was possible to convert it, this method returns the interface.
        /// The document is obtained from the <see cref="IPoderosaView.Document">Document property</see> of the view that calls the <see cref="AsViewOrLastActivatedView">AsViewOrLastActivatedView method</see> when it is not possible to convert it and obtains it.
        /// </en>
        /// </remarks>
        public static IPoderosaDocument AsDocumentOrViewOrLastActivatedDocument(ICommandTarget target)
        {
            IPoderosaDocument doc = null;

            if (target != null)
            {
                doc = (IPoderosaDocument)target.GetAdapter(typeof(IPoderosaDocument));
            }

            if (doc != null)
            {
                return(doc);
            }
            else
            {
                IPoderosaView view = AsViewOrLastActivatedView(target);
                if (view != null)
                {
                    return(view.Document);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Command execution
        /// </summary>
        public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            PipeTerminalParameter paramInit    = null;
            PipeTerminalSettings  settingsInit = null;

            IExtensionPoint ext = PipePlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.loginDialogUISupport");

            if (ext != null && ext.ExtensionInterface == typeof(ILoginDialogUISupport))
            {
                foreach (ILoginDialogUISupport sup in ext.GetExtensions())
                {
                    ITerminalParameter terminalParam;
                    ITerminalSettings  terminalSettings;
                    sup.FillTopDestination(typeof(PipeTerminalParameter), out terminalParam, out terminalSettings);
                    PipeTerminalParameter paramTemp    = terminalParam as PipeTerminalParameter;
                    PipeTerminalSettings  settingsTemp = terminalSettings as PipeTerminalSettings;
                    if (paramInit == null)
                    {
                        paramInit = paramTemp;
                    }
                    if (settingsInit == null)
                    {
                        settingsInit = settingsTemp;
                    }
                }
            }
            if (paramInit == null)
            {
                paramInit = new PipeTerminalParameter();
            }
            if (settingsInit == null)
            {
                settingsInit = new PipeTerminalSettings();
            }

            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            CommandResult commandResult = CommandResult.Failed;

            using (OpenPipeDialog dialog = new OpenPipeDialog()) {
                dialog.OpenPipe =
                    delegate(PipeTerminalParameter param, PipeTerminalSettings settings) {
                    PipeTerminalConnection connection = PipeCreator.CreateNewPipeTerminalConnection(param, settings);
                    commandResult = PipePlugin.Instance.CommandManager.Execute(
                        PipePlugin.Instance.TerminalSessionsService.TerminalSessionStartCommand,
                        window, connection, settings);
                    return(commandResult == CommandResult.Succeeded);
                };

                dialog.ApplyParams(paramInit, settingsInit);

                DialogResult dialogResult = dialog.ShowDialog(window != null ? window.AsForm() : null);
                if (dialogResult == DialogResult.Cancel)
                {
                    commandResult = CommandResult.Cancelled;
                }
            }

            return(commandResult);
        }
Пример #6
0
 /// <summary>
 /// Gets System.Windows.Forms.Form of the target.
 /// </summary>
 /// <param name="target">Target object which has been passed to the IPoderosaCommand's method.</param>
 /// <returns>Form object if it is available. Otherwise null.</returns>
 protected Form GetForm(ICommandTarget target)
 {
     IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
     if (window != null)
         return window.AsForm();
     else
         return null;
 }
Пример #7
0
        /// <summary>
        /// <ja>
        /// ポップアップウィンドウへと変換します。
        /// </ja>
        /// <en>
        /// Convert to the popup window.
        /// </en>
        /// </summary>
        /// <param name="target">
        /// <ja>対象となるターゲットです。</ja>
        /// <en>It is a target that becomes an object. </en>
        /// </param>
        /// <returns>
        /// <ja>変換したインターフェイスです。変換できないときにはnullが戻ります。</ja>
        /// <en>It is a converted interface. Null returns when it is not possible to convert it. </en>
        /// </returns>
        public static IPoderosaPopupWindow AsPopupWindow(ICommandTarget target)
        {
            if (target == null)
            {
                return(null);
            }
            IPoderosaPopupWindow window = (IPoderosaPopupWindow)target.GetAdapter(typeof(IPoderosaPopupWindow));

            return(window);
        }
Пример #8
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)   //ターミナルコントロールがないときは無理に設定しにいかない
                {
                    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);
            }
        }
        //Parameterからスタートするタイプ 今はtargetはwindow強制だがViewでも可能にしたい
        public ITerminalSession StartTerminalSession(ICommandTarget target, ITerminalParameter destination, ITerminalSettings settings)
        {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            if (window == null)
            {
                IPoderosaView view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
                window = (IPoderosaMainWindow)view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow));
            }
            Debug.Assert(window != null);

            ITerminalConnection connection = OpenConnection(window, destination, settings);

            if (connection == null)
            {
                return(null);
            }

            return(StartTerminalSession(target, connection, settings));
        }
Пример #10
0
 public static IPoderosaView AsLastActivatedView(ICommandTarget target) {
     IPoderosaMainWindow window = AsWindow(target);
     if (window != null)
         return window.LastActivatedView;
     else {
         IPoderosaPopupWindow popup = (IPoderosaPopupWindow)target.GetAdapter(typeof(IPoderosaPopupWindow));
         if (popup != null)
             return popup.InternalView;
         else
             return null;
     }
 }
Пример #11
0
        //ちょっと恣意的だが、ビュー直接またはLastActivatedViewで
        public static IPoderosaView AsViewOrLastActivatedView(ICommandTarget target)
        {
            IPoderosaView view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));

            if (view != null)
            {
                return(view); //成功
            }
            else
            {
                return(AsLastActivatedView(target));
            }
        }
Пример #12
0
        /// <summary>
        /// Get ITerminalConnection object from the target.
        /// </summary>
        /// <param name="target">Target object which has been passed to the IPoderosaCommand's method.</param>
        /// <returns>A ITerminalConnection object corresponding with current terminal. Null if it cannot be found.</returns>
        private IPoderosaDocument GetTerminalDocument(ICommandTarget target)
        {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            if (window != null && window.LastActivatedView != null)
            {
                return(window.LastActivatedView.Document);
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
        /// <summary>
        /// Gets System.Windows.Forms.Form of the target.
        /// </summary>
        /// <param name="target">Target object which has been passed to the IPoderosaCommand's method.</param>
        /// <returns>Form object if it is available. Otherwise null.</returns>
        protected Form GetForm(ICommandTarget target)
        {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            if (window != null)
            {
                return(window.AsForm());
            }
            else
            {
                return(null);
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        /// <summary>
        /// Command execution
        /// </summary>
        public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            PipeTerminalParameter paramInit = null;
            PipeTerminalSettings settingsInit = null;

            IExtensionPoint ext = PipePlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.loginDialogUISupport");
            if (ext != null && ext.ExtensionInterface == typeof(ILoginDialogUISupport)) {
                foreach (ILoginDialogUISupport sup in ext.GetExtensions()) {
                    ITerminalParameter terminalParam;
                    ITerminalSettings terminalSettings;
                    sup.FillTopDestination(typeof(PipeTerminalParameter), out terminalParam, out terminalSettings);
                    PipeTerminalParameter paramTemp = terminalParam as PipeTerminalParameter;
                    PipeTerminalSettings settingsTemp = terminalSettings as PipeTerminalSettings;
                    if (paramInit == null)
                        paramInit = paramTemp;
                    if (settingsInit == null)
                        settingsInit = settingsTemp;
                }
            }
            if (paramInit == null)
                paramInit = new PipeTerminalParameter();
            if (settingsInit == null)
                settingsInit = new PipeTerminalSettings();

            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            CommandResult commandResult = CommandResult.Failed;

            using (OpenPipeDialog dialog = new OpenPipeDialog()) {

                dialog.OpenPipe =
                    delegate(PipeTerminalParameter param, PipeTerminalSettings settings) {
                        PipeTerminalConnection connection = PipeCreator.CreateNewPipeTerminalConnection(param, settings);
                        commandResult = PipePlugin.Instance.CommandManager.Execute(
                                            PipePlugin.Instance.TerminalSessionsService.TerminalSessionStartCommand,
                                            window, connection, settings);
                        return (commandResult == CommandResult.Succeeded);
                    };

                dialog.ApplyParams(paramInit, settingsInit);

                DialogResult dialogResult = dialog.ShowDialog(window != null ? window.AsForm() : null);
                if (dialogResult == DialogResult.Cancel)
                    commandResult = CommandResult.Cancelled;
            }

            return commandResult;
        }
Пример #16
0
 private bool GetViewAndSession(ICommandTarget target, out IPoderosaView view, out ITerminalSession session)
 {
     view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
     if (view != null && view.Document != null)
     {
         session = (ITerminalSession)view.Document.OwnerSession.GetAdapter(typeof(ITerminalSession));
         if (!session.TerminalConnection.IsClosed)
         {
             return(true);
         }
     }
     else
     {
         session = null;
     }
     return(false);
 }
Пример #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) { //ターミナルコントロールがないときは無理に設定しにいかない
                    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;
            }
        }
Пример #18
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) {
                //�ςȃt�@�C����h���b�v�����Ȃǂŗ�O�͊ȒP�ɋN���肤��
                window.Warning(String.Format("Failed to read {0}\n{1}", filename, ex.Message));
                return CommandResult.Failed;
            }

            try {
                //�Ɨ��E�B���h�E�Ƀ|�b�v�A�b�v������悤�Ȃ��Ƃ͍l���Ă��Ȃ�
                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) { //�^�[�~�i���R���g���[�����Ȃ��Ƃ��͖����ɐݒ肵�ɂ����Ȃ�
                    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;
            }
        }
Пример #19
0
        public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            CharacterDocumentViewer control = (CharacterDocumentViewer)target.GetAdapter(typeof(CharacterDocumentViewer));
            ITextSelection          s       = control.ITextSelection;

            if (s.IsEmpty || !control.EnabledEx)
            {
                return(CommandResult.Ignored);
            }

            string t = s.GetSelectedText(TextFormatOption.Default);

            if (t.Length > 0)
            {
                CopyToClipboard(t);
            }
            return(CommandResult.Succeeded);
        }
Пример #20
0
        public static IPoderosaView AsLastActivatedView(ICommandTarget target)
        {
            IPoderosaMainWindow window = AsWindow(target);

            if (window != null)
            {
                return(window.LastActivatedView);
            }
            else
            {
                IPoderosaPopupWindow popup = (IPoderosaPopupWindow)target.GetAdapter(typeof(IPoderosaPopupWindow));
                if (popup != null)
                {
                    return(popup.InternalView);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #21
0
            public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
                SerialLoginDialog   dlg    = new SerialLoginDialog();

                using (dlg) {
                    SerialTerminalParam    tp = new SerialTerminalParam();
                    SerialTerminalSettings ts = SerialPortUtil.CreateDefaultSerialTerminalSettings(tp.Port);
                    dlg.ApplyParam(tp, ts);

                    if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK)   //TODO 親ウィンドウ指定
                    {
                        ITerminalConnection con = dlg.ResultConnection;
                        if (con != null)
                        {
                            return(_instance.CommandManager.Execute(_instance.TerminalSessionsService.TerminalSessionStartCommand,
                                                                    window, con, dlg.ResultTerminalSettings));
                        }
                    }
                }
                return(CommandResult.Cancelled);
            }
Пример #22
0
            public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

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

                dlg.ApplyParam();

                CommandResult res = CommandResult.Cancelled;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    ITerminalConnection con = dlg.Result;
                    if (con != null)
                    {
                        ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                        TerminalSession ts = new TerminalSession(con, dlg.TerminalSettings);
                        sm.StartNewSession(ts, (IPoderosaView)dlg.TargetView.GetAdapter(typeof(IPoderosaView)));
                        sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                        IAutoExecMacroParameter autoExecParam = con.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                        if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null)
                        {
                            TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                        }

                        return(CommandResult.Succeeded);
                    }
                }
                dlg.Dispose();

                return(res);
            }
Пример #23
0
        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;
        }
Пример #24
0
 /// <summary>
 /// Get ITerminalConnection object from the target.
 /// </summary>
 /// <param name="target">Target object which has been passed to the IPoderosaCommand's method.</param>
 /// <returns>A ITerminalConnection object corresponding with current terminal. Null if it cannot be found.</returns>
 private IPoderosaDocument GetTerminalDocument(ICommandTarget target)
 {
     IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
     if (window != null && window.LastActivatedView != null)
         return window.LastActivatedView.Document;
     else
         return null;
 }
Пример #25
0
            public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
                if (window == null)
                    return CommandResult.Ignored;

                #if OLD_LOGIN_DIALOG
                TelnetSSHLoginDialog dlg = new TelnetSSHLoginDialog(window);

                dlg.ApplyParam();

                CommandResult res = CommandResult.Cancelled;
                if (dlg.ShowDialog() == DialogResult.OK) {
                    ITerminalConnection con = dlg.Result;
                    if (con != null) {
                        ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                        TerminalSession ts = new TerminalSession(con, dlg.TerminalSettings);
                        sm.StartNewSession(ts, (IPoderosaView)dlg.TargetView.GetAdapter(typeof(IPoderosaView)));
                        sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                        IAutoExecMacroParameter autoExecParam = con.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                        if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null) {
                            TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                        }

                        return CommandResult.Succeeded;
                    }
                }
                dlg.Dispose();

                return res;
                #else
                using (OpenSessionDialog dlg = new OpenSessionDialog(window)) {
                    if (dlg.ShowDialog() == DialogResult.OK) {
                        IContentReplaceableView view = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
                        IPoderosaView targetView = view.AssureViewClass(typeof(TerminalView));

                        ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                        TerminalSession ts = new TerminalSession(dlg.TerminalConnection, dlg.TerminalSettings);
                        sm.StartNewSession(ts, targetView);
                        sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                        IAutoExecMacroParameter autoExecParam = dlg.TerminalConnection.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                        if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null) {
                            TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                        }
                        return CommandResult.Succeeded;
                    }
                    return CommandResult.Cancelled;
                }
                #endif
            }
Пример #26
0
            public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
                if (window == null)
                    return CommandResult.Ignored;
                LocalShellLoginDialog dlg = new LocalShellLoginDialog(window);
                using (dlg) {

                    dlg.ApplyParam();

                    if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK) {
                        ITerminalConnection con = dlg.Result;
                        if (con != null) {
                            ISessionManager sm = (ISessionManager)CygwinPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                            TerminalSession ts = new TerminalSession(con, dlg.TerminalSettings);
                            sm.StartNewSession(ts, dlg.TargetView);
                            sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                            IAutoExecMacroParameter autoExecParam = con.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                            if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && CygwinPlugin.Instance.MacroEngine != null) {
                                CygwinPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                            }

                            return CommandResult.Succeeded;
                        }
                    }
                }

                return CommandResult.Cancelled;
            }
Пример #27
0
        public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            CharacterDocumentViewer control = (CharacterDocumentViewer)target.GetAdapter(typeof(CharacterDocumentViewer));
            ITextSelection s = control.ITextSelection;
            if (s.IsEmpty || !control.EnabledEx)
                return CommandResult.Ignored;

            string t = s.GetSelectedText(TextFormatOption.Default);
            if (t.Length > 0)
                CopyToClipboard(t);
            return CommandResult.Succeeded;
        }
Пример #28
0
 /// <summary>
 /// <ja>GetViewAndSession</ja>
 /// </summary>
 private bool GetViewAndSession(ICommandTarget target, out IPoderosaView view, out ITerminalSession session)
 {
     view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
     if ((view != null) && (view.Document != null)) {
         session = (ITerminalSession)view.Document.OwnerSession.GetAdapter(typeof(ITerminalSession));
         if (!session.TerminalConnection.IsClosed) return true;
     } else {
         session = null;
     }
     return false;
 }
Пример #29
0
 /// <summary>
 /// <ja>
 /// ポップアップウィンドウへと変換します。
 /// </ja>
 /// <en>
 /// Convert to the popup window.
 /// </en>
 /// </summary>
 /// <param name="target">
 /// <ja>対象となるターゲットです。</ja>
 /// <en>It is a target that becomes an object. </en>
 /// </param>
 /// <returns>
 /// <ja>変換したインターフェイスです。変換できないときにはnullが戻ります。</ja>
 /// <en>It is a converted interface. Null returns when it is not possible to convert it. </en>
 /// </returns>
 public static IPoderosaPopupWindow AsPopupWindow(ICommandTarget target)
 {
     if (target == null)
         return null;
     IPoderosaPopupWindow window = (IPoderosaPopupWindow)target.GetAdapter(typeof(IPoderosaPopupWindow));
     return window;
 }
Пример #30
0
 public bool CanExecute(ICommandTarget target)
 {
     CharacterDocumentViewer control = (CharacterDocumentViewer)target.GetAdapter(typeof(CharacterDocumentViewer));
     return control.EnabledEx && !control.ITextSelection.IsEmpty;
 }
Пример #31
0
        public static IPoderosaMainWindow AsWindow(ICommandTarget target)
        {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            return(window);
        }
Пример #32
0
        public bool CanExecute(ICommandTarget target)
        {
            CharacterDocumentViewer control = (CharacterDocumentViewer)target.GetAdapter(typeof(CharacterDocumentViewer));

            return(control.EnabledEx && !control.ITextSelection.IsEmpty);
        }
Пример #33
0
        //Parameterからスタートするタイプ 今はtargetはwindow強制だがViewでも可能にしたい
        public ITerminalSession StartTerminalSession(ICommandTarget target, ITerminalParameter destination, ITerminalSettings settings) {
            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
            if (window == null) {
                IPoderosaView view = (IPoderosaView)target.GetAdapter(typeof(IPoderosaView));
                window = (IPoderosaMainWindow)view.ParentForm.GetAdapter(typeof(IPoderosaMainWindow));
            }
            Debug.Assert(window != null);

            ITerminalConnection connection = OpenConnection(window, destination, settings);
            if (connection == null)
                return null;

            return StartTerminalSession(target, connection, settings);

        }
Пример #34
0
 public static IPoderosaMainWindow AsWindow(ICommandTarget target) {
     IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
     return window;
 }
Пример #35
0
            public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
                if (window == null)
                    return CommandResult.Ignored;
                TelnetSSHLoginDialog dlg = new TelnetSSHLoginDialog(window);

                dlg.ApplyParam();

                CommandResult res = CommandResult.Cancelled;
                //Task.Run(() =>
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        ITerminalConnection con = dlg.Result;
                        if (con != null)
                        {
                            ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager));
                            TerminalSession ts = new TerminalSession(con, dlg.TerminalSettings);
                            sm.StartNewSession(ts, (IPoderosaView)dlg.TargetView.GetAdapter(typeof(IPoderosaView)));
                            sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction);

                            IAutoExecMacroParameter autoExecParam = con.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;
                            if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null)
                            {
                                TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts);
                            }

                            return CommandResult.Succeeded;
                        }
                    }
                    dlg.Dispose();
                }
                //);

                return res;
            }
Пример #36
0
        //ドキュメント直接指定か、Viewか、ウィンドウの最後にアクティブになったドキュメント
        /// <summary>
        /// <ja>
        /// ドキュメントまたは最後にアクティブであったドキュメントに変換します。
        /// </ja>
        /// <en>
        /// It converts it at the document or the end into an active document. 
        /// </en>
        /// </summary>
        /// <param name="target">
        /// <ja>対象となるターゲット。</ja>
        /// <en>It is a target that becomes an object. </en>
        /// </param>
        /// <returns>
        /// <ja>変換したインターフェイスです。変換できないときにはnullが戻ります。</ja>
        /// <en>It is a converted interface. Null returns when it is not possible to convert it. </en>
        /// </returns>
        /// <remarks>
        /// <ja>
        /// このメソッドは、まず、<paramref name="target"/>をIPoderosaDocumentに変換しようとし、変換できたならそのインターフェイスを返します。
        /// 変換できない場合には、<see cref="AsViewOrLastActivatedView">AsViewOrLastActivatedViewメソッド</see>を呼び出して得たビューの<see cref="IPoderosaView.Document">Documentプロパティ</see>
        /// からドキュメントを得ます。
        /// </ja>
        /// <en>
        /// If it tries to convert <paramref name="target"/> into IPoderosaDocument first of all, and it was possible to convert it, this method returns the interface. 
        /// The document is obtained from the <see cref="IPoderosaView.Document">Document property</see> of the view that calls the <see cref="AsViewOrLastActivatedView">AsViewOrLastActivatedView method</see> when it is not possible to convert it and obtains it. 
        /// </en>
        /// </remarks>
        public static IPoderosaDocument AsDocumentOrViewOrLastActivatedDocument(ICommandTarget target)
        {
            IPoderosaDocument doc = null;
            if (target != null)
                doc = (IPoderosaDocument)target.GetAdapter(typeof(IPoderosaDocument));

            if (doc != null)
                return doc;
            else {
                IPoderosaView view = AsViewOrLastActivatedView(target);
                if (view != null)
                    return view.Document;
                else
                    return null;
            }
        }
Пример #37
0
            public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
            {
                IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));
                SerialLoginDialog dlg = new SerialLoginDialog();
                using (dlg) {
                    SerialTerminalParam tp = new SerialTerminalParam();
                    SerialTerminalSettings ts = SerialPortUtil.CreateDefaultSerialTerminalSettings(tp.PortName);
                    dlg.ApplyParam(tp, ts);

                    if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK) { //TODO 親ウィンドウ指定
                        ITerminalConnection con = dlg.ResultConnection;
                        if (con != null) {
                            return _instance.CommandManager.Execute(_instance.TerminalSessionsService.TerminalSessionStartCommand,
                                window, con, dlg.ResultTerminalSettings);
                        }
                    }
                }
                return CommandResult.Cancelled;
            }
Пример #38
0
 /// <exclude/>
 public static IContentReplaceableView AsContentReplaceableViewOrLastActivatedView(ICommandTarget target)
 {
     if (target == null)
         return null;
     IContentReplaceableViewSite view = (IContentReplaceableViewSite)target.GetAdapter(typeof(IContentReplaceableViewSite));
     if (view != null)
         return view.CurrentContentReplaceableView; //成功
     else {
         IContentReplaceableView view2 = (IContentReplaceableView)target.GetAdapter(typeof(IContentReplaceableView));
         if (view2 != null)
             return view2;
         else {
             IPoderosaMainWindow window = AsWindow(target);
             if (window != null)
                 return window.LastActivatedView;
             else
                 return null;
         }
     }
 }