-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathedframe.cpp
More file actions
3595 lines (2992 loc) · 103 KB
/
edframe.cpp
File metadata and controls
3595 lines (2992 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of Poedit (http://poedit.net)
*
* Copyright (C) 1999-2014 Vaclav Slavik
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include <wx/wx.h>
#include <wx/config.h>
#include <wx/html/htmlwin.h>
#include <wx/statline.h>
#include <wx/sizer.h>
#include <wx/fs_mem.h>
#include <wx/datetime.h>
#include <wx/tokenzr.h>
#include <wx/xrc/xmlres.h>
#include <wx/settings.h>
#include <wx/button.h>
#include <wx/statusbr.h>
#include <wx/splitter.h>
#include <wx/fontutil.h>
#include <wx/textfile.h>
#include <wx/wupdlock.h>
#include <wx/iconbndl.h>
#include <wx/clipbrd.h>
#include <wx/dnd.h>
#include <wx/windowptr.h>
#ifdef __WXOSX__
#include "osx_helpers.h"
#endif
#ifdef USE_SPELLCHECKING
#ifdef __WXGTK__
#include <gtk/gtk.h>
extern "C" {
#include <gtkspell/gtkspell.h>
}
#endif // __WXGTK__
#endif // USE_SPELLCHECKING
#ifdef __WXMAC__
#import <AppKit/NSDocumentController.h>
#endif
#include <map>
#include <algorithm>
#include <future>
#include "catalog.h"
#include "edapp.h"
#include "edframe.h"
#include "propertiesdlg.h"
#include "prefsdlg.h"
#include "fileviewer.h"
#include "findframe.h"
#include "tm/transmem.h"
#include "language.h"
#include "progressinfo.h"
#include "commentdlg.h"
#include "manager.h"
#include "pluralforms/pl_evaluate.h"
#include "attentionbar.h"
#include "errorbar.h"
#include "utility.h"
#include "languagectrl.h"
#include "welcomescreen.h"
#include "errors.h"
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(PoeditFramesList);
PoeditFramesList PoeditFrame::ms_instances;
// this should be high enough to not conflict with any wxNewId-allocated value,
// but there's a check for this in the PoeditFrame ctor, too
const wxWindowID ID_POEDIT_FIRST = wxID_HIGHEST + 10000;
const unsigned ID_POEDIT_STEP = 1000;
const wxWindowID ID_POPUP_REFS = ID_POEDIT_FIRST + 1*ID_POEDIT_STEP;
const wxWindowID ID_POPUP_TRANS = ID_POEDIT_FIRST + 2*ID_POEDIT_STEP;
const wxWindowID ID_POPUP_DUMMY = ID_POEDIT_FIRST + 3*ID_POEDIT_STEP;
const wxWindowID ID_BOOKMARK_GO = ID_POEDIT_FIRST + 4*ID_POEDIT_STEP;
const wxWindowID ID_BOOKMARK_SET = ID_POEDIT_FIRST + 5*ID_POEDIT_STEP;
const wxWindowID ID_POEDIT_LAST = ID_POEDIT_FIRST + 6*ID_POEDIT_STEP;
const wxWindowID ID_LIST = wxNewId();
const wxWindowID ID_TEXTORIG = wxNewId();
const wxWindowID ID_TEXTORIGPLURAL = wxNewId();
const wxWindowID ID_TEXTTRANS = wxNewId();
const wxWindowID ID_TEXTCOMMENT = wxNewId();
#ifdef __VISUALC__
// Disabling the useless and annoying MSVC++'s
// warning C4800: 'long' : forcing value to bool 'true' or 'false'
// (performance warning):
#pragma warning ( disable : 4800 )
#endif
// I don't like this global flag, but all PoeditFrame instances must share it
bool g_focusToText = false;
/*static*/ PoeditFrame *PoeditFrame::Find(const wxString& filename)
{
wxFileName fn(filename);
for (PoeditFramesList::const_iterator n = ms_instances.begin();
n != ms_instances.end(); ++n)
{
if (wxFileName((*n)->m_fileName) == fn)
return *n;
}
return NULL;
}
/*static*/ PoeditFrame *PoeditFrame::UnusedActiveWindow()
{
for (PoeditFramesList::const_iterator n = ms_instances.begin();
n != ms_instances.end(); ++n)
{
PoeditFrame *win = *n;
if (win->IsActive() && win->m_catalog == NULL)
return win;
}
return NULL;
}
/*static*/ bool PoeditFrame::AnyWindowIsModified()
{
for (PoeditFramesList::const_iterator n = ms_instances.begin();
n != ms_instances.end(); ++n)
{
if ((*n)->IsModified())
return true;
}
return false;
}
/*static*/ PoeditFrame *PoeditFrame::Create(const wxString& filename)
{
PoeditFrame *f = PoeditFrame::Find(filename);
if (f)
{
f->Raise();
}
else
{
// NB: duplicated in ReadCatalog()
Catalog *cat = new Catalog(filename);
if (!cat->IsOk())
{
wxMessageDialog dlg
(
nullptr,
_("The file cannot be opened."),
_("Invalid file"),
wxOK | wxICON_ERROR
);
dlg.SetExtendedMessage(
_("The file may be either corrupted or in a format not recognized by Poedit.")
);
dlg.ShowModal();
delete cat;
return nullptr;
}
f = new PoeditFrame();
f->Show(true);
f->ReadCatalog(cat);
}
f->Show(true);
if (g_focusToText && f->m_textTrans)
f->m_textTrans->SetFocus();
else if (f->m_list)
f->m_list->SetFocus();
return f;
}
/*static*/ PoeditFrame *PoeditFrame::CreateEmpty()
{
PoeditFrame *f = new PoeditFrame;
f->Show(true);
return f;
}
/*static*/ PoeditFrame *PoeditFrame::CreateWelcome()
{
PoeditFrame *f = new PoeditFrame;
f->EnsureContentView(Content::Welcome);
f->Show(true);
return f;
}
class ListHandler;
class TextctrlHandler : public wxEvtHandler
{
public:
TextctrlHandler(PoeditFrame* frame) {}
private:
#ifdef __WXMSW__
// We use wxTE_RICH2 style, which allows for pasting rich-formatted
// text into the control. We want to allow only plain text (all the
// formatting done is Poedit's syntax highlighting), so we need to
// override copy/cut/paste command.s Plus, the richedit control
// (or wx's use of it) has a bug in it that causes it to copy wrong
// data when copying from the same text control to itself after its
// content was programatically changed:
// https://sourceforge.net/tracker/index.php?func=detail&aid=1910234&group_id=27043&atid=389153
bool DoCopy(wxTextCtrl *textctrl)
{
long from, to;
textctrl->GetSelection(&from, &to);
if ( from == to )
return false;
const wxString sel = textctrl->GetRange(from, to);
wxClipboardLocker lock;
wxCHECK_MSG( !!lock, false, "failed to lock clipboard" );
wxClipboard::Get()->SetData(new wxTextDataObject(sel));
return true;
}
void OnCopy(wxClipboardTextEvent& event)
{
wxTextCtrl *textctrl = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
wxCHECK_RET( textctrl, "wrong use of event handler" );
DoCopy(textctrl);
}
void OnCut(wxClipboardTextEvent& event)
{
wxTextCtrl *textctrl = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
wxCHECK_RET( textctrl, "wrong use of event handler" );
if ( !DoCopy(textctrl) )
return;
long from, to;
textctrl->GetSelection(&from, &to);
textctrl->Remove(from, to);
}
void OnPaste(wxClipboardTextEvent& event)
{
wxTextCtrl *textctrl = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
wxCHECK_RET( textctrl, "wrong use of event handler" );
wxClipboardLocker lock;
wxCHECK_RET( !!lock, "failed to lock clipboard" );
wxTextDataObject d;
wxClipboard::Get()->GetData(d);
long from, to;
textctrl->GetSelection(&from, &to);
textctrl->Replace(from, to, d.GetText());
}
#endif // __WXMSW__
DECLARE_EVENT_TABLE()
friend class ListHandler;
};
BEGIN_EVENT_TABLE(TextctrlHandler, wxEvtHandler)
#ifdef __WXMSW__
EVT_TEXT_COPY(-1, TextctrlHandler::OnCopy)
EVT_TEXT_CUT(-1, TextctrlHandler::OnCut)
EVT_TEXT_PASTE(-1, TextctrlHandler::OnPaste)
#endif
END_EVENT_TABLE()
class TransTextctrlHandler : public TextctrlHandler
{
public:
TransTextctrlHandler(PoeditFrame* frame)
: TextctrlHandler(frame), m_frame(frame) {}
private:
void OnText(wxCommandEvent& event)
{
m_frame->UpdateFromTextCtrl();
event.Skip();
}
PoeditFrame *m_frame;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(TransTextctrlHandler, TextctrlHandler)
EVT_TEXT(-1, TransTextctrlHandler::OnText)
END_EVENT_TABLE()
// special handling of events in listctrl
class ListHandler : public wxEvtHandler
{
public:
ListHandler(PoeditFrame *frame) :
wxEvtHandler(), m_frame(frame) {}
private:
void OnSel(wxListEvent& event) { m_frame->OnListSel(event); }
void OnRightClick(wxMouseEvent& event) { m_frame->OnListRightClick(event); }
void OnFocus(wxFocusEvent& event) { m_frame->OnListFocus(event); }
DECLARE_EVENT_TABLE()
PoeditFrame *m_frame;
};
BEGIN_EVENT_TABLE(ListHandler, wxEvtHandler)
EVT_LIST_ITEM_SELECTED (ID_LIST, ListHandler::OnSel)
EVT_RIGHT_DOWN ( ListHandler::OnRightClick)
EVT_SET_FOCUS ( ListHandler::OnFocus)
END_EVENT_TABLE()
class UnfocusableTextCtrl : public wxTextCtrl
{
public:
UnfocusableTextCtrl(wxWindow *parent,
wxWindowID winid,
const wxString &value = wxEmptyString,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString &name = wxTextCtrlNameStr)
: wxTextCtrl(parent, winid, value, pos, size, style, validator, name)
{
#ifdef __WXOSX__
NSScrollView *scroll = (NSScrollView*)GetHandle();
NSTextView *text = [scroll documentView];
[text setAutomaticQuoteSubstitutionEnabled:NO];
[text setAutomaticDashSubstitutionEnabled:NO];
#endif
}
virtual bool AcceptsFocus() const { return false; }
};
class TranslationTextCtrl : public wxTextCtrl
{
public:
TranslationTextCtrl(wxWindow *parent, wxWindowID winid)
: wxTextCtrl(parent, winid, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH2)
{
#ifdef __WXOSX__
NSScrollView *scroll = (NSScrollView*)GetHandle();
NSTextView *text = [scroll documentView];
[text setAutomaticQuoteSubstitutionEnabled:NO];
[text setAutomaticDashSubstitutionEnabled:NO];
#endif
}
};
BEGIN_EVENT_TABLE(PoeditFrame, wxFrame)
// OS X and GNOME apps should open new documents in a new window. On Windows,
// however, the usual thing to do is to open the new document in the already
// open window and replace the current document.
#ifdef __WXMSW__
EVT_MENU (wxID_NEW, PoeditFrame::OnNew)
EVT_MENU (XRCID("menu_new_from_pot"),PoeditFrame::OnNew)
EVT_MENU (wxID_OPEN, PoeditFrame::OnOpen)
#ifndef __WXOSX__
EVT_MENU_RANGE (wxID_FILE1, wxID_FILE9, PoeditFrame::OnOpenHist)
#endif
#endif // __WXMSW__
EVT_MENU (wxID_CLOSE, PoeditFrame::OnCloseCmd)
EVT_MENU (wxID_SAVE, PoeditFrame::OnSave)
EVT_MENU (wxID_SAVEAS, PoeditFrame::OnSaveAs)
EVT_MENU (XRCID("menu_export"), PoeditFrame::OnExport)
EVT_MENU (XRCID("menu_catproperties"), PoeditFrame::OnProperties)
EVT_MENU (XRCID("menu_update"), PoeditFrame::OnUpdate)
EVT_MENU (XRCID("menu_update_from_pot"),PoeditFrame::OnUpdate)
EVT_MENU (XRCID("menu_validate"), PoeditFrame::OnValidate)
EVT_MENU (XRCID("menu_purge_deleted"), PoeditFrame::OnPurgeDeleted)
EVT_MENU (XRCID("menu_fuzzy"), PoeditFrame::OnFuzzyFlag)
EVT_MENU (XRCID("menu_quotes"), PoeditFrame::OnQuotesFlag)
EVT_MENU (XRCID("menu_ids"), PoeditFrame::OnIDsFlag)
EVT_MENU (XRCID("menu_comment_win"), PoeditFrame::OnCommentWinFlag)
EVT_MENU (XRCID("menu_auto_comments_win"), PoeditFrame::OnAutoCommentsWinFlag)
EVT_MENU (XRCID("sort_by_order"), PoeditFrame::OnSortByFileOrder)
EVT_MENU (XRCID("sort_by_source"), PoeditFrame::OnSortBySource)
EVT_MENU (XRCID("sort_by_translation"), PoeditFrame::OnSortByTranslation)
EVT_MENU (XRCID("sort_untrans_first"), PoeditFrame::OnSortUntranslatedFirst)
EVT_MENU (XRCID("menu_copy_from_src"), PoeditFrame::OnCopyFromSource)
EVT_MENU (XRCID("menu_clear"), PoeditFrame::OnClearTranslation)
EVT_MENU (XRCID("menu_references"), PoeditFrame::OnReferencesMenu)
EVT_MENU (wxID_FIND, PoeditFrame::OnFind)
EVT_MENU (XRCID("menu_find_next"), PoeditFrame::OnFindNext)
EVT_MENU (XRCID("menu_find_prev"), PoeditFrame::OnFindPrev)
EVT_MENU (XRCID("menu_comment"), PoeditFrame::OnEditComment)
EVT_MENU (XRCID("go_done_and_next"), PoeditFrame::OnDoneAndNext)
EVT_MENU (XRCID("go_prev"), PoeditFrame::OnPrev)
EVT_MENU (XRCID("go_next"), PoeditFrame::OnNext)
EVT_MENU (XRCID("go_prev_page"), PoeditFrame::OnPrevPage)
EVT_MENU (XRCID("go_next_page"), PoeditFrame::OnNextPage)
EVT_MENU (XRCID("go_prev_unfinished"), PoeditFrame::OnPrevUnfinished)
EVT_MENU (XRCID("go_next_unfinished"), PoeditFrame::OnNextUnfinished)
EVT_MENU_RANGE (ID_POPUP_REFS, ID_POPUP_REFS + 999, PoeditFrame::OnReference)
EVT_MENU_RANGE (ID_POPUP_TRANS, ID_POPUP_TRANS + 999,
PoeditFrame::OnAutoTranslate)
EVT_MENU (XRCID("menu_auto_translate"), PoeditFrame::OnAutoTranslateAll)
EVT_MENU_RANGE (ID_BOOKMARK_GO, ID_BOOKMARK_GO + 9,
PoeditFrame::OnGoToBookmark)
EVT_MENU_RANGE (ID_BOOKMARK_SET, ID_BOOKMARK_SET + 9,
PoeditFrame::OnSetBookmark)
EVT_CLOSE ( PoeditFrame::OnCloseWindow)
EVT_TEXT (ID_TEXTCOMMENT,PoeditFrame::OnCommentWindowText)
EVT_IDLE (PoeditFrame::OnIdle)
EVT_SIZE (PoeditFrame::OnSize)
END_EVENT_TABLE()
class PoeditDropTarget : public wxFileDropTarget
{
public:
PoeditDropTarget(PoeditFrame *win) : m_win(win) {}
virtual bool OnDropFiles(wxCoord /*x*/, wxCoord /*y*/,
const wxArrayString& files)
{
if ( files.size() != 1 )
{
wxLogError(_("You can't drop more than one file on Poedit window."));
return false;
}
wxFileName f(files[0]);
if ( f.GetExt().Lower() != "po" )
{
wxLogError(_("File '%s' is not a message catalog."),
f.GetFullPath().c_str());
return false;
}
if ( !f.FileExists() )
{
wxLogError(_("File '%s' doesn't exist."), f.GetFullPath().c_str());
return false;
}
m_win->OpenFile(f.GetFullPath());
return true;
}
private:
PoeditFrame *m_win;
};
// Frame class:
PoeditFrame::PoeditFrame() :
wxFrame(NULL, -1, _("Poedit"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE,
"mainwin"),
m_contentType(Content::Invalid),
m_contentView(nullptr),
m_catalog(nullptr),
m_fileExistsOnDisk(false),
m_list(nullptr),
m_modified(false),
m_hasObsoleteItems(false),
m_dontAutoclearFuzzyStatus(false),
m_setSashPositionsWhenMaximized(false)
{
m_list = nullptr;
m_textTrans = nullptr;
m_textOrig = nullptr;
m_textOrigPlural = nullptr;
m_textComment = nullptr;
m_textAutoComments = nullptr;
m_bottomSplitter = nullptr;
m_splitter = nullptr;
// make sure that the [ID_POEDIT_FIRST,ID_POEDIT_LAST] range of IDs is not
// used for anything else:
wxASSERT_MSG( wxGetCurrentId() < ID_POEDIT_FIRST ||
wxGetCurrentId() > ID_POEDIT_LAST,
"detected ID values conflict!" );
wxRegisterId(ID_POEDIT_LAST);
wxConfigBase *cfg = wxConfig::Get();
m_displayQuotes = (bool)cfg->Read("display_quotes", (long)false);
m_displayIDs = (bool)cfg->Read("display_lines", (long)false);
m_displayCommentWin =
(bool)cfg->Read("display_comment_win", (long)false);
m_displayAutoCommentsWin =
(bool)cfg->Read("display_auto_comments_win", (long)true);
m_commentWindowEditable =
(bool)cfg->Read("comment_window_editable", (long)false);
g_focusToText = (bool)cfg->Read("focus_to_text", (long)false);
#if defined(__WXGTK__)
wxIconBundle appicons;
appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(16,16)));
appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(32,32)));
appicons.AddIcon(wxArtProvider::GetIcon("poedit", wxART_FRAME_ICON, wxSize(48,48)));
SetIcons(appicons);
#elif defined(__WXMSW__)
SetIcon(wxICON(appicon));
#endif
// This is different from the default, because it's a bit smaller on OS X
m_normalGuiFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
m_boldGuiFont = m_normalGuiFont;
m_boldGuiFont.SetWeight(wxFONTWEIGHT_BOLD);
wxMenuBar *MenuBar = wxXmlResource::Get()->LoadMenuBar("mainmenu");
if (MenuBar)
{
#ifndef __WXOSX__
wxString menuName(_("&File"));
menuName.Replace(wxT("&"), wxEmptyString);
m_menuForHistory = MenuBar->GetMenu(MenuBar->FindMenu(menuName));
FileHistory().UseMenu(m_menuForHistory);
FileHistory().AddFilesToMenu(m_menuForHistory);
#endif
SetMenuBar(MenuBar);
AddBookmarksMenu(MenuBar->GetMenu(MenuBar->FindMenu(_("&Go"))));
#ifdef __WXOSX__
wxGetApp().TweakOSXMenuBar(MenuBar);
#endif
}
else
{
wxLogError("Cannot load main menu from resource, something must have went terribly wrong.");
wxLog::FlushActive();
return;
}
wxXmlResource::Get()->LoadToolBar(this, "toolbar");
GetMenuBar()->Check(XRCID("menu_quotes"), m_displayQuotes);
GetMenuBar()->Check(XRCID("menu_ids"), m_displayIDs);
GetMenuBar()->Check(XRCID("menu_comment_win"), m_displayCommentWin);
GetMenuBar()->Check(XRCID("menu_auto_comments_win"), m_displayAutoCommentsWin);
CreateStatusBar(1, wxST_SIZEGRIP);
m_contentWrappingSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(m_contentWrappingSizer);
m_attentionBar = new AttentionBar(this);
m_contentWrappingSizer->Add(m_attentionBar, wxSizerFlags().Expand());
SetAccelerators();
RestoreWindowState(this, wxSize(980, 700), WinState_Size | WinState_Pos);
UpdateMenu();
ms_instances.Append(this);
SetDropTarget(new PoeditDropTarget(this));
#ifdef __WXOSX__
NSWindow *wnd = (NSWindow*)GetWXWindow();
[wnd setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
#endif
}
void PoeditFrame::EnsureContentView(Content type)
{
if (m_contentType == type)
return;
#ifdef __WXMSW__
wxWindowUpdateLocker no_updates(this);
#endif
if (m_contentView)
DestroyContentView();
switch (type)
{
case Content::Invalid:
m_contentType = Content::Invalid;
return; // nothing to do
case Content::Welcome:
m_contentView = CreateContentViewWelcome();
break;
case Content::Empty_PO:
m_contentView = CreateContentViewEmptyPO();
break;
case Content::PO:
m_contentView = CreateContentViewPO();
break;
}
m_contentType = type;
m_contentWrappingSizer->Add(m_contentView, wxSizerFlags(1).Expand());
Layout();
#ifdef __WXMSW__
m_contentView->Show();
Layout();
#endif
}
wxWindow* PoeditFrame::CreateContentViewPO()
{
#if defined(__WXMSW__)
const int SPLITTER_FLAGS = wxSP_NOBORDER;
#elif defined(__WXMAC__)
// wxMac doesn't show XORed line:
const int SPLITTER_FLAGS = wxSP_LIVE_UPDATE;
#else
const int SPLITTER_FLAGS = wxSP_3DBORDER;
#endif
m_splitter = new wxSplitterWindow(this, -1,
wxDefaultPosition, wxDefaultSize,
SPLITTER_FLAGS);
#ifdef __WXMSW__
// don't create the window as shown, avoid flicker
m_splitter->Hide();
#endif
// make only the upper part grow when resizing
m_splitter->SetSashGravity(1.0);
wxPanel *topPanel = new wxPanel(m_splitter, wxID_ANY);
m_list = new PoeditListCtrl(topPanel,
ID_LIST,
wxDefaultPosition, wxDefaultSize,
wxLC_REPORT | wxLC_SINGLE_SEL,
m_displayIDs);
wxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(m_list, wxSizerFlags(1).Expand());
topPanel->SetSizer(topSizer);
m_bottomSplitter = new wxSplitterWindow(m_splitter, -1,
wxDefaultPosition, wxDefaultSize,
SPLITTER_FLAGS);
// left part (translation) should grow, not comments one:
m_bottomSplitter->SetSashGravity(1.0);
m_bottomLeftPanel = new wxPanel(m_bottomSplitter);
m_bottomRightPanel = new wxPanel(m_bottomSplitter);
wxStaticText *labelSource =
new wxStaticText(m_bottomLeftPanel, -1, _("Source text:"));
labelSource->SetFont(m_boldGuiFont);
m_labelContext = new wxStaticText(m_bottomLeftPanel, -1, wxEmptyString);
m_labelContext->SetFont(m_normalGuiFont);
m_labelContext->Hide();
m_labelSingular = new wxStaticText(m_bottomLeftPanel, -1, _("Singular:"));
m_labelSingular->SetFont(m_normalGuiFont);
m_textOrig = new UnfocusableTextCtrl(m_bottomLeftPanel,
ID_TEXTORIG, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH2 | wxTE_READONLY);
m_labelPlural = new wxStaticText(m_bottomLeftPanel, -1, _("Plural:"));
m_labelPlural->SetFont(m_normalGuiFont);
m_textOrigPlural = new UnfocusableTextCtrl(m_bottomLeftPanel,
ID_TEXTORIGPLURAL, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH2 | wxTE_READONLY);
wxStaticText *labelTrans =
new wxStaticText(m_bottomLeftPanel, -1, _("Translation:"));
labelTrans->SetFont(m_boldGuiFont);
m_textTrans = new TranslationTextCtrl(m_bottomLeftPanel, ID_TEXTTRANS);
m_textTrans->PushEventHandler(new TransTextctrlHandler(this));
// in case of plurals form, this is the control for n=1:
m_textTransSingularForm = NULL;
m_pluralNotebook = new wxNotebook(m_bottomLeftPanel, -1);
m_labelAutoComments = new wxStaticText(m_bottomRightPanel, -1, _("Notes for translators:"));
m_labelAutoComments->SetFont(m_boldGuiFont);
m_textAutoComments = new UnfocusableTextCtrl(m_bottomRightPanel,
ID_TEXTORIG, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH2 | wxTE_READONLY);
m_labelComment = new wxStaticText(m_bottomRightPanel, -1, _("Comment:"));
m_labelComment->SetFont(m_boldGuiFont);
m_textComment = NULL;
// This call will force the creation of the right kind of control
// for the m_textComment member
UpdateCommentWindowEditable();
m_errorBar = new ErrorBar(m_bottomLeftPanel);
SetCustomFonts();
wxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *rightSizer = new wxBoxSizer(wxVERTICAL);
wxFlexGridSizer *gridSizer = new wxFlexGridSizer(2);
gridSizer->AddGrowableCol(1);
gridSizer->AddGrowableRow(0);
gridSizer->AddGrowableRow(1);
gridSizer->Add(m_labelSingular, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
gridSizer->Add(m_textOrig, 1, wxEXPAND);
gridSizer->Add(m_labelPlural, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
gridSizer->Add(m_textOrigPlural, 1, wxEXPAND);
gridSizer->SetItemMinSize(m_textOrig, 1, 1);
gridSizer->SetItemMinSize(m_textOrigPlural, 1, 1);
leftSizer->Add(m_labelContext, 0, wxEXPAND | wxALL, 3);
leftSizer->Add(labelSource, 0, wxEXPAND | wxALL, 3);
leftSizer->Add(gridSizer, 1, wxEXPAND);
leftSizer->Add(labelTrans, 0, wxEXPAND | wxALL, 3);
leftSizer->Add(m_textTrans, 1, wxEXPAND);
leftSizer->Add(m_pluralNotebook, 1, wxEXPAND);
leftSizer->Add(m_errorBar, 0, wxEXPAND | wxALL, 2);
rightSizer->Add(m_labelAutoComments, 0, wxEXPAND | wxALL, 3);
rightSizer->Add(m_textAutoComments, 1, wxEXPAND);
rightSizer->Add(m_labelComment, 0, wxEXPAND | wxALL, 3);
rightSizer->Add(m_textComment, 1, wxEXPAND);
m_bottomLeftPanel->SetAutoLayout(true);
m_bottomLeftPanel->SetSizer(leftSizer);
m_bottomRightPanel->SetAutoLayout(true);
m_bottomRightPanel->SetSizer(rightSizer);
m_bottomSplitter->SetMinimumPaneSize(250);
m_bottomRightPanel->Show(false);
m_bottomSplitter->Initialize(m_bottomLeftPanel);
m_splitter->SetMinimumPaneSize(200);
m_list->PushEventHandler(new ListHandler(this));
ShowPluralFormUI(false);
UpdateMenu();
switch ( m_list->sortOrder.by )
{
case SortOrder::By_FileOrder:
GetMenuBar()->Check(XRCID("sort_by_order"), true);
break;
case SortOrder::By_Source:
GetMenuBar()->Check(XRCID("sort_by_source"), true);
break;
case SortOrder::By_Translation:
GetMenuBar()->Check(XRCID("sort_by_translation"), true);
break;
}
GetMenuBar()->Check(XRCID("sort_untrans_first"), m_list->sortOrder.untransFirst);
// Call splitter splitting later, when the window is layed out, otherwise
// the sizes would get truncated immediately:
CallAfter([=]{
// This is a hack -- windows are not maximized immediately and so we can't
// set correct sash position in ctor (unmaximized window may be too small
// for sash position when maximized -- see bug #2120600)
if ( wxConfigBase::Get()->Read(WindowStatePath(this) + "maximized", long(0)) )
m_setSashPositionsWhenMaximized = true;
m_splitter->SplitHorizontally(topPanel, m_bottomSplitter, (int)wxConfigBase::Get()->Read("splitter", -250L));
UpdateDisplayCommentWin();
});
return m_splitter;
}
wxWindow* PoeditFrame::CreateContentViewWelcome()
{
return new WelcomeScreenPanel(this);
}
wxWindow* PoeditFrame::CreateContentViewEmptyPO()
{
return new EmptyPOScreenPanel(this);
}
void PoeditFrame::DestroyContentView()
{
if (!m_contentView)
return;
if (m_list)
m_list->PopEventHandler(true/*delete*/);
if (m_textTrans)
m_textTrans->PopEventHandler(true/*delete*/);
for (size_t i = 0; i < m_textTransPlural.size(); i++)
{
if (m_textTransPlural[i])
{
m_textTransPlural[i]->PopEventHandler(true/*delete*/);
m_textTransPlural[i] = nullptr;
}
}
if (m_textComment)
m_textComment->PopEventHandler(true/*delete*/);
if (m_list)
m_list->CatalogChanged(NULL);
if (m_bottomSplitter && (m_displayCommentWin || m_displayAutoCommentsWin))
{
wxConfigBase::Get()->Write("/bottom_splitter",
(long)m_bottomSplitter->GetSashPosition());
}
if (m_splitter)
wxConfigBase::Get()->Write("/splitter", (long)m_splitter->GetSashPosition());
m_contentWrappingSizer->Detach(m_contentView);
m_contentView->Destroy();
m_contentView = nullptr;
m_list = nullptr;
m_textTrans = nullptr;
m_textOrig = nullptr;
m_textOrigPlural = nullptr;
m_textComment = nullptr;
m_textAutoComments = nullptr;
m_bottomSplitter = nullptr;
m_splitter = nullptr;
}
PoeditFrame::~PoeditFrame()
{
ms_instances.DeleteObject(this);
DestroyContentView();
wxConfigBase *cfg = wxConfig::Get();
cfg->SetPath("/");
cfg->Write("display_quotes", m_displayQuotes);
cfg->Write("display_lines", m_displayIDs);
cfg->Write("display_comment_win", m_displayCommentWin);
cfg->Write("display_auto_comments_win", m_displayAutoCommentsWin);
SaveWindowState(this);
#ifndef __WXOSX__
FileHistory().RemoveMenu(m_menuForHistory);
FileHistory().Save(*cfg);
#endif
// write all changes:
cfg->Flush();
delete m_catalog;
m_catalog = NULL;
// shutdown the spellchecker:
InitSpellchecker();
}
void PoeditFrame::SetAccelerators()
{
wxAcceleratorEntry entries[] = {
#ifdef __WXMSW__
{ wxACCEL_CTRL, WXK_F3, XRCID("menu_find_next") },
{ wxACCEL_CTRL | wxACCEL_SHIFT, WXK_F3, XRCID("menu_find_prev") },
#endif
{ wxACCEL_CTRL, WXK_PAGEUP, XRCID("go_prev_page") },
{ wxACCEL_CTRL, WXK_NUMPAD_PAGEUP, XRCID("go_prev_page") },
{ wxACCEL_CTRL, WXK_PAGEDOWN, XRCID("go_next_page") },
{ wxACCEL_CTRL, WXK_NUMPAD_PAGEDOWN, XRCID("go_next_page") },
{ wxACCEL_CTRL, WXK_UP, XRCID("go_prev") },
{ wxACCEL_CTRL, WXK_NUMPAD_UP, XRCID("go_prev") },
{ wxACCEL_CTRL, WXK_DOWN, XRCID("go_next") },
{ wxACCEL_CTRL, WXK_NUMPAD_DOWN, XRCID("go_next") },
{ wxACCEL_CTRL, WXK_RETURN, XRCID("go_done_and_next") },
{ wxACCEL_CTRL, WXK_NUMPAD_ENTER, XRCID("go_done_and_next") }
};
wxAcceleratorTable accel(WXSIZEOF(entries), entries);
SetAcceleratorTable(accel);
}
#ifdef USE_SPELLCHECKING
#ifdef __WXGTK__
// helper functions that finds GtkTextView of wxTextCtrl:
static GtkTextView *GetTextView(wxTextCtrl *ctrl)
{
GtkWidget *parent = ctrl->m_widget;
GList *child = gtk_container_get_children(GTK_CONTAINER(parent));
while (child)
{
if (GTK_IS_TEXT_VIEW(child->data))
{
return GTK_TEXT_VIEW(child->data);
}
child = child->next;
}
wxFAIL_MSG( "couldn't find GtkTextView for text control" );
return NULL;
}
#if GTK_CHECK_VERSION(3,0,0)
static bool DoInitSpellchecker(wxTextCtrl *text,
bool enable, const Language& lang)
{
GtkTextView *textview = GetTextView(text);
wxASSERT_MSG( textview, "wxTextCtrl is supposed to use GtkTextView" );
GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview);
if (enable)
{
if (!spell)
{
spell = gtk_spell_checker_new();
gtk_spell_checker_attach(spell, textview);
}
return gtk_spell_checker_set_language(spell, lang.Code().c_str(), nullptr);
}
else
{
if (spell)
gtk_spell_checker_detach(spell);
return true;
}
}
#else // GTK+ 2.x
static bool DoInitSpellchecker(wxTextCtrl *text,
bool enable, const Language& lang)
{
GtkTextView *textview = GetTextView(text);
wxASSERT_MSG( textview, "wxTextCtrl is supposed to use GtkTextView" );
GtkSpell *spell = gtkspell_get_from_text_view(textview);
GError *err = NULL;
if (enable)
{