<commit_before>/*
 * project collectd_edit
 * ing. <NAME>
 * Brescia 2015
 * Copyright 2015 Sputnik7
 */

#include "add_plugin_block.h"
#include "ui_structure.h"
#include <gtkmm/dialog.h>
#include <gtkmm/treeview.h>

#include "is_a.h"
#include "join.h"
#include "icompare.h"
#include "depth_first.h"

#include <map>
#include <iostream>

namespace ns_all {
    using namespace std;
    using namespace Gtk;
    using namespace Glib;
    using namespace model;
    using namespace parse_conf;
    using namespace ui_structure;
}
using namespace ns_all;

struct add_plugin_block::plugins_t : map<string, RANGE::path_t, iless> {
    const AST *ast;
    plugins_t(const AST *ast) : ast(ast) {
        depth_first df;
        df.visit(ast->elements, [&](const RANGE &r) {
            if (r.type == XML_LIKE_t) {
                auto id = plugin_id(r, ast->text);
                if (!id.empty())
                    ((*this)[id] = df).push_back(&r);
                return false;
            }
            return true;
        });
    }
};

add_plugin_block::add_plugin_block(BaseObjectType *cobject, const RefPtr<Builder> &refBuilder)
    : Dialog(cobject)
{
    treestore = RefPtr<TreeStore>::cast_dynamic(refBuilder->get_object("add_plugin_treestore"));
    if (treestore) {
        instance_widget<Button>(refBuilder, "btn_add_plugin")
            ->signal_clicked().connect(sigc::mem_fun(this, &add_plugin_block::on_add_plugin));
    }
}
add_plugin_block::~add_plugin_block() {
    delete tem_map;
    delete in_view;
}

void add_plugin_block::on_add_plugin() {
    auto treeview = is_a<TreeView>(locate_by_name(this, "add_plugin_treeview"));
    auto sel = treeview->get_selection();
    auto row = sel->get_selected();

    string v; row->get_value(c_name, v);
    bool in; row->get_value(c_used, in);
    if (!in) {
        auto i = tem_map->find(v);
        string p = i->second(tem_map->text);
        editor->add_plugin(p);
    }
}

namespace implementation {

/*
typedef RANGE::path_t path;
typedef map<path, const RANGE *> block_indexing_t;
typedef vector<string> strings;

inline string path_image(const path &p, kstring s) {
    strings S;
    for (auto r: p)
        if (r->type == XML_LIKE_t) {
            S.push_back((*r)[HEAD_l][HTAG_l](s));
        }
    return join(S, '/');
}
struct cmp_nesting_paths : less<path> {<commit_msg>fixed text access on selected plugin block<commit_after>/*
 * project collectd_edit
 * ing. <NAME>
 * Brescia 2015
 * Copyright 2015 Sputnik7
 */

#include "add_plugin_block.h"
#include "ui_structure.h"
#include <gtkmm/dialog.h>
#include <gtkmm/treeview.h>

#include "is_a.h"
#include "join.h"
#include "icompare.h"
#include "depth_first.h"

#include <map>
#include <iostream>

namespace ns_all {
    using namespace std;
    using namespace Gtk;
    using namespace Glib;
    using namespace model;
    using namespace parse_conf;
    using namespace ui_structure;
}
using namespace ns_all;

struct add_plugin_block::plugins_t : map<string, RANGE::path_t, iless> {
    const AST *ast;
    plugins_t(const AST *ast) : ast(ast) {
        depth_first df;
        df.visit(ast->elements, [&](const RANGE &r) {
            if (r.type == XML_LIKE_t) {
                auto id = plugin_id(r, ast->text);
                if (!id.empty())
                    ((*this)[id] = df).push_back(&r);
                return false;
            }
            return true;
        });
    }
};

add_plugin_block::add_plugin_block(BaseObjectType *cobject, const RefPtr<Builder> &refBuilder)
    : Dialog(cobject)
{
    treestore = RefPtr<TreeStore>::cast_dynamic(refBuilder->get_object("add_plugin_treestore"));
    if (treestore) {
        instance_widget<Button>(refBuilder, "btn_add_plugin")
            ->signal_clicked().connect(sigc::mem_fun(this, &add_plugin_block::on_add_plugin));
    }
}
add_plugin_block::~add_plugin_block() {
    delete tem_map;
    delete in_view;
}

void add_plugin_block::on_add_plugin() {
    auto treeview = is_a<TreeView>(locate_by_name(this, "add_plugin_treeview"));
    auto sel = treeview->get_selection();
    auto row = sel->get_selected();

    string v; row->get_value(c_name, v);
    bool in; row->get_value(c_used, in);
    if (!in) {
        auto i = tem_map->find(v);
        const RANGE &r = *(i->second.back());
        string p = r(tem_map->ast->text);
        editor->add_plugin(p);
    }
}

namespace implementation {

/*
typedef RANGE::path_t path;
typedef map<path, const RANGE *> block_indexing_t;
typedef vector<string> strings;

inline string path_image(const path &p, kstring s) {
    strings S;
    for (auto r: p)
        if (r->type == XML_LIKE_t) {
            S.push_back((*r)[HEAD_l][HTAG_l](s));
        }
    return join(S, '/');
}
struct cmp_nesting_paths : less<path> {
{'fraction_non_alphanumeric': 0.13802521008403362, 'fraction_numerical': 0.003781512605042017, 'mean_word_length': 3.1256499133448874, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 56, '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': '5283673', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1651, 'n_words': 348}