atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * *
|
| 5 | * This program is free software; you can redistribute it and/or modify *
|
| 6 | * it under the terms of the GNU General Public License as published by *
|
| 7 | * the Free Software Foundation; either version 3 of the License, or *
|
| 8 | * (at your option) any later version. *
|
| 9 | * *
|
| 10 | * This program is distributed in the hope that it will be useful, *
|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 13 | * GNU General Public License for more details. *
|
| 14 | * *
|
| 15 | * You should have received a copy of the GNU General Public License *
|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 17 | **************************************************************************/
|
| 18 | #include "pch.h"
|
| 19 |
|
| 20 | #include "RingConsolePanel.xaml.h"
|
| 21 |
|
| 22 | using namespace RingClientUWP;
|
| 23 | using namespace RingClientUWP::Views;
|
| 24 | using namespace Windows::ApplicationModel::Core;
|
| 25 | using namespace Windows::UI::Core;
|
| 26 | using namespace Windows::UI::Xaml::Documents;
|
| 27 |
|
| 28 | RingConsolePanel::RingConsolePanel()
|
| 29 | {
|
| 30 | InitializeComponent();
|
| 31 |
|
| 32 | RingDebug::instance->messageToScreen += ref new debugMessageToScreen([this](Platform::String^ message) {
|
| 33 | output(message);
|
| 34 | });
|
| 35 | }
|
| 36 |
|
| 37 | void
|
| 38 | RingConsolePanel::output(Platform::String^ message)
|
| 39 | {
|
| 40 | try {
|
| 41 | Run^ inlineText = ref new Run();
|
| 42 | inlineText->Text = message;
|
| 43 | Paragraph^ paragraph = ref new Paragraph();
|
| 44 | paragraph->Inlines->Append(inlineText);
|
| 45 | _debugWindowOutput_->Blocks->Append(paragraph);
|
| 46 | _scrollView_->UpdateLayout();
|
| 47 | _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
|
| 48 | }
|
| 49 | catch (Platform::Exception^ e) {
|
| 50 | return;
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | void RingConsolePanel::_btnSendDbgCmd__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 55 | {
|
| 56 | sendCommand();
|
| 57 | }
|
| 58 |
|
| 59 |
|
| 60 | void RingConsolePanel::_sendDbgCmd__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
|
| 61 | {
|
| 62 | if (e->Key == Windows::System::VirtualKey::Enter && _tBoxDbg_->Text != "") {
|
| 63 | sendCommand();
|
| 64 | }
|
| 65 | else if (e->Key == Windows::System::VirtualKey::PageUp) {
|
| 66 |
|
| 67 | if (historyLevel < 1)
|
| 68 | return;
|
| 69 | if (historyLevel == historyCmds.Size)
|
| 70 | currentCmd = _tBoxDbg_->Text;
|
| 71 | historyLevel--;
|
| 72 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 73 |
|
| 74 | }
|
| 75 | else if (e->Key == Windows::System::VirtualKey::PageDown) {
|
| 76 | if (historyLevel < historyCmds.Size) {
|
| 77 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 78 | historyLevel++;
|
| 79 |
|
| 80 | }
|
| 81 | else {
|
| 82 | _tBoxDbg_->Text = currentCmd;
|
| 83 | }
|
| 84 | return;
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | /*\ ADD EACH NEW COMMAND TO THE HELP LIST \*/
|
| 89 | void RingConsolePanel::sendCommand()
|
| 90 | {
|
| 91 | auto cmdInput = _tBoxDbg_->Text;
|
| 92 | addCommandToHistory();
|
| 93 | historyLevel++;
|
| 94 | _tBoxDbg_->Text = "";
|
| 95 | currentCmd = "";
|
| 96 | historyLevel = historyCmds.Size;
|
| 97 |
|
| 98 | if (cmdInput == "") {
|
| 99 | return;
|
| 100 | }
|
| 101 | else if (cmdInput == "help") {
|
| 102 | MSG_(">> Help :");
|
| 103 | MSG_("use PgUp/PgDown for crawling commands history.");
|
| 104 | return;
|
| 105 | }
|
| 106 |
|
| 107 | std::wstring wStr(cmdInput->Begin());
|
| 108 | std::string result(wStr.begin(), wStr.end());
|
| 109 |
|
| 110 | MSG_(">> error, command \'" + result + "\' not found");
|
| 111 | }
|
| 112 |
|
| 113 | void RingConsolePanel::addCommandToHistory()
|
| 114 | {
|
| 115 | historyCmds.Append(_tBoxDbg_->Text);
|
Nicolas Jager | 32ed1a2 | 2016-08-17 08:36:02 -0400 | [diff] [blame] | 116 | }
|