35#include <wx/textdlg.h>
43 m_currentSettings( nullptr ),
73 for(
const std::pair<const int, COLOR_SWATCH*>& pair :
m_swatches )
75 int layer = pair.first;
101 return PANEL_COLOR_SETTINGS_BASE::Show( show );
118 if( idx ==
static_cast<int>(
m_cbTheme->GetCount() ) - 2 )
124 if( idx == (
int)
m_cbTheme->GetCount() - 1 )
132 wxTextEntryDialog dlg(
this,
_(
"New theme name:" ),
_(
"Add Color Theme" ) );
133 dlg.SetTextValidator( themeNameValidator );
135 if( dlg.ShowModal() != wxID_OK )
138 wxString themeName = dlg.GetValue();
139 wxFileName fn( themeName + wxT(
".json" ) );
144 wxMessageBox(
_(
"Theme already exists!" ) );
150 newSettings->
SetName( themeName );
158 idx =
m_cbTheme->Insert( themeName, idx - 1,
static_cast<void*
>( newSettings ) );
197 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
199 pair.second->SetSwatchBackground( background );
201 pair.second->SetReadOnly( isReadOnly );
212 m_cbTheme->GetTextExtent(
_(
"New Theme..." ), &width, &height );
213 int minwidth = width;
221 int pos =
m_cbTheme->Append(
name,
static_cast<void*
>( settings ) );
223 if( settings->GetFilename() == aCurrent )
227 minwidth = std::max( minwidth, width );
233 m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
259 swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
265 m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
270 swatch->Bind( wxEVT_RIGHT_DOWN,
271 [&, aLayer]( wxMouseEvent& aEvent )
285 wxCHECK_RET( selected, wxT(
"Invalid color theme selected" ) );
288 COLOR4D saved = selected->GetColor( aLayer );
295 if( !readOnly &&
m_copied != COLOR4D::UNSPECIFIED )
298 if( !readOnly && current != saved )
301 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
302 [&]( wxCommandEvent& aCmd )
304 switch( aCmd.GetId() )
311 updateColor( aLayer, m_copied );
315 updateColor( aLayer, saved );
346 m_swatches[aLayer]->SetSwatchColor( aColor,
false );
352 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
353 pair.second->SetSwatchBackground( background );
387 name += wxS(
" " ) +
_(
"(read-only)" );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetName(const wxString &aName)
void SetColor(int aLayer, const COLOR4D &aColor)
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
COLOR4D GetDefaultColor(int aLayer)
void SetOverrideSchItemColors(bool aFlag)
const wxString & GetName() const
A simple color swatch of the kind used to set layer colors.
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetReadOnly(bool aReadOnly)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
wxString GetFilename() const
A color representation with 4 components: red, green, blue, alpha.
Class PANEL_COLOR_SETTINGS_BASE.
wxCheckBox * m_optOverrideColors
wxFlexGridSizer * m_colorsGridSizer
wxButton * m_btnOpenFolder
wxScrolledWindow * m_colorsListWindow
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
void createSwatch(int aLayer, const wxString &aName)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
void OnThemeChanged(wxCommandEvent &aEvent) override
virtual bool saveCurrentTheme(bool aValidate)
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
virtual void ResetPanel() override
Reset the contents of this panel.
void OnBtnOpenThemeFolderClicked(wxCommandEvent &event) override
void OnColorChanged(wxCommandEvent &aEvent)
std::map< int, wxStaticText * > m_labels
virtual void onNewThemeSelected()
Event fired when a new theme is selected that can be overridden in children.
wxString GetSettingsDropdownName(COLOR_SETTINGS *aSettings)
Retrieves the drop down name to be displayed for a color setting.
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
COLOR_SETTINGS * m_currentSettings
PANEL_COLOR_SETTINGS(wxWindow *aParent)
void ShowColorContextMenu(wxMouseEvent &aEvent, int aLayer)
void OnLeftDownTheme(wxMouseEvent &event) override
bool Show(bool show) override
virtual void createSwatches()=0
virtual void onColorChanged()
Event fired when the user changes any color.
virtual bool validateSave(bool aQuiet=false)
Performs a pre-save validation of the current color theme.
std::map< int, COLOR_SWATCH * > m_swatches
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Returns the path a given settings file should be loaded from / stored to.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
static wxString GetColorSettingsPath()
Returns the path where color scheme files are stored; creating it if missing (normally .
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Registers a new color settings object with the given filename.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
@ LAYER_PCB_BACKGROUND
PCB background color.
SCH_LAYER_ID
Eeschema drawing layers.
constexpr int FIRST_BUTTON_ID
SETTINGS_MANAGER * GetSettingsManager()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Custom text control validator definitions.