CFindDialog::CFindDialog(QWidget *parent, const QString& settingsRootCategory) :
	QDialog(parent),
	_settingsRootCategory(settingsRootCategory),
	ui(new Ui::CFindDialog)
{
	ui->setupUi(this);

	connect(ui->_btnCancel, &QPushButton::clicked, this, &QDialog::reject);
	connect(ui->_btnFind, &QPushButton::clicked, this, &QDialog::accept);
	connect(ui->_btnFind, &QPushButton::clicked, this, &CFindDialog::find);
	connect(ui->_btnFindNext, &QPushButton::clicked, this, &CFindDialog::findNext);

	connect(ui->_searchText, &CHistoryComboBox::itemActivated, ui->_btnFind, &QPushButton::click);

	if (!_settingsRootCategory.isEmpty())
	{
		CSettings s;
		ui->_searchText->addItems(s.value(_settingsRootCategory + SETTINGS_SEARCH_EXPRESSION_LIST).toStringList());
		ui->_cbSearchBackwards->setChecked(s.value(_settingsRootCategory + SETTINGS_BACKWARDS).toBool());
		ui->_cbCaseSensitive->setChecked(s.value(_settingsRootCategory + SETTINGS_CASE_SENSITIVE).toBool());
		ui->_cbRegex->setChecked(s.value(_settingsRootCategory + SETTINGS_REGEX).toBool());
		ui->_cbWholeWords->setChecked(s.value(_settingsRootCategory + SETTINGS_WHOLE_WORDS).toBool());
	}

#if QT_VERSION < QT_VERSION_CHECK(5,3,0)
	ui->_cbRegex->setVisible(false);
#endif
}
DISABLE_COMPILER_WARNINGS
#include "ui_cfinddialog.h"

#include <QLineEdit>
RESTORE_COMPILER_WARNINGS

#define SETTINGS_SEARCH_EXPRESSION_LIST "Expressions"

#define SETTINGS_REGEX                  "Regex"
#define SETTINGS_BACKWARDS              "SearchBackwards"
#define SETTINGS_CASE_SENSITIVE         "CaseSensitive"
#define SETTINGS_WHOLE_WORDS            "WholeWords"

#define SETTINGS_GEOMETRY               "Geometry"

CFindDialog::CFindDialog(QWidget *parent, const QString& settingsRootCategory) :
	QDialog(parent),
	_settingsRootCategory(settingsRootCategory),
	ui(new Ui::CFindDialog)
{
	ui->setupUi(this);

	ui->_searchText->enableAutoSave(_settingsRootCategory + SETTINGS_SEARCH_EXPRESSION_LIST);

	connect(ui->_btnCancel, &QPushButton::clicked, this, &QDialog::reject);
	connect(ui->_btnFind, &QPushButton::clicked, this, &QDialog::accept);
	connect(ui->_btnFind, &QPushButton::clicked, this, &CFindDialog::find);
	connect(ui->_btnFindNext, &QPushButton::clicked, this, &CFindDialog::findNext);

	connect(ui->_searchText, &CHistoryComboBox::itemActivated, ui->_btnFind, &QPushButton::click);

	if (!_settingsRootCategory.isEmpty())
	{
		CSettings s;
		ui->_cbSearchBackwards->setChecked(s.value(_settingsRootCategory + SETTINGS_BACKWARDS).toBool());
		ui->_cbCaseSensitive->setChecked(s.value(_settingsRootCategory + SETTINGS_CASE_SENSITIVE).toBool());
		ui->_cbRegex->setChecked(s.value(_settingsRootCategory + SETTINGS_REGEX).toBool());
		ui->_cbWholeWords->setChecked(s.value(_settingsRootCategory + SETTINGS_WHOLE_WORDS).toBool());
	}
}
void CMainWindow::updateInterface()
{
	CSettings s;
	restoreGeometry(s.value(KEY_GEOMETRY).toByteArray());
	restoreState(s.value(KEY_STATE).toByteArray());
	ui->splitter->restoreState(s.value(KEY_SPLITTER_SIZES).toByteArray());
	ui->leftPanel->restorePanelGeometry(s.value(KEY_LPANEL_GEOMETRY).toByteArray());
	ui->leftPanel->restorePanelState(s.value(KEY_LPANEL_STATE).toByteArray());
	ui->rightPanel->restorePanelGeometry(s.value(KEY_RPANEL_GEOMETRY).toByteArray());
	ui->rightPanel->restorePanelState(s.value(KEY_RPANEL_STATE).toByteArray());

	ui->commandLine->addItems(s.value(KEY_LAST_COMMANDS_EXECUTED).toStringList());
	ui->commandLine->lineEdit()->clear();

	show();

	Panel lastActivePanel = (Panel)CSettings().value(KEY_LAST_ACTIVE_PANEL, LeftPanel).toInt();
	if (lastActivePanel == LeftPanel)
		ui->leftPanel->setFocusToFileList();
	else
		ui->rightPanel->setFocusToFileList();
}