RingConsolePanel.xaml.cpp 3.93 KB
Newer Older
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
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com>              *
*                                                                         *
* 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 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program is distributed in the hope that it will be useful,         *
* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
* GNU General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
#include "pch.h"

#include "RingConsolePanel.xaml.h"

using namespace RingClientUWP;
using namespace RingClientUWP::Views;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Documents;

RingConsolePanel::RingConsolePanel()
{
    InitializeComponent();

    RingDebug::instance->messageToScreen += ref new debugMessageToScreen([this](Platform::String^ message) {
        output(message);
    });
}

void
RingConsolePanel::output(Platform::String^ message)
{
    try {
        Run^ inlineText = ref new Run();
        inlineText->Text = message;
        Paragraph^ paragraph = ref new Paragraph();
        paragraph->Inlines->Append(inlineText);
        _debugWindowOutput_->Blocks->Append(paragraph);
        _scrollView_->UpdateLayout();
        _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
    }
    catch (Platform::Exception^ e) {
        return;
    }
}

void RingConsolePanel::_btnSendDbgCmd__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    sendCommand();
}


void RingConsolePanel::_sendDbgCmd__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    if (e->Key == Windows::System::VirtualKey::Enter && _tBoxDbg_->Text != "") {
        sendCommand();
    }
    else if (e->Key == Windows::System::VirtualKey::PageUp) {

        if (historyLevel < 1)
            return;
        if (historyLevel == historyCmds.Size)
            currentCmd = _tBoxDbg_->Text;
        historyLevel--;
        _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);

    }
    else if (e->Key == Windows::System::VirtualKey::PageDown) {
        if (historyLevel < historyCmds.Size) {
            _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
            historyLevel++;

        }
        else {
            _tBoxDbg_->Text = currentCmd;
        }
        return;
    }
}

/*\ ADD EACH NEW COMMAND TO THE HELP LIST \*/
void RingConsolePanel::sendCommand()
{
    auto cmdInput = _tBoxDbg_->Text;
    addCommandToHistory();
    historyLevel++;
    _tBoxDbg_->Text = "";
    currentCmd = "";
    historyLevel = historyCmds.Size;

98
    if (cmdInput->IsEmpty()) {
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        return;
    }
    else if (cmdInput == "help") {
        MSG_(">> Help :");
        MSG_("use PgUp/PgDown for crawling commands history.");
        return;
    }

    std::wstring wStr(cmdInput->Begin());
    std::string result(wStr.begin(), wStr.end());

    MSG_(">> error, command \'" + result + "\' not found");
}

void RingConsolePanel::addCommandToHistory()
{
    historyCmds.Append(_tBoxDbg_->Text);
Nicolas Jager's avatar
Nicolas Jager committed
116
}