1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : console_frame.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 21 2009)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "console_frame.h"
#include "drawingutils.h"
#include "event_notifier.h"
#include "globals.h"
#include "imanager.h"
#include "plugin.h"
#include "windowattrmanager.h"
#include <wx/app.h>
///////////////////////////////////////////////////////////////////////////
ConsoleFrame::ConsoleFrame(wxWindow* parent)
: wxFrame(parent, wxID_ANY, _("Console"))
{
CreateGUIControls();
}
#if USE_SFTP
ConsoleFrame::ConsoleFrame(wxWindow* parent, clSSH::Ptr_t ssh)
: wxFrame(parent, wxID_ANY, _("Console"))
, m_ssh(ssh)
{
CreateGUIControls();
m_terminal->Bind(wxEVT_TERMINAL_EXECUTE_COMMAND, &ConsoleFrame::OnExecuteRemoteCommand, this);
m_channel.reset(new clSSHChannel(m_ssh, clSSHChannel::kRemoteCommand, this));
Bind(wxEVT_SSH_CHANNEL_CLOSED, &ConsoleFrame::OnChannelClosed, this);
Bind(wxEVT_SSH_CHANNEL_READ_ERROR, &ConsoleFrame::OnChannelReadError, this);
Bind(wxEVT_SSH_CHANNEL_READ_OUTPUT, &ConsoleFrame::OnChannelRead, this);
Bind(wxEVT_SSH_CHANNEL_PTY, &ConsoleFrame::OnChannelPty, this);
}
#endif
ConsoleFrame::~ConsoleFrame()
{
m_terminal->Unbind(wxEVT_TERMINAL_EXIT_WHEN_DONE, &ConsoleFrame::OnExitWhenDone, this);
m_terminal->Unbind(wxEVT_TERMINAL_CTRL_C, &ConsoleFrame::OnTerminalCtrlC, this);
}
void ConsoleFrame::CreateGUIControls()
{
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer(wxVERTICAL);
m_terminal = new wxTerminal(this);
m_terminal->SetInteractive(true);
bSizer1->Add(m_terminal, 1, wxEXPAND);
this->SetSizer(bSizer1);
this->Layout();
m_terminal->Focus();
SetSize(wxDLG_UNIT(this, wxSize(500, 300)));
SetName("ConsoleFrame");
CenterOnScreen();
WindowAttrManager::Load(this);
m_terminal->Bind(wxEVT_TERMINAL_EXIT_WHEN_DONE, &ConsoleFrame::OnExitWhenDone, this);
m_terminal->Bind(wxEVT_TERMINAL_CTRL_C, &ConsoleFrame::OnTerminalCtrlC, this);
}
#if USE_SFTP
void ConsoleFrame::OnExecuteRemoteCommand(clCommandEvent& event)
{
try {
if(m_channel->IsOpen()) {
return;
}
if(!m_channel->IsOpen()) {
m_channel->Open();
}
m_channel->Execute(event.GetString());
} catch(clException& e) {
m_terminal->AddTextWithEOL(e.What());
}
}
void ConsoleFrame::OnChannelReadError(clCommandEvent& event)
{
wxUnusedVar(event);
m_terminal->AddTextRaw("\n");
m_terminal->CaretToEnd();
m_channel->Close();
}
void ConsoleFrame::OnChannelRead(clCommandEvent& event)
{
m_terminal->AddTextRaw(event.GetString());
m_terminal->CaretToEnd();
}
void ConsoleFrame::OnChannelClosed(clCommandEvent& event)
{
wxUnusedVar(event);
m_terminal->AddTextRaw("\n");
m_terminal->CaretToEnd();
m_channel->Close();
}
void ConsoleFrame::OnChannelPty(clCommandEvent& event)
{
m_terminal->AddTextRaw("TTY=" + event.GetString() + "\n");
m_terminal->CaretToEnd();
}
#endif
void ConsoleFrame::Execute(const wxString& command, const wxString& wd) { m_terminal->Execute(command, true, wd); }
void ConsoleFrame::OnExitWhenDone(clCommandEvent& event)
{
wxUnusedVar(event);
Close();
}
void ConsoleFrame::OnTerminalCtrlC(clCommandEvent& event)
{
event.Skip();
#if USE_SFTP
if(m_channel->IsOpen()) {
m_channel->Close();
m_terminal->AddTextWithEOL(_("\nInterrupted"));
event.Skip(false); // No need for the default action
}
#endif
}
|