From 7c9418f6674856c001774b4ba9a08d8f0c7a3161 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 13 Oct 2014 18:42:28 +0200 Subject: [PATCH] Add FILE_NAME_WITH_PATH_CHAR_VALIDATOR, a custom wxValidator which allows file names with paths, in schematic sheet editor ( FILE_NAME_CHAR_VALIDATOR previously used in this dialog does not allow chars used in path names, like / and on Windows \ and : ) --- eeschema/dialogs/dialog_sch_sheet_props.cpp | 2 +- include/validators.h | 37 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/eeschema/dialogs/dialog_sch_sheet_props.cpp b/eeschema/dialogs/dialog_sch_sheet_props.cpp index 4f47e572b1..8b34f4838c 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props.cpp +++ b/eeschema/dialogs/dialog_sch_sheet_props.cpp @@ -6,7 +6,7 @@ DIALOG_SCH_SHEET_PROPS::DIALOG_SCH_SHEET_PROPS( wxWindow* parent ) : DIALOG_SCH_SHEET_PROPS_BASE( parent ) { - m_textFileName->SetValidator( FILE_NAME_CHAR_VALIDATOR() ); + m_textFileName->SetValidator( FILE_NAME_WITH_PATH_CHAR_VALIDATOR() ); m_textFileName->SetFocus(); m_sdbSizer1OK->SetDefault(); } diff --git a/include/validators.h b/include/validators.h index 9cca5b0951..124fd0897f 100644 --- a/include/validators.h +++ b/include/validators.h @@ -43,7 +43,7 @@ public: wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) { // The Windows (DOS) file system forbidden characters already include the forbidden - // file name characters for both Posix and OSX systems. The characters \/*?|"<> are + // file name characters for both Posix and OSX systems. The characters \/:*?|"<> are // illegal and filtered by the validator. wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS ); wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); @@ -55,3 +55,38 @@ public: SetExcludes( illegalCharList ); } }; + +/** + * Class FILE_NAME_WITH_PATH_CHAR_VALIDATOR + * + * This class provides a custom wxValidator object for limiting the allowable characters when + * defining file names with path, for instance in schematic sheet file names. + */ +class FILE_NAME_WITH_PATH_CHAR_VALIDATOR : public wxTextValidator +{ +public: + FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = NULL ) : + wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) + { + // The Windows (DOS) file system forbidden characters already include the forbidden + // file name characters for both Posix and OSX systems. The characters *?|"<> are + // illegal and filtered by the validator, but /\: are valid (\ and : only on Windows. + wxString illegalChars = wxFileName::GetForbiddenChars(wxPATH_DOS ); + wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); + wxArrayString illegalCharList; + + for( unsigned i = 0; i < illegalChars.size(); i++ ) + { + if( illegalChars[i] == '/' ) + continue; + +#if defined (__WINDOWS__) + if( illegalChars[i] == '\\' || illegalChars[i] == ':' ) + continue; +#endif + illegalCharList.Add( wxString( illegalChars[i] ) ); + } + + SetExcludes( illegalCharList ); + } +};