2
* Copyright 2005-2007 Gerald Schmidt.
4
* This file is part of Xml Copy Editor.
6
* Xml Copy Editor is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* Xml Copy Editor is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Xml Copy Editor; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <wx/aboutdlg.h>
24
#include "xmlcopyeditor.h"
28
#include "wraplibxml.h"
29
#include "xmlschemalocator.h"
30
#include "xsllocator.h"
31
#include "xmlutf8reader.h"
32
#include "xmlpromptgenerator.h"
33
#include "xmlencodingspy.h"
34
#include "styledialog.h"
35
#include "mypropertysheet.h"
36
#include "wraptempfilename.h"
37
#include "globalreplacedialog.h"
39
#include "associatedialog.h"
40
#include "xmlassociatexsd.h"
41
#include "xmlassociatexsl.h"
42
#include "xmlassociatedtd.h"
43
#include "wrapdaisy.h"
44
#include "aboutdialog.h"
45
#include "pathresolver.h"
46
#include "locationpanel.h"
47
#include "insertpanel.h"
48
#include "xmlwordcount.h"
49
#include "mynotebook.h"
50
#include "getlinuxappdir.h"
51
#include "commandpanel.h"
52
#include "binaryfile.h"
53
#include "exportdialog.h"
54
#include <wx/aui/auibook.h>
55
#include <wx/richtext/richtextsymboldlg.h>
56
#include <wx/textctrl.h>
57
#include <wx/artprov.h>
58
#include <wx/stockitem.h>
61
#define ngettext wxGetTranslation
64
#include "findreplacepanel.h"
67
#include "wrapxerces.h"
69
#include "xpm/appicon.xpm"
72
BEGIN_EVENT_TABLE ( MyFrame, wxFrame )
73
EVT_ACTIVATE_APP ( MyFrame::OnActivateApp )
74
EVT_CLOSE ( MyFrame::OnFrameClose )
75
EVT_KEY_DOWN ( MyFrame::OnKeyPressed )
76
EVT_MENU ( wxID_ABOUT, MyFrame::OnAbout )
77
EVT_MENU ( wxID_CLOSE, MyFrame::OnClose )
78
EVT_MENU ( wxID_CLOSE_ALL, MyFrame::OnCloseAll )
79
EVT_MENU ( wxID_CUT, MyFrame::OnCut )
80
EVT_MENU ( wxID_COPY, MyFrame::OnCopy )
81
EVT_MENU ( wxID_HELP, MyFrame::OnHelp )
82
EVT_MENU ( wxID_PASTE, MyFrame::OnPaste )
83
EVT_MENU ( ID_PASTE_NEW_DOCUMENT, MyFrame::OnPasteNewDocument )
84
EVT_MENU ( wxID_EXIT, MyFrame::OnQuit )
85
EVT_MENU ( wxID_NEW, MyFrame::OnNew )
86
EVT_MENU ( wxID_OPEN, MyFrame::OnOpen )
87
EVT_MENU ( wxID_SAVE, MyFrame::OnSave )
88
EVT_MENU ( wxID_SAVEAS, MyFrame::OnSaveAs )
89
EVT_MENU ( ID_RELOAD, MyFrame::OnReload )
90
EVT_MENU ( wxID_UNDO, MyFrame::OnUndo )
91
EVT_MENU ( wxID_REDO, MyFrame::OnRedo )
92
EVT_MENU ( wxID_REVERT, MyFrame::OnRevert )
93
EVT_MENU ( ID_INSERT_CHILD, MyFrame::OnInsertChild )
94
EVT_MENU ( ID_INSERT_SIBLING, MyFrame::OnInsertSibling )
95
EVT_MENU ( ID_INSERT_ENTITY, MyFrame::OnInsertEntity )
96
EVT_MENU ( ID_INSERT_TWIN, MyFrame::OnInsertTwin )
97
EVT_MENU ( ID_INSERT_SYMBOL, MyFrame::OnInsertSymbol )
98
EVT_MENU ( ID_TOGGLE_FOLD, MyFrame::OnToggleFold )
99
EVT_MENU ( ID_FOLD_ALL, MyFrame::OnFoldAll )
100
EVT_MENU ( ID_UNFOLD_ALL, MyFrame::OnUnfoldAll )
101
EVT_MENU ( ID_OPEN_LARGE_FILE, MyFrame::OnOpen )
102
EVT_MENU ( ID_PRINT_PREVIEW, MyFrame::OnPrintPreview )
103
EVT_MENU ( ID_PRINT_SETUP, MyFrame::OnPrintSetup )
104
EVT_MENU ( ID_PRINT, MyFrame::OnPrint )
105
EVT_MENU ( ID_WORD_COUNT, MyFrame::OnWordCount )
106
EVT_MENU ( ID_IMPORT_MSWORD, MyFrame::OnImportMSWord )
107
EVT_MENU ( ID_EXPORT_MSWORD, MyFrame::OnExportMSWord )
108
EVT_MENU ( ID_EXPORT, MyFrame::OnExport )
109
EVT_MENU ( ID_HIDE_PANE, MyFrame::OnClosePane )
110
EVT_MENU ( ID_COMMAND, MyFrame::OnCommand )
111
EVT_MENU ( ID_FIND, MyFrame::OnFind )
112
EVT_MENU ( ID_FIND_AGAIN, MyFrame::OnFindAgain )
113
EVT_MENU ( ID_GOTO, MyFrame::OnGoto )
114
EVT_MENU ( ID_FEEDBACK, MyFrame::OnFeedback )
115
EVT_MENU ( ID_PREVIOUS_DOCUMENT, MyFrame::OnPreviousDocument )
116
EVT_MENU ( ID_NEXT_DOCUMENT, MyFrame::OnNextDocument )
117
EVT_MENU ( ID_BROWSER, MyFrame::OnBrowser )
118
EVT_MENU ( ID_REPLACE, MyFrame::OnFindReplace )
119
EVT_MENU ( ID_GLOBAL_REPLACE, MyFrame::OnGlobalReplace )
120
EVT_MENU ( ID_CHECK_WELLFORMED, MyFrame::OnCheckWellformedness )
121
EVT_MENU ( ID_VALIDATE_RELAX_NG, MyFrame::OnValidateRelaxNG )
122
EVT_MENU ( ID_VALIDATE_W3C_SCHEMA, MyFrame::OnValidateSchema )
123
EVT_MENU ( ID_XPATH, MyFrame::OnXPath )
124
EVT_MENU_RANGE ( ID_XSLT, ID_XSLT_WORDML_DOCBOOK, MyFrame::OnXslt )
125
EVT_MENU ( ID_PRETTYPRINT, MyFrame::OnPrettyPrint )
126
EVT_MENU ( ID_ENCODING, MyFrame::OnEncoding )
127
EVT_MENU ( ID_STYLE, MyFrame::OnSpelling )
128
EVT_MENU ( ID_SPELL, MyFrame::OnSpelling )
129
EVT_MENU ( ID_FONT_SMALLER, MyFrame::OnFontSmaller )
130
EVT_MENU ( ID_FONT_NORMAL, MyFrame::OnFontMedium )
131
EVT_MENU ( ID_FONT_LARGER, MyFrame::OnFontLarger )
132
EVT_MENU ( ID_OPTIONS, MyFrame::OnOptions )
133
EVT_MENU ( ID_HOME, MyFrame::OnHome )
134
EVT_MENU ( ID_DOWNLOAD_SOURCE, MyFrame::OnDownloadSource )
135
EVT_MENU ( ID_TOOLBAR_VISIBLE, MyFrame::OnToolbarVisible )
136
EVT_MENU ( ID_LOCATION_PANE_VISIBLE, MyFrame::OnLocationPaneVisible )
137
EVT_MENU ( ID_PROTECT_TAGS, MyFrame::OnProtectTags )
138
EVT_MENU ( ID_WRAP_WORDS, MyFrame::OnWrapWords )
139
EVT_MENU_RANGE ( ID_SHOW_TAGS, ID_HIDE_TAGS, MyFrame::OnVisibilityState )
140
EVT_MENU_RANGE ( ID_ASSOCIATE_DTD_PUBLIC, ID_ASSOCIATE_XSL, MyFrame::OnAssociate )
141
EVT_MENU_RANGE ( wxID_FILE1, wxID_FILE9, MyFrame::OnHistoryFile )
143
ID_VALIDATE_PRESET1, ID_VALIDATE_PRESET9, MyFrame::OnValidatePreset )
145
ID_COLOR_SCHEME_DEFAULT,
146
ID_COLOR_SCHEME_NONE,
147
MyFrame::OnColorScheme )
152
MyFrame::OnSplitTab )
154
EVT_UPDATE_UI_RANGE ( ID_REPLACE, ID_GLOBAL_REPLACE, MyFrame::OnUpdateReplaceRange )
155
EVT_FIND ( wxID_ANY, MyFrame::OnDialogFind )
156
EVT_FIND_NEXT ( wxID_ANY, MyFrame::OnDialogFind )
157
EVT_FIND_REPLACE ( wxID_ANY, MyFrame::OnDialogReplace )
158
EVT_FIND_REPLACE_ALL ( wxID_ANY, MyFrame::OnDialogReplaceAll )
159
EVT_ICONIZE ( MyFrame::OnIconize )
160
EVT_UPDATE_UI ( ID_LOCATION_PANE_VISIBLE, MyFrame::OnUpdateLocationPaneVisible )
161
EVT_UPDATE_UI ( wxID_CLOSE, MyFrame::OnUpdateDocRange )
162
EVT_UPDATE_UI ( wxID_SAVEAS, MyFrame::OnUpdateDocRange )
163
EVT_UPDATE_UI ( wxID_CLOSE_ALL, MyFrame::OnUpdateCloseAll )
164
EVT_UPDATE_UI_RANGE ( ID_SPLIT_TAB_TOP, ID_SPLIT_TAB_LEFT, MyFrame::OnUpdateCloseAll )
165
EVT_UPDATE_UI ( wxID_REVERT, MyFrame::OnUpdateUndo )
166
EVT_UPDATE_UI ( wxID_SAVE, MyFrame::OnUpdateDocRange ) // always allow save if doc present
167
EVT_UPDATE_UI ( wxID_UNDO, MyFrame::OnUpdateUndo )
168
EVT_UPDATE_UI ( wxID_REDO, MyFrame::OnUpdateRedo )
169
EVT_UPDATE_UI ( wxID_PASTE, MyFrame::OnUpdatePaste )
170
EVT_UPDATE_UI ( wxID_CUT, MyFrame::OnUpdateCutCopy )
171
EVT_UPDATE_UI ( wxID_COPY, MyFrame::OnUpdateCutCopy )
172
EVT_UPDATE_UI ( ID_FIND_AGAIN, MyFrame::OnUpdateFindAgain )
173
EVT_UPDATE_UI_RANGE ( ID_FIND, ID_EXPORT_MSWORD, MyFrame::OnUpdateDocRange )
174
EVT_UPDATE_UI ( ID_PREVIOUS_DOCUMENT, MyFrame::OnUpdatePreviousDocument )
175
EVT_UPDATE_UI ( ID_NEXT_DOCUMENT, MyFrame::OnUpdateNextDocument )
176
EVT_UPDATE_UI ( ID_HIDE_PANE, MyFrame::OnUpdateClosePane )
177
EVT_UPDATE_UI ( ID_RELOAD, MyFrame::OnUpdateReload )
178
EVT_IDLE ( MyFrame::OnIdle )
179
EVT_AUINOTEBOOK_PAGE_CLOSE ( wxID_ANY, MyFrame::OnPageClosing )
181
EVT_DROP_FILES ( MyFrame::OnDropFiles )
185
IMPLEMENT_APP ( MyApp)
187
MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
189
config ( new wxFileConfig ( _T ( ".xmlcopyeditor" ) ) )//( _T ( "SourceForge Project\\XML Copy Editor" ) ) )
191
config ( new wxFileConfig ( _T ( "xmlcopyeditor" ) ) )
197
int fdnull = open ( "/dev/null", O_WRONLY, 0 );
198
dup2 ( fdnull, STDERR_FILENO );
201
int systemLocale = myLocale.GetSystemLanguage();
202
switch ( systemLocale )
204
case wxLANGUAGE_GERMAN:
205
case wxLANGUAGE_GERMAN_AUSTRIAN:
206
case wxLANGUAGE_GERMAN_BELGIUM:
207
case wxLANGUAGE_GERMAN_LIECHTENSTEIN:
208
case wxLANGUAGE_GERMAN_LUXEMBOURG:
209
case wxLANGUAGE_GERMAN_SWISS:
210
systemLocale = wxLANGUAGE_GERMAN;
212
case wxLANGUAGE_CHINESE_SIMPLIFIED:
213
systemLocale = wxLANGUAGE_CHINESE_SIMPLIFIED;
215
case wxLANGUAGE_CHINESE_TRADITIONAL:
216
systemLocale = wxLANGUAGE_CHINESE_TRADITIONAL;
218
case wxLANGUAGE_CATALAN:
219
systemLocale = wxLANGUAGE_CATALAN;
221
case wxLANGUAGE_SPANISH:
222
case wxLANGUAGE_SPANISH_ARGENTINA:
223
case wxLANGUAGE_SPANISH_BOLIVIA:
224
case wxLANGUAGE_SPANISH_CHILE:
225
case wxLANGUAGE_SPANISH_COLOMBIA:
226
case wxLANGUAGE_SPANISH_COSTA_RICA:
227
case wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC:
228
case wxLANGUAGE_SPANISH_ECUADOR:
229
case wxLANGUAGE_SPANISH_EL_SALVADOR:
230
case wxLANGUAGE_SPANISH_GUATEMALA:
231
case wxLANGUAGE_SPANISH_HONDURAS:
232
case wxLANGUAGE_SPANISH_MEXICAN:
233
case wxLANGUAGE_SPANISH_MODERN:
234
case wxLANGUAGE_SPANISH_NICARAGUA:
235
case wxLANGUAGE_SPANISH_PANAMA:
236
case wxLANGUAGE_SPANISH_PARAGUAY:
237
case wxLANGUAGE_SPANISH_PERU:
238
case wxLANGUAGE_SPANISH_PUERTO_RICO:
239
case wxLANGUAGE_SPANISH_URUGUAY:
240
case wxLANGUAGE_SPANISH_US:
241
case wxLANGUAGE_SPANISH_VENEZUELA:
242
systemLocale = wxLANGUAGE_SPANISH;
244
case wxLANGUAGE_SLOVAK:
245
systemLocale = wxLANGUAGE_SLOVAK;
247
case wxLANGUAGE_SWEDISH:
248
systemLocale = wxLANGUAGE_SWEDISH;
250
case wxLANGUAGE_FRENCH:
251
systemLocale = wxLANGUAGE_FRENCH;
253
case wxLANGUAGE_UKRAINIAN:
254
systemLocale = wxLANGUAGE_UKRAINIAN;
256
case wxLANGUAGE_ITALIAN:
257
systemLocale = wxLANGUAGE_ITALIAN;
259
case wxLANGUAGE_RUSSIAN:
260
systemLocale = wxLANGUAGE_RUSSIAN;
262
case wxLANGUAGE_DUTCH:
263
systemLocale = wxLANGUAGE_DUTCH;
266
systemLocale = wxLANGUAGE_ENGLISH_US;
273
singleInstanceCheck = config->Read ( _T ( "singleInstanceCheck" ), true );
276
singleInstanceCheck = config->Read ( _T ( "singleInstanceCheck" ), longFalse );
278
lang = config->Read ( _T ( "lang" ), systemLocale );
284
singleInstanceCheck = true;
286
singleInstanceCheck = false;
290
myLocale.Init ( lang, wxLOCALE_LOAD_DEFAULT );
291
wxLocale::AddCatalogLookupPathPrefix ( wxT ( "." ) );
292
wxLocale::AddCatalogLookupPathPrefix ( wxT ( ".." ) );
295
wxString poDir = GetLinuxAppDir::run() + wxFileName::GetPathSeparator() + _T ( "po" ) + wxFileName::GetPathSeparator();
296
wxLocale::AddCatalogLookupPathPrefix ( poDir );
299
if ( !myLocale.AddCatalog ( _T ( "messages" ) ) )
305
myLocale.AddCatalog ( _T ( "fileutils" ) );
320
wxString name, service, hostName;
321
name.Printf ( _T ( "xmlcopyeditor-%s" ), wxGetUserId().c_str() );
322
service = IPC_SERVICE;
323
hostName = _T ( "localhost" );
325
if ( singleInstanceCheck )
327
checker = new wxSingleInstanceChecker ( name );
328
while ( checker->IsAnotherRunning() )
330
// attempt calling server
331
client = new MyClient();
332
connection = ( MyClientConnection * )
333
client->MakeConnection ( hostName, service, IPC_TOPIC );
334
if ( !connection || !connection->StartAdvise ( IPC_ADVISE_NAME ) )
338
wxString argument, what;
340
what = _T ( "Data" );
341
whatBuffer = (wxChar *)what.c_str();
342
if ( this->argc > 1 )
344
for ( int i = 1; i < this->argc; i++ )
346
argument = ( wxString ) this->argv[i];
347
argument = PathResolver::run ( argument );
348
if ( ! connection->Poke ( argument, whatBuffer ) )
354
argument = ( wxString ) IPC_NO_FILE;
355
connection->Poke ( argument, whatBuffer );
362
server = new MyServer;
363
server->Create ( service );
368
wxImage::AddHandler ( new wxPNGHandler );
369
wxSystemOptions::SetOption ( _T ( "msw.remap" ), 0 );
370
frame = new MyFrame (
371
_ ( "XML Copy Editor" ),
376
frame->Show ( true );
377
if ( frame->getHandleCommandLineFlag() )
378
frame->handleCommandLine();
380
catch ( exception &e )
384
wxString wideWhat, errorString;
385
wideWhat = wxString ( what, wxConvLocal, strlen ( what ) );
387
if ( wideWhat.empty() )
388
wideWhat = _ ( "(unknown error)" );
390
errorString = _ ( "XML Copy Editor has encountered the following error and needs to close: " );
391
errorString += wideWhat;
392
errorString += _T ( "." );
398
MB_ICONERROR | MB_TASKMODAL );
400
wxMessageBox ( errorString, _ ( "Error" ), wxICON_ERROR );
402
exit ( EXIT_FAILURE );
406
exit ( EXIT_FAILURE );
411
void MyApp::OnUnhandledException()
416
_ ( "XML Copy Editor has encountered an error and needs to close." ),
418
MB_ICONERROR | MB_TASKMODAL );
421
_ ( "XML Copy Editor has encountered an error and needs to close." ),
425
exit ( EXIT_FAILURE );
428
bool MyApp::OnExceptionInMainLoop()
439
_ ( "The operating system has turned down a request for additional memory" ),
440
_ ( "Out of memory" ),
445
catch ( exception &e )
449
wxString wideWhat, errorString;
450
wideWhat = wxString ( what, wxConvLocal, strlen ( what ) );
452
if ( wideWhat.empty() )
453
_ ( "(unknown error)" );
455
errorString = _ ( "The following error has occurred: " );
456
errorString += wideWhat;
457
errorString += _ ( ".\n\nSelect \"Abort\" to exit, \"Retry\" to close this window and \"Ignore\" to continue." );
459
int ret = ::MessageBox (
463
MB_ABORTRETRYIGNORE |
469
exit ( EXIT_FAILURE );
479
// wxGTK does not reach this point; see HandleEvent below
489
wxString otherError ( _ ( "XML Copy Editor has encountered an error and needs to close." ) );
509
void MyApp::HandleEvent ( wxEvtHandler *handler, wxEventFunction func, wxEvent& event ) const
513
wxApp::HandleEvent ( handler, func, event );
515
catch ( std::bad_alloc& )
518
_ ( "The operating system has turned down a request for additional memory" ),
519
_ ( "Out of memory" ),
523
catch ( std::exception& e )
525
std::string s ( e.what() );
526
wxString ws = wxString ( s.c_str(), wxConvUTF8, s.size() );
541
const wxString& title,
542
wxFileConfig *configParameter,
544
bool singleInstanceCheckParameter,
545
int langParameter ) :
546
wxFrame ( NULL, wxID_ANY, title ),
547
config ( configParameter ),
549
singleInstanceCheck ( singleInstanceCheckParameter ),
550
lang ( langParameter ),
551
htmlPrinting ( new wxHtmlEasyPrinting (
556
helpController ( new wxHtmlHelpController() ),
562
restoreFocusToNotebook ( false )
564
manager.SetManagedWindow ( this );
570
wxString defaultFont =
574
_T ( "Bitstream Vera Sans" );
579
// fetch configuration
580
if ( config ) // config found
582
history.Load ( *config );
583
properties.insertCloseTag =
584
config->Read ( _T ( "insertCloseTag" ), true );
585
properties.completion =
586
config->Read ( _T ( "completion" ), true );
588
config->Read ( _T ( "number" ), true );
590
config->Read ( _T ( "fold" ), true );
591
properties.currentLine =
592
config->Read ( _T ( "currentLine" ), true );
593
properties.highlightSyntax =
594
config->Read ( _T ( "highlightSyntax" ), true );
595
properties.whitespaceVisible =
596
config->Read ( _T ( "whitespaceVisible" ), true );
597
properties.indentLines =
598
config->Read ( _T ( "indentLines" ), true );
599
properties.toggleLineBackground =
600
config->Read ( _T ( "toggleLineBackground" ), true );
601
properties.protectHiddenElements =
602
config->Read ( _T ( "protectHiddenElements" ), true );
603
properties.deleteWholeTag =
604
config->Read ( _T ( "deleteWholeTag" ), true );
605
properties.validateAsYouType =
606
config->Read ( _T ( "validateAsYouType" ), true );
608
config->Read ( _T ( "font" ), defaultFont );
610
config->Read ( _T ( "findRegex" ), true );
612
config->Read ( _T ( "xpathExpression" ), wxEmptyString );
614
config->Read ( _T ( "lastXslStylesheet" ), wxEmptyString );
616
config->Read ( _T ( "lastRelaxNGSchema" ), wxEmptyString );
618
lastXslStylesheet.Replace ( _T ( " " ), _T ( "%20" ), true );
619
lastRelaxNGSchema.Replace ( _T ( " " ), _T ( "%20" ), true );
622
config->Read ( _T ( "exportQuiet" ), (long)false );
624
config->Read ( _T ( "exportMp3Album" ), (long)false );
628
config->Read ( _T ( "applicationDir" ), wxEmptyString );
629
if ( applicationDir.empty() )
633
config->Read ( _T ( "InstallPath" ), wxGetCwd() );
635
applicationDir = GetLinuxAppDir::run();
639
config->Read ( _T ( "browserCommand" ), wxEmptyString );
641
// if default value != true, type as long int
642
long valZoom, longFalse;
645
frameWidth = frameHeight = framePosX = framePosY = 0;
648
config->Read ( _T ( "wrap" ), longFalse );
651
config->Read ( _T ( "zoom" ), valZoom );
653
properties.colorScheme = config->Read ( _T ( "colorScheme" ), COLOR_SCHEME_DEFAULT );
655
globalReplaceAllDocuments =
656
config->Read ( _T ( "globalReplaceAllDocuments" ), longFalse );
657
showFullPathOnFrame =
658
config->Read ( _T ( "showFullPathOnFrame" ), longFalse );
660
config->Read ( _T ( "findMatchCase" ), longFalse );
662
commandSync = config->Read ( _T ( "commandSync" ), longFalse );
663
commandOutput = config->Read ( _T ( "commandOutput" ), ID_COMMAND_OUTPUT_IGNORE );
664
commandString = config->Read ( _T ( "commandString" ), wxEmptyString );
666
exportStylesheet = config->Read ( _T ( "exportStylesheet" ), wxEmptyString );
667
exportFolder = config->Read ( _T ( "exportFolder" ), wxEmptyString );
670
config->Read ( _T ( "ruleSetPreset" ), _ ( "Default style" ) );
672
config->Read ( _T ( "dictionaryPreset" ), _ ( "en_US" ) );
675
config->Read ( _T ( "filterPreset" ), _ ( "(No filter)" ) );
676
findData.SetFindString ( config->Read ( _T ( "findReplaceFind" ), _T ( "" ) ) );
677
findData.SetReplaceString ( config->Read ( _T ( "findReplaceReplace" ), _T ( "" ) ) );
680
config->Read ( _T ( "toolbarVisible" ), true );
681
protectTags = config->Read ( _T ( "protectTags" ), longFalse );
682
visibilityState = config->Read ( _T ( "visibilityState" ), ID_SHOW_TAGS );
684
framePosX = config->Read ( _T ( "framePosX" ), framePosX );
685
framePosY = config->Read ( _T ( "framePosY" ), framePosY );
686
frameWidth = config->Read ( _T ( "frameWidth" ), frameWidth );
687
frameHeight = config->Read ( _T ( "frameHeight" ), frameHeight );
688
rememberOpenTabs = config->Read ( _T ( "rememberOpenTabs" ), true );
689
libxmlNetAccess = config->Read ( _T ( "libxmlNetAccess" ), longFalse );
690
openTabsOnClose = config->Read ( _T ( "openTabsOnClose" ), _T ( "" ) );
691
notebookStyle = config->Read ( _T ( "notebookStyle" ), ID_NOTEBOOK_STYLE_VC8_COLOR );
692
saveBom = config->Read ( _T ( "saveBom" ), true );
693
unlimitedUndo = config->Read ( _T ( "unlimitedUndo" ), true );
694
layout = config->Read ( _T ( "layout" ), wxEmptyString );
695
restoreLayout = config->Read ( _T ( "restoreLayout" ), true );
696
showLocationPane = config->Read ( _T ( "showLocationPane" ), true );
697
showInsertChildPane = config->Read ( _T ( "showInsertChildPane" ), true );
698
showInsertSiblingPane = config->Read ( _T ( "showInsertSiblingPane" ), true );
699
showInsertEntityPane = config->Read ( _T ( "showInsertEntityPane" ), true );
700
expandInternalEntities = config->Read ( _T ( "expandInternalEntities" ), true );
703
else // config not found
705
properties.insertCloseTag =
706
properties.completion =
707
properties.currentLine =
708
properties.indentLines =
709
properties.protectHiddenElements =
710
properties.toggleLineBackground =
711
properties.deleteWholeTag =
712
properties.highlightSyntax = true;
713
properties.font = defaultFont;
714
properties.wrap = properties.whitespaceVisible = false;
716
properties.colorScheme = COLOR_SCHEME_DEFAULT;
718
applicationDir = wxGetCwd();
720
applicationDir = GetLinuxAppDir::run();//getLinuxApplicationDir();
722
ruleSetPreset = _ ( "Default style" );
723
dictionaryPreset = _ ( "en_US" );
724
filterPreset = _ ( "No filter" );
725
xpathExpression = lastXslStylesheet = lastRelaxNGSchema = wxEmptyString;
727
findMatchCase = globalReplaceAllDocuments =
728
showFullPathOnFrame = false;
729
toolbarVisible = true;
731
visibilityState = SHOW_TAGS;
732
framePosX = framePosY = frameWidth = frameHeight = 0;
733
rememberOpenTabs = true;
734
libxmlNetAccess = false;
735
openTabsOnClose = wxEmptyString;
736
browserCommand = wxEmptyString;
737
notebookStyle = ID_NOTEBOOK_STYLE_VC8_COLOR;
738
saveBom = unlimitedUndo = true;
739
layout = wxEmptyString;
740
restoreLayout = true;
741
showLocationPane = true;
742
showInsertChildPane = true;
743
showInsertSiblingPane = true;
744
showInsertEntityPane = true;
745
expandInternalEntities = true;
746
properties.validateAsYouType = true;
749
commandOutput = ID_COMMAND_OUTPUT_IGNORE;
750
commandString = wxEmptyString;
752
exportStylesheet = exportFolder = wxEmptyString;
753
exportQuiet = exportMp3Album = false;
757
largeFileProperties.completion = false;
758
largeFileProperties.fold = false;
759
largeFileProperties.whitespaceVisible = false;
760
largeFileProperties.wrap = false;
761
largeFileProperties.indentLines = false;
762
largeFileProperties.protectHiddenElements = false;
763
largeFileProperties.toggleLineBackground = false;
764
largeFileProperties.toggleLineBackground = false;
765
largeFileProperties.insertCloseTag = false;
766
largeFileProperties.deleteWholeTag = false;
767
largeFileProperties.highlightSyntax = false;
768
largeFileProperties.validateAsYouType = false;
769
largeFileProperties.number = properties.number;
770
largeFileProperties.currentLine = properties.currentLine;
771
largeFileProperties.font = properties.font;
772
largeFileProperties.zoom = 0;
773
largeFileProperties.colorScheme = COLOR_SCHEME_NONE;
778
size_t findFlags = 0;
779
findFlags |= wxFR_DOWN;
782
findFlags |= wxFR_MATCHCASE;
784
findData.SetFlags ( findFlags );
786
if ( browserCommand.empty() )
789
browserCommand = binDir + _T ( "navigate.exe" );
791
browserCommand = getLinuxBrowser();
795
// initialise document count for tab labels
798
SetIcon ( wxICON ( appicon ) );
801
wxStatusBar *status = GetStatusBar();
802
int widths[] = { -24, -6, -6, -6, -8 };
803
status->SetFieldsCount ( 5 );
804
status->SetStatusWidths ( 5, widths );
816
SetSize ( 50, 50, 640, 480 );
821
SetSize ( framePosX, framePosY, frameWidth, frameHeight );
824
stylePosition = aboutPosition = wxDefaultPosition;
825
styleSize = wxSize ( 720, 540 );
827
showTopBars ( toolbarVisible );
829
long style = wxAUI_NB_TOP |
832
wxAUI_NB_WINDOWLIST_BUTTON |
833
wxAUI_NB_CLOSE_ON_ALL_TABS |
836
mainBook = new MyNotebook (
843
manager.AddPane ( mainBook, wxAuiPaneInfo().CenterPane()
844
.PaneBorder ( false ).Name ( _T ( "documentPane" ) ) );
845
manager.GetPane ( mainBook ).dock_proportion = 10;
847
// add insert child panes
848
locationPanel = new LocationPanel ( this, ID_LOCATION_PANEL );
849
insertChildPanel = new InsertPanel ( this, ID_INSERT_CHILD_PANEL,
850
INSERT_PANEL_TYPE_CHILD );
851
insertSiblingPanel = new InsertPanel ( this, ID_INSERT_SIBLING_PANEL,
852
INSERT_PANEL_TYPE_SIBLING );
853
insertEntityPanel = new InsertPanel ( this, ID_INSERT_ENTITY_PANEL,
854
INSERT_PANEL_TYPE_ENTITY );
857
manager.AddPane ( ( wxWindow * ) locationPanel, wxRIGHT, _ ( "Current Element" ) );
858
manager.AddPane ( ( wxWindow * ) insertChildPanel, wxRIGHT, _ ( "Insert Element" ) );
859
manager.AddPane ( ( wxWindow * ) insertSiblingPanel, wxRIGHT, _ ( "Insert Sibling" ) );
860
manager.AddPane ( ( wxWindow * ) insertEntityPanel, wxRIGHT, _ ( "Insert Entity" ) );
862
manager.AddPane ( ( wxWindow * ) insertEntityPanel, wxRIGHT, _ ( "Insert Entity" ) );
863
manager.AddPane ( ( wxWindow * ) insertSiblingPanel, wxRIGHT, _ ( "Insert Sibling" ) );
864
manager.AddPane ( ( wxWindow * ) insertChildPanel, wxRIGHT, _ ( "Insert Element" ) );
865
manager.AddPane ( ( wxWindow * ) locationPanel, wxRIGHT, _ ( "Current Element" ) );
868
manager.GetPane ( locationPanel ).Name ( _T ( "locationPane" ) ).Show (
869
( restoreLayout ) ? showLocationPane : true ).DestroyOnClose ( false ).PinButton ( true );
870
manager.GetPane ( locationPanel ).dock_proportion = 1;
872
manager.GetPane ( insertChildPanel ).Name ( _T ( "insertChildPane" ) ).Show (
873
( restoreLayout ) ? showInsertChildPane : true ).DestroyOnClose ( false ).PinButton ( true );
874
manager.GetPane ( insertChildPanel ).dock_proportion = 1;
876
manager.GetPane ( insertSiblingPanel ).Name ( _T ( "insertSiblingPane" ) ).Show (
877
( restoreLayout ) ? showInsertSiblingPane : true ).DestroyOnClose ( false ).PinButton ( true );
878
manager.GetPane ( insertSiblingPanel ).dock_proportion = 1;
880
manager.GetPane ( insertEntityPanel ).Name ( _T ( "insertEntityPane" ) ).Show (
881
( restoreLayout ) ? showInsertEntityPane : true ).DestroyOnClose ( false ).PinButton ( true );
882
manager.GetPane ( insertEntityPanel ).dock_proportion = 1;
884
// add (hidden) message pane
885
htmlReport = new MyHtmlPane (
891
const int sizeArray[] =
893
8, 9, 10, 11, 12, 13, 14
895
htmlReport->SetFonts ( wxEmptyString, wxEmptyString, sizeArray );
897
htmlReport->SetBorders ( 0 );
898
manager.AddPane ( htmlReport, wxAuiPaneInfo().Movable().Bottom()
899
.Hide().Name ( _T ( "messagePane" ) )
900
.DestroyOnClose ( false ).Layer ( 1 ) );
901
manager.GetPane ( htmlReport ).dock_proportion = 1;
903
#ifdef NEWFINDREPLACE
904
findReplacePanel = new FindReplacePanel (
906
ID_FIND_REPLACE_PANEL,
912
( wxWindow * ) findReplacePanel,
913
wxAuiPaneInfo().Bottom().Hide().Caption ( wxEmptyString ).
914
DestroyOnClose ( false ).Layer ( 2 ) );
917
commandPanel = new CommandPanel (
920
commandString, // tbd
925
( wxWindow * ) commandPanel,
926
wxAuiPaneInfo().Bottom().Hide().Caption ( _T ( "Command" ) ).DestroyOnClose ( false ).Layer ( 3 ) );
928
if ( !wxFileName::DirExists ( applicationDir ) )
930
GetStatusBar()->SetStatusText ( _ ( "Cannot open application directory: see Tools, Options..., General" ) );
932
GetStatusBar()->SetStatusText ( _ ( "Cannot open application directory: see Edit, Preferences..., General" ) );
935
// handle command line and, on Windows, MS Word integration
936
handleCommandLineFlag = ( wxTheApp->argc > 1 ) ? true : false;
938
if ( rememberOpenTabs && !openTabsOnClose.empty() )
939
openRememberedTabs();
942
if ( !handleCommandLineFlag )
943
newDocument ( wxEmptyString );
947
DragAcceptFiles ( true ); // currently Windows only
950
XmlDoc *doc = getActiveDocument();
951
insertEntityPanel->update ( doc ); // NULL is ok
956
defaultLayout = manager.SavePerspective();
958
// restore layout if req'd
959
if (restoreLayout && !layout.empty())
961
if (!manager.LoadPerspective(layout, true))
962
manager.LoadPerspective(defaultLayout, true);
969
std::vector<wxString>::iterator it;
970
for ( it = tempFileVector.begin(); it != tempFileVector.end(); it++ )
971
wxRemoveFile ( *it );
973
layout = manager.SavePerspective();
976
history.Save ( *config );
977
config->Write ( _T ( "insertCloseTag" ), properties.insertCloseTag );
978
config->Write ( _T ( "completion" ), properties.completion );
979
config->Write ( _T ( "number" ), properties.number );
980
config->Write ( _T ( "fold" ), properties.fold );
981
config->Write ( _T ( "currentLine" ), properties.currentLine );
982
config->Write ( _T ( "whitespaceVisible" ), properties.whitespaceVisible );
983
config->Write ( _T ( "wrap" ), properties.wrap );
984
config->Write ( _T ( "indentLines" ), properties.indentLines );
985
config->Write ( _T ( "zoom" ), properties.zoom );
986
config->Write ( _T ( "colorScheme" ), properties.colorScheme );
987
config->Write ( _T ( "protectHiddenElements" ), properties.protectHiddenElements );
988
config->Write ( _T ( "toggleLineBackground" ), properties.toggleLineBackground );
989
config->Write ( _T ( "deleteWholeTag" ), properties.deleteWholeTag );
990
config->Write ( _T ( "validateAsYouType" ), properties.validateAsYouType );
991
config->Write ( _T ( "font" ), properties.font );
992
config->Write ( _T ( "highlightSyntax" ), properties.highlightSyntax );
993
config->Write ( _T ( "applicationDir" ), applicationDir );
994
config->Write ( _T ( "ruleSetPreset" ), ruleSetPreset );
995
config->Write ( _T ( "dictionaryPreset" ), dictionaryPreset );
996
config->Write ( _T ( "filterPreset" ), filterPreset );
997
config->Write ( _T ( "xpathExpression" ), xpathExpression );
998
config->Write ( _T ( "findReplaceFind" ), findData.GetFindString() );
999
config->Write ( _T ( "findReplaceReplace" ), findData.GetReplaceString() );
1000
config->Write ( _T ( "globalReplaceAllDocuments" ), globalReplaceAllDocuments );
1001
config->Write ( _T ( "showFullPathOnFrame" ), showFullPathOnFrame );
1002
config->Write ( _T ( "toolbarVisible" ), toolbarVisible );
1003
config->Write ( _T ( "protectTags" ), protectTags );
1004
config->Write ( _T ( "visibilityState" ), visibilityState );
1005
config->Write ( _T ( "browserCommand" ), browserCommand );
1006
config->Write ( _T ( "showLocationPane" ), manager.GetPane ( locationPanel ).IsShown() );
1007
config->Write ( _T ( "showInsertChildPane" ), manager.GetPane ( insertChildPanel ).IsShown() );
1008
config->Write ( _T ( "showInsertSiblingPane" ), manager.GetPane ( insertSiblingPanel ).IsShown() );
1009
config->Write ( _T ( "showInsertEntityPane" ), manager.GetPane ( insertEntityPanel ).IsShown() );
1010
config->Write ( _T ( "expandInternalEntities" ), expandInternalEntities );
1011
config->Write ( _T ( "findRegex" ), findReplacePanel->getRegex() );
1012
config->Write ( _T ( "findMatchCase" ), ( findData.GetFlags() ) & wxFR_MATCHCASE );
1013
config->Write ( _T ( "commandSync" ), commandPanel->getSync() );
1014
config->Write ( _T ( "commandOutput" ), commandPanel->getOutput() );
1015
config->Write ( _T ( "commandString" ), commandPanel->getCommand() );
1016
config->Write ( _T ( "restoreLayout" ), restoreLayout );
1017
config->Write ( _T ( "lastXslStylesheet" ), lastXslStylesheet );
1018
config->Write ( _T ( "lastRelaxNGSchema" ), lastRelaxNGSchema );
1019
config->Write ( _T ( "exportStylesheet" ), exportStylesheet );
1020
config->Write ( _T ( "exportFolder" ), exportFolder );
1021
config->Write ( _T ( "exportQuiet" ), exportQuiet );
1022
config->Write ( _T ( "exportMp3Album" ), exportMp3Album );
1024
GetPosition ( &framePosX, &framePosY );
1025
config->Write ( _T ( "framePosX" ), framePosX );
1026
config->Write ( _T ( "framePosY" ), framePosY );
1027
GetSize ( &frameWidth, &frameHeight );
1028
config->Write ( _T ( "frameWidth" ), frameWidth );
1029
config->Write ( _T ( "frameHeight" ), frameHeight );
1031
config->Write ( _T ( "rememberOpenTabs" ), rememberOpenTabs );
1032
config->Write ( _T ( "openTabsOnClose" ), openTabsOnClose );
1033
config->Write ( _T ( "libxmlNetAccess" ), libxmlNetAccess );
1035
config->Write ( _T ( "singleInstanceCheck" ), singleInstanceCheck );
1036
config->Write ( _T ( "lang" ), lang );
1037
config->Write ( _T ( "notebookStyle" ), notebookStyle );
1038
config->Write ( _T ( "saveBom" ), saveBom );
1039
config->Write ( _T ( "unlimitedUndo" ), unlimitedUndo );
1041
wxTheClipboard->Flush();
1044
wxString MyFrame::getLinuxBrowser()
1047
const int stringArrayLen = 10;
1048
wxString stringArray[stringArrayLen];
1049
stringArray[0] = _T ( "/usr/bin/x-www-browser" );
1050
stringArray[1] = _T ( "/usr/bin/firefox" );
1051
stringArray[2] = _T ( "/usr/bin/mozilla" );
1052
stringArray[3] = _T ( "/usr/bin/opera" );
1053
stringArray[4] = _T ( "/usr/bin/dillo" );
1054
stringArray[5] = _T ( "/opt/gnome/bin/epiphany" );
1055
stringArray[6] = _T ( "/opt/gnome/bin/galeon" );
1056
stringArray[7] = _T ( "/opt/kde/bin/konqueror" );
1057
stringArray[8] = _T ( "/opt/mozilla/bin/firefox" );
1058
stringArray[9] = wxEmptyString; // empty option is safe
1060
for ( int i = 0; i < stringArrayLen; i++ )
1063
if ( wxFileName::FileExists ( s ) )
1069
void MyFrame::showTopBars ( bool b )
1073
SetToolBar ( NULL );
1074
menuBar = getMenuBar();
1075
SetMenuBar ( menuBar );
1080
toolBar = getToolBar();
1081
SetToolBar ( toolBar );
1085
SetToolBar ( NULL );
1091
void MyFrame::handleCommandLine()
1093
bool wordFlag, styleFlag;
1094
wordFlag = styleFlag = false;
1097
int m_argc = wxTheApp->argc;
1098
wxChar **m_argv = wxTheApp->argv;
1100
while ( ( --m_argc > 0 && ( *++m_argv ) [0] == L'-' ) != 0 )
1102
wxString wideVersion ( ABOUT_VERSION );
1103
std::string version = ( const char * ) wideVersion.mb_str ( wxConvUTF8 );
1104
while ( ( c = *++m_argv[0] ) != 0 )
1115
if ( *++m_argv[0] == L'v' )
1117
std::cout << version.c_str() << std::endl;
1121
std::cout << "Usage: xmlcopyeditor [--version --help] [<file>] [<file2>]" << std::endl << std::endl;
1125
messagePane ( _ ( "Unknown command line switch (expecting 'w', 's', --version or --help)" ),
1132
if ( ! ( *m_argv ) )
1134
messagePane ( _ ( "Command line processing incomplete: no file specified" ),
1141
// no flags specified or not Windows
1143
if ( !styleFlag && !wordFlag )
1146
for ( ; *m_argv; ++m_argv )
1148
fileName = wxString ( *m_argv, wxConvLocal, wcslen ( *m_argv ) );
1149
fileName = PathResolver::run ( fileName );
1150
if ( isOpen ( fileName ) )
1152
else if ( !openFile ( fileName ) )
1158
// options only available on Windows
1159
fileName = wxString ( *m_argv, wxConvLocal, wcslen ( *m_argv ) );
1161
// fetch as many parameters as possible
1165
if ( ! ( *m_argv ) )
1167
ruleSetPreset = wxString ( *m_argv, wxConvLocal, wcslen ( *m_argv ) );
1170
if ( ! ( *m_argv ) )
1172
filterPreset = wxString ( *m_argv, wxConvLocal, wcslen ( *m_argv ) );
1175
if ( ! ( *m_argv ) )
1177
applicationDir = wxString ( *m_argv, wxConvLocal, wcslen ( *m_argv ) );
1183
importMSWord ( fileName );
1185
openFile ( fileName );
1187
if ( styleFlag && !ruleSetPreset.empty() && !filterPreset.empty() )
1194
bool MyFrame::isOpen ( const wxString& fileName )
1196
return ( openFileSet.find ( fileName ) != openFileSet.end() );
1199
bool MyFrame::activateTab ( const wxString& fileName )
1201
int pageCount = mainBook->GetPageCount();
1203
for ( int i = 0; i < pageCount; ++i )
1205
currentDoc = ( XmlDoc * ) mainBook->GetPage ( i );
1208
if ( currentDoc->getFullFileName() == fileName )
1210
mainBook->SetSelection ( i );
1217
void MyFrame::OnAbout ( wxCommandEvent& WXUNUSED ( event ) )
1219
wxString description;
1220
description = ABOUT_DESCRIPTION;
1221
description.Append ( _T("\n\nFramework version: ") );
1222
description.Append ( wxVERSION_STRING );
1223
description.Append ( _T("\n") );
1225
wxAboutDialogInfo info;
1226
info.SetName ( _ ( "XML Copy Editor" ) );
1227
info.SetWebSite ( _T ( "http://xml-copy-editor.sourceforge.net" ) );
1228
info.SetVersion ( ABOUT_VERSION );
1229
info.SetCopyright ( ABOUT_COPYRIGHT );
1230
info.AddDeveloper ( _ ( "Gerald Schmidt (development) <gnschmidt at users dot sourceforge dot net>" ) );
1231
info.AddDeveloper ( _ ( "Matt Smigielski (testing) <alectrus at users dot sourceforge dot net>" ) );
1232
info.AddDeveloper ( _ ( "Justin Dearing (development) <j-pimp at users dot sourceforge dot net>" ) );
1233
info.AddDeveloper ( _ ( "Kev James (development) <kmjames at users dot sourceforge dot net>" ) );
1234
info.AddDeveloper ( _ ( "Anh Trinh (development) <ant271 at users dot sourceforge dot net>" ) );
1235
info.AddDeveloper ( _ ( "Esther L\x00F6liger (development) <eloeliger at users dot sourceforge dot net>" ) );
1236
info.AddTranslator ( _ ( "Viliam Búr (Slovak) <viliam at bur dot sk>" ) );
1237
info.AddTranslator ( _ ( "David Håsäther (Swedish) <hasather at gmail dot com>" ) );
1238
info.AddTranslator ( _ ( "François Badier (French) <frabad at gmail dot com>" ) );
1239
info.AddTranslator ( _ ( "Thomas Wenzel (German) <thowen at users dot sourceforge.net>" ) );
1240
info.AddTranslator ( _ ( "SHiNE CsyFeK (Chinese Simplified) <csyfek at gmail dot com>" ) );
1241
info.AddTranslator ( _ ( "HSU PICHAN, YANG SHUFUN, CHENG PAULIAN, CHUANG KUO-PING, Marcus Bingenheimer (Chinese Traditional)" ) );
1242
info.AddTranslator ( _ ( "Serhij Dubyk (Ukrainian) <dubyk at library dot lviv dot ua>" ) );
1243
info.AddTranslator ( _ ( "Antonio Angelo (Italian) <aangelo at users dot sourceforge dot net>" ) );
1244
info.AddTranslator ( _ ( "Siarhei Kuchuk (Russian) <Cuchuk dot Sergey at gmail dot com>" ) );
1245
info.AddTranslator ( _ ( "Marcos Pérez González (Spanish) <marcos_pg at yahoo dot com>" ) );
1246
info.AddTranslator ( _ ( "Rob Elemans (Dutch) <relemans at gmail dot com>" ) );
1247
info.AddTranslator ( _ ( "Robert Falc\xf3 Miramontes <rfalco at acett dot org>" ) );
1248
info.SetLicense ( ABOUT_LICENSE );
1249
info.SetDescription ( description );
1250
wxAboutBox ( info );
1252
if ( ( doc = getActiveDocument() ) == NULL )
1257
void MyFrame::OnCheckWellformedness ( wxCommandEvent& event )
1259
statusProgress ( wxEmptyString );
1261
if ( ( doc = getActiveDocument() ) == NULL )
1264
std::string utf8Buffer;
1265
getRawText ( doc, utf8Buffer );
1266
if ( utf8Buffer.empty() )
1269
// handle unusual encodings
1270
if ( !XmlEncodingHandler::setUtf8 ( utf8Buffer ) )
1276
doc->clearErrorIndicators();
1277
statusProgress ( _ ( "Parse in progress..." ) );
1279
// check for well-formedness
1280
auto_ptr<WrapExpat> we ( new WrapExpat() );
1281
if ( !we->parse ( utf8Buffer.c_str() ) )
1283
std::string error = we->getLastError();
1284
wxString werror = wxString ( error.c_str(), wxConvUTF8, error.size() );
1285
statusProgress ( wxEmptyString );
1286
messagePane ( werror, CONST_WARNING );
1287
std::pair<int, int> posPair = we->getErrorPosition();
1288
-- ( posPair.first );
1290
doc->PositionFromLine ( posPair.first );
1291
doc->SetSelection ( cursorPos, cursorPos );
1293
doc->setErrorIndicator ( posPair.first, posPair.second );
1297
statusProgress ( wxEmptyString );
1298
documentOk ( _ ( "well-formed" ) );
1301
void MyFrame::OnPageClosing ( wxAuiNotebookEvent& event ) //wxNotebookEvent& event)//wxFlatNotebookEvent& event)
1303
deletePageVetoed = false;
1305
if ( insertChildPanel && insertSiblingPanel && locationPanel )
1307
insertChildPanel->update ( NULL, wxEmptyString );
1308
insertSiblingPanel->update ( NULL, wxEmptyString );
1309
locationPanel->update();
1314
doc = ( XmlDoc * ) mainBook->GetPage ( event.GetSelection() );
1318
statusProgress ( wxEmptyString );
1321
if ( doc->GetModify() ) //CanUndo())
1325
if ( ( selection = mainBook->GetSelection() ) != -1 )
1326
fileName = doc->getShortFileName();
1328
int answer = wxMessageBox (
1329
_ ( "Do you want to save the changes to " ) + fileName + _T ( "?" ),
1330
_ ( "XML Copy Editor" ),
1331
wxYES_NO | wxCANCEL | wxICON_QUESTION,
1334
if ( answer == wxCANCEL )
1337
deletePageVetoed = true;
1340
else if ( answer == wxYES )
1342
wxCommandEvent event;
1346
statusProgress ( wxEmptyString );
1348
openFileSet.erase ( doc->getFullFileName() );
1352
void MyFrame::OnClose ( wxCommandEvent& WXUNUSED ( event ) )
1354
closeActiveDocument();
1357
void MyFrame::OnCloseAll ( wxCommandEvent& WXUNUSED ( event ) )
1361
openTabsOnClose = wxEmptyString;
1364
if ( rememberOpenTabs && !openFileSet.empty() )
1368
size_t maxTabs = mainBook->GetPageCount();
1369
for ( size_t i = 0; i < maxTabs; ++i )
1371
doc = ( XmlDoc * ) mainBook->GetPage ( i );
1374
fullPath = doc->getFullFileName();
1375
if ( !fullPath.empty() )
1377
openTabsOnClose.Append ( fullPath );
1378
openTabsOnClose.Append ( _T ( "|" ) );
1384
while ( closeActiveDocument() )
1388
void MyFrame::OnClosePane ( wxCommandEvent& WXUNUSED ( event ) )
1391
//closeFindReplacePane();
1392
//closeCommandPane();
1394
XmlDoc *doc = getActiveDocument();
1399
void MyFrame::closePane()
1403
manager.GetPane ( htmlReport ).Hide();
1407
if ( ( doc = getActiveDocument() ) == NULL )
1412
void MyFrame::closeFindReplacePane()
1414
if ( manager.GetPane ( findReplacePanel ).IsShown() )
1415
manager.GetPane ( findReplacePanel ).Hide();
1419
void MyFrame::closeCommandPane()
1421
if ( manager.GetPane ( commandPanel ).IsShown() )
1422
manager.GetPane ( commandPanel ).Hide();
1426
bool MyFrame::panelHasFocus()
1428
XmlDoc *doc = getActiveDocument();
1429
return ( !doc || ( FindFocus() != ( wxWindow * ) doc ) );
1432
void MyFrame::OnCut ( wxCommandEvent& event )
1434
if ( panelHasFocus() )
1441
if ( ( doc = getActiveDocument() ) == NULL )
1445
doc->adjustSelection();
1448
doc->setValidationRequired ( true );
1451
void MyFrame::OnCopy ( wxCommandEvent& event )
1453
if ( panelHasFocus() )
1460
if ( ( doc = getActiveDocument() ) == NULL )
1465
void MyFrame::OnPaste ( wxCommandEvent& event )
1467
if ( panelHasFocus() )
1473
if ( ( doc = getActiveDocument() ) == NULL )
1476
// this has to be handled here to override Scintilla's default Ctrl+V support
1479
if ( !wxTheClipboard->Open() || !wxTheClipboard->IsSupported ( wxDF_TEXT ) )
1481
wxTextDataObject data;
1482
wxTheClipboard->GetData ( data );
1483
wxString buffer = data.GetText();
1484
wxTheClipboard->Close();
1485
xmliseWideTextNode ( buffer );
1486
doc->adjustCursor();
1487
doc->AddText ( buffer );
1493
void MyFrame::OnIdle ( wxIdleEvent& event )
1495
wxStatusBar *status = GetStatusBar();
1500
// IPC handling: take one file from fileQueue at a time
1501
if ( !fileQueue.empty() )
1503
openFile ( * ( fileQueue.begin() ) );
1504
fileQueue.erase( fileQueue.begin() );
1508
// update attributes hidden field even if no document loaded
1509
wxString currentHiddenStatus = status->GetStatusText ( STATUS_HIDDEN );
1510
if ( visibilityState == HIDE_ATTRIBUTES )
1512
if ( currentHiddenStatus != _ ( "Attributes hidden" ) )
1513
status->SetStatusText (
1514
_ ( "Attributes hidden" ),
1517
else if ( visibilityState == HIDE_TAGS )
1519
if ( currentHiddenStatus != _ ( "Tags hidden" ) )
1520
status->SetStatusText (
1521
_ ( "Tags hidden" ),
1526
if ( !currentHiddenStatus.empty() )
1527
status->SetStatusText ( wxEmptyString, STATUS_HIDDEN );
1530
// update protected field even if no document loaded
1531
wxString currentProtectedStatus = status->GetStatusText ( STATUS_PROTECTED );
1534
if ( currentProtectedStatus != _ ( "Tags locked" ) )
1535
status->SetStatusText (
1536
_ ( "Tags locked" ),
1541
if ( !currentProtectedStatus.empty() )
1542
status->SetStatusText ( wxEmptyString, STATUS_PROTECTED );
1545
// check if document loaded
1546
wxString frameTitle = GetTitle();
1549
if ( ( doc = getActiveDocument() ) == NULL )
1551
if ( lastDoc != NULL )
1554
status->SetStatusText ( wxEmptyString, STATUS_MODIFIED );
1555
status->SetStatusText ( wxEmptyString, STATUS_POSITION );
1556
locationPanel->update ( NULL, wxEmptyString );
1557
insertChildPanel->update ( NULL, wxEmptyString );
1558
insertSiblingPanel->update ( NULL, wxEmptyString );
1559
insertEntityPanel->update ( NULL, wxEmptyString );
1560
wxString minimal = _ ( "XML Copy Editor" );
1561
if ( frameTitle != minimal )
1562
SetTitle ( minimal );
1564
closeFindReplacePane();
1572
if ( restoreFocusToNotebook )
1575
restoreFocusToNotebook = false;
1579
if ( doc->getFullFileName().empty() || !showFullPathOnFrame )
1580
docTitle = doc->getShortFileName();
1582
docTitle = doc->getFullFileName();
1584
docTitle += _T ( " - " );
1585
docTitle += _ ( "XML Copy Editor" );
1587
if ( frameTitle != docTitle )
1588
SetTitle ( docTitle );
1590
// update modified field
1593
int index = mainBook->GetSelection();
1595
wxString currentModifiedStatus = status->GetStatusText ( STATUS_MODIFIED );
1596
wxString currentTabLabel = mainBook->GetPageText ( index );
1597
if ( doc->GetModify() )
1599
if ( currentModifiedStatus != _ ( "Modified" ) )
1601
status->SetStatusText ( _ ( "Modified" ), STATUS_MODIFIED );
1603
if ( ! ( currentTabLabel.Mid ( 0, 1 ) == _T ( "*" ) ) )
1605
currentTabLabel.Prepend ( _T ( "*" ) );
1606
mainBook->SetPageText ( index, currentTabLabel );
1612
if ( !currentModifiedStatus.empty() )
1614
status->SetStatusText ( _T ( "" ), STATUS_MODIFIED );
1616
if ( currentTabLabel.Mid ( 0, 1 ) == _T ( "*" ) )
1618
currentTabLabel.Remove ( 0, 1 );
1619
mainBook->SetPageText ( index, currentTabLabel );
1624
// update coordinates field
1625
std::pair<int, int> myControlCoordinates;
1626
int current = doc->GetCurrentPos();
1627
myControlCoordinates.first = doc->LineFromPosition ( current ) + 1;
1628
myControlCoordinates.second = doc->GetColumn ( current ) + 1;
1630
if ( myControlCoordinates != controlCoordinates )
1632
wxString coordinates;
1633
coordinates.Printf (
1634
_ ( "Ln %i Col %i" ),
1635
myControlCoordinates.first,
1636
myControlCoordinates.second );
1637
GetStatusBar()->SetStatusText ( coordinates, STATUS_POSITION );
1638
controlCoordinates = myControlCoordinates;
1641
// update parent element field
1642
wxString parent, grandparent;
1643
if ( current == lastPos && doc == lastDoc )
1650
// don't try to find parent if pane is not shown
1651
if ( !manager.GetPane ( insertChildPanel ).IsShown() && !properties.validateAsYouType )
1654
int parentCloseAngleBracket = -1;
1655
if ( !doc->canInsertAt ( current ) )
1656
parent = grandparent = wxEmptyString;
1659
parentCloseAngleBracket = doc->getParentCloseAngleBracket ( current );
1660
parent = doc->getLastElementName ( parentCloseAngleBracket );
1663
if ( !parent.empty() && properties.validateAsYouType && doc->getValidationRequired() )
1665
// tbd: limit to parent element
1666
doc->backgroundValidate();
1670
if ( parent == lastParent )
1672
lastParent = parent;
1674
bool mustUpdate = false;
1675
if ( locationPanel && insertChildPanel && insertEntityPanel )
1677
locationPanel->update ( doc, parent );
1678
insertChildPanel->update ( doc, parent );
1679
insertEntityPanel->update ( doc );
1683
if ( parent.empty() )
1685
if ( insertSiblingPanel )
1686
insertSiblingPanel->update ( doc, wxEmptyString );
1692
if ( !manager.GetPane ( insertSiblingPanel ).IsShown() )
1699
// try to fetch grandparent if necessary/possible
1700
if ( !parent.empty() && parentCloseAngleBracket != -1 )
1702
int grandParentCloseAngleBracket;
1703
grandParentCloseAngleBracket =
1704
doc->getParentCloseAngleBracket (
1705
doc->getTagStartPos ( parentCloseAngleBracket ) );
1706
grandparent = doc->getLastElementName ( grandParentCloseAngleBracket );
1708
if ( insertSiblingPanel )
1709
insertSiblingPanel->update ( doc, parent, grandparent );
1710
if ( grandparent != lastGrandparent )
1713
lastGrandparent = grandparent;
1721
void MyFrame::OnInsertChild ( wxCommandEvent& event )
1723
if ( !insertChildPanel )
1726
wxAuiPaneInfo info = manager.GetPane ( insertChildPanel );
1731
if ( !info.IsShown() )
1733
manager.GetPane ( insertChildPanel ).Show ( true );
1736
insertChildPanel->setEditFocus();
1739
void MyFrame::OnInsertSibling ( wxCommandEvent& event )
1741
if ( !insertSiblingPanel )
1744
wxAuiPaneInfo info = manager.GetPane ( insertSiblingPanel );
1750
if ( !info.IsShown() )
1752
manager.GetPane ( insertSiblingPanel ).Show ( true );
1755
insertSiblingPanel->setEditFocus();
1758
void MyFrame::OnInsertEntity ( wxCommandEvent& event )
1760
if ( !insertEntityPanel )
1763
wxAuiPaneInfo info = manager.GetPane ( insertEntityPanel );
1769
if ( !info.IsShown() )
1771
manager.GetPane ( insertEntityPanel ).Show ( true );
1774
insertEntityPanel->setEditFocus();
1777
void MyFrame::OnInsertSymbol ( wxCommandEvent& event )
1780
if ( ( doc = getActiveDocument() ) == NULL )
1782
wxSymbolPickerDialog dlg ( _T ( "*" ), wxEmptyString, properties.font, this );
1784
if ( dlg.ShowModal() == wxID_OK )
1786
if ( dlg.HasSelection() )
1788
doc->AddText ( dlg.GetSymbol() );
1793
void MyFrame::OnInsertTwin ( wxCommandEvent& event )
1796
if ( ( doc = getActiveDocument() ) == NULL )
1799
wxString parent = doc->getParent();
1800
if ( !doc->insertSibling ( parent, parent ) )
1803
msg.Printf ( _T ( "Cannot insert twin '%s'" ), parent.c_str() );
1804
messagePane ( msg, CONST_STOP );
1806
doc->setValidationRequired ( true );
1810
void MyFrame::OnPasteNewDocument ( wxCommandEvent& event )
1812
if ( !wxTheClipboard->Open() )
1814
messagePane ( _ ( "Cannot open clipboard" ), CONST_STOP );
1817
if ( !wxTheClipboard->IsSupported ( wxDF_TEXT ) )
1819
messagePane ( _ ( "Cannot paste as new document: no text on clipboard" ), CONST_STOP );
1822
wxTextDataObject data;
1823
wxTheClipboard->GetData ( data );
1825
wxString buffer = data.GetText();
1826
xmliseWideTextNode ( buffer );
1828
buffer.Prepend ( _T ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>" ) );
1829
buffer.Append ( _T ( "</root>\n" ) );
1831
newDocument ( buffer );
1832
wxTheClipboard->Close();
1835
void MyFrame::OnDialogFind ( wxFindDialogEvent& event )
1837
findAgain ( event.GetFindString(), event.GetFlags() );
1840
void MyFrame::OnDialogReplace ( wxFindDialogEvent& event )
1842
statusProgress ( wxEmptyString );
1844
if ( ( doc = getActiveDocument() ) == NULL )
1848
if ( findReplacePanel->getRegex() )
1850
regexWidth = doc->ReplaceTargetRE ( event.GetReplaceString() );
1854
doc->ReplaceTarget ( event.GetReplaceString() );
1856
OnDialogFind ( event );
1859
void MyFrame::OnDialogReplaceAll ( wxFindDialogEvent& event )
1861
statusProgress ( wxEmptyString );
1863
if ( ( doc = getActiveDocument() ) == NULL )
1867
if ( event.GetFlags() & wxFR_WHOLEWORD )
1868
flags |= wxSTC_FIND_WHOLEWORD;
1869
if ( event.GetFlags() & wxFR_MATCHCASE )
1870
flags |= wxSTC_FIND_MATCHCASE;
1871
if ( findReplacePanel->getRegex() )
1872
flags |= wxSTC_FIND_REGEXP;
1874
doc->SetTargetStart ( 0 );
1875
doc->SetTargetEnd ( doc->GetLength() );
1876
doc->SetSearchFlags ( flags );
1878
int newLocation, replacementCount, regexWidth;
1879
newLocation = replacementCount = regexWidth = 0;
1881
while ( ( newLocation = doc->SearchInTarget ( event.GetFindString() ) ) != -1 )
1883
if ( findReplacePanel->getRegex() )
1885
regexWidth = doc->ReplaceTargetRE ( event.GetReplaceString() );
1886
doc->SetTargetStart ( newLocation + regexWidth );
1890
doc->ReplaceTarget ( event.GetReplaceString() );
1891
doc->SetTargetStart ( newLocation + event.GetReplaceString().size() );
1893
doc->SetTargetEnd ( doc->GetLength() );
1899
ngettext ( L"%i replacement made", L"%i replacements made", replacementCount ),
1901
statusProgress ( msg );
1904
void MyFrame::OnPrintSetup ( wxCommandEvent &WXUNUSED ( event ) )
1906
if ( !htmlPrinting.get() )
1908
htmlPrinting->PageSetup();
1911
void MyFrame::OnPrintPreview ( wxCommandEvent &WXUNUSED ( event ) )
1914
if ( !htmlPrinting.get() || ( doc = getActiveDocument() ) == NULL )
1916
wxString shortFileName, header;
1917
shortFileName = doc->getShortFileName();
1918
if ( !shortFileName.empty() )
1919
header = shortFileName + _T ( " " );
1920
header += _T ( "(@PAGENUM@/@PAGESCNT@)<hr>" );
1922
htmlPrinting->SetHeader (
1925
statusProgress ( _ ( "Preparing Print Preview..." ) );
1926
wxString htmlBuffer = getHtmlBuffer();
1927
statusProgress ( wxEmptyString );
1928
if ( ! ( htmlPrinting->PreviewText ( htmlBuffer ) ) )
1932
void MyFrame::OnPrint ( wxCommandEvent &WXUNUSED ( event ) )
1935
if ( !htmlPrinting.get() || ( doc = getActiveDocument() ) == NULL )
1937
wxString shortFileName, header;
1938
shortFileName = doc->getShortFileName();
1939
if ( !shortFileName.empty() )
1940
header = shortFileName + _T ( " " );
1941
header += _T ( "(@PAGENUM@/@PAGESCNT@)<hr>" );
1943
htmlPrinting->SetHeader (
1946
statusProgress ( _ ( "Preparing to print..." ) );
1947
wxString htmlBuffer = getHtmlBuffer();
1948
statusProgress ( wxEmptyString );
1949
if ( ! ( htmlPrinting->PrintText ( htmlBuffer ) ) )
1953
wxString MyFrame::getHtmlBuffer()
1956
if ( ( doc = getActiveDocument() ) == NULL )
1957
return _T ( "<html><head></head><body></body></html>" );
1958
wxString buffer, htmlBuffer;
1959
buffer = doc->GetText();
1960
size_t size = buffer.size();
1961
htmlBuffer.reserve ( size * 2 );
1963
htmlBuffer = _T ( "<html><body><p>" );
1964
bool startOfLine = true;
1965
for ( size_t i = 0; i < size; ++i )
1967
wchar_t c = buffer[i];
1971
htmlBuffer += ( startOfLine ) ? _T ( " " ) : _T ( " " );
1974
htmlBuffer += _T ( " " );
1977
htmlBuffer += _T ( "<" );
1978
startOfLine = false;
1981
htmlBuffer += _T ( ">" );
1982
startOfLine = false;
1985
htmlBuffer += _T ( "<br>" );
1989
htmlBuffer + _T ( "&" );
1990
startOfLine = false;
1994
startOfLine = false;
1998
htmlBuffer += _T ( "</p></body></html>" );
2002
void MyFrame::OnFind ( wxCommandEvent& WXUNUSED ( event ) )
2004
#ifdef NEWFINDREPLACE
2005
manager.GetPane ( findReplacePanel ).Caption ( _ ( "Find" ) );
2006
bool visible = manager.GetPane ( findReplacePanel ).IsShown();
2009
manager.GetPane ( findReplacePanel ).Show();
2012
findReplacePanel->refresh();
2013
findReplacePanel->setReplaceVisible ( false );
2014
findReplacePanel->focusOnFind();
2018
if ( findDialog.get() )
2020
findDialog = std::auto_ptr<wxFindReplaceDialog> ( 0 );
2022
findDialog = ( std::auto_ptr<wxFindReplaceDialog> ( new wxFindReplaceDialog (
2029
void MyFrame::OnImportMSWord ( wxCommandEvent& event )
2032
messagePane ( _ ( "This functionality requires Microsoft Windows" ) );
2036
std::auto_ptr<wxFileDialog> fd ( new wxFileDialog (
2038
_ ( "Import Microsoft Word Document" ),
2041
_T ( "Microsoft Word (*.doc)|*.doc" ),
2042
wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR
2044
if ( fd->ShowModal() == wxID_CANCEL )
2047
wxString path = fd->GetPath();
2049
if ( path == _T ( "" ) )
2052
importMSWord ( path );
2055
void MyFrame::OnExport ( wxCommandEvent& event )
2057
statusProgress ( wxEmptyString );
2061
if ( ( doc = getActiveDocument() ) == NULL )
2064
wxString testDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "daisy" );
2065
bool downloadLink = !wxDirExists ( testDir );
2067
std::auto_ptr<ExportDialog> ed ( new ExportDialog (
2072
true, //suppressOptional
2080
int ret = ed->ShowModal();
2082
if ( ret != wxID_OK )
2085
exportStylesheet = ed->getUrlString();
2086
exportFolder = ed->getFolderString();
2087
exportQuiet = ed->getQuiet();
2088
exportMp3Album = ed->getMp3Album();
2090
std::string rawBufferUtf8;
2091
getRawText ( doc, rawBufferUtf8 );
2092
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) )
2098
WrapTempFileName tempFileName ( doc->getFullFileName() );
2100
ofstream rawBufferStream ( tempFileName.name().c_str() );
2101
if ( !rawBufferStream )
2103
rawBufferStream << rawBufferUtf8;
2104
rawBufferStream.close();
2106
wxString tempFile= tempFileName.wideName();
2108
WrapDaisy wd ( this, daisyDir, doc->getFullFileName() );
2109
if ( !wd.run ( tempFile, exportStylesheet, exportFolder, exportQuiet, exportMp3Album, true, true, true, true ) )
2111
messagePane ( _ ("[b]DAISY export stopped[/b]: ") + wd.getLastError(), CONST_STOP );
2114
messagePane ( _ ( "DAISY export completed. Output files are stored in: [b]" ) + exportFolder + _T ( "[/b]." ), CONST_INFO );
2117
void MyFrame::importMSWord ( const wxString& path )
2120
messagePane ( _ ( "This functionality requires Microsoft Windows" ) );
2124
WrapTempFileName tempFileName ( _T ( "" ) ), swapFileName ( _T ( "" ) );
2125
wxString completeSwapFileName = swapFileName.wideName() + _T ( ".doc" );
2126
if ( !wxCopyFile ( path, completeSwapFileName, true ) )
2129
message.Printf ( _ ( "Cannot open [b]%s[/b] for import" ), path.c_str() );
2130
messagePane ( message, CONST_STOP );
2134
wxString cmd = binDir +
2135
_T ( "doc2xml.exe \"" ) +
2136
completeSwapFileName + _T ( "\" \"" ) +
2137
tempFileName.wideName() + _T ( "\"" );
2139
statusProgress ( _ ( "Import in progress..." ) );
2140
int result = wxExecute ( cmd, wxEXEC_SYNC );
2142
wxRemoveFile ( completeSwapFileName ); // necessary because .doc extension added
2144
statusProgress ( wxEmptyString );
2146
wxString versionMessage (
2147
_ ( "(lossless conversion requires version 2003 or later)" ) );
2154
messagePane ( _ ( "Cannot start Microsoft Word" ), CONST_STOP );
2158
_ ( "A more recent version of Microsoft Word is required" ), CONST_STOP );
2161
message.Printf ( _T ( "Microsoft Word cannot open [b]%s[/b]" ), path.c_str() );
2162
messagePane ( message + path, CONST_STOP );
2165
message.Printf ( _ ( "Microsoft Word cannot save [b]%s[/b] as XML" ), path.c_str() );
2166
messagePane ( message, CONST_STOP );
2170
_ ( "Microsoft Word cannot save this document as WordprocessingML " ) +
2178
statusProgress ( _ ( "Opening imported file..." ) );
2181
wxString displayBuffer;
2183
if ( result != 5 ) // Word 2003 or later
2185
std::auto_ptr<WrapLibxml> prettyPrinter ( new WrapLibxml ( libxmlNetAccess ) );
2186
prettyPrinter->parse ( tempFileName.name(), true );
2187
buffer = prettyPrinter->getOutput();
2188
displayBuffer = wxString ( buffer.c_str(), wxConvUTF8, buffer.size() );
2190
else // earlier versions
2192
if ( !ReadFile::run ( tempFileName.name(), buffer ) )
2194
statusProgress ( wxEmptyString );
2195
messagePane ( _ ( "Cannot open imported file" ), CONST_STOP );
2198
displayBuffer = wxString ( buffer.c_str(), wxConvUTF8, buffer.size() );
2199
displayBuffer.Remove ( 0, 1 ); // remove byte order mark
2200
xmliseWideTextNode ( displayBuffer );
2202
displayBuffer.Prepend (
2203
_T ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>" ) );
2204
displayBuffer.Append ( _T ( "</root>\n" ) );
2207
newDocument ( displayBuffer, tempFileName.wideName() );
2208
statusProgress ( wxEmptyString );
2211
void MyFrame::OnExportMSWord ( wxCommandEvent& event )
2214
messagePane ( _ ( "This functionality requires Microsoft Windows" ) );
2217
statusProgress ( wxEmptyString );
2219
// fetch document contents
2221
if ( ( doc = getActiveDocument() ) == NULL )
2224
WrapTempFileName wtfn ( _T ( "" ) );
2225
wxString sourceFileName = doc->getFullFileName();
2227
if ( sourceFileName.empty() )
2229
sourceFileName = wtfn.wideName();
2230
std::fstream ofs ( wtfn.name().c_str() );
2234
std::string utf8Buffer;
2235
getRawText ( doc, utf8Buffer );
2239
else if ( doc->GetModify() ) //CanUndo())
2245
std::auto_ptr<wxFileDialog> fd ( new wxFileDialog (
2247
_ ( "Export Microsoft Word Document" ),
2250
_T ( "Microsoft Word (*.doc)|*.doc" ),
2251
wxSAVE | wxOVERWRITE_PROMPT ) );
2254
wxString path = fd->GetPath();
2256
if ( path == _T ( "" ) )
2259
wxString cmd = binDir +
2260
_T ( "xml2doc.exe -v \"" ) +
2261
sourceFileName + _T ( "\" \"" ) +
2264
statusProgress ( _ ( "Export in progress..." ) );
2265
int result = wxExecute ( cmd, wxEXEC_SYNC );
2266
statusProgress ( wxEmptyString );
2271
messagePane ( _ ( "Cannot start Microsoft Word" ), CONST_STOP );
2275
_ ( "A more recent version of Microsoft Word is required" ), CONST_STOP );
2278
message.Printf ( _ ( "Microsoft Word cannot save %s" ), path.c_str() );
2279
messagePane ( message, CONST_STOP );
2288
void MyFrame::OnBrowser ( wxCommandEvent& WXUNUSED ( event ) )
2290
statusProgress ( wxEmptyString );
2292
// fetch document contents
2294
if ( ( doc = getActiveDocument() ) == NULL )
2297
wxString sourceFileName = doc->getFullFileName();
2298
WrapTempFileName wtfn ( sourceFileName, _T ( ".html" ) );
2300
if ( sourceFileName.empty() || doc->GetModify() )
2302
sourceFileName = wtfn.wideName();
2304
std::ofstream ofs ( ( const char * ) wtfn.name().c_str() );
2307
messagePane ( _ ( "Cannot save temporary file" ), CONST_STOP );
2311
std::string utf8Buffer;
2312
getRawText ( doc, utf8Buffer );
2316
// keep files until application closes
2317
tempFileVector.push_back ( sourceFileName );
2318
tempFileVector.push_back ( wtfn.originalWideName() );
2319
wtfn.setKeepFiles ( true );
2322
navigate ( sourceFileName );
2325
void MyFrame::OnHelp ( wxCommandEvent& event )
2328
wxString cmd = _T ( "hh.exe \"" ) + helpDir + _T ( "xmlcopyeditor.chm\"" );
2331
wxString helpFileName = helpDir + _T ( "xmlcopyeditor.hhp" );
2332
helpController->AddBook ( wxFileName ( helpFileName ) );
2333
helpController->DisplayContents();
2337
void MyFrame::OnSplitTab ( wxCommandEvent& event )
2340
int id = event.GetId();
2341
XmlDoc *doc = getActiveDocument();
2344
wxString fileName = doc->getFullFileName();
2346
// mainBook->GetSelection() is currently unreliable, so fetch by title
2348
int pageCount = mainBook->GetPageCount();
2350
int currentSelection = -1;
2351
for ( int i = 0; i < pageCount; ++i )
2353
currentDoc = ( XmlDoc * ) mainBook->GetPage ( i );
2356
if ( currentDoc->getFullFileName() == fileName )
2358
currentSelection = i;
2361
if ( currentSelection == -1 )
2364
int currentSelection, direction;
2365
currentSelection = mainBook->GetSelection();
2366
direction = wxAUI_NB_RIGHT;
2371
direction = wxAUI_NB_TOP;
2374
direction = wxAUI_NB_RIGHT;
2376
ID_SPLIT_TAB_BOTTOM:
2377
direction = wxAUI_NB_BOTTOM;
2380
direction = wxAUI_NB_LEFT;
2383
direction = wxAUI_NB_RIGHT;
2387
mainBook->Split ( currentSelection, direction );
2390
void MyFrame::OnColorScheme ( wxCommandEvent& event )
2392
int id = event.GetId();
2395
case ID_COLOR_SCHEME_DEFAULT:
2396
properties.colorScheme = COLOR_SCHEME_DEFAULT;
2398
case ID_COLOR_SCHEME_DEFAULT_BACKGROUND:
2399
properties.colorScheme = COLOR_SCHEME_DEFAULT_BACKGROUND;
2401
case ID_COLOR_SCHEME_REDUCED_GLARE:
2402
properties.colorScheme = COLOR_SCHEME_REDUCED_GLARE;
2404
case ID_COLOR_SCHEME_NONE:
2405
properties.colorScheme = COLOR_SCHEME_NONE;
2410
colorSchemeMenu->Check ( id, true );
2413
if ( ( doc = getActiveDocument() ) == NULL )
2416
properties.zoom = doc->GetZoom(); // ensure temp changes to font size are kept
2418
applyEditorProperties ( false );
2422
void MyFrame::OnFontSmaller ( wxCommandEvent& event )
2425
if ( ( doc = getActiveDocument() ) == NULL )
2428
properties.zoom = doc->GetZoom();
2429
applyEditorProperties ( true );
2433
void MyFrame::OnFontMedium ( wxCommandEvent& event )
2436
if ( ( doc = getActiveDocument() ) == NULL )
2439
properties.zoom = doc->GetZoom();
2440
applyEditorProperties ( true );
2444
void MyFrame::OnFontLarger ( wxCommandEvent& event )
2447
if ( ( doc = getActiveDocument() ) == NULL )
2450
properties.zoom = doc->GetZoom();
2451
applyEditorProperties ( true );
2455
void MyFrame::OnOptions ( wxCommandEvent& WXUNUSED ( event ) )
2457
// ensure font size does not change after
2458
XmlDoc *doc = getActiveDocument();
2461
properties.zoom = doc->GetZoom();
2466
( _ ( "Options" ) );
2468
( _ ( "Preferences" ) );
2470
std::auto_ptr<MyPropertySheet> mpsd ( new MyPropertySheet (
2477
singleInstanceCheck,
2481
expandInternalEntities,
2482
showFullPathOnFrame,
2486
if ( mpsd->ShowModal() == wxID_OK )
2488
properties = mpsd->getProperties();
2489
applyEditorProperties();
2490
applicationDir = mpsd->getApplicationDir();
2491
browserCommand = mpsd->getBrowserCommand();
2492
rememberOpenTabs = mpsd->getRememberOpenTabs();
2493
libxmlNetAccess = mpsd->getLibxmlNetAccess();
2494
singleInstanceCheck = mpsd->getSingleInstanceCheck();
2495
saveBom = mpsd->getSaveBom();
2496
unlimitedUndo = mpsd->getUnlimitedUndo();
2497
restoreLayout = mpsd->getRestoreLayout();
2498
expandInternalEntities = mpsd->getExpandInternalEntities();
2499
showFullPathOnFrame = mpsd->getShowFullPathOnFrame();
2500
lang = mpsd->getLang();
2507
void MyFrame::OnHistoryFile ( wxCommandEvent& event )
2509
wxString f ( history.GetHistoryFile ( event.GetId() - wxID_FILE1 ) );
2514
void MyFrame::OnGoto ( wxCommandEvent& WXUNUSED ( event ) )
2516
statusProgress ( wxEmptyString );
2519
if ( ( doc = getActiveDocument() ) == NULL )
2522
wxTextEntryDialog *dlg = new wxTextEntryDialog (
2524
_ ( "Enter line number:" ),
2526
int ret = dlg->ShowModal();
2527
if ( ret == wxID_CANCEL )
2529
wxString val = dlg->GetValue();
2531
if ( !val.ToLong ( &line ) || line < 1 )
2534
msg.Printf ( _ ( "'%s' is not a valid line number" ), val.c_str() );
2535
messagePane ( msg, CONST_STOP );
2539
doc->GotoLine ( ( int ) line );
2543
void MyFrame::OnFindAgain ( wxCommandEvent& event )
2545
//findAgain(findData.GetFindString(), findData.GetFlags());
2546
findReplacePanel->OnFindNext ( event );
2549
void MyFrame::OnCommand ( wxCommandEvent& WXUNUSED ( event ) )
2551
bool visible = manager.GetPane ( commandPanel ).IsShown();
2554
manager.GetPane ( commandPanel ).Show();
2557
commandPanel->focusOnCommand();
2560
void MyFrame::OnFindReplace ( wxCommandEvent& WXUNUSED ( event ) )
2562
#ifdef NEWFINDREPLACE
2563
manager.GetPane ( findReplacePanel ).Caption ( _ ( "Replace" ) );
2564
bool visible = manager.GetPane ( findReplacePanel ).IsShown();
2567
manager.GetPane ( findReplacePanel ).Show();
2570
findReplacePanel->refresh();
2571
findReplacePanel->setReplaceVisible ( true );
2572
findReplacePanel->focusOnFind();
2577
if ( findDialog.get() )
2579
findDialog = std::auto_ptr<wxFindReplaceDialog> ( 0 );
2581
findDialog = std::auto_ptr<wxFindReplaceDialog> ( new wxFindReplaceDialog (
2584
_ ( "Find and Replace" ),
2585
wxFR_REPLACEDIALOG ) );
2589
void MyFrame::OnGlobalReplace ( wxCommandEvent& event )
2592
if ( ( doc = getActiveDocument() ) == NULL )
2595
size_t flags = findData.GetFlags();
2596
std::auto_ptr<GlobalReplaceDialog> grd ( new GlobalReplaceDialog (
2598
findData.GetFindString(),
2599
findData.GetReplaceString(),
2600
flags & wxFR_MATCHCASE,
2601
globalReplaceAllDocuments,
2603
int res = grd->ShowModal();
2607
if ( grd->getMatchCase() )
2608
flags |= wxFR_MATCHCASE;
2609
findRegex = grd->getRegex();
2610
globalReplaceAllDocuments = grd->getAllDocuments();
2612
findData.SetFindString ( grd->getFindString() );
2613
findData.SetReplaceString ( grd->getReplaceString() );
2614
findData.SetFlags ( flags );
2615
findReplacePanel->setRegex ( findRegex );
2616
findReplacePanel->setMatchCase ( flags & wxFR_MATCHCASE );
2617
findReplacePanel->refresh();
2619
if ( res != wxID_OK )
2624
int globalMatchCount, pageCount;
2625
globalMatchCount = 0;
2626
pageCount = mainBook->GetPageCount();
2627
XmlDoc *currentDoc = getActiveDocument();
2631
for ( int i = 0; i < pageCount; ++i )
2633
std::string bufferUtf8;
2634
if ( !globalReplaceAllDocuments )
2636
getRawText ( currentDoc, bufferUtf8 );
2640
currentDoc = ( XmlDoc * ) mainBook->GetPage ( i );
2643
getRawText ( currentDoc, bufferUtf8 );
2646
size_t flags = findData.GetFlags();
2649
std::string findUtf8, replaceUtf8;
2650
findUtf8 =findData.GetFindString().mb_str ( wxConvUTF8 );
2651
replaceUtf8 = findData.GetReplaceString().mb_str ( wxConvUTF8 );
2652
globalMatchCount += Replace::run (
2656
flags & wxFR_MATCHCASE );
2657
currentDoc->SetTextRaw ( bufferUtf8.c_str() );
2658
currentDoc->setValidationRequired ( true );
2664
std::auto_ptr<WrapRegex> wr ( new WrapRegex (
2665
( const char * ) findData.GetFindString().mb_str ( wxConvUTF8 ),
2666
flags & wxFR_MATCHCASE,
2667
( const char * ) findData.GetReplaceString().mb_str ( wxConvUTF8 ) ) );
2670
std::string outputBuffer = wr->replaceGlobal ( bufferUtf8, &matchCount );
2671
globalMatchCount += matchCount;
2672
currentDoc->SetTextRaw ( outputBuffer.c_str() );
2673
currentDoc->setValidationRequired ( true );
2675
catch ( std::exception& e )
2677
wxString wideError = wxString ( e.what(), wxConvUTF8, strlen ( e.what() ) );
2678
messagePane ( _ ( "Cannot replace: " ) + wideError, CONST_STOP );
2682
if ( !globalReplaceAllDocuments )
2688
ngettext ( L"%i replacement made", L"%i replacements made", globalMatchCount ),
2691
statusProgress ( msg );
2694
void MyFrame::OnFrameClose ( wxCloseEvent& event )
2698
if ( mainBook->GetPageCount() )
2706
void MyFrame::OnNew ( wxCommandEvent& WXUNUSED ( event ) )
2708
wxString defaultSelection, typeSelection, templateFile;
2709
defaultSelection = _ ( "XML document (*.xml)" );
2710
wxArrayString templateArray;
2711
if ( wxFileName::DirExists ( templateDir ) )
2713
wxString templateMask, name, extension, entry;
2714
templateMask = templateDir + wxFileName::GetPathSeparator() + _T ( "*.*" );
2715
templateFile = wxFindFirstFile ( templateMask, wxFILE );
2718
if ( !templateFile.empty() )
2720
fn.Assign ( templateFile );
2721
name = fn.GetName();
2722
extension = fn.GetExt();
2724
entry.Printf ( _T ( "%s (*.%s)" ), name.c_str(), extension.c_str() );
2725
templateArray.Add ( entry );
2729
templateFile = wxFindNextFile();
2730
if ( templateFile.empty() )
2732
fn.Assign ( templateFile );
2733
name = fn.GetName();
2734
extension = fn.GetExt();
2736
entry.Printf ( _T ( "%s (*.%s)" ), name.c_str(), extension.c_str() );
2737
templateArray.Add ( entry );
2740
templateArray.Sort();
2741
templateArray.Insert ( defaultSelection, 0 );
2743
const int arraySize = templateArray.GetCount();
2745
wxString choiceArray[arraySize + 1];
2746
for ( int i = 0; i < arraySize; ++i )
2747
* ( choiceArray + i ) = templateArray.Item ( i );
2749
wxSingleChoiceDialog scd (
2750
this, _ ( "Choose a document type:" ), _ ( "New Document" ), arraySize, choiceArray );
2751
if ( scd.ShowModal() == wxID_CANCEL )
2753
XmlDoc *doc = getActiveDocument();
2758
typeSelection = scd.GetStringSelection();
2761
if ( typeSelection == defaultSelection )
2763
wxString emptyString ( _T ( "" ) );
2764
newDocument ( emptyString );
2768
typeSelection.Replace ( _T ( " (*" ), wxEmptyString );
2769
typeSelection.Replace ( _T ( ")" ), wxEmptyString );
2770
templateFile = templateDir + typeSelection;
2771
std::string templateFileLocal, buffer;
2772
templateFileLocal = templateFile.mb_str ( wxConvLocal );
2773
ReadFile::run ( templateFileLocal, buffer );
2774
wxString documentContents = wxString ( buffer.c_str(), wxConvUTF8, buffer.size() );
2776
newDocument ( documentContents,
2777
wxString ( templateFileLocal.c_str(), wxConvUTF8, templateFileLocal.size() ) );
2780
void MyFrame::newDocument ( const wxString& s, const wxString& path, bool canSave )
2782
std::string bufferUtf8 = ( const char * ) s.mb_str ( wxConvUTF8 );
2783
std::string pathUtf8 = ( const char * ) path.mb_str ( wxConvUTF8 );
2784
newDocument ( bufferUtf8, pathUtf8, canSave );
2787
void MyFrame::newDocument ( const std::string& s, const std::string& path, bool canSave )
2791
wxString documentLabel;
2792
documentLabel.Printf ( _ ( "Document%i" ), documentCount++ );
2794
std::string auxPath = getAuxPath ( path );
2797
doc = ( s.empty() ) ?
2805
NULL, 0 // new: NULL pointer leads to default document
2814
s.c_str(), // modified
2820
mainBook->AddPage ( ( wxWindow * ) doc, documentLabel, true );
2823
mainBook->Refresh();
2824
if ( properties.completion )
2825
doc->updatePromptMaps();
2826
doc->setShortFileName ( documentLabel );
2829
locationPanel->update ( doc, wxEmptyString );
2830
insertChildPanel->update ( doc, wxEmptyString );
2831
insertSiblingPanel->update ( doc, wxEmptyString );
2832
insertEntityPanel->update ( doc );
2833
if ( properties.validateAsYouType )
2834
doc->backgroundValidate();
2837
void MyFrame::OnOpen ( wxCommandEvent& event )
2840
largeFile = ( event.GetId() == ID_OPEN_LARGE_FILE );
2842
wxString defaultFile, defaultDir;
2844
if ( ( doc = getActiveDocument() ) != NULL )
2846
defaultFile = doc->getFullFileName();
2847
if ( !defaultFile.empty() )
2849
wxFileName fn ( defaultFile );
2850
defaultDir = fn.GetPath();
2854
wxFileDialog *fd = new wxFileDialog (
2856
( largeFile ) ? _ ( "Open Large Document" ) : _ ( "Open" ),
2860
wxOPEN | wxMULTIPLE | wxFILE_MUST_EXIST | wxCHANGE_DIR
2864
if ( fd->ShowModal() == wxID_CANCEL )
2867
wxArrayString paths;
2868
fd->GetPaths ( paths );
2869
size_t count = paths.Count();
2872
for ( size_t i = 0; i < count; ++i )
2873
if ( !openFile ( paths[i], largeFile ) )
2877
bool MyFrame::openFile ( wxString& fileName, bool largeFile )
2880
// truncate string up to file:/ portion added by GNOME
2881
wxString filePrefix = _T ( "file:" );
2882
int index = fileName.Find ( filePrefix.c_str() );
2885
fileName = fileName.Mid ( ( size_t ) index + filePrefix.Length() );
2889
if ( !wxFileName::FileExists ( fileName ) )
2892
message.Printf ( _ ( "Cannot open %s." ), fileName.c_str() );
2893
messagePane ( message, CONST_STOP );
2897
if ( openFileSet.count ( fileName ) )
2900
message.Printf ( _ ( "%s is already open" ), fileName.c_str() );
2901
statusProgress ( message );
2902
activateTab ( fileName );
2906
wxString directory, name, extension;
2907
wxFileName::SplitPath ( fileName, NULL, &directory, &name, &extension );
2909
if ( !extension.empty() )
2917
pair<int, int> posPair;
2920
int type = getFileType ( fileName );
2921
std::string auxPath = getAuxPath ( ( const char * ) fileName.mb_str ( wxConvLocal ) );
2923
char *docBuffer = 0;
2924
size_t docBufferLen = 0;
2925
bool fileEmpty = false;
2927
statusProgress ( _T ( "Opening file..." ) );
2928
//wxMemoryMappedFile *memorymap = NULL;
2929
BinaryFile *binaryfile = NULL;
2931
binaryfile = new BinaryFile ( ( const char * ) fileName.mb_str ( wxConvLocal ) );
2932
if ( !binaryfile->getData() )
2935
message.Printf ( _ ( "Cannot open %s" ), fileName.c_str() );
2936
messagePane ( message, CONST_STOP );
2937
statusProgress ( wxEmptyString );
2941
memorymap = new wxMemoryMappedFile(
2949
catch (wxMemoryMappedFileEmptyException&)
2955
bool isUtf8 = false;
2959
docBuffer = ( char * ) binaryfile->getData();//memorymap->GetStream();
2960
docBufferLen = binaryfile->getDataLen();//memorymap->GetMapSize();
2969
statusProgress ( wxEmptyString );
2971
char *iconvBuffer = 0;
2972
size_t iconvBufferLen = 0;
2975
size_t finalBufferLen;
2977
// adjust for UTF-8 BOM
2979
( unsigned char ) docBuffer[0] == 0xEF &&
2980
( unsigned char ) docBuffer[1] == 0xBB &&
2981
( unsigned char ) docBuffer[2] == 0xBF )
2988
// no UTF-8 BOM found
2989
std::string encoding;
2990
if ( !isUtf8 || !binaryfile->getDataLen() )
2993
es.parse ( docBuffer, docBufferLen );
2994
encoding = es.getEncoding();
2995
if ( encoding == "UTF-8" ||
2996
encoding == "utf-8" ||
2997
encoding == "US-ASCII" ||
2998
encoding == "us-ascii" ) // US-ASCII is a subset of UTF-8
3002
// convert buffer if not UTF-8
3005
finalBuffer = docBuffer;
3006
finalBufferLen = docBufferLen;
3010
// clear any other BOMs
3012
if ( docBuffer && // UTF-32 BE
3013
( unsigned char ) docBuffer[0] == 0x00 &&
3014
( unsigned char ) docBuffer[1] == 0x00 &&
3015
( unsigned char ) docBuffer[2] == 0xFE &&
3016
( unsigned char ) docBuffer[3] == 0xFF )
3021
if ( docBuffer && // UTF-32 LE
3022
( unsigned char ) docBuffer[0] == 0xFF &&
3023
( unsigned char ) docBuffer[1] == 0xFE &&
3024
( unsigned char ) docBuffer[2] == 0x00 &&
3025
( unsigned char ) docBuffer[3] == 0x00 )
3031
if ( docBuffer && //UTF-16 BE
3032
( unsigned char ) docBuffer[0] == 0xFE &&
3033
( unsigned char ) docBuffer[1] == 0xFF )
3038
if ( docBuffer && //UTF-16 LE
3039
( unsigned char ) docBuffer[0] == 0xFF &&
3040
( unsigned char ) docBuffer[1] == 0xFE )
3046
if ( !encoding.size() ) // Expat couldn't parse file (e.g. UTF-32)
3048
encoding = getApproximateEncoding ( docBuffer, docBufferLen );
3051
wxString wideEncoding = wxString (
3055
iconv_t cd = iconv_open ( "UTF-8", encoding.c_str() );
3056
if ( cd == ( iconv_t )-1 )
3059
message.Printf ( _ ( "Cannot open %s: unknown encoding %s" ),
3061
wideEncoding.c_str() );
3062
messagePane ( message, CONST_STOP );
3063
delete binaryfile;//memorymap;
3067
int iconvLenMultiplier = 4; // worst case scenario
3068
if ( encoding == "ISO-8859-1" ||
3069
encoding == "UTF-16" ||
3070
encoding == "UTF-16BE" ||
3071
encoding == "UTF-16LE" )
3073
iconvLenMultiplier = 2;
3075
else if ( encoding == "UTF-32" ||
3076
encoding == "UTF-32BE" ||
3077
encoding == "UTF-32LE" )
3079
iconvLenMultiplier = 1;
3082
size_t iconvBufferLeft, docBufferLeft;
3083
iconvBufferLen = iconvBufferLeft = docBufferLen * iconvLenMultiplier + 1;
3084
docBufferLeft = docBufferLen;
3085
iconvBuffer = new char[iconvBufferLen];
3086
finalBuffer = iconvBuffer; // iconvBuffer will be incremented by iconv
3099
*iconvBuffer = '\0';
3103
if ( nconv == ( size_t )-1 )
3106
message.Printf ( _ ( "Cannot open %s: conversion from encoding %s failed" ),
3108
wideEncoding.c_str() );
3109
messagePane ( message, CONST_STOP );
3110
delete[] finalBuffer;
3111
delete binaryfile; //delete memorymap;
3114
finalBufferLen = iconvBufferLen - iconvBufferLeft;
3117
statusProgress ( _ ( "Creating document view..." ) );
3121
( largeFile ) ? largeFileProperties: properties,
3124
( !binaryfile->getDataLen() ) ? FILE_TYPE_XML : type,
3130
( const char * ) fileName.mb_str ( wxConvLocal ),
3133
doc->SetUndoCollection ( false );
3134
doc->SetUndoCollection ( true );
3137
doc->setFullFileName ( fileName );
3138
doc->setShortFileName ( name );
3139
doc->setDirectory ( directory );
3140
openFileSet.insert ( fileName );
3141
history.AddFileToHistory ( fileName );
3143
wxFileName ofn ( fileName );
3144
doc->setLastModified ( ofn.GetModificationTime() );
3146
mainBook->AddPage ( ( wxWindow * ) doc, name, _T ( "" ) );
3148
statusProgress ( wxEmptyString );
3150
mainBook->Refresh();
3152
wxFileName fn ( fileName );
3153
doc->setLastModified ( fn.GetModificationTime() );
3156
if ( type != FILE_TYPE_XML || !binaryfile->getDataLen() )
3158
delete binaryfile;//memorymap;
3162
// NOW parse the document, but don't create a UTF-8 copy
3163
statusProgress ( _T ( "Parsing document..." ) );
3164
std::auto_ptr<WrapExpat> we ( new WrapExpat() );
3166
bool optimisedParseSuccess = false;
3168
// omit XML declaration
3169
if ( !isUtf8 && finalBufferLen &&
3170
finalBuffer[0] == '<' &&
3171
finalBuffer[1] == '?' &&
3172
finalBuffer[2] == 'x' &&
3173
finalBuffer[3] == 'm' &&
3174
finalBuffer[4] == 'l' )
3176
for ( ; *finalBuffer && finalBufferLen; finalBuffer++ && finalBufferLen-- )
3178
if ( *finalBuffer == '>' )
3189
optimisedParseSuccess = we->parse ( finalBuffer, finalBufferLen );
3190
statusProgress ( wxEmptyString );
3193
// NOW update prompt maps if necessary
3194
if ( !largeFile && ( properties.completion || properties.validateAsYouType ) )
3196
statusProgress ( _T ( "Compiling autocompletion lists..." ) );
3197
doc->updatePromptMaps ( finalBuffer, finalBufferLen );
3198
statusProgress ( wxEmptyString );
3201
if ( !largeFile && ( properties.validateAsYouType && doc->getGrammarFound() ) )
3203
statusProgress ( _T ( "Validating document..." ) );
3204
//doc->backgroundValidate ( finalBuffer, doc->getFullFileName().mb_str(wxConvUTF8), finalBufferLen );
3205
doc->backgroundValidate();
3206
statusProgress ( wxEmptyString );
3209
if ( !optimisedParseSuccess )
3211
std::string error = we->getLastError();
3212
wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
3213
posPair = we->getErrorPosition();
3214
-- ( posPair.first );
3215
messagePane ( wideError, CONST_WARNING );
3217
int newPosition = doc->PositionFromLine ( posPair.first );
3218
doc->SetSelection ( newPosition, newPosition );
3225
delete binaryfile; //delete memorymap;
3229
std::string MyFrame::getApproximateEncoding ( char *docBuffer,
3230
size_t docBufferLen )
3232
std::string line, encoding;
3238
i = 0, it = docBuffer;
3239
i < docBufferLen && *it != '\n' && i < BUFSIZ;
3246
std::pair<int, int> limits = XmlEncodingHandler::getEncodingValueLimits ( line );
3248
if ( limits.first == -1 || limits.second == -1 )
3251
return line.substr ( limits.first, limits.second );
3254
void MyFrame::OnToggleFold ( wxCommandEvent& WXUNUSED ( event ) )
3257
if ( ( doc = getActiveDocument() ) == NULL )
3262
void MyFrame::OnFoldAll ( wxCommandEvent& WXUNUSED ( event ) )
3265
if ( ( doc = getActiveDocument() ) == NULL )
3271
void MyFrame::OnUnfoldAll ( wxCommandEvent& WXUNUSED ( event ) )
3274
if ( ( doc = getActiveDocument() ) == NULL )
3281
void MyFrame::OnQuit ( wxCommandEvent& WXUNUSED ( event ) )
3286
void MyFrame::OnUndo ( wxCommandEvent& WXUNUSED ( event ) )
3289
if ( ( doc = getActiveDocument() ) == NULL )
3292
doc->setValidationRequired ( true );
3296
void MyFrame::OnRedo ( wxCommandEvent& WXUNUSED ( event ) )
3299
if ( ( doc = getActiveDocument() ) == NULL )
3302
doc->setValidationRequired ( true );
3306
void MyFrame::OnRevert ( wxCommandEvent& WXUNUSED ( event ) )
3309
if ( ( doc = getActiveDocument() ) == NULL )
3312
while ( doc->GetModify() )
3314
if ( !doc->CanUndo() )
3317
doc->setValidationRequired ( true );
3322
void MyFrame::OnSpelling ( wxCommandEvent& event )
3325
if ( ( doc = getActiveDocument() ) == NULL )
3328
statusProgress ( wxEmptyString );
3332
doc->SetUndoCollection ( false );
3333
doc->SetUndoCollection ( true );
3338
type = (id == ID_STYLE) ? ID_TYPE_STYLE : ID_TYPE_SPELL;
3341
std::string rawBufferUtf8;
3342
getRawText ( doc, rawBufferUtf8 );
3343
bool success = true; // always true for now: well-formedness not req'd
3345
auto_ptr<StyleDialog> sd ( new StyleDialog (
3349
doc->getShortFileName(),
3353
( type == ID_TYPE_SPELL ) ? dictionaryPreset : ruleSetPreset,
3360
( success ) ? false : true,
3364
if ( sd->ShowModal() == wxID_OK )
3366
std::string bufferUtf8 = sd->getEditedString();
3367
if ( bufferUtf8.empty() )
3368
messagePane ( _ ( "Edited document empty" ), CONST_STOP );
3370
doc->SetTextRaw ( bufferUtf8.c_str() );
3373
// update presets if report has been created (even if followed by cancel)
3374
if (type == ID_TYPE_STYLE)
3376
ruleSetPreset = sd->getRuleSetPreset();
3377
filterPreset = sd->getFilterPreset();
3380
dictionaryPreset = sd->getRuleSetPreset();
3383
stylePosition = sd->getPosition();
3384
styleSize = sd->getSize();
3388
void MyFrame::OnPreviousDocument ( wxCommandEvent& WXUNUSED ( event ) )
3390
if ( !getActiveDocument() )
3393
statusProgress ( wxEmptyString );
3396
int currentSelection = mainBook->GetSelection();
3397
if ( currentSelection < 1 )
3399
mainBook->SetSelection ( --currentSelection );
3400
XmlDoc *doc = getActiveDocument();
3405
void MyFrame::OnNextDocument ( wxCommandEvent& WXUNUSED ( event ) )
3407
if ( !getActiveDocument() )
3410
statusProgress ( wxEmptyString );
3413
int currentSelection = mainBook->GetSelection();
3414
int maxSelection = mainBook->GetPageCount();
3415
if ( currentSelection >= ( maxSelection - 1 ) )
3417
mainBook->SetSelection ( ++currentSelection );
3418
XmlDoc *doc = getActiveDocument();
3423
void MyFrame::OnSave ( wxCommandEvent& event )
3428
void MyFrame::save()
3431
if ( ( doc = getActiveDocument() ) == NULL )
3435
if ( ( fileName = doc->getFullFileName() ) == _T ( "" ) )
3437
wxCommandEvent event;
3442
if ( !saveFile ( doc, fileName, true ) )
3443
; // handle messages in saveFile
3446
void MyFrame::OnReload ( wxCommandEvent& event )
3451
void MyFrame::reloadTab()
3454
if ( ( doc = getActiveDocument() ) == NULL )
3456
wxString fileName = doc->getFullFileName();
3458
if ( closeActiveDocument() )
3459
openFile ( fileName );
3462
void MyFrame::OnSaveAs ( wxCommandEvent& event )
3467
void MyFrame::saveAs()
3470
if ( ( doc = getActiveDocument() ) == NULL )
3473
wxString defaultFile, defaultDir;
3474
defaultFile = doc->getFullFileName();
3475
if ( !defaultFile.empty() )
3477
wxFileName fn ( defaultFile );
3478
defaultDir = fn.GetPath();
3480
auto_ptr<wxFileDialog> fd ( new wxFileDialog (
3486
wxSAVE | wxOVERWRITE_PROMPT ) );
3487
if ( fd->ShowModal() == wxID_CANCEL )
3490
wxString path = fd->GetPath();
3493
openFileSet.count ( path ) &&
3494
path != doc->getFullFileName() )
3497
message.Printf ( _ ( "%s is already open" ), path.c_str() );
3498
messagePane ( message, CONST_STOP );
3502
wxString name = fd->GetFilename();
3504
wxFileName::SplitPath ( path, &directory, NULL, NULL );
3505
if ( path == _T ( "" ) )
3508
if ( !saveFile ( doc, path, false ) )
3511
// if already named, remove from set of open files
3512
openFileSet.erase ( doc->getFullFileName() );
3514
doc->setFullFileName ( path );
3515
doc->setShortFileName ( name );
3516
doc->setDirectory ( directory );
3518
history.AddFileToHistory ( path ); // update history
3522
if ( ( selection = mainBook->GetSelection() ) == -1 )
3524
mainBook->SetPageText ( selection, name );
3527
void MyFrame::OnUpdateCloseAll ( wxUpdateUIEvent& event )
3529
event.Enable ( mainBook->GetPageCount() > 1 );
3532
void MyFrame::OnUpdateReload ( wxUpdateUIEvent& event )
3535
if ( ( doc = getActiveDocument() ) == NULL )
3537
event.Enable ( false );
3540
event.Enable ( !doc->getFullFileName().empty() );
3543
void MyFrame::OnUpdateCutCopy ( wxUpdateUIEvent& event )
3546
if ( ( doc = getActiveDocument() ) == NULL )
3548
event.Enable ( false );
3551
event.Enable ( true );
3554
void MyFrame::OnUpdateLocationPaneVisible ( wxUpdateUIEvent& event )
3558
wxAuiPaneInfo info = manager.GetPane ( locationPanel );
3559
event.Check ( info.IsShown() );
3562
void MyFrame::OnUpdateSavedOnly ( wxUpdateUIEvent& event )
3565
if ( ( doc = getActiveDocument() ) == NULL )
3567
event.Enable ( false );
3571
( doc->getFullFileName().empty() ) ? false : true );
3574
void MyFrame::OnUpdateDocRange ( wxUpdateUIEvent& event )
3577
if ( ( doc = getActiveDocument() ) == NULL )
3579
event.Enable ( false );
3582
event.Enable ( true );
3585
void MyFrame::OnUpdateReplaceRange ( wxUpdateUIEvent& event )
3588
if ( ( doc = getActiveDocument() ) == NULL ) // || protectTags)
3590
event.Enable ( false );
3593
event.Enable ( true );
3596
void MyFrame::OnUpdateFindAgain ( wxUpdateUIEvent& event )
3598
if ( !getActiveDocument() || findData.GetFindString().empty() )
3600
event.Enable ( false );
3603
event.Enable ( true );
3606
void MyFrame::OnUpdateUndo ( wxUpdateUIEvent& event )
3609
if ( ( doc = getActiveDocument() ) == NULL )
3611
event.Enable ( false );
3615
event.Enable((doc->CanUndo()) ? true : false);
3617
event.Enable ( ( doc->GetModify() ) ? true : false );
3621
void MyFrame::OnUpdateRedo ( wxUpdateUIEvent& event )
3624
if ( ( doc = getActiveDocument() ) == NULL )
3626
event.Enable ( false );
3629
event.Enable ( doc->CanRedo() );
3632
void MyFrame::OnUpdatePaste ( wxUpdateUIEvent& event )
3635
if ( ( doc = getActiveDocument() ) == NULL )
3637
event.Enable ( false );
3640
event.Enable ( true );
3643
void MyFrame::OnUpdatePreviousDocument ( wxUpdateUIEvent& event )
3645
if ( !getActiveDocument() )
3647
event.Enable ( false );
3650
int currentDocument = mainBook->GetSelection();
3651
event.Enable ( ( currentDocument < 1 ) ? false : true );
3654
void MyFrame::OnUpdateNextDocument ( wxUpdateUIEvent& event )
3656
if ( !getActiveDocument() )
3658
event.Enable ( false );
3661
int currentDocument = mainBook->GetSelection();
3662
int maxDocument = mainBook->GetPageCount();
3663
event.Enable ( ( currentDocument >= ( maxDocument - 1 ) ) ? false : true );
3666
void MyFrame::OnUpdateClosePane ( wxUpdateUIEvent& event )
3668
wxAuiPaneInfo i1, i2, i3;
3669
i1 = manager.GetPane ( htmlReport );
3670
i2 = manager.GetPane ( findReplacePanel );
3671
i3 = manager.GetPane ( commandPanel );
3672
event.Enable ( i1.IsShown() || i2.IsShown() || i3.IsShown() );
3675
void MyFrame::OnValidateDTD ( wxCommandEvent& event )
3677
statusProgress ( wxEmptyString );
3679
// fetch document contents
3681
if ( ( doc = getActiveDocument() ) == NULL )
3684
updatePaths(); // needed to ensure catalog is available
3686
wxString fname = doc->getFullFileName();
3688
WrapTempFileName wtfn ( fname );
3689
if ( fname.empty() || doc->GetModify() )
3691
wxString wideBuffer = doc->GetText();
3693
std::string buffer = ( const char * ) wideBuffer.mb_str ( wxConvUTF8 );
3699
_ ( "Cannot save temporary copy for validation; please save or discard changes" ),
3703
fname = wtfn.wideName();
3706
std::string fnameLocal = ( const char * ) fname.mb_str ( wxConvLocal );
3708
doc->clearErrorIndicators();
3709
statusProgress ( _ ( "DTD Validation in progress..." ) );
3711
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) );
3713
if ( !wl->validate ( fnameLocal ) )
3715
std::string error = wl->getLastError();
3716
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
3717
statusProgress ( wxEmptyString );
3718
messagePane ( wideError, CONST_WARNING );
3720
std::pair<int, int> posPair = wl->getErrorPosition();
3721
-- ( posPair.first );
3723
doc->PositionFromLine ( posPair.first );
3724
doc->SetSelection ( cursorPos, cursorPos );
3726
// shallow validate all
3727
doc->backgroundValidate(); // has to come first as it deletes all indicators
3728
doc->setErrorIndicator ( posPair.first, posPair.second );
3732
statusProgress ( wxEmptyString );
3733
documentOk ( _ ( "valid" ) );
3736
void MyFrame::OnValidateRelaxNG ( wxCommandEvent& event )
3738
statusProgress ( wxEmptyString );
3741
if ( ( doc = getActiveDocument() ) == NULL )
3744
wxString fileName = doc->getFullFileName();
3746
wxString defaultFile, defaultDir;
3747
defaultFile = doc->getFullFileName();
3748
if ( !defaultFile.empty() )
3750
wxFileName fn ( defaultFile );
3751
defaultDir = fn.GetPath();
3753
AssociateDialog ad (
3755
_ ( "Select RELAX NG grammar" ),
3756
_ ( "Choose a file:" ),
3757
_ ( "RELAX NG grammar" ),
3759
lastRelaxNGSchema );
3760
if ( ad.ShowModal() != wxID_OK )
3763
wxString path = lastRelaxNGSchema = ad.getUrl();
3767
statusProgress ( wxEmptyString );
3771
validateRelaxNG ( doc, path, fileName );
3774
void MyFrame::validateRelaxNG (
3776
const wxString& schemaName,
3777
wxString& fileName ) // not const: may change if empty/document modified
3779
statusProgress ( wxEmptyString );
3784
WrapTempFileName wtfn ( fileName );
3785
if ( fileName.empty() || doc->GetModify() )
3787
wxString wideBuffer = doc->GetText();
3789
std::string buffer = ( const char * ) wideBuffer.mb_str ( wxConvUTF8 );
3795
_ ( "Cannot save temporary copy for validation; please save or discard changes" ),
3799
fileName = wtfn.wideName();
3802
doc->clearErrorIndicators();
3803
statusProgress ( _ ( "RELAX NG validation in progress..." ) );
3805
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) );
3807
std::string schemaFileNameLocal = ( const char * ) schemaName.mb_str ( wxConvLocal );
3808
std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal );
3809
if ( !wl->validateRelaxNG ( schemaFileNameLocal, fileNameLocal ) )
3811
std::string error = wl->getLastError();
3812
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
3813
statusProgress ( wxEmptyString );
3815
std::pair<int, int> posPair = wl->getErrorPosition();
3816
-- ( posPair.first );
3819
doc->PositionFromLine ( posPair.first );
3820
doc->SetSelection ( cursorPos, cursorPos );
3821
doc->setErrorIndicator ( posPair.first, posPair.second );
3822
messagePane ( wideError, CONST_WARNING );
3827
statusProgress ( wxEmptyString );
3828
documentOk ( _ ( "valid" ) );
3832
void MyFrame::OnValidatePreset ( wxCommandEvent& event )
3835
if ( ( doc = getActiveDocument() ) == NULL )
3838
wxString fileName = doc->getFullFileName();
3840
int id = event.GetId();
3841
wxString schemaFileName = validationPresetMap[id];
3842
if ( schemaFileName.empty() )
3844
validateRelaxNG ( doc, schemaFileName, fileName );
3847
void MyFrame::OnValidateSchema ( wxCommandEvent& event )
3849
statusProgress ( wxEmptyString );
3852
if ( ( doc = getActiveDocument() ) == NULL )
3855
// branch: if no XML Schema found, use LibXML DTD parser instead
3856
// so the catalog is read - switch when Xerces-C implements
3857
// XMLCatalogResolver
3860
std::string rawBuffer, schemaLocation;
3861
getRawText ( doc, rawBuffer );
3862
auto_ptr<XmlSchemaLocator> xsl ( new XmlSchemaLocator() );
3863
xsl->parse ( rawBuffer.c_str() );
3864
if ( ( xsl->getSchemaLocation() ) . empty() )
3866
OnValidateDTD ( event );
3873
std::string tempFileNameLocal;
3874
fileName = doc->getFullFileName();
3876
WrapTempFileName wtfn ( fileName );
3877
if ( fileName.empty() || doc->GetModify() )
3879
wxString wideBuffer = doc->GetText();
3881
std::string buffer = ( const char * ) wideBuffer.mb_str ( wxConvUTF8 );
3887
_ ( "Cannot save temporary copy for validation; please save or discard changes" ),
3891
fileName = wtfn.wideName();
3894
statusProgress ( _ ( "Validation in progress..." ) );
3895
doc->clearErrorIndicators();
3900
std::auto_ptr<WrapXerces> validator (
3901
new WrapXerces( catalogPath, catalogUtilityPath )
3903
std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal );
3904
if ( !validator->validate ( fileNameLocal ) )
3906
statusProgress ( wxEmptyString );
3907
error = validator->getLastError();
3908
wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
3909
messagePane ( wideError, CONST_WARNING );
3910
std::pair<int, int> posPair = validator->getErrorPosition();
3913
doc->PositionFromLine ( posPair.first - 1 );
3914
doc->SetSelection ( cursorPos, cursorPos );
3915
doc->setErrorIndicator ( posPair.first - 1, 0 );
3918
documentOk ( _ ( "valid" ) );
3921
void MyFrame::OnXPath ( wxCommandEvent& event )
3923
statusProgress ( wxEmptyString );
3927
if ( ( doc = getActiveDocument() ) == NULL )
3930
auto_ptr<wxTextEntryDialog> dlg ( new wxTextEntryDialog (
3932
_ ( "Enter XPath:" ),
3933
_ ( "Evaluate XPath" ),
3934
xpathExpression ) );
3936
int ret = dlg->ShowModal();
3937
if ( ret == wxID_CANCEL )
3939
xpathExpression = dlg->GetValue();
3940
std::string valUtf8 = ( const char * ) xpathExpression.mb_str ( wxConvUTF8 );
3942
// fetch document contents
3943
std::string rawBufferUtf8;
3944
getRawText ( doc, rawBufferUtf8 );
3945
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) )
3951
WrapTempFileName tempFileName ( doc->getFullFileName() );
3953
ofstream rawBufferStream ( tempFileName.name().c_str() );
3954
if ( !rawBufferStream )
3956
rawBufferStream << rawBufferUtf8;
3957
rawBufferStream.close();
3959
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) );
3961
bool success = wl->xpath ( valUtf8, tempFileName.name() );
3965
std::string error = wl->getLastError();
3966
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
3967
if ( !wideError.empty() )
3968
wideError.Prepend ( _T ( ": " ) );
3969
wideError.Prepend ( _ ( "Cannot evaluate XPath" ) );
3971
messagePane ( wideError, CONST_WARNING );
3975
statusProgress ( wxEmptyString );
3976
std::string buffer = wl->getOutput();
3978
if ( buffer.empty() )
3980
messagePane ( _ ( "No matching nodes found" ), CONST_WARNING );
3983
newDocument ( buffer );
3984
statusProgress ( wxEmptyString );
3987
void MyFrame::OnXslt ( wxCommandEvent& event )
3989
statusProgress ( wxEmptyString );
3992
// fetch document contents
3994
if ( ( doc = getActiveDocument() ) == NULL )
3996
std::string rawBufferUtf8;
3997
getRawText ( doc, rawBufferUtf8 );
3998
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) )
4004
WrapTempFileName tempFileName ( doc->getFullFileName() );
4006
ofstream rawBufferStream ( tempFileName.name().c_str() );
4007
if ( !rawBufferStream )
4009
rawBufferStream << rawBufferUtf8;
4010
rawBufferStream.close();
4014
int id = event.GetId();
4015
if ( id == ID_XSLT )
4018
xl.parse ( rawBufferUtf8 );
4019
std::string location = xl.getXslLocation();
4021
path = wxString ( location.c_str(), wxConvUTF8, location.size() );
4022
path.Replace ( _T ( "%20" ), _T ( " " ), true );
4024
path = PathResolver::run ( path, doc->getFullFileName() );
4026
if ( !wxFileName::FileExists ( path ) )
4028
if ( !path.empty() )
4031
message.Printf ( _ ( "Cannot open stylesheet %s" ), path.c_str() );
4032
messagePane ( message, CONST_WARNING );
4035
wxString defaultFile, defaultDir;
4036
defaultFile = doc->getFullFileName();
4037
if ( !defaultFile.empty() )
4039
wxFileName fn ( defaultFile );
4040
defaultDir = fn.GetPath();
4042
AssociateDialog ad (
4044
_ ( "Select stylesheet" ),
4045
_ ( "Choose a file:" ),
4046
_ ( "XSLT stylesheet" ),
4047
_T ( "*.xsl;*.xslt" ),
4048
lastXslStylesheet );
4049
if ( ad.ShowModal() != wxID_OK )
4052
path = lastXslStylesheet = ad.getUrl();
4055
if ( path.empty() ) // Cancel selected
4057
statusProgress ( wxEmptyString );
4065
sep.Append ( wxFileName::GetPathSeparator() );
4068
case ID_XSLT_TEI_FO:
4069
path = applicationDir + sep + _T ( "tei" ) + sep + _T ( "fo" ) + sep +
4072
case ID_XSLT_TEI_HTML:
4073
path = applicationDir + sep + _T ( "tei" ) + sep + _T ( "html" ) + sep +
4076
case ID_XSLT_TEI_XHTML:
4077
path = applicationDir + sep + _T ( "tei" ) + sep + _T ( "xhtml" ) + sep +
4080
case ID_XSLT_TEI_LATEX:
4081
path = applicationDir + sep + _T ( "tei" ) + sep + _T ( "latex" ) + sep +
4084
case ID_XSLT_DOCBOOK_FO:
4085
path = applicationDir + sep + _T ( "docbook" ) + sep + _T ( "fo" ) + sep +
4086
_T ( "docbook.xsl" );
4088
case ID_XSLT_DOCBOOK_HTML:
4089
path = applicationDir + sep + _T ( "docbook" ) + sep + _T ( "html" ) + sep +
4090
_T ( "docbook.xsl" );
4092
case ID_XSLT_DOCBOOK_XHTML:
4093
path = applicationDir + sep + _T ( "docbook" ) + sep + _T ( "xhtml" ) + sep +
4094
_T ( "docbook.xsl" );
4100
statusProgress ( _ ( "XSL transformation in progress..." ) );
4102
std::string stylefnameLocal = ( const char * ) path.mb_str ( wxConvLocal );
4104
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) );
4105
if ( !wl->xslt ( stylefnameLocal, tempFileName.name() ) )
4107
std::string error = wl->getLastError();
4108
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
4109
wideError.Prepend ( _ ( "Cannot transform: " ) );
4110
statusProgress ( wxEmptyString );
4111
messagePane ( wideError, CONST_WARNING );
4114
std::string buffer = wl->getOutput();
4115
if ( buffer.empty() )
4117
messagePane ( _ ( "Output document empty" ), CONST_WARNING );
4120
statusProgress ( wxEmptyString );
4121
newDocument ( buffer );
4124
void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
4126
statusProgress ( wxEmptyString );
4129
// fetch document contents
4131
if ( ( doc = getActiveDocument() ) == NULL )
4134
int line = doc->LineFromPosition ( doc->GetCurrentPos() );
4136
std::string rawBufferUtf8;
4137
getRawText ( doc, rawBufferUtf8 );
4139
std::string encoding = XmlEncodingHandler::get ( rawBufferUtf8 );
4141
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8, true ) )
4147
statusProgress ( _ ( "Pretty-printing in progress..." ) );
4149
for ( int i = 0; i < 2; i++ ) // perform two iterations
4151
WrapTempFileName tempFileName ( doc->getFullFileName() );
4153
ofstream rawBufferStream ( tempFileName.name().c_str() );
4154
if ( !rawBufferStream )
4156
rawBufferStream << rawBufferUtf8;
4157
rawBufferStream.close();
4159
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) );
4160
bool success = wl->parse ( tempFileName.name(), true );
4164
std::string error = wl->getLastError();
4165
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
4166
wideError.Prepend ( _ ( "Cannot pretty-print: " ) );
4167
statusProgress ( wxEmptyString );
4168
messagePane ( wideError, CONST_WARNING );
4171
rawBufferUtf8 = wl->getOutput();
4174
statusProgress ( wxEmptyString );
4175
if ( rawBufferUtf8.empty() )
4177
_ ( "Pretty-print unsuccessful: output document empty" ),
4182
if (encoding != "UTF-8")
4184
std::string output = getEncodedBuffer(rawBufferUtf8, encoding);
4185
if (!output.empty())
4186
rawBufferUtf8 = output;
4189
if ( encoding != "UTF-8" && !encoding.empty() )
4191
XmlEncodingHandler::set ( rawBufferUtf8, encoding );
4193
doc->SetTextRaw ( rawBufferUtf8.c_str() );
4194
statusProgress ( wxEmptyString );
4197
doc->setValidationRequired ( true );
4198
doc->GotoLine ( line );
4202
void MyFrame::OnEncoding ( wxCommandEvent& event )
4204
statusProgress ( wxEmptyString );
4207
// fetch document contents
4209
if ( ( doc = getActiveDocument() ) == NULL )
4212
std::vector<wxString> encodingVector;
4213
encodingVector.push_back ( _T ( "UTF-8" ) );
4214
encodingVector.push_back ( _T ( "UTF-16" ) );
4215
encodingVector.push_back ( _T ( "UTF-16LE" ) );
4216
encodingVector.push_back ( _T ( "UTF-16BE" ) );
4217
encodingVector.push_back ( _T ( "ISO-8859-1" ) );
4218
encodingVector.push_back ( _T ( "US-ASCII" ) );
4219
const int vectorSize = encodingVector.size();
4220
wxString choiceArray[vectorSize + 1];
4221
for ( int i = 0; i < vectorSize; ++i )
4222
* ( choiceArray + i ) = encodingVector.at ( i );
4223
wxSingleChoiceDialog scd (
4224
this, _ ( "Choose an encoding:" ), _ ( "Encoding" ), vectorSize, choiceArray );
4226
if ( scd.ShowModal() == wxID_CANCEL )
4230
std::string selectionUtf8, bufferUtf8;
4232
selection = scd.GetStringSelection();
4233
selectionUtf8 = selection.mb_str ( wxConvUTF8 );
4235
getRawText ( doc, bufferUtf8 );
4236
XmlEncodingHandler::setUtf8 ( bufferUtf8, true );
4238
WrapTempFileName tempFileName ( _T ( "" ) );
4240
std::auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
4243
WrapTempFileName sourceFileName ( doc->getFullFileName() );
4244
saveRawUtf8 ( sourceFileName.name(), bufferUtf8 );
4246
res = wl->saveEncodingFromFile ( sourceFileName.name(), tempFileName.name(), selectionUtf8 );
4249
std::string error = wl->getLastError();
4250
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
4251
wideError.Prepend ( _ ( "Cannot set encoding: " ) );
4252
messagePane ( wideError, CONST_STOP );
4256
std::string newBuffer;
4257
bool success = ReadFile::run ( tempFileName.name(), newBuffer );
4260
messagePane ( _ ( "Cannot set encoding (cannot open temporary file)" ),
4265
std::auto_ptr<XmlUtf8Reader> xur ( new XmlUtf8Reader (
4267
expandInternalEntities,
4268
newBuffer.size() ) );
4269
if ( !xur->parse ( newBuffer ) )
4271
messagePane ( _ ( "Cannot set encoding (cannot parse temporary file)" ),
4276
doc->SetTextRaw ( xur->getBuffer().c_str() );
4277
doc->setValidationRequired ( true );
4281
void MyFrame::OnHome ( wxCommandEvent& event )
4283
navigate ( _T ( "http://xml-copy-editor.sourceforge.net" ) );
4286
void MyFrame::OnDownloadSource ( wxCommandEvent& event )
4288
navigate ( _T ( "http://xml-copy-editor.svn.sourceforge.net/viewvc/xml-copy-editor/" ) );
4291
void MyFrame::OnToolbarVisible ( wxCommandEvent& event )
4295
toolbarVisible = ( toolbarVisible ) ? false : true;
4296
viewMenu->Check ( ID_TOOLBAR_VISIBLE, toolbarVisible );
4297
showTopBars ( toolbarVisible );
4301
void MyFrame::OnWrapWords ( wxCommandEvent& event )
4307
wrapWords = ( properties.wrap ) ? false : true;
4309
viewMenu->Check ( ID_WRAP_WORDS, wrapWords );
4310
properties.wrap = wrapWords;
4312
// update all documents
4313
int pageCount = mainBook->GetPageCount();
4315
for ( int i = 0; i < pageCount; ++i )
4317
currentDoc = ( XmlDoc * ) mainBook->GetPage ( i );
4320
currentDoc->SetWrapMode ( wrapWords );
4324
void MyFrame::OnLocationPaneVisible ( wxCommandEvent& event )
4326
wxAuiPaneInfo info = manager.GetPane ( locationPanel );
4327
bool visible = ( info.IsShown() ) ? false : true;
4328
manager.GetPane ( locationPanel ).Show ( visible );
4332
if ( ( doc = getActiveDocument() ) == NULL )
4337
void MyFrame::OnProtectTags ( wxCommandEvent& event )
4341
protectTags = ( protectTags ) ? false : true;
4343
xmlMenu->Check ( ID_PROTECT_TAGS, protectTags );
4345
toolBar->ToggleTool ( ID_PROTECT_TAGS, protectTags );
4348
if ( ( doc = getActiveDocument() ) == NULL )
4352
doc->adjustCursor(); // apply to all open docs?
4357
void MyFrame::OnVisibilityState ( wxCommandEvent& event )
4365
visibilityState = SHOW_TAGS;
4366
//GetStatusBar()->SetStatusText(wxEmptyString, STATUS_PARENT);
4368
case ID_HIDE_ATTRIBUTES:
4369
visibilityState = HIDE_ATTRIBUTES;
4370
//GetStatusBar()->SetStatusText(wxEmptyString, STATUS_PARENT);
4373
visibilityState = HIDE_TAGS;
4376
visibilityState = SHOW_TAGS;
4380
viewMenu->Check ( id, true );
4382
// iterate over all open documents
4383
int pageCount = mainBook->GetPageCount();
4385
for ( int i = 0; i < pageCount; ++i )
4387
currentDoc = ( XmlDoc * ) mainBook->GetPage ( i );
4390
currentDoc->applyVisibilityState ( visibilityState );
4393
if ( visibilityState == HIDE_ATTRIBUTES || visibilityState == HIDE_TAGS )
4395
if ( properties.protectHiddenElements && !protectTags )
4398
OnProtectTags ( e );
4402
// fetch current document
4404
if ( ( doc = getActiveDocument() ) == NULL )
4407
// set focus for current document
4411
void MyFrame::OnFeedback ( wxCommandEvent& event )
4414
_T ( "https://sourceforge.net/forum/forum.php?forum_id=475215" );
4415
navigate ( forumUrl );
4418
void MyFrame::navigate ( const wxString& url )
4420
wxString testString = browserCommand;
4421
testString.Replace ( _T ( " -remote" ), wxEmptyString, true );
4422
if ( browserCommand.empty() )
4425
_ ( "Cannot open in browser: no browser defined (see Tools, Options..., General)" ),
4429
else if ( !wxFileName::FileExists ( testString ) )
4433
_ ( "Cannot open in browser: %s not found (see Tools, Options..., General)" ),
4434
testString.c_str() );
4435
messagePane ( message, CONST_STOP );
4439
cmd = browserCommand + _T ( " \"" ) + url + _T ( "\"" );
4440
wxExecute ( cmd, wxEXEC_ASYNC ); // make ASYNC an option?
4443
void MyFrame::findAgain ( wxString s, int flags )
4445
findReplacePanel->flagNotFound ( false );
4450
statusProgress ( wxEmptyString );
4452
if ( ( doc = getActiveDocument() ) == NULL )
4455
// update regex parameter to keep global replace in sync
4456
findRegex = findReplacePanel->getRegex();
4460
if ( flags & wxFR_WHOLEWORD )
4461
myFlags |= wxSTC_FIND_WHOLEWORD;
4462
if ( flags & wxFR_MATCHCASE )
4463
myFlags |= wxSTC_FIND_MATCHCASE;
4464
if ( findReplacePanel->getRegex() )
4465
myFlags |= wxSTC_FIND_REGEXP;
4467
bool incrementalFind =
4468
( findReplacePanel->getIncrementalFind() ) ? true : false;
4470
//doc->SetYCaretPolicy(wxSTC_CARET_SLOP | wxSTC_CARET_STRICT, 10);
4472
if ( flags & wxFR_DOWN ) // find next
4474
doc->SetTargetStart ( ( incrementalFind ) ?
4475
doc->GetSelectionStart() : doc->GetSelectionEnd() );
4476
doc->SetTargetEnd ( doc->GetLength() );
4477
doc->SetSearchFlags ( myFlags );
4478
newLocation = doc->SearchInTarget ( s );
4480
// try once more from top
4481
if ( newLocation == -1 )
4483
doc->SetTargetStart ( 0 );
4484
doc->SetTargetEnd ( doc->GetLength() );
4485
newLocation = doc->SearchInTarget ( s );
4488
else // find previous
4490
doc->SetCurrentPos (
4491
( doc->GetSelectionStart() ) ? doc->GetSelectionStart() - 1 : 0 );
4492
doc->SearchAnchor();
4493
newLocation = doc->SearchPrev ( myFlags, s );
4496
//doc->SetYCaretPolicy(wxSTC_CARET_SLOP, 0);
4499
if ( newLocation == -1 )
4501
findReplacePanel->flagNotFound ( true );
4503
err.Printf ( _ ( "Cannot find '%s'" ), s.c_str() );
4504
doc->SetSelectionEnd ( doc->GetSelectionStart() );
4506
statusProgress ( err );
4508
// must clear target to prevent replace affecting whole document
4509
doc->SetTargetStart ( 0 );
4510
doc->SetTargetEnd ( 0 );
4515
doc->SetSelection ( doc->GetTargetStart(), doc->GetTargetEnd() );
4516
doc->EnsureCaretVisible();
4519
bool MyFrame::closeActiveDocument()
4521
statusProgress ( wxEmptyString );
4524
int selection = mainBook->GetSelection();
4525
if ( selection == -1 || !mainBook->GetPageCount() ) // GetPageCount needed for wxAuiNotebook
4528
locationPanel->update ( NULL, wxEmptyString );
4529
insertChildPanel->update ( NULL, wxEmptyString );
4530
insertSiblingPanel->update ( NULL, wxEmptyString );
4532
// workaround -- wxAuiNotebook: send virtual close event? DeletePage doesn't generate one
4533
wxAuiNotebookEvent e;
4534
e.SetSelection ( selection );
4535
OnPageClosing ( e );
4536
if ( deletePageVetoed )
4539
mainBook->DeletePage ( selection ); // check this is still correct
4542
// apparently fixed betw. 2.8.0 and 2.8.6, so from v. 1.1.0.3, BUT this is once more:
4543
// 1.1.0.5: reverted to above workaround - no confirmation dialog?
4544
// watch memory usage for DeletePage call
4545
//mainBook->DeletePage ( selection );
4546
//return ( !deletePageVetoed );
4549
bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified )
4554
statusProgress ( wxEmptyString );
4556
if ( checkLastModified )
4558
wxFileName fn ( fileName );
4561
wxDateTime myLastModified = fn.GetModificationTime();
4562
if ( !myLastModified.IsEqualTo ( doc->getLastModified() ) )
4564
int choice = wxMessageBox (
4565
_ ( "File has been modified by another application.\nDo you want to proceed?" ),
4566
_ ( "Confirmation" ),
4567
wxICON_QUESTION | wxYES_NO | wxCANCEL );
4568
if ( choice != wxYES )
4575
std::string utf8Buffer, encoding, fileNameLocal;
4579
getRawText ( doc, utf8Buffer );
4581
es.parse ( utf8Buffer );
4582
encoding = es.getEncoding();
4584
fileNameLocal = fileName.mb_str ( wxConvLocal );
4589
if ( getFileType ( fileName ) != FILE_TYPE_XML )
4594
// raw file conditions
4595
if ( doc->getType() == FILE_TYPE_BINARY )
4597
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
4599
bytes = utf8Buffer.size();
4603
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4604
messagePane ( message, CONST_STOP );
4609
else if ( !isXml && encoding.empty() )
4611
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
4613
bytes = utf8Buffer.size();
4617
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4618
messagePane ( message, CONST_STOP );
4622
else if ( encoding == "UTF-8" )
4624
auto_ptr<WrapExpat> we ( new WrapExpat() );
4626
if ( !we->parse ( utf8Buffer ) )
4628
std::string error = we->getLastError();
4629
wxString werror = wxString ( error.c_str(), wxConvUTF8, error.size() );
4630
if ( we->isEncodingError() )
4632
messagePane ( werror, CONST_WARNING );
4634
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
4636
bytes = utf8Buffer.size();
4640
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4641
messagePane ( message, CONST_STOP );
4647
wxString wideEncoding = wxString ( encoding.c_str(), wxConvLocal, encoding.size() );
4649
// IF Unicode, use iconv to convert buffer
4650
if ( encoding == "UTF-16" || encoding == "UTF-16LE" ||
4651
encoding == "UTF-16BE" || encoding == "UTF-32" || encoding == "UTF-32LE" ||
4652
encoding == "UTF-32BE" )
4654
iconv_t cd = iconv_open ( encoding.c_str(), "UTF-8" );
4655
if ( cd == ( iconv_t )-1 )
4657
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml );
4660
bytes = utf8Buffer.size();
4663
_ ( "%s saved in default encoding UTF-8: unknown encoding %s" ),
4665
wideEncoding.c_str() );
4666
messagePane ( message, CONST_WARNING );
4671
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4672
messagePane ( message, CONST_STOP );
4678
size_t utf8BufferLen = utf8Buffer.size();
4680
size_t iconvBufferLen, iconvBufferLeft, utf8BufferLeft;
4681
int iconvLenMultiplier = 4; // worst case scenario
4682
if ( encoding == "UTF-16" ||
4683
encoding == "UTF-16BE" ||
4684
encoding == "UTF-16LE" )
4686
iconvLenMultiplier = 2;
4688
else if ( encoding == "UTF-32" ||
4689
encoding == "UTF-32BE" ||
4690
encoding == "UTF-32LE" )
4692
iconvLenMultiplier = 4;
4695
iconvBufferLen = iconvBufferLeft =
4696
utf8BufferLen * iconvLenMultiplier + 4; // worst case scenario
4699
char *iconvBuffer = new char[iconvBufferLen];
4701
utf8BufferLeft = utf8BufferLen;
4702
iconvBuffer = new char[iconvBufferLen];
4703
finalBuffer = iconvBuffer; // iconvBuffer will be incremented by iconv
4727
if ( nconv == ( size_t )-1 ) // conversion failed
4729
delete[] finalBuffer;
4730
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml );
4733
bytes = utf8Buffer.size();
4736
_ ( "%s saved in default encoding UTF-8: conversion to %s failed" ),
4738
wideEncoding.c_str() );
4739
messagePane ( message, CONST_WARNING );
4744
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4745
messagePane ( message, CONST_STOP );
4751
size_t finalBufferLen = iconvBufferLen - iconvBufferLeft;
4753
std::ofstream ofs ( fileNameLocal.c_str(), std::ios::out | std::ios::binary );
4756
delete[] finalBuffer;
4758
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4759
messagePane ( message, CONST_STOP );
4763
// iconv adds boms for UTF-16 & UTF-32 automatically
4765
ofs.write ( finalBuffer, finalBufferLen );
4767
delete[] finalBuffer;
4768
bytes = finalBufferLen;
4772
else // all other encodings handled by Libxml
4774
XmlEncodingHandler::setUtf8 ( utf8Buffer );
4775
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
4777
WrapTempFileName sourceFileName ( fileName );
4778
saveRawUtf8 ( sourceFileName.name(), utf8Buffer );
4779
int result = wl->saveEncodingFromFile ( sourceFileName.name(), fileNameLocal, encoding );
4782
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml );
4785
std::string libxmlError = wl->getLastError();
4786
bytes = utf8Buffer.size();
4787
wxString msg, wideEncoding, wideError;
4789
wxString ( encoding.c_str(), wxConvUTF8, encoding.size() );
4790
wideError = wxString ( libxmlError.c_str(), wxConvUTF8, libxmlError.size() );
4791
if ( wideError.empty() )
4792
wideError = _ ( "unknown error" );
4794
msg.Printf ( _ ( "Cannot save document in %s: %s (saved in default encoding UTF-8)" ),
4795
wideEncoding.c_str(), wideError.c_str() );
4796
messagePane ( msg, CONST_INFO );
4801
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4802
messagePane ( message, CONST_STOP );
4811
catch ( std::bad_alloc& )
4813
if ( encoding != "UTF-8" )
4815
int answer = wxMessageBox (
4816
_ ( "Out of memory: attempt to save in default encoding UTF-8?" ),
4817
_ ( "Out of memory" ),
4818
wxYES_NO | wxCANCEL | wxICON_QUESTION,
4820
if ( answer == wxCANCEL || answer == wxNO )
4823
bool success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
4826
bytes = utf8Buffer.size();
4829
_ ( "%s saved in default encoding UTF-8" ),
4831
messagePane ( message, CONST_INFO );
4836
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
4837
messagePane ( message, CONST_STOP );
4844
doc->SetSavePoint();
4846
if ( properties.validateAsYouType && isXml )
4848
doc->clearErrorIndicators();
4849
//doc->backgroundValidate ( utf8Buffer.c_str(), doc->getFullFileName().mb_str(wxConvUTF8), utf8Buffer.size() );
4850
doc->backgroundValidate();
4853
if ( !unlimitedUndo )
4854
doc->EmptyUndoBuffer();
4855
wxFileName fn ( fileName );
4857
doc->setLastModified ( fn.GetModificationTime() );
4858
openFileSet.insert ( fileName );
4859
displaySavedStatus ( bytes );
4863
bool MyFrame::saveRawUtf8 (
4864
const std::string& fileNameLocal,
4865
std::string& bufferUtf8,
4866
bool ignoreEncoding,
4869
ofstream ofs ( fileNameLocal.c_str(), std::ios::out | std::ios::binary );
4873
if ( !ignoreEncoding && isXml )
4874
XmlEncodingHandler::setUtf8 ( bufferUtf8, true );
4876
if ( saveBom && isXml )
4883
ofs.write ( bom, 3 );
4885
ofs.write ( bufferUtf8.c_str(), bufferUtf8.size() );
4890
void MyFrame::displaySavedStatus ( int bytes )
4894
if ( bytes > 1000000 )
4896
result = bytes / 1000000;
4899
else if ( bytes > 1000 )
4901
result = bytes / 1000;
4904
else if ( bytes >= 0 )
4907
unit = ngettext ( L"byte", L"bytes", bytes );
4915
_ ( "%g %s saved" ),
4918
statusProgress ( msg );
4921
bool MyFrame::getHandleCommandLineFlag()
4923
return handleCommandLineFlag;
4926
wxMenuBar *MyFrame::getMenuBar()
4928
fileMenu = new wxMenu; // use class-wide data member
4929
updateFileMenu ( false );
4932
wxMenu *editMenu = new wxMenu;
4934
wxMenuItem *undoItem =
4935
new wxMenuItem ( NULL, wxID_UNDO, _ ( "&Undo\tCtrl+Z" ), _ ( "Undo" ) );
4936
undoItem->SetBitmap ( undo16Bitmap );
4938
wxMenuItem *redoItem =
4939
new wxMenuItem ( NULL, wxID_REDO, _ ( "&Redo\tCtrl+Y" ), _ ( "Redo" ) );
4940
redoItem->SetBitmap ( redo16Bitmap );
4942
wxMenuItem *cutItem =
4943
new wxMenuItem ( NULL, wxID_CUT, _ ( "&Cut\tCtrl+X" ), _ ( "Cut" ) );
4944
cutItem->SetBitmap ( cutBitmap );
4946
wxMenuItem *copyItem =
4947
new wxMenuItem ( NULL, wxID_COPY, _ ( "C&opy\tCtrl+C" ), _ ( "Copy" ) );
4948
copyItem->SetBitmap ( copyBitmap );
4950
wxMenuItem *pasteItem =
4951
new wxMenuItem ( NULL, wxID_PASTE, _ ( "&Paste\tCtrl+V" ), _ ( "Paste" ) );
4952
pasteItem->SetBitmap ( pasteBitmap );
4954
wxMenuItem *pasteNewDocumentItem =
4957
ID_PASTE_NEW_DOCUMENT,
4958
_ ( "P&aste As New Document" ),
4959
_ ( "Paste As New Document" ) );
4960
pasteNewDocumentItem->SetBitmap ( wxNullBitmap );
4962
wxMenuItem *findItem =
4963
new wxMenuItem ( NULL, ID_FIND, _ ( "&Find...\tCtrl+F" ), _ ( "Find..." ) );
4964
findItem->SetBitmap ( searchBitmap );
4966
wxMenuItem *findAgainItem =
4967
new wxMenuItem ( NULL, ID_FIND_AGAIN, _ ( "F&ind Again\tF3" ), _ ( "Find Again" ) );
4968
findAgainItem->SetBitmap ( wxNullBitmap );
4970
wxMenuItem *replaceItem =
4971
new wxMenuItem ( NULL, ID_REPLACE, _ ( "&Replace...\tCtrl+R" ), _ ( "Replace..." ) );
4972
replaceItem->SetBitmap ( wxNullBitmap );
4974
wxMenuItem *globalReplaceItem =
4978
_ ( "&Global Replace...\tCtrl+Shift+R" ),
4979
_ ( "Global Replace..." ) );
4980
globalReplaceItem->SetBitmap ( wxNullBitmap );
4982
wxMenuItem *gotoItem =
4983
new wxMenuItem ( NULL, ID_GOTO, _ ( "G&o To...\tCtrl+G" ), _ ( "Go To..." ) );
4984
gotoItem->SetBitmap ( wxNullBitmap );
4986
editMenu->Append ( undoItem );
4987
editMenu->Append ( redoItem );
4988
editMenu->AppendSeparator();
4989
editMenu->Append ( cutItem );
4990
editMenu->Append ( copyItem );
4991
editMenu->Append ( pasteItem );
4992
editMenu->Append ( pasteNewDocumentItem );
4993
editMenu->AppendSeparator();
4994
editMenu->Append ( findItem );
4995
editMenu->Append ( findAgainItem );
4996
editMenu->Append ( replaceItem );
4997
editMenu->Append ( globalReplaceItem );
4998
editMenu->AppendSeparator();
4999
editMenu->Append ( gotoItem );
5002
wxMenuItem *preferencesItem =
5003
new wxMenuItem ( NULL, ID_OPTIONS, _ ( "Pr&eferences..." ), _ ( "Preferences..." ) );
5004
editMenu->AppendSeparator();
5005
editMenu->Append ( preferencesItem );
5009
wxMenu *fontSizeMenu = new wxMenu;
5010
fontSizeMenu->Append (
5011
ID_FONT_LARGER, _ ( "Increase\tCtrl+U" ), _ ( "Increase" ) );
5012
fontSizeMenu->Append (
5013
ID_FONT_SMALLER, _ ( "Decrease\tCtrl+D" ), _ ( "Decrease" ) );
5014
fontSizeMenu->AppendSeparator();
5015
fontSizeMenu->Append ( ID_FONT_NORMAL, _ ( "Normal\tCtrl+0" ), _ ( "Normal" ) );
5017
// color scheme menu
5018
colorSchemeMenu = new wxMenu;
5019
colorSchemeMenu->AppendRadioItem (
5020
ID_COLOR_SCHEME_DEFAULT, _ ( "&Default" ), _ ( "Default" ) );
5021
colorSchemeMenu->AppendRadioItem (
5022
ID_COLOR_SCHEME_REDUCED_GLARE,
5023
_ ( "&Blue background, white text" ),
5024
_ ( "Blue background, white text" ) );
5025
colorSchemeMenu->AppendRadioItem (
5026
ID_COLOR_SCHEME_DEFAULT_BACKGROUND,
5029
colorSchemeMenu->AppendRadioItem (
5030
ID_COLOR_SCHEME_NONE,
5034
switch ( properties.colorScheme )
5036
case COLOR_SCHEME_DEFAULT:
5037
colorSchemeMenu->Check ( ID_COLOR_SCHEME_DEFAULT, true );
5039
case COLOR_SCHEME_DEFAULT_BACKGROUND:
5040
colorSchemeMenu->Check ( ID_COLOR_SCHEME_DEFAULT_BACKGROUND, true );
5042
case COLOR_SCHEME_REDUCED_GLARE:
5043
colorSchemeMenu->Check ( ID_COLOR_SCHEME_REDUCED_GLARE, true );
5045
case COLOR_SCHEME_NONE:
5046
colorSchemeMenu->Check ( ID_COLOR_SCHEME_NONE, true );
5052
/* WAIT FOR AUI LIBRARY TO SUPPORT THIS - currently always splits left
5053
wxMenu *splitTabMenu = new wxMenu;
5054
splitTabMenu->Append ( ID_SPLIT_TAB_TOP, _ ( "&Top" ), _ ( "Top" ));
5055
splitTabMenu->Append ( ID_SPLIT_TAB_RIGHT, _ ( "&Right" ), _ ( "Right" ));
5056
splitTabMenu->Append ( ID_SPLIT_TAB_BOTTOM, _ ( "&Bottom" ), _ ( "Bottom" ));
5057
splitTabMenu->Append ( ID_SPLIT_TAB_LEFT, _ ( "&Left" ), _ ( "Left" ));
5060
viewMenu = new wxMenu; // use class-wide data member
5061
viewMenu->Append ( ID_PREVIOUS_DOCUMENT, _ ( "&Previous Document\tCtrl+PgUp" ), _ ( "Previous Document" ) );
5062
viewMenu->Append ( ID_NEXT_DOCUMENT, _ ( "&Next Document\tCtrl+PgDn" ), _ ( "Next Document" ) );
5064
//viewMenu->Append ( wxID_ANY, _ ( "&Split Tab" ), splitTabMenu );
5066
viewMenu->Append ( ID_BROWSER, _ ( "&Browser\tCtrl+B" ), _ ( "Browser" ) );
5067
viewMenu->AppendSeparator();
5068
viewMenu->AppendRadioItem (
5070
_ ( "&Show Tags and Attributes\tCtrl+T" ), _ ( "Show Tags and Attributes" ) );
5071
viewMenu->AppendRadioItem (
5073
_ ( "&Hide Attributes Only\tCtrl+Shift+A" ), _ ( "Hide Attributes Only" ) );
5074
viewMenu->AppendRadioItem (
5076
_ ( "H&ide Tags and Attributes\tCtrl+Shift+T" ), _ ( "Hide Tags and Attributes" ) );
5078
switch ( visibilityState )
5081
viewMenu->Check ( ID_SHOW_TAGS, true );
5084
viewMenu->Check ( ID_HIDE_TAGS, true );
5086
case HIDE_ATTRIBUTES:
5087
viewMenu->Check ( ID_HIDE_ATTRIBUTES, true );
5090
viewMenu->Check ( ID_SHOW_TAGS, true );
5093
viewMenu->AppendSeparator();
5095
ID_TOGGLE_FOLD, _ ( "&Toggle Fold\tCtrl+Alt+T" ), _ ( "Toggle Fold" ) );
5097
ID_FOLD_ALL, _ ( "&Fold Tags\tCtrl+Shift+F" ), _ ( "Fold Tags" ) );
5099
ID_UNFOLD_ALL, _ ( "&Unfold Tags\tCtrl+Shift+U" ), _T ( "Unfold Tags" ) );
5100
viewMenu->AppendSeparator();
5101
viewMenu->AppendCheckItem (
5102
ID_WRAP_WORDS, _ ( "&Wrap Words\tCtrl+W" ), _T ( "Wrap Words" ) );
5103
viewMenu->Check ( ID_WRAP_WORDS, properties.wrap );
5104
viewMenu->Append ( wxID_ANY, _ ( "&Color Scheme" ), colorSchemeMenu );
5105
viewMenu->Append ( wxID_ANY, _ ( "&Text Size" ), fontSizeMenu );
5106
viewMenu->AppendSeparator();
5108
viewMenu->AppendCheckItem (
5109
ID_LOCATION_PANE_VISIBLE,
5110
_ ( "S&how Current Element Pane" ),
5111
_ ( "Show Current Element Pane" ) );
5112
viewMenu->Check ( ID_LOCATION_PANE_VISIBLE, false );
5113
viewMenu->AppendCheckItem (
5114
ID_TOOLBAR_VISIBLE, _ ( "Sh&ow Toolbar" ), _ ( "Show Toolbar" ) );
5115
viewMenu->Check ( ID_TOOLBAR_VISIBLE, toolbarVisible );
5117
ID_HIDE_PANE, _ ( "C&lose Message Pane\tAlt+C" ), _ ( "Close Message Pane" ) );
5120
wxMenu *insertMenu = new wxMenu;
5121
insertMenu->Append ( ID_INSERT_CHILD, _ ( "&Element...\tCtrl+I" ), _ ( "Element..." ) );
5122
insertMenu->Append ( ID_INSERT_SIBLING, _ ( "&Sibling...\tCtrl+Shift+I" ), _ ( "Sibling..." ) );
5123
insertMenu->Append ( ID_INSERT_ENTITY, _ ( "&Entity...\tCtrl+E" ), _ ( "Entity..." ) );
5124
insertMenu->AppendSeparator();
5125
insertMenu->Append ( ID_INSERT_TWIN, _ ( "&Twin\tCtrl+Enter" ), _ ( "Twin" ) );
5126
insertMenu->AppendSeparator();
5127
insertMenu->Append ( ID_INSERT_SYMBOL, _ ( "S&ymbol..." ), _ ( "Symbol..." ) );
5130
wxMenu *validationMenu = new wxMenu;
5132
validationMenu->Append ( ID_VALIDATE_DTD, _ ( "&DTD\tF4" ), _ ( "DTD" ) );
5134
validationMenu->Append (
5135
ID_VALIDATE_W3C_SCHEMA, _ ( "&DTD/XML Schema\tF5" ), _ ( "DTD/XML Schema" ) );
5136
validationMenu->AppendSeparator();
5137
validationMenu->Append (
5138
ID_VALIDATE_RELAX_NG, _ ( "&RELAX NG...\tF6" ), _ ( "RELAX NG..." ) );
5140
wxMenu *associateMenu = new wxMenu;
5141
associateMenu->Append ( ID_ASSOCIATE_DTD_PUBLIC, _ ( "&Public DTD..." ), _ ( "Public DTD..." ) );
5142
associateMenu->Append ( ID_ASSOCIATE_DTD_SYSTEM, _ ( "&System DTD..." ), _ ( "System DTD..." ) );
5143
associateMenu->Append ( ID_ASSOCIATE_W3C_SCHEMA, _ ( "&XML Schema..." ), _ ( "XML Schema..." ) );
5144
associateMenu->Append ( ID_ASSOCIATE_XSL, _ ( "XS< stylesheet..." ), _ ( "XSLT stylesheet..." ) );
5146
if ( wxFileName::DirExists ( rngDir ) )
5148
wxString rngMask, rngFile, displayName, shortcutString;
5149
rngMask = rngDir + wxFileName::GetPathSeparator() + _T ( "*.rng" );
5150
rngFile = wxFindFirstFile ( rngMask, wxFILE );
5152
int id = ID_VALIDATE_PRESET1;
5154
if ( !rngFile.empty() )
5156
validationPresetMap.insert ( make_pair ( id, rngFile ) );
5157
wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL );
5158
displayName.Replace ( _T ( ".rng" ), _T ( "" ) );
5159
shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 );
5161
validationMenu->Append ( id, displayName + shortcutString, displayName );
5163
for ( id = ID_VALIDATE_PRESET2; id <= ID_VALIDATE_PRESET9; ++id )
5165
rngFile = wxFindNextFile();
5166
if ( rngFile.empty() )
5168
validationPresetMap.insert ( make_pair ( id, rngFile ) );
5169
wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL );
5170
shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 );
5171
displayName.Replace ( _T ( ".rng" ), _T ( "" ) );
5172
validationMenu->Append ( id, displayName + shortcutString, displayName );
5179
wxMenu *xslMenu = new wxMenu;
5180
xslMenu->Append ( ID_XSLT, _ ( "&XSL Transform...\tF8" ),
5181
_ ( "XSL Transform..." ) );
5182
xslMenu->AppendSeparator();
5184
ID_XSLT_DOCBOOK_HTML,
5185
_ ( "&DocBook to HTML\tAlt+1" ), _ ( "DocBook to HTML" ) );
5187
ID_XSLT_DOCBOOK_XHTML,
5188
_ ( "&DocBook to XHTML\tAlt+2" ), _ ( "DocBook to XHTML" ) );
5191
_ ( "D&ocBook to XSL-FO\tAlt+3" ), _ ( "DocBook to XSL-FO" ) );
5194
_ ( "&TEI to HTML\tAlt+4" ), _ ( "TEI to HTML" ) );
5197
_ ( "T&EI to LaTeX\tAlt+5" ), _ ( "TEI to LaTeX" ) );
5200
_ ( "TE&I to XHTML\tAlt+6" ), _ ( "TEI to XHTML" ) );
5203
_ ( "TEI to &XSL-FO\tAlt+7" ), _ ( "TEI to XSL-FO" ) );
5207
xmlMenu = new wxMenu; // use class-wide data member
5209
ID_CHECK_WELLFORMED,
5210
_ ( "&Check Well-formedness\tF2" ), _ ( "Check Well-formedness" ) );
5215
xmlMenu->AppendSeparator();
5220
xmlMenu->AppendSeparator();
5221
xmlMenu->Append ( ID_XSLT, _ ( "&XSL Transform...\tF8" ),
5222
_ ( "XSL Transform..." ) );
5225
_ ( "&Evaluate XPath...\tF9" ),
5226
_ ( "Evaluate XPath..." ) );
5228
xmlMenu->AppendSeparator();
5231
_ ( "&Pretty-print\tF11" ), _ ( "Pretty-print" ) );
5232
xmlMenu->AppendSeparator();
5233
xmlMenu->AppendCheckItem (
5235
_ ( "&Lock Tags\tCtrl+L" ),
5236
_ ( "Lock Tags" ) );
5237
xmlMenu->Check ( ID_PROTECT_TAGS, protectTags );
5238
xmlMenu->AppendSeparator();
5241
_ ( "E&ncoding..." ), _ ( "Encoding..." ) );
5244
wxMenu *toolsMenu = new wxMenu;
5246
wxMenuItem *spellingItem =
5250
_ ( "&Spelling...\tF7" ),
5251
_ ( "Spelling..." ) );
5252
spellingItem->SetBitmap ( spelling16Bitmap );
5254
wxMenuItem *styleItem =
5258
_ ( "&Style...\tShift+F7" ),
5260
styleItem->SetBitmap ( wxNullBitmap );
5262
wxMenuItem *wordCountItem =
5266
_ ( "&Word Count" ),
5267
_ ( "Word Count" ) );
5268
wordCountItem->SetBitmap ( wxNullBitmap );
5270
wxMenuItem *commandItem =
5274
_ ( "&Command\tCtrl+Alt+C" ),
5276
commandItem->SetBitmap ( wxNullBitmap );
5278
toolsMenu->Append ( spellingItem );
5279
toolsMenu->Append ( styleItem );
5280
toolsMenu->Append ( wordCountItem );
5281
toolsMenu->AppendSeparator();
5282
toolsMenu->Append ( commandItem );
5285
toolsMenu->AppendSeparator();
5286
wxMenuItem *optionsItem =
5290
_ ( "&Options..." ),
5291
_ ( "Options..." ) );
5292
optionsItem->SetBitmap ( wxNullBitmap );
5293
toolsMenu->Append ( optionsItem );
5297
wxMenu *helpMenu = new wxMenu;
5299
wxMenuItem *helpItem =
5300
new wxMenuItem ( NULL, wxID_HELP,
5301
_ ( "&XML Copy Editor Help\tF1" ), _ ( "Help" ) );
5302
helpItem->SetBitmap ( helpBitmap );
5303
wxMenuItem *homeItem =
5304
new wxMenuItem ( NULL, ID_HOME,
5305
_ ( "&Home Page" ), _ ( "Home Page" ) );
5306
homeItem->SetBitmap ( wxNullBitmap );
5307
wxMenuItem *feedbackItem =
5308
new wxMenuItem ( NULL, ID_FEEDBACK, _ ( "&Forum" ), _ ( "Forum" ) );
5309
feedbackItem->SetBitmap ( wxNullBitmap );
5310
wxMenuItem *aboutItem =
5311
new wxMenuItem ( NULL, wxID_ABOUT,
5312
_ ( "&About XML Copy Editor" ), _ ( "About" ) );
5313
aboutItem->SetBitmap ( wxNullBitmap );
5314
wxMenuItem *downloadSourceItem =
5315
new wxMenuItem ( NULL, ID_DOWNLOAD_SOURCE,
5316
_ ( "&Browse Source" ), _ ( "Browse Source" ) );
5317
downloadSourceItem->SetBitmap ( wxNullBitmap );
5318
helpMenu->Append ( helpItem );
5319
helpMenu->AppendSeparator();
5320
helpMenu->Append ( homeItem );
5321
helpMenu->Append ( feedbackItem );
5322
helpMenu->Append ( downloadSourceItem );
5323
helpMenu->AppendSeparator();
5324
helpMenu->Append ( aboutItem );
5326
wxMenuBar *menuBar = new wxMenuBar ( wxMB_DOCKABLE );
5327
menuBar->Append ( fileMenu, _ ( "&File" ) );
5328
menuBar->Append ( editMenu, _ ( "&Edit" ) );
5329
menuBar->Append ( viewMenu, _ ( "&View" ) );
5330
menuBar->Append ( insertMenu, _ ( "&Insert" ) );
5331
menuBar->Append ( xmlMenu, _ ( "&XML" ) );
5332
menuBar->Append ( toolsMenu, _ ( "&Tools" ) );
5333
menuBar->Append ( helpMenu, _ ( "&Help" ) );
5337
void MyFrame::updateFileMenu ( bool deleteExisting )
5339
if ( deleteExisting )
5341
wxMenuItemList list = fileMenu->GetMenuItems();
5342
size_t count = list.size();
5343
for ( size_t i = 0; i < count; ++i )
5344
fileMenu->Delete ( list[i] );
5347
wxMenuItem *newItem =
5348
new wxMenuItem ( NULL, wxID_NEW, _ ( "&New...\tCtrl+N" ), _ ( "New..." ) );
5349
newItem->SetBitmap ( new16Bitmap );
5350
wxMenuItem *openItem =
5351
new wxMenuItem ( NULL, wxID_OPEN, _ ( "&Open...\tCtrl+O" ), _ ( "Open..." ) );
5352
openItem->SetBitmap ( open16Bitmap );
5353
wxMenuItem *openLargeFileItem =
5354
new wxMenuItem ( NULL, ID_OPEN_LARGE_FILE,
5355
_ ( "O&pen Large Document...\tCtrl+Shift+O" ), _ ( "Open Large Document..." ) );
5356
openLargeFileItem->SetBitmap ( wxNullBitmap );
5358
wxMenuItem *closeItem =
5359
new wxMenuItem ( NULL, wxID_CLOSE, _ ( "&Close\tCtrl+F4" ), _ ( "Close" ) );
5360
closeItem->SetBitmap ( wxNullBitmap );
5361
wxMenuItem *closeAllItem =
5362
new wxMenuItem ( NULL, wxID_CLOSE_ALL, _ ( "C&lose All" ), _ ( "Close All" ) );
5363
closeAllItem->SetBitmap ( wxNullBitmap );
5364
wxMenuItem *saveItem =
5365
new wxMenuItem ( NULL, wxID_SAVE, _ ( "&Save\tCtrl+S" ), _ ( "Save" ) );
5366
saveItem->SetBitmap ( save16Bitmap );
5368
wxMenuItem *saveAsItem =
5369
new wxMenuItem ( NULL, wxID_SAVEAS, _ ( "S&ave As...\tF12" ), _ ( "Save As..." ) );
5370
saveAsItem->SetBitmap ( wxNullBitmap );
5372
wxMenuItem *exportItem =
5373
new wxMenuItem ( NULL, ID_EXPORT, _ ( "&DAISY Export..." ), _ ( "DAISY Export..." ) );
5374
exportItem->SetBitmap ( wxNullBitmap );
5376
wxMenuItem *reloadItem =
5377
new wxMenuItem ( NULL, ID_RELOAD, _ ( "&Reload" ), _ ( "Reload" ) );
5378
reloadItem->SetBitmap ( wxNullBitmap );
5379
wxMenuItem *revertItem =
5380
new wxMenuItem ( NULL, wxID_REVERT, _ ( "&Revert" ), _ ( "Revert" ) );
5381
revertItem->SetBitmap ( wxNullBitmap );
5382
wxMenuItem *printSetupItem =
5383
new wxMenuItem ( NULL, ID_PRINT_SETUP, _ ( "Pa&ge Setup..." ), _ ( "Page Setup..." ) );
5384
printSetupItem->SetBitmap ( wxNullBitmap );
5385
wxMenuItem *printPreviewItem =
5386
new wxMenuItem ( NULL, ID_PRINT_PREVIEW, _ ( "Pr&int Preview..." ), _ ( "Print Preview..." ) );
5387
printPreviewItem->SetBitmap ( printPreviewBitmap );
5388
wxMenuItem *printItem =
5389
new wxMenuItem ( NULL, ID_PRINT, _ ( "Pri&nt...\tCtrl+P" ), _ ( "Print..." ) );
5390
printItem->SetBitmap ( print16Bitmap );
5391
wxMenuItem *importMSWordItem =
5393
NULL, ID_IMPORT_MSWORD, _ ( "I&mport Microsoft Word Document..." ) );
5394
importMSWordItem->SetBitmap ( wxNullBitmap );
5395
wxMenuItem *exportMSWordItem =
5397
NULL, ID_EXPORT_MSWORD, _ ( "Expor&t Microsoft Word Document..." ) );
5398
exportMSWordItem->SetBitmap ( wxNullBitmap );
5400
wxMenuItem *exitItem =
5401
new wxMenuItem ( NULL, wxID_EXIT, _ ( "E&xit" ), _ ( "Exit" ) );
5402
exitItem->SetBitmap ( wxNullBitmap );
5404
fileMenu->Append ( newItem );
5405
fileMenu->Append ( openItem );
5406
fileMenu->Append ( openLargeFileItem );
5407
fileMenu->AppendSeparator();
5408
fileMenu->Append ( closeItem );
5409
fileMenu->Append ( closeAllItem );
5410
fileMenu->Append ( saveItem );
5411
fileMenu->Append ( saveAsItem );
5412
fileMenu->AppendSeparator();
5413
fileMenu->Append ( reloadItem );
5414
fileMenu->Append ( revertItem );
5415
fileMenu->AppendSeparator();
5416
fileMenu->Append ( printSetupItem );
5417
fileMenu->Append ( printPreviewItem );
5418
fileMenu->Append ( printItem );
5420
fileMenu->AppendSeparator();
5421
fileMenu->Append ( exportItem );
5422
fileMenu->Append ( importMSWordItem );
5423
fileMenu->Append ( exportMSWordItem );
5425
history.AddFilesToMenu ( fileMenu );
5426
fileMenu->AppendSeparator();
5427
fileMenu->Append ( exitItem );
5430
wxToolBar *MyFrame::getToolBar()
5432
wxToolBar *toolBar = new wxToolBar (
5441
w = saveBitmap.GetWidth(), h = saveBitmap.GetHeight();
5442
toolBar->SetToolBitmapSize ( wxSize ( w, h ) );
5469
ID_CHECK_WELLFORMED,
5470
_ ( "Check Well-formedness" ),
5471
checkWellformedBitmap,
5474
_ ( "Check Well-formedness" ) );
5476
ID_VALIDATE_W3C_SCHEMA,
5497
toolBar->AddCheckTool (
5502
_ ( "Lock Tags" ) );
5503
toolBar->ToggleTool (
5504
ID_PROTECT_TAGS, protectTags );
5510
XmlDoc *MyFrame::getActiveDocument()
5512
if ( !mainBook->GetPageCount() )
5514
return ( XmlDoc * ) mainBook->GetPage ( mainBook->GetSelection() );
5517
void MyFrame::addSafeSeparator ( wxToolBar *toolBar )
5519
wxStaticText *staticControl = new wxStaticText (
5523
toolBar->AddControl ( staticControl );
5526
void MyFrame::statusProgress ( const wxString& s )
5528
wxStatusBar *status = GetStatusBar();
5531
status->SetStatusText ( s, 0 );
5534
void MyFrame::messagePane ( const wxString& s, int iconType, bool forcePane )
5536
statusProgress ( wxEmptyString );
5540
case ( CONST_INFO ) :
5541
paneTitle = _ ( "Information" );
5543
case ( CONST_WARNING ) :
5544
paneTitle = _ ( "Warning" );
5546
case ( CONST_STOP ) :
5547
paneTitle = _ ( "Stopped" );
5549
case ( CONST_QUESTION ) :
5550
paneTitle = _ ( "Question" );
5553
paneTitle = _ ( "Message" );
5557
wxAuiPaneInfo info = manager.GetPane ( htmlReport );
5558
if ( !info.IsShown() )
5560
manager.GetPane ( htmlReport ).Show ( true );
5564
manager.GetPane ( htmlReport ).Caption ( paneTitle );
5566
wxString htmlString = s;
5567
htmlString.Replace ( _T ( "&" ), _T ( "&" ), true );
5568
htmlString.Replace ( _T ( "<" ), _T ( "<" ), true );
5569
htmlString.Replace ( _T ( ">" ), _T ( ">" ), true );
5571
htmlString.Replace ( _T("[br/]"), _T("<br/>"), true );
5572
htmlString.Replace ( _T("[b]"), _T("<b>"), true );
5573
htmlString.Replace ( _T("[/b]"), _T("</b>"), true );
5574
htmlString.Replace ( _T("[i]"), _T("<i>"), true );
5575
htmlString.Replace ( _T("[/i]"), _T("</i>"), true );
5578
wxString htmlBuffer;
5579
htmlBuffer += _T ( "<html><body><table><tr><td width=\"5%\"><img src=\"" );
5582
case ( CONST_INFO ) :
5583
htmlBuffer += pngDir;
5584
htmlBuffer += _T ( "stock_dialog-info-32.png" );
5586
case ( CONST_WARNING ) :
5587
htmlBuffer += pngDir;
5588
htmlBuffer += _T ( "stock_dialog-warning-32.png" );
5590
case ( CONST_STOP ) :
5591
htmlBuffer += pngDir;
5592
htmlBuffer += _T ( "stock_dialog-stop-32.png" );
5594
case ( CONST_QUESTION ) :
5595
htmlBuffer += pngDir;
5596
htmlBuffer += _T ( "stock_dialog-question-32.png" );
5601
htmlBuffer += _T ( "\"></td><td width=\"95%\">" );
5602
htmlBuffer += htmlString;
5603
htmlBuffer += _T ( "</td></tr></table></body></html>" );
5605
htmlReport->SetPage ( htmlBuffer );
5610
void MyFrame::documentOk ( const wxString& status )
5613
if ( ( doc = getActiveDocument() ) == NULL )
5616
message.Printf ( _ ( "%s is %s" ),
5617
doc->getShortFileName().c_str(),
5619
messagePane ( message, CONST_INFO );
5622
void MyFrame::applyEditorProperties ( bool zoomOnly )
5625
size_t documentCount = mainBook->GetPageCount();
5626
for ( size_t i = 0; i < documentCount; i++ )
5628
doc = ( XmlDoc * ) mainBook->GetPage ( i );
5631
doc->applyProperties ( properties, zoomOnly );
5632
if ( !properties.validateAsYouType )
5633
doc->clearErrorIndicators();
5638
void MyFrame::modifiedMessage()
5641
_ ( "Document has been modified: save or discard changes" ),
5645
void MyFrame::xmliseWideTextNode ( wxString& s )
5647
s.Replace ( _T ( "&" ), _T ( "&" ), true );
5648
s.Replace ( _T ( "<" ), _T ( "<" ), true );
5649
s.Replace ( _T ( ">" ), _T ( ">" ), true );
5652
int MyFrame::getFileType ( const wxString& fileName )
5654
std::string fileNameLocal, fileNameLocalLC;
5655
fileNameLocal = fileName.mb_str ( wxConvLocal );
5656
fileNameLocalLC = CaseHandler::lowerCase ( fileNameLocal );
5658
if ( fileNameLocalLC.find ( ".dtd" ) != std::string::npos ||
5659
fileNameLocalLC.find ( ".ent" ) != std::string::npos )
5660
return FILE_TYPE_DTD;
5661
else if ( fileNameLocalLC.find ( ".css" ) != std::string::npos )
5662
return FILE_TYPE_CSS;
5663
else if ( fileNameLocalLC.find ( ".php" ) != std::string::npos )
5664
return FILE_TYPE_PHP;
5665
else if ( fileNameLocalLC.find ( ".exe" ) != std::string::npos )
5666
return FILE_TYPE_BINARY;
5667
else if ( fileNameLocalLC.find ( ".rnc" ) != std::string::npos )
5668
return FILE_TYPE_RNC;
5669
return FILE_TYPE_XML;
5672
long MyFrame::getNotebookStyleMask()
5675
if (notebookStyleMenu->IsChecked(ID_NOTEBOOK_STYLE_FLAT))
5676
return wxFNB_FANCY_TABS | wxFNB_MOUSE_MIDDLE_CLOSES_TABS | wxFNB_X_ON_TAB;
5677
else if (notebookStyleMenu->IsChecked(ID_NOTEBOOK_STYLE_VC8))
5678
return wxFNB_BACKGROUND_GRADIENT | wxFNB_VC8 | wxFNB_MOUSE_MIDDLE_CLOSES_TABS |
5679
wxFNB_X_ON_TAB | wxFNB_DROPDOWN_TABS_LIST | wxFNB_NO_NAV_BUTTONS;
5681
return wxFNB_BACKGROUND_GRADIENT | wxFNB_VC8 | wxFNB_MOUSE_MIDDLE_CLOSES_TABS | wxFNB_COLORFUL_TABS |
5682
wxFNB_X_ON_TAB | wxFNB_DROPDOWN_TABS_LIST | wxFNB_NO_NAV_BUTTONS;
5683
//wxFNB_BACKGROUND_GRADIENT | wxFNB_VC8 | wxFNB_MOUSE_MIDDLE_CLOSES_TABS | wxFNB_COLORFUL_TABS;
5688
bool MyFrame::isSpecialFileType ( const wxString& fileName )
5690
std::string fileNameLocal, fileNameLocalLC;
5691
fileNameLocal = fileName.mb_str ( wxConvLocal );
5692
fileNameLocalLC = CaseHandler::lowerCase ( fileNameLocal );
5695
fileNameLocalLC.find ( ".dtd" ) != std::string::npos ||
5696
fileNameLocalLC.find ( ".css" ) != std::string::npos ||
5697
fileNameLocalLC.find ( ".php" ) != std::string::npos );
5700
void MyFrame::encodingMessage()
5702
wxString msg = _ ( "Encoding should be one of " );
5703
msg += ENCODING_INFO;
5704
messagePane ( msg, CONST_STOP );
5707
void MyFrame::updatePaths()
5709
ruleSetDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "rulesets" );
5710
filterDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "filters" );
5711
templateDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "templates" ) +
5712
wxFileName::GetPathSeparator();
5713
binDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "bin" ) +
5714
wxFileName::GetPathSeparator();
5715
helpDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "help" ) +
5716
wxFileName::GetPathSeparator();
5717
rngDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "rng" ) +
5718
wxFileName::GetPathSeparator();
5719
htmlDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "html" ) +
5720
wxFileName::GetPathSeparator();
5721
pngDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "png" ) +
5722
wxFileName::GetPathSeparator();
5723
daisyDir = applicationDir + wxFileName::GetPathSeparator() + _T ( "daisy" ) +
5724
wxFileName::GetPathSeparator();
5725
wxString wideCatalogPath =
5726
applicationDir + wxFileName::GetPathSeparator() + _T ( "catalog" ) +
5727
wxFileName::GetPathSeparator() + _T ( "catalog" );
5728
catalogPath = wideCatalogPath.mb_str ( wxConvLocal );
5729
wxString wideCatalogUtilityPath = applicationDir + wxFileName::GetPathSeparator() + _T ( "xmlcatalog" );
5730
catalogUtilityPath = wideCatalogUtilityPath.mb_str ( wxConvLocal );
5731
wxString wideXslDtdPath =
5732
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
5733
wxFileName::GetPathSeparator() + _T ( "xslt10.dtd" );
5734
xslDtdPath = wideXslDtdPath.mb_str ( wxConvLocal );
5735
wxString wideRssDtdPath =
5736
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
5737
wxFileName::GetPathSeparator() + _T ( "rss2.dtd" );
5738
rssDtdPath = wideRssDtdPath.mb_str ( wxConvLocal );
5739
wxString wideXtmDtdPath =
5740
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
5741
wxFileName::GetPathSeparator() + _T ( "xtm1.dtd" );
5742
xtmDtdPath = wideXtmDtdPath.mb_str ( wxConvLocal );
5743
wxString wideLzxDtdPath =
5744
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
5745
wxFileName::GetPathSeparator() + _T ( "lzx.dtd" );
5746
lzxDtdPath = wideLzxDtdPath.mb_str ( wxConvLocal );
5747
wxString wideXliffDtdPath =
5748
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
5749
wxFileName::GetPathSeparator() + _T ( "xliff.dtd" );
5750
xliffDtdPath = wideXliffDtdPath.mb_str ( wxConvLocal );
5751
wxString wideAspellDataPath = applicationDir + wxFileName::GetPathSeparator() +
5752
_T ( "aspell" ) + wxFileName::GetPathSeparator() + _T ( "data" );
5753
aspellDataPath = wideAspellDataPath.mb_str ( wxConvLocal );
5754
wxString wideAspellDictPath = applicationDir + wxFileName::GetPathSeparator() +
5755
_T ( "aspell" ) + wxFileName::GetPathSeparator() + _T ( "dict" );
5756
aspellDictPath = wideAspellDictPath.mb_str ( wxConvLocal );
5759
void MyFrame::OnAssociate ( wxCommandEvent& event )
5762
if ( ( doc = getActiveDocument() ) == NULL )
5765
wxString title, label, type, extension, path, defaulturl, defaultaux;
5766
wxString auxiliaryLabel;
5767
int id = event.GetId();
5770
case ID_ASSOCIATE_DTD_PUBLIC:
5771
type = _ ( "Public DTD" );
5772
extension = _T ( "*.dtd" );
5773
defaulturl = lastDtdPublic;
5774
defaultaux = lastDtdPublicAux;
5776
case ID_ASSOCIATE_DTD_SYSTEM:
5777
type = _ ( "System DTD" );
5778
extension = _T ( "*.dtd" );
5779
defaulturl = lastDtdSystem;
5780
defaultaux = _T ( "" );
5782
case ID_ASSOCIATE_W3C_SCHEMA:
5783
type = _ ( "XML Schema" );
5784
extension = _T ( "*.xsd" );
5785
defaulturl = lastSchema;
5786
defaultaux = _T ( "" );
5788
case ID_ASSOCIATE_XSL:
5789
type = _ ( "XSLT stylesheet" );
5790
extension = _T ( "*.xsl;*.xslt" );
5791
defaulturl = lastXslStylesheet;
5792
defaultaux = _T ( "" );
5798
std::string utf8Buffer;
5799
getRawText ( doc, utf8Buffer );
5800
std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() );
5801
if ( !wellformedparser->parse ( utf8Buffer ) )
5803
std::string error = wellformedparser->getLastError();
5804
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
5807
_ ( "Cannot associate %s: %s" ),
5809
wideError.c_str() );
5810
messagePane ( message,
5815
title.Printf ( _ ( "Associate %s" ), type.c_str() );
5816
label = _ ( "Choose a file:" );
5819
( id == ID_ASSOCIATE_DTD_PUBLIC );
5820
//(id == ID_ASSOCIATE_W3C_SCHEMA_NS || id == ID_ASSOCIATE_DTD_PUBLIC);
5823
auxiliaryLabel = _ ( "Choose a public identifier:" );
5825
(id == ID_ASSOCIATE_DTD_PUBLIC) ? _("Choose a public identifier:") :
5826
_("Choose a namespace:");
5830
AssociateDialog ad (
5840
if ( ad.ShowModal() != wxID_OK )
5845
wxString aux, schemaPathMemory;
5852
std::string utf8Path = ( const char * ) path.mb_str ( wxConvUTF8 );
5854
std::string modifiedBuffer;
5859
case ID_ASSOCIATE_W3C_SCHEMA:
5862
case ID_ASSOCIATE_DTD_PUBLIC:
5863
lastDtdPublic = path;
5864
lastDtdPublicAux = aux;
5866
case ID_ASSOCIATE_DTD_SYSTEM:
5867
lastDtdSystem = path;
5869
case ID_ASSOCIATE_XSL:
5870
lastXslStylesheet = path;
5876
if ( id == ID_ASSOCIATE_W3C_SCHEMA )
5878
std::auto_ptr<XmlAssociateXsd> parser ( new XmlAssociateXsd ( utf8Path ) );
5879
if ( !parser->parse ( utf8Buffer ) )
5881
modifiedBuffer = parser->getBuffer();
5883
else if ( id == ID_ASSOCIATE_DTD_SYSTEM || id == ID_ASSOCIATE_DTD_PUBLIC )
5885
std::auto_ptr<XmlAssociateDtd> parser ( new XmlAssociateDtd (
5887
( auxiliaryBox ) ? ( const char * ) aux.mb_str ( wxConvUTF8 ) : "" ) );
5888
if ( !parser->parse ( utf8Buffer ) )
5890
modifiedBuffer = parser->getBuffer();
5892
else if ( id == ID_ASSOCIATE_XSL )
5894
std::auto_ptr<XmlAssociateXsl> parser ( new XmlAssociateXsl (
5896
if ( !parser->parse ( utf8Buffer ) )
5898
modifiedBuffer = parser->getBuffer();
5902
doc->SetTextRaw ( modifiedBuffer.c_str() );
5906
void MyFrame::openRememberedTabs()
5908
if ( openTabsOnClose.empty() )
5911
s = it = ( wchar_t * ) openTabsOnClose.wc_str();
5912
std::vector<wxString> v;
5913
wxString buffer = wxEmptyString;
5918
if ( !buffer.empty() )
5920
v.push_back ( buffer );
5922
buffer = wxEmptyString;
5927
if ( !buffer.empty() )
5929
v.push_back ( buffer );
5935
std::vector<wxString>::iterator vit;
5936
for ( vit = v.begin(); vit != v.end(); vit++ )
5938
if ( !openFile ( *vit ) )
5942
if ( ( doc = getActiveDocument() ) != NULL )
5946
void MyFrame::getRawText ( XmlDoc *doc, std::string& buffer )
5953
buffer = doc->myGetTextRaw();
5956
void MyFrame::OnWordCount ( wxCommandEvent& event )
5959
if ( ( doc = getActiveDocument() ) == NULL )
5961
wxString wideBuffer;
5963
wideBuffer = doc->GetText();
5964
buffer = wideBuffer.mb_str ( wxConvUTF8 );
5966
auto_ptr<XmlWordCount> xwc ( new XmlWordCount() );
5968
if ( !xwc->parse ( buffer.c_str() ) )
5970
std::string error = xwc->getLastError();
5971
wxString werror = wxString ( error.c_str(), wxConvUTF8, error.size() );
5972
statusProgress ( wxEmptyString );
5974
msg.Printf ( _ ( "Cannot count words: %s" ), werror.c_str() );
5975
messagePane ( msg, CONST_STOP );
5979
int count = xwc->getWordCount();
5982
ngettext ( L"%s contains %i word", L"%s contains %i words", count ),
5983
doc->getShortFileName().c_str(), count );
5985
messagePane ( msg, CONST_INFO, true );
5989
void MyFrame::removeUtf8Bom ( std::string& buffer )
5991
if ( buffer.size() > 3 &&
5992
( unsigned char ) buffer[0] == 0xEF &&
5993
( unsigned char ) buffer[1] == 0xBB &&
5994
( unsigned char ) buffer[2] == 0xBF )
5996
buffer.erase ( 0, 3 );
6000
void MyFrame::loadBitmaps()
6004
newBitmap = wxBITMAP ( stock_new );
6005
openBitmap = wxBITMAP ( stock_open );
6006
saveBitmap = wxBITMAP ( stock_save );
6007
printBitmap = wxBITMAP ( stock_print );
6008
spellingBitmap = wxBITMAP ( stock_spellcheck );
6009
internetBitmap = wxBITMAP ( stock_internet );
6010
hyperlinkBitmap = wxBITMAP ( stock_hyperlink );
6011
filtersBitmap = wxBITMAP ( stock_filters );
6012
checkWellformedBitmap = wxBITMAP ( stock_calc-accept );
6013
checkValidBitmap = wxBITMAP ( stock_calc-accept-green );
6016
new16Bitmap = wxBITMAP ( stock_new_16 );
6017
open16Bitmap = wxBITMAP ( stock_open_16 );
6018
save16Bitmap = wxBITMAP ( stock_save_16 );
6019
printPreviewBitmap = wxBITMAP ( stock_print_preview_16 );
6020
print16Bitmap = wxBITMAP ( stock_print_16 );
6021
undo16Bitmap = wxBITMAP ( stock_undo_16 );
6022
redo16Bitmap = wxBITMAP ( stock_redo_16 );
6023
cutBitmap = wxBITMAP ( stock_cut_16 );
6024
copyBitmap = wxBITMAP ( stock_copy_16 );
6025
pasteBitmap = wxBITMAP ( stock_paste_16 );
6026
findBitmap = wxBITMAP ( stock_search_16 );
6027
spelling16Bitmap = wxBITMAP ( stock_spellcheck_16 );
6028
helpBitmap = wxBITMAP ( stock_help_16 );
6031
newBitmap = wxArtProvider::GetBitmap ( wxART_NEW, wxART_TOOLBAR );
6032
openBitmap = wxArtProvider::GetBitmap ( wxART_FILE_OPEN, wxART_TOOLBAR );
6033
saveBitmap = wxArtProvider::GetBitmap ( wxART_FILE_SAVE, wxART_TOOLBAR );
6034
printBitmap = wxArtProvider::GetBitmap ( wxART_PRINT, wxART_TOOLBAR );
6035
spellingBitmap = wxArtProvider::GetBitmap ( _T ( "gtk-spell-check" ), wxART_TOOLBAR );
6037
// no stock icons for the following
6038
internetBitmap.LoadFile ( pngDir + _T ( "stock_internet.png" ), wxBITMAP_TYPE_PNG );
6039
hyperlinkBitmap.LoadFile ( pngDir + _T ( "stock_hyperlink.png" ), wxBITMAP_TYPE_PNG );
6040
checkWellformedBitmap.LoadFile ( pngDir + _T ( "stock_calc-accept.png" ), wxBITMAP_TYPE_PNG );
6041
checkValidBitmap.LoadFile ( pngDir + _T ( "stock_calc-accept-green.png" ), wxBITMAP_TYPE_PNG );
6044
new16Bitmap = wxNullBitmap;
6045
open16Bitmap = wxNullBitmap;
6046
save16Bitmap = wxNullBitmap;
6047
printPreviewBitmap = wxNullBitmap;
6048
print16Bitmap = wxNullBitmap;
6049
undo16Bitmap = wxNullBitmap;
6050
redo16Bitmap = wxNullBitmap;
6051
cutBitmap = wxNullBitmap;
6052
copyBitmap = wxNullBitmap;
6053
pasteBitmap = wxNullBitmap;
6054
findBitmap = wxNullBitmap;
6055
spelling16Bitmap = wxNullBitmap;
6056
helpBitmap = wxNullBitmap;
6061
void MyFrame::OnDropFiles ( wxDropFilesEvent& event )
6063
int no = event.GetNumberOfFiles();
6064
wxString *iterator = event.GetFiles();
6066
if ( !no || !iterator )
6069
for ( int i = 0; i < no; i++, iterator++ )
6071
if ( !openFile ( *iterator ) )
6077
std::string MyFrame::getAuxPath ( const std::string& fileName )
6079
if ( fileName.find ( ".xsl" ) != std::string::npos ||
6080
fileName.find ( ".XSL" ) != std::string::npos )
6082
else if ( fileName.find ( ".rss" ) != std::string::npos ||
6083
fileName.find ( ".RSS" ) != std::string::npos )
6085
else if ( fileName.find ( ".xtm" ) != std::string::npos ||
6086
fileName.find ( ".xtmm" ) != std::string::npos ||
6087
fileName.find ( ".XTM" ) != std::string::npos ||
6088
fileName.find ( ".XTMM" ) != std::string::npos )
6090
else if ( fileName.find ( ".lzx" ) != std::string::npos ||
6091
fileName.find ( ".LZX" ) != std::string::npos )
6093
else if ( fileName.find ( ".xlf" ) != std::string::npos ||
6094
fileName.find ( ".XLF" ) != std::string::npos )
6095
return xliffDtdPath;
6099
void MyFrame::OnActivateApp ( wxActivateEvent& event )
6102
if ( !mainBook || !event.GetActive() )
6104
restoreFocusToNotebook = true;
6107
void MyFrame::OnIconize ( wxIconizeEvent& event )
6110
if ( event.Iconized() )
6112
restoreFocusToNotebook = true;
6115
void MyFrame::OnKeyPressed ( wxKeyEvent& event )
6120
void MyFrame::setStrictScrolling ( bool b )
6123
doc = getActiveDocument();
6126
doc->SetYCaretPolicy ( ( b ) ? ( wxSTC_CARET_STRICT | wxSTC_CARET_SLOP ) : wxSTC_CARET_EVEN,
6130
void MyFrame::addToFileQueue ( wxString& fileName )
6132
fileQueue.push_back ( fileName );