<commit_before>#include "filename.h"

#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <QHBoxLayout>
#include <QStyle>
#include <QFileDialog>
#include <QAction>
#include <QApplication>
#include <QMainWindow>

#include <possumwood_sdk/app.h>

filename_ui::filename_ui() {
	m_widget = new QWidget(NULL);

	QHBoxLayout* layout = new QHBoxLayout(m_widget);
	layout->setContentsMargins(0,0,0,0);

	m_lineEdit = new QLineEdit();
	layout->addWidget(m_lineEdit, 1);

	m_lineEditConnection = QObject::connect(
		m_lineEdit,
		&QLineEdit::editingFinished,
		[this]() -> void {
			callValueChangedCallbacks();
		}
	);

	m_browseButton = new QToolButton();
	m_browseButton->setIcon(m_browseButton->style()->standardIcon(QStyle::SP_DialogOpenButton));
	layout->addWidget(m_browseButton);

	m_buttonConnection = QObject::connect(
		m_browseButton,
		&QToolButton::released,
		[this]() -> void {
			// starting directory
			QString path = m_lineEdit->text();
			if(path.isEmpty())
				path = possumwood::App::instance().filename().parent_path().string().c_str();

			// run the file dialog
			path = QFileDialog::getOpenFileName(
				possumwood::App::instance().mainWindow(),
				"Select an input file...",
				path,
				boost::algorithm::join(m_value.extensions(), ";;").c_str()
			);

			if(!path.isEmpty()) {
				boost::filesystem::path result = path.toStdString();
				const auto pp = possumwood::App::instance().filename().parent_path();

				if(boost::starts_with(result.string(), pp.string()))
					result = result.string().substr(pp.string().length()+1);

				m_lineEdit->setText(result.string().c_str());
				m_lineEdit->editingFinished();
			}
		}
	);
}

filename_ui::~filename_ui() {
	QObject::disconnect(m_lineEditConnection);
}

void filename_ui::get(Filename& value) const {
	value.setFilename(m_lineEdit->text().toStdString());
}<commit_msg>Fixed file browser stripping beginning of the path, even for empty root paths<commit_after>#include "filename.h"

#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <QHBoxLayout>
#include <QStyle>
#include <QFileDialog>
#include <QAction>
#include <QApplication>
#include <QMainWindow>

#include <possumwood_sdk/app.h>

filename_ui::filename_ui() {
	m_widget = new QWidget(NULL);

	QHBoxLayout* layout = new QHBoxLayout(m_widget);
	layout->setContentsMargins(0,0,0,0);

	m_lineEdit = new QLineEdit();
	layout->addWidget(m_lineEdit, 1);

	m_lineEditConnection = QObject::connect(
		m_lineEdit,
		&QLineEdit::editingFinished,
		[this]() -> void {
			callValueChangedCallbacks();
		}
	);

	m_browseButton = new QToolButton();
	m_browseButton->setIcon(m_browseButton->style()->standardIcon(QStyle::SP_DialogOpenButton));
	layout->addWidget(m_browseButton);

	m_buttonConnection = QObject::connect(
		m_browseButton,
		&QToolButton::released,
		[this]() -> void {
			// starting directory
			QString path = m_lineEdit->text();
			if(path.isEmpty())
				path = possumwood::App::instance().filename().parent_path().string().c_str();

			// run the file dialog
			path = QFileDialog::getOpenFileName(
				possumwood::App::instance().mainWindow(),
				"Select an input file...",
				path,
				boost::algorithm::join(m_value.extensions(), ";;").c_str()
			);

			if(!path.isEmpty()) {
				boost::filesystem::path result = path.toStdString();
				const auto pp = possumwood::App::instance().filename().parent_path();

				if(!pp.string().empty() && boost::starts_with(result.string(), pp.string()))
					result = result.string().substr(pp.string().length()+1);

				m_lineEdit->setText(result.string().c_str());
				m_lineEdit->editingFinished();
			}
		}
	);
}

filename_ui::~filename_ui() {
	QObject::disconnect(m_lineEditConnection);
}

void filename_ui::get(Filename& value) const {
	value.setFilename(m_lineEdit->text().toStdString());
}
{'fraction_non_alphanumeric': 0.16881775942178626, 'fraction_numerical': 0.003097573567372225, 'mean_word_length': 5.404958677685951, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, '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': '2475403', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1313, 'n_words': 203}