//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : project_settings_dlg.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef __project_settings_dlg__
#define __project_settings_dlg__

/**
@file
Subclass of ProjectSettingsBaseDlg, which is generated by wxFormBuilder.
@todo Add your event handlers directly to this file.
*/

#include "project_settings_base_dlg.h"
#include "project_settings.h"
#include "compiler.h"

extern const wxString APPEND_TO_GLOBAL_SETTINGS;
extern const wxString OVERWRITE_GLOBAL_SETTINGS;
extern const wxString PREPEND_GLOBAL_SETTINGS;
class PSGeneralPage;
class ProjectSettingsDlg;
/////////////////////////////////////////////////////////////
// base class for the project settings pages
/////////////////////////////////////////////////////////////
class IProjectSettingsPage
{
public:
	IProjectSettingsPage() {}
	virtual ~IProjectSettingsPage() {}

	virtual void Save(BuildConfigPtr buildConf, ProjectSettingsPtr projSettingsPtr) = 0;
	virtual void Load(BuildConfigPtr buildConf) = 0;
	virtual void Clear() = 0;

	virtual bool PopupAddOptionDlg(wxTextCtrl *ctrl);
	virtual bool SelectChoiceWithGlobalSettings(wxChoice* c, const wxString& text);
	virtual bool PopupAddOptionCheckDlg(wxTextCtrl *ctrl, const wxString& title, const Compiler::CmpCmdLineOptions& options);
};

/**
 * Implementing GlobalSettingsBasePanel
 */
class GlobalSettingsPanel : public GlobalSettingsBasePanel, public IProjectSettingsPage
{
	wxString            m_projectName;
	ProjectSettingsDlg *m_dlg;
	PSGeneralPage *     m_gp;
	
public:
	GlobalSettingsPanel(wxWindow* parent, const wxString &projectName, ProjectSettingsDlg *dlg, PSGeneralPage *gp);

	virtual void Clear();
	virtual void Load(BuildConfigPtr buildConf);
	virtual void Save(BuildConfigPtr buildConf, ProjectSettingsPtr projSettingsPtr);

protected:

	virtual void OnButtonAddCCompilerOptions(wxCommandEvent& event);
	virtual void OnCmdEvtVModified( wxCommandEvent& event );
	virtual void OnButtonAddCompilerOptions(wxCommandEvent &event);
	virtual void OnAddSearchPath(wxCommandEvent &event);
	virtual void OnButtonAddPreprocessor(wxCommandEvent &event);

	virtual void OnAddLibraryPath(wxCommandEvent &event);
	virtual void OnAddLibrary(wxCommandEvent &event);
	virtual void OnButtonAddLinkerOptions(wxCommandEvent &event);

	virtual void OnResourceCmpAddPath(wxCommandEvent &e);
	virtual void OnResourceCmpAddOption(wxCommandEvent &e);
};

/**
 * Implementing ProjectSettingsBaseDlg
 */
class ProjectSettingsDlg : public ProjectSettingsBaseDlg
{
	wxString  m_projectName;
	wxString  m_configName;
	bool      m_isDirty;
	bool      m_isCustomBuild;

protected:
	void SaveValues();
	void ClearValues();
	void LoadValues(const wxString &configName);
	void BuildTree();

public:
	bool IsCustomBuildEnabled() const {
		return m_isCustomBuild;
	}
	void SetCustomBuildEnabled(bool b) {
		if(b != m_isCustomBuild) {
			SetIsDirty(true);
		}
		m_isCustomBuild = b;
	}
	void SetIsDirty(bool isDirty) {
		this->m_isDirty = isDirty;
	}
	bool GetIsDirty() const {
		return m_isDirty;
	}

public:
	/** Constructor */
	ProjectSettingsDlg( wxWindow* parent, const wxString &configName, const wxString &projectName, const wxString &title );
	virtual ~ProjectSettingsDlg();

	DECLARE_EVENT_TABLE();

	virtual void OnButtonApply(wxCommandEvent &event);
	virtual void OnButtonOK(wxCommandEvent &event);
	virtual void OnButtonHelp(wxCommandEvent &e);
	virtual void OnButtonApplyUI(wxUpdateUIEvent& event);
	virtual void OnConfigurationChanged(wxCommandEvent& event);

};

#endif // __project_settings_dlg__
