<commit_before>/*
 * DebuggerView.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "DebuggerView.h"
#include <Xsc/Version.h>
#include <sstream>
#include <memory>
#include <vector>
#include <fstream>
#include <wx/menu.h>
#include <wx/mimetype.h>
#include <wx/msgdlg.h>


namespace Xsc
{


static long DebuggerViewStyle()
{
    return (wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxCLOSE_BOX);
}

DebuggerView::DebuggerView(const wxPoint& pos, const wxSize& size) :
    wxFrame{ nullptr, wxID_ANY, "Xsc Debugger", pos, size, DebuggerViewStyle() }
{
    #ifdef _WIN32
    SetIcon(wxICON(APP_ICON));
    #endif

    CreateLayout();

    Centre();

    Bind(wxEVT_CLOSE_WINDOW, &DebuggerView::OnClose, this);

    /* Initialize descriptor structure */
    shaderInput_.shaderTarget = ShaderTarget::VertexShader;

    inputSourceView_->SetFocus();
}

static const std::string settingsFilename("XscDebuggerSettings");
static const std::string codeFilename("XscDebuggerCode");

void DebuggerView::SaveSettings()
{
    std::ofstream settingsFile(settingsFilename);
    if (settingsFile.good())
    {
        settingsFile << propGrid_->SaveEditableState().ToStdString() << std::endl;
        settingsFile << propGrid_->GetPropertyValueAsString("entry").ToStdString() << std::endl;
    }

    std::ofstream codeFile(codeFilename);
    if (codeFile.good())
        codeFile << inputSourceView_->GetText();
}

void DebuggerView::LoadSettings()
{
    std::ifstream settingsFile(settingsFilename);
    if (settingsFile.good())
    {
        std::string state;
        std::getline(settingsFile, state);
        propGrid_->RestoreEditableState(state);

        std::getline(settingsFile, state);
        propGrid_->SetPropertyValueString("entry", state);
        shaderInput_.entryPoint = state;
    }

    std::ifstream codeFile(codeFilename);
    if (codeFile.good())
    {
        inputSourceView_->SetText(
            std::string(
                ( std::istreambuf_iterator<char>(codeFile) ),
                ( std::istreambuf_iterator<char>() )
            )
        );<commit_msg>Fixed source code line-ending in XscDebugger.<commit_after>/*
 * DebuggerView.cpp
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "DebuggerView.h"
#include <Xsc/Version.h>
#include <sstream>
#include <memory>
#include <vector>
#include <fstream>
#include <wx/menu.h>
#include <wx/mimetype.h>
#include <wx/msgdlg.h>


namespace Xsc
{


static long DebuggerViewStyle()
{
    return (wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxCLOSE_BOX);
}

DebuggerView::DebuggerView(const wxPoint& pos, const wxSize& size) :
    wxFrame{ nullptr, wxID_ANY, "Xsc Debugger", pos, size, DebuggerViewStyle() }
{
    #ifdef _WIN32
    SetIcon(wxICON(APP_ICON));
    #endif

    CreateLayout();

    Centre();

    Bind(wxEVT_CLOSE_WINDOW, &DebuggerView::OnClose, this);

    /* Initialize descriptor structure */
    shaderInput_.shaderTarget = ShaderTarget::VertexShader;

    inputSourceView_->SetFocus();
}

static const std::string settingsFilename("XscDebuggerSettings");
static const std::string codeFilename("XscDebuggerCode");

static void RemoveCharFromString(std::string& s, char c)
{
    for (auto it = s.begin(); it != s.end();)
    {
        if (*it == c)
            it = s.erase(it);
        else
            ++it;
    }
}

void DebuggerView::SaveSettings()
{
    std::ofstream settingsFile(settingsFilename);
    if (settingsFile.good())
    {
        settingsFile << propGrid_->SaveEditableState().ToStdString() << std::endl;
        settingsFile << propGrid_->GetPropertyValueAsString("entry").ToStdString() << std::endl;
    }

    std::ofstream codeFile(codeFilename);
    if (codeFile.good())
    {
        auto sourceCode = inputSourceView_->GetText().ToStdString();
        RemoveCharFromString(sourceCode, '\r');
        codeFile << sourceCode;
    }
}

void DebuggerView::LoadSettings()
{
    std::ifstream settingsFile(settingsFilename);
    if (settingsFile.good())
    {
        std::string state;
        std::getline(settingsFile, state);
        propGrid_->RestoreEditableState(state);

        std::getline(settingsFile, state);
        propGrid_->SetPropertyValueString("entry", state);
        shaderInput_.entryPoint = state;
    }

    std::ifstream codeFile(codeFilename);
    if (codeFile.good())
    {
        inputSourceView_->SetText(
            std::string(
                ( std::istreambuf_iterator<char>(codeFile) ),
                ( std::istreambuf_iterator<char>() )
            )
        );
{'fraction_non_alphanumeric': 0.1326127624194554, 'fraction_numerical': 0.0041571398877572234, 'mean_word_length': 3.552507095553453, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2242567', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1501, 'n_words': 291}