Sweeping changes to style-spelling check interfaces. Known issue: edit from spellcheck.

This commit is contained in:
Gerald Schmidt 2008-04-20 17:22:29 +00:00
parent b6c1b7b8df
commit da958e3326
9 changed files with 182 additions and 22 deletions

View File

@ -46,13 +46,18 @@ CommandPanel::CommandPanel (
name = _ ( "{name}" ); name = _ ( "{name}" );
extension = _ ( "{extension}" ); extension = _ ( "{extension}" );
fullpath = _ ( "{fullpath}" ); fullpath = _ ( "{fullpath}" );
int sizerOffset = 2;
wxButton *pathButton = new wxButton ( this, ID_BUTTON_PATH, path, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER ); wxButton *pathButton = new wxButton ( this, ID_BUTTON_PATH, path, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *nameButton = new wxButton ( this, ID_BUTTON_NAME, name, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER ); wxButton *nameButton = new wxButton ( this, ID_BUTTON_NAME, name, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *extensionButton = new wxButton ( this, ID_BUTTON_EXTENSION, extension, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER ); wxButton *extensionButton = new wxButton ( this, ID_BUTTON_EXTENSION, extension, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
wxButton *fullpathButton = new wxButton ( this, ID_BUTTON_FULLPATH, fullpath, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER ); wxButton *fullpathButton = new wxButton ( this, ID_BUTTON_FULLPATH, fullpath, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER );
int editWidth = 480;
int editWidth, editHeight;
parent->GetSize( &editWidth, &editHeight);
editWidth -= sizerOffset * 2;
commandEdit = new wxTextCtrl ( commandEdit = new wxTextCtrl (
this, this,
wxID_ANY, wxID_ANY,
@ -60,6 +65,7 @@ CommandPanel::CommandPanel (
wxDefaultPosition, wxDefaultPosition,
wxSize ( editWidth, -1 ) wxSize ( editWidth, -1 )
); );
commandEdit->SetValue ( cmd ); commandEdit->SetValue ( cmd );
runButton = new wxButton ( runButton = new wxButton (
@ -118,7 +124,6 @@ CommandPanel::CommandPanel (
wxID_ANY, wxID_ANY,
_ ( "Variables" ) ); _ ( "Variables" ) );
int sizerOffset = 2;
wxStaticBoxSizer *outputSizer = new wxStaticBoxSizer ( outputBox, wxHORIZONTAL ); wxStaticBoxSizer *outputSizer = new wxStaticBoxSizer ( outputBox, wxHORIZONTAL );
outputSizer->Add ( outputIgnore, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset ); outputSizer->Add ( outputIgnore, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
@ -134,12 +139,12 @@ CommandPanel::CommandPanel (
topSizer = new wxBoxSizer ( wxHORIZONTAL ); topSizer = new wxBoxSizer ( wxHORIZONTAL );
topSizer->Add ( commandEdit, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, sizerOffset ); topSizer->Add ( commandEdit, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND, sizerOffset );
topSizer->Add ( runButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
topSizer->Add ( syncBox, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
topSizer->Layout(); topSizer->Layout();
bottomSizer = new wxBoxSizer ( wxHORIZONTAL ); bottomSizer = new wxBoxSizer ( wxHORIZONTAL );
bottomSizer->Add ( runButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( syncBox, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( variablesSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset ); bottomSizer->Add ( variablesSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
bottomSizer->Add ( outputSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset ); bottomSizer->Add ( outputSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );

View File

@ -60,7 +60,6 @@ class CommandPanel : public wxPanel
private: private:
wxString path, name, extension, fullpath; wxString path, name, extension, fullpath;
wxTextCtrl *commandEdit; wxTextCtrl *commandEdit;
//wxStaticText *label;
wxButton *runButton; wxButton *runButton;
wxCheckBox *syncBox; wxCheckBox *syncBox;
wxRadioButton *outputIgnore, *outputInsert, *outputNewDocument; wxRadioButton *outputIgnore, *outputInsert, *outputNewDocument;

View File

@ -18,10 +18,14 @@
*/ */
#include "getlinuxappdir.h" #include "getlinuxappdir.h"
#include <wx/filename.h> #include <wx/stdpaths.h>
//#include <wx/filename.h>
wxString GetLinuxAppDir::run() wxString GetLinuxAppDir::run()
{ {
wxStandardPaths *paths = ( wxStandardPaths *) &wxStandardPaths::Get();
return paths->GetDataDir();
/*
wxString s; wxString s;
const int stringArrayLen = 2; const int stringArrayLen = 2;
wxString stringArray[stringArrayLen]; wxString stringArray[stringArrayLen];
@ -38,4 +42,5 @@ wxString GetLinuxAppDir::run()
s = wxGetCwd(); s = wxGetCwd();
return s; return s;
*/
} }

View File

@ -52,9 +52,15 @@ char *GetWord::run ( char **s, size_t *len )
} }
t = u; t = u;
} }
else if ( *t == '<' )
{
t = skipTags ( t );
}
else else
{
t += bytes; t += bytes;
} }
}
return NULL; return NULL;
} }
@ -95,3 +101,51 @@ bool GetWord::isWordCharacter ( char *s, size_t *bytes )
return true; return true;
} }
} }
char *GetWord::skipTags ( char *s )
{
if (*s == '<')
{
// CDATA
if ( * ( s + 1 ) == '!' &&
* ( s + 2) == '[' &&
* ( s + 3) == 'C' )
{
s += 3;
for ( ; *s; s++ )
{
if ( *s == ']' &&
* (s + 1 ) == ']' &&
* (s + 2 ) == '>')
{
return s += 3;
}
}
}
// comment
else if ( * ( s + 1 ) == '!' &&
* ( s + 2 ) == '-' &&
* ( s + 3 ) == '-')
{
s += 3;
for ( ; *s; s++ )
{
if ( *s == '-' &&
* ( s + 1 ) == '-' &&
* ( s + 2 ) == '>')
{
return s + 3;
}
}
}
else
{
for ( ; *s; s++ )
{
if ( *s == '>' )
return ++s;
}
}
}
return s;
}

View File

@ -28,6 +28,7 @@ class GetWord
static char *run ( char **s, size_t *len ); static char *run ( char **s, size_t *len );
private: private:
static bool isWordCharacter ( char *s, size_t *bytes ); static bool isWordCharacter ( char *s, size_t *bytes );
static char *skipTags ( char *s );
}; };
#endif #endif

View File

@ -50,9 +50,11 @@ void HouseStyle::collectFilter (
std::set<std::string>& excludeSet, std::set<std::string>& excludeSet,
int *filterCount ) int *filterCount )
{ {
if ( type == HS_TYPE_SPELL || fileName == "(No filter)" ) // from v. 1.1.0.7: always ignore
//if ( type == HS_TYPE_SPELL || fileName == "(No filter)" )
return; return;
/*
string filePath, buffer; string filePath, buffer;
filePath = filterDirectory + pathSeparator + fileName; filePath = filterDirectory + pathSeparator + fileName;
@ -107,6 +109,7 @@ void HouseStyle::collectFilter (
if ( !excludeSet.count ( *includeIterator ) ) if ( !excludeSet.count ( *includeIterator ) )
collectFilter ( *includeIterator, excludeSet, filterCount ); collectFilter ( *includeIterator, excludeSet, filterCount );
} }
*/
} }
void HouseStyle::collectRules ( string& fileName, void HouseStyle::collectRules ( string& fileName,
@ -170,6 +173,7 @@ bool HouseStyle::createReport()
return false; return false;
} }
/*
updateFilter(); updateFilter();
auto_ptr<HouseStyleReader> xtr ( new HouseStyleReader ( filterMap ) ); auto_ptr<HouseStyleReader> xtr ( new HouseStyleReader ( filterMap ) );
@ -178,8 +182,10 @@ bool HouseStyle::createReport()
error = "file is not well-formed"; error = "file is not well-formed";
return false; return false;
} }
*/
std::vector<std::pair<std::string, unsigned> > nodeVector; std::vector<std::pair<std::string, unsigned> > nodeVector;
xtr->getNodeVector ( nodeVector ); //xtr->getNodeVector ( nodeVector );
nodeVector.push_back( make_pair ( buffer, 0 ) ); // new from 1.1.0.7
int ruleVectorsize, nodeVectorSize; int ruleVectorsize, nodeVectorSize;

View File

@ -101,7 +101,7 @@ StyleDialog::StyleDialog (
_T ( "" ), _T ( "" ),
wxDefaultPosition, wxDefaultPosition,
wxSize ( 200, -1 ) ); wxSize ( 200, -1 ) );
if (type != ID_TYPE_STYLE) //if (type != ID_TYPE_STYLE) // from v. 1.1.0.7: never show
filterCombo->Show ( false ); filterCombo->Show ( false );
wxButton *createReportButton = new wxButton ( wxButton *createReportButton = new wxButton (
@ -164,7 +164,7 @@ StyleDialog::StyleDialog (
new wxButton ( new wxButton (
this, this,
ID_STYLE_CHANGE_ALL, ID_STYLE_CHANGE_ALL,
_ ( "&Select all" ), _ ( "C&hange all" ),
wxDefaultPosition, wxDefaultPosition,
wxSize ( -1, buttonSize.GetHeight() ), wxSize ( -1, buttonSize.GetHeight() ),
0 ); 0 );
@ -215,7 +215,7 @@ StyleDialog::StyleDialog (
entries[1].Set ( wxACCEL_ALT, ( int ) 'A', ID_STYLE_EDIT ); entries[1].Set ( wxACCEL_ALT, ( int ) 'A', ID_STYLE_EDIT );
entries[2].Set ( wxACCEL_ALT, ( int ) 'W', ID_STYLE_WEB_REPORT ); entries[2].Set ( wxACCEL_ALT, ( int ) 'W', ID_STYLE_WEB_REPORT );
entries[3].Set ( wxACCEL_ALT, ( int ) 'B', ID_STYLE_WEB_SUMMARY ); entries[3].Set ( wxACCEL_ALT, ( int ) 'B', ID_STYLE_WEB_SUMMARY );
entries[4].Set ( wxACCEL_ALT, ( int ) 'S', ID_STYLE_CHANGE_ALL ); entries[4].Set ( wxACCEL_ALT, ( int ) 'H', ID_STYLE_CHANGE_ALL );
entries[5].Set ( wxACCEL_ALT, ( int ) 'I', ID_STYLE_IGNORE_ALL ); entries[5].Set ( wxACCEL_ALT, ( int ) 'I', ID_STYLE_IGNORE_ALL );
entries[6].Set ( wxACCEL_ALT, ( int ) 'N', wxID_CANCEL ); entries[6].Set ( wxACCEL_ALT, ( int ) 'N', wxID_CANCEL );
@ -489,6 +489,7 @@ void StyleDialog::OnStyleEdit ( wxCommandEvent& event )
sort ( v.begin(), v.end(), elementAndOffsetCompareFunction ); sort ( v.begin(), v.end(), elementAndOffsetCompareFunction );
/*
HouseStyleWriter hsw ( v ); HouseStyleWriter hsw ( v );
if ( !hsw.parse ( bufferUtf8 ) ) if ( !hsw.parse ( bufferUtf8 ) )
{ {
@ -502,6 +503,56 @@ void StyleDialog::OnStyleEdit ( wxCommandEvent& event )
return; return;
} }
bufferUtf8 = hsw.getOutput(); bufferUtf8 = hsw.getOutput();
*/
//unsigned elementCount = 1; // from v. 1.1.0.7: one raw text element only
int vectorsize, os_adjust, exclusion;
vectorsize = v.size();
os_adjust = exclusion = 0;
string cmp1, cmp2, buffer;
buffer = bufferUtf8;
for ( int i = 0; i < vectorsize; ++i )
{
/*
unsigned vectorElementCount = v[i].elementCount;
if ( vectorElementCount < elementCount )
continue;
else if ( vectorElementCount > elementCount )
break;
else if ( vectorElementCount == elementCount )
{
*/
int offset = ( int ) v[i].offset + os_adjust;
if ( offset < exclusion )
continue;
try
{
cmp1 = v[i].match;
cmp2 = buffer.substr ( offset, v[i].match.size() );
}
catch ( std::exception& e )
{
continue;
}
if ( cmp1.compare ( cmp2 ) )
continue;
buffer.replace ( offset, v[i].match.size(), v[i].replace.c_str() );
os_adjust += v[i].replace.size() - v[i].match.size();
exclusion = offset + v[i].replace.size();
//}
}
bufferUtf8 = buffer;
wxCommandEvent e; wxCommandEvent e;
EndModal ( wxID_OK ); EndModal ( wxID_OK );
} }

View File

@ -21,6 +21,7 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <wx/aboutdlg.h> #include <wx/aboutdlg.h>
#include <wx/stdpaths.h>
#include "xmlcopyeditor.h" #include "xmlcopyeditor.h"
#include "readfile.h" #include "readfile.h"
#include "xmldoc.h" #include "xmldoc.h"
@ -194,8 +195,8 @@ MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
int fdnull = open ( "/dev/null", O_WRONLY, 0 ); int fdnull = open ( "/dev/null", O_WRONLY, 0 );
dup2 ( fdnull, STDERR_FILENO ); dup2 ( fdnull, STDERR_FILENO );
#endif #endif
myLocale.Init(); //myLocale.Init();
int systemLocale = myLocale.GetSystemLanguage(); int systemLocale = wxLocale::GetSystemLanguage();//myLocale.GetSystemLanguage();
switch ( systemLocale ) switch ( systemLocale )
{ {
case wxLANGUAGE_GERMAN: case wxLANGUAGE_GERMAN:
@ -275,17 +276,49 @@ MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
#endif #endif
} }
myLocale.Init ( lang, wxLOCALE_LOAD_DEFAULT ); /*
#ifndef __WXMSW__
lang = wxLANGUAGE_ENGLISH; // temp
#endif
*/
myLocale.Init ( lang, wxLOCALE_CONV_ENCODING );
#ifdef __WXMSW__
wxLocale::AddCatalogLookupPathPrefix ( wxT ( "." ) ); wxLocale::AddCatalogLookupPathPrefix ( wxT ( "." ) );
wxLocale::AddCatalogLookupPathPrefix ( wxT ( ".." ) ); wxLocale::AddCatalogLookupPathPrefix ( wxT ( ".." ) );
#ifndef __WXMSW__
wxString poDir = GetLinuxAppDir::run() + wxFileName::GetPathSeparator() + _T ( "po" ) + wxFileName::GetPathSeparator();
wxLocale::AddCatalogLookupPathPrefix ( poDir );
#endif
if ( !myLocale.AddCatalog ( _T ( "messages" ) ) ) if ( !myLocale.AddCatalog ( _T ( "messages" ) ) )
; ;
#else // Linux
if ( wxLocale::IsAvailable ( lang ) )
{
wxStandardPaths *paths = (wxStandardPaths *) &wxStandardPaths::Get();
wxString prefix = paths->GetInstallPrefix();
myLocale.AddCatalogLookupPathPrefix( prefix );
myLocale.AddCatalog ( _T ("xmlcopyeditor") );
if (!myLocale.IsOk() )
{
std::cout << "Locale is not OK" << std::endl;
}
}
else
{
std::cout << "Locale unavailable" << std::endl;
}
#endif
/*
#ifndef __WXMSW__
wxString poDir = GetLinuxAppDir::run() + wxFileName::GetPathSeparator() + _T ( "po" ); //+ wxFileName::GetPathSeparator();
//wxLocale::AddCatalogLookupPathPrefix ( poDir );
//myLocale.AddCatalogLookupPathPrefix ( poDir );
//std::cout << poDir.mb_str(wxConvUTF8) << std::endl;
if (lang == wxLANGUAGE_ITALIAN)
std::cout << "OK it's set to Italian... let's see" << std::endl;
myLocale.AddCatalogLookupPathPrefix ( _T ("/usr/share/locale/it/LC_MESSAGES") );
#endif
#ifndef __WXMSW__ #ifndef __WXMSW__
{ {
@ -293,6 +326,7 @@ MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
myLocale.AddCatalog ( _T ( "fileutils" ) ); myLocale.AddCatalog ( _T ( "fileutils" ) );
} }
#endif #endif
*/
} }
MyApp::~MyApp() MyApp::~MyApp()
@ -3235,6 +3269,10 @@ void MyFrame::OnSpelling ( wxCommandEvent& event )
std::string rawBufferUtf8; std::string rawBufferUtf8;
getRawText ( doc, rawBufferUtf8 ); getRawText ( doc, rawBufferUtf8 );
/*
* removed due to entity reference headaches
* from v. 1.1.0.7 always check raw text only
*
// handle unusual encodings // handle unusual encodings
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) ) if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) )
{ {
@ -3276,11 +3314,12 @@ void MyFrame::OnSpelling ( wxCommandEvent& event )
{ {
bufferParameterUtf8 = wl->getOutput(); bufferParameterUtf8 = wl->getOutput();
} }
*/
auto_ptr<StyleDialog> sd ( new StyleDialog ( auto_ptr<StyleDialog> sd ( new StyleDialog (
this, this,
wxICON ( appicon ), wxICON ( appicon ),
bufferParameterUtf8, rawBufferUtf8, //bufferParameterUtf8,
doc->getShortFileName(), doc->getShortFileName(),
ruleSetDir, ruleSetDir,
filterDir, filterDir,
@ -3288,7 +3327,7 @@ void MyFrame::OnSpelling ( wxCommandEvent& event )
( type == ID_TYPE_SPELL ) ? dictionaryPreset : ruleSetPreset, ( type == ID_TYPE_SPELL ) ? dictionaryPreset : ruleSetPreset,
filterPreset, filterPreset,
type, type,
( success ) ? false : true, false,//( success ) ? false : true,
stylePosition, stylePosition,
styleSize ) ); styleSize ) );

View File

@ -41,5 +41,5 @@
"License along with this program; if not, write to the Free\n"\ "License along with this program; if not, write to the Free\n"\
"Software Foundation, Inc., 59 Temple Place, Suite 330,\n"\ "Software Foundation, Inc., 59 Temple Place, Suite 330,\n"\
"Boston, MA 02111-1307 USA.") "Boston, MA 02111-1307 USA.")
#define ABOUT_VERSION _T("1.1.0.6") #define ABOUT_VERSION _T("1.1.0.7")
#define XMLCE_VAR _T("XMLCE_VAR") #define XMLCE_VAR _T("XMLCE_VAR")