Skip to content

Commit

Permalink
add option to make comment window editable; misc fixes to comment win…
Browse files Browse the repository at this point in the history
…dow code (both Olivier Sannier)
  • Loading branch information
vslavik committed Jan 25, 2004
1 parent 8125079 commit da4372c
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 56 deletions.
3 changes: 3 additions & 0 deletions poedit/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Version 1.2.5
- fixed bug in displaying list entries in ANSI build introduced in 1.2.4
- fixed opening of source files specified using absolute path
- poEdit now preserves fuzzy status if set after partially editing an entry
- many fixes to comment window (Olivier Sannier)
- comment window is now (optionally) editable (Olivier Sannier)
- fixed preferences dialog if translation memory is not used (Olivier Sannier)
- added Mongolian translation (Mendbayar Bayar, Khurelbaatar Lkhagvasuren)


Expand Down
34 changes: 22 additions & 12 deletions poedit/src/commentdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,14 @@ CommentDialog::CommentDialog(wxWindow *parent, const wxString& comment) : wxDial
{
wxXmlResource::Get()->LoadDialog(this, parent, _T("comment_dlg"));
m_text = XRCCTRL(*this, "comment", wxTextCtrl);

wxString txt;
wxStringTokenizer tkn(comment, _T("\n\r"));
while (tkn.HasMoreTokens())
txt << tkn.GetNextToken().Mid(2)/* "# " */ << _T("\n");
m_text->SetValue(txt);

m_text->SetValue(RemoveStartHash(comment));
}

wxString CommentDialog::GetComment() const
{
wxString txt, txt2;
txt = m_text->GetValue();
wxStringTokenizer tkn(txt, _T("\n\r"));
while (tkn.HasMoreTokens())
txt2 << _T("# ") << tkn.GetNextToken() << _T("\n");
return txt2;
// Put the start hash back
return AddStartHash(m_text->GetValue());
}

BEGIN_EVENT_TABLE(CommentDialog, wxDialog)
Expand All @@ -58,3 +50,21 @@ void CommentDialog::OnClear(wxCommandEvent& event)
m_text->Clear();
}


/*static*/ wxString CommentDialog::RemoveStartHash(const wxString& comment)
{
wxString tmpComment;
wxStringTokenizer tkn(comment, _T("\n\r"));
while (tkn.HasMoreTokens())
tmpComment << tkn.GetNextToken().Mid(2) << _T("\n");
return tmpComment;
}

/*static*/ wxString CommentDialog::AddStartHash(const wxString& comment)
{
wxString tmpComment;
wxStringTokenizer tkn(comment, _T("\n\r"));
while (tkn.HasMoreTokens())
tmpComment << _T("# ") << tkn.GetNextToken() << _T("\n");
return tmpComment;
}
8 changes: 7 additions & 1 deletion poedit/src/commentdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
A trivial dialog for editing comments
(c) Vaclav Slavik, 2001
(c) Vaclav Slavik, 2001-2004
*/

Expand All @@ -31,6 +31,12 @@ class WXDLLEXPORT wxTextCtrl;
class CommentDialog : public wxDialog
{
public:
/// Returns the given comment without the leading "# "
static wxString RemoveStartHash(const wxString& comment);

/// Returns the given comment with the leading "# " added
static wxString AddStartHash(const wxString& comment);

/** Ctor.
\param parent Parent frame, FindFrame will float on it
\param comment Initial value of comment
Expand Down
148 changes: 110 additions & 38 deletions poedit/src/edframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ enum
EDC_LIST = 1000,
EDC_TEXTORIG,
EDC_TEXTTRANS,
EDC_TEXTCOMMENT,
EDC_TEXTCOMMENT,

ED_POPUP_REFS = 2000,
ED_POPUP_TRANS = 3000,
Expand Down Expand Up @@ -217,14 +217,14 @@ class ListHandler : public wxEvtHandler
void OnActivated(wxListEvent& event)
{
if (gs_focusToText)
m_text->SetFocus();
else
event.Skip();
m_text->SetFocus();
else
event.Skip();
}

void OnListSel(wxListEvent& event)
{
*m_sel = event.GetIndex();
*m_sel = event.GetIndex();
*m_selItem = ((wxListCtrl*)event.GetEventObject())->GetItemData(*m_sel);
event.Skip();
}
Expand Down Expand Up @@ -254,8 +254,8 @@ class ListHandler : public wxEvtHandler
{
if (gs_focusToText)
m_text->SetFocus();
else
event.Skip();
else
event.Skip();
}

DECLARE_EVENT_TABLE()
Expand Down Expand Up @@ -414,6 +414,7 @@ BEGIN_EVENT_TABLE(poEditFrame, wxFrame)
EVT_LIST_ITEM_DESELECTED
(EDC_LIST, poEditFrame::OnListDesel)
EVT_CLOSE ( poEditFrame::OnCloseWindow)
EVT_TEXT (EDC_TEXTCOMMENT,poEditFrame::OnCommentWindowText)
#ifdef __WXMSW__
EVT_DROP_FILES (poEditFrame::OnFileDrop)
#endif
Expand Down Expand Up @@ -454,7 +455,10 @@ poEditFrame::poEditFrame() :

m_displayQuotes = (bool)cfg->Read(_T("display_quotes"), (long)false);
m_displayLines = (bool)cfg->Read(_T("display_lines"), (long)false);
m_displayCommentWin = (bool)cfg->Read(_T("display_comment_win"), (long)false);
m_displayCommentWin =
(bool)cfg->Read(_T("display_comment_win"), (long)true);
m_commentWindowEditable =
(bool)cfg->Read(_T("comment_window_editable"), (long)false);
gs_focusToText = (bool)cfg->Read(_T("focus_to_text"), (long)false);
gs_shadedList = (bool)cfg->Read(_T("shaded_list"), (long)true);

Expand Down Expand Up @@ -499,13 +503,12 @@ poEditFrame::poEditFrame() :
wxLC_REPORT | wxLC_SINGLE_SEL,
m_displayLines);

m_bottomSplitter = new wxSplitterWindow(m_splitter, -1);
m_bottomLeftPanel = new wxPanel(m_bottomSplitter);
m_bottomSplitter = new wxSplitterWindow(m_splitter, -1);
m_bottomLeftPanel = new wxPanel(m_bottomSplitter);

m_textComment = new UnfocusableTextCtrl(m_bottomSplitter,
EDC_TEXTCOMMENT, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY);
m_textComment = NULL;
// create the control:
UpdateCommentWindowEditable();

m_textOrig = new UnfocusableTextCtrl(m_bottomLeftPanel,
EDC_TEXTORIG, wxEmptyString,
Expand All @@ -519,7 +522,7 @@ poEditFrame::poEditFrame() :
SetCustomFonts();

wxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
leftSizer->Add(m_textOrig, 1, wxEXPAND);
leftSizer->Add(m_textOrig, 1, wxEXPAND);
leftSizer->Add(m_textTrans, 1, wxEXPAND);

m_bottomLeftPanel->SetAutoLayout(true);
Expand Down Expand Up @@ -553,8 +556,8 @@ poEditFrame::poEditFrame() :
m_statusGauge = new wxGauge(bar, -1, 100, wxDefaultPosition, wxDefaultSize, wxGA_SMOOTH);
bar->SetStatusWidths(2, widths);
bar->PushEventHandler(new StatusbarHandler(bar, m_statusGauge));
#ifdef __WXMSW__
bar->SetSize(-1,-1,-1,-1);
#ifdef __WXMSW__
bar->SetSize(-1,-1,-1,-1);
#endif

UpdateMenu();
Expand Down Expand Up @@ -722,7 +725,7 @@ void poEditFrame::OnOpen(wxCommandEvent&)
wxString path = wxPathOnly(m_fileName);
if (path.empty())
path = wxConfig::Get()->Read(_T("last_file_path"), wxEmptyString);
wxString name = wxFileSelector(_("Open catalog"),
path, wxEmptyString, wxEmptyString,
_("GNU GetText catalogs (*.po)|*.po|All files (*.*)|*.*"),
Expand Down Expand Up @@ -967,6 +970,7 @@ void poEditFrame::OnPreferences(wxCommandEvent&)
gs_focusToText = (bool)wxConfig::Get()->Read(_T("focus_to_text"),
(long)false);
SetCustomFonts();
UpdateCommentWindowEditable();
}
}

Expand Down Expand Up @@ -1087,8 +1091,8 @@ void poEditFrame::ShowReference(int num)
else
path = wxPathOnly(m_fileName) + _T("/") + m_catalog->Header().BasePath;

if (path.Last() == _T('/') || path.Last() == _T('\\'))
path.RemoveLast();
if (path.Last() == _T('/') || path.Last() == _T('\\'))
path.RemoveLast();

if (wxIsAbsolutePath(path))
basepath = path;
Expand Down Expand Up @@ -1156,23 +1160,7 @@ void poEditFrame::OnLinesFlag(wxCommandEvent& event)

void poEditFrame::OnCommentWinFlag(wxCommandEvent& event)
{
m_displayCommentWin = GetMenuBar()->IsChecked(XRCID("menu_comment_win"));
if (m_displayCommentWin)
{
m_bottomSplitter->SplitVertically(
m_bottomLeftPanel, m_textComment,
wxConfig::Get()->Read(_T("bottom_splitter"), -200L));
m_textComment->Show(true);
}
else
{
wxConfig::Get()->Write(_T("bottom_splitter"),
(long)m_bottomSplitter->GetSashPosition());
m_textComment->Show(false);
m_bottomSplitter->Unsplit();
}
m_list->SetDisplayLines(m_displayLines);
RefreshControls();
UpdateDisplayCommentWin();
}


Expand Down Expand Up @@ -1374,7 +1362,11 @@ void poEditFrame::UpdateToTextCtrl(int item)
t_c.Replace(_T("\\n"), _T("\\n\n"));
t_t = quote + (*m_catalog)[ind].GetTranslation() + quote;
t_t.Replace(_T("\\n"), _T("\\n\n"));


// remove "# " in front of every comment line
t_c = CommentDialog::RemoveStartHash(t_c);


#if !wxUSE_UNICODE
// Convert from UTF-8 to environment's default charset:
t_o = convertToLocalCharset(t_o);
Expand Down Expand Up @@ -1582,6 +1574,8 @@ void poEditFrame::UpdateMenu()
GetMenuBar()->EnableTop(1, false);
GetMenuBar()->EnableTop(2, false);
m_textTrans->Enable(false);
m_textOrig->Enable(false);
m_textComment->Enable(false);
m_list->Enable(false);
}
else
Expand All @@ -1595,6 +1589,8 @@ void poEditFrame::UpdateMenu()
GetMenuBar()->EnableTop(1, true);
GetMenuBar()->EnableTop(2, true);
m_textTrans->Enable(true);
m_textOrig->Enable(true);
m_textComment->Enable(true);
m_list->Enable(true);
bool doupdate = m_catalog->Header().SearchPaths.GetCount() > 0;
GetToolBar()->EnableTool(XRCID("menu_update"), doupdate);
Expand Down Expand Up @@ -1661,6 +1657,9 @@ void poEditFrame::OnEditComment(wxCommandEvent& event)
int icon = GetItemIcon((*m_catalog)[m_selItem]);
m_list->SetItemImage(listitem, icon, icon);
m_list->SetItem(listitem);

// update comment window
m_textComment->SetValue(CommentDialog::RemoveStartHash(comment));
}
}

Expand Down Expand Up @@ -1858,3 +1857,76 @@ void poEditFrame::SetCustomFonts()
}
}
}

void poEditFrame::UpdateCommentWindowEditable()
{
wxConfigBase *cfg = wxConfig::Get();
bool commentWindowEditable =
(bool)cfg->Read(_T("comment_window_editable"), (long)false);
if (m_textComment == NULL ||
commentWindowEditable != m_commentWindowEditable)
{
m_commentWindowEditable = commentWindowEditable;
m_bottomSplitter->Unsplit();
delete m_textComment;
if (m_commentWindowEditable)
{
m_textComment = new wxTextCtrl(m_bottomSplitter,
EDC_TEXTCOMMENT, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE);
}
else
{
m_textComment = new UnfocusableTextCtrl(m_bottomSplitter,
EDC_TEXTCOMMENT, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY);
}
UpdateDisplayCommentWin();
}
}

void poEditFrame::UpdateDisplayCommentWin()
{
m_displayCommentWin = GetMenuBar()->IsChecked(XRCID("menu_comment_win"));
if (m_displayCommentWin)
{
m_bottomSplitter->SplitVertically(
m_bottomLeftPanel, m_textComment,
wxConfig::Get()->Read(_T("bottom_splitter"), -200L));
m_textComment->Show(true);
}
else
{
wxConfig::Get()->Write(_T("bottom_splitter"),
(long)m_bottomSplitter->GetSashPosition());
m_textComment->Show(false);
m_bottomSplitter->Unsplit();
}
m_list->SetDisplayLines(m_displayLines);
RefreshControls();
}

void poEditFrame::OnCommentWindowText(wxCommandEvent&)
{
wxString comment;
comment = convertFromLocalCharset(
CommentDialog::AddStartHash(m_textComment->GetValue()));
CatalogData& data((*m_catalog)[m_selItem]);

data.SetComment(comment);

wxListItem listitem;
listitem.SetId(m_sel);
m_list->GetItem(listitem);
int icon = GetItemIcon((*m_catalog)[m_selItem]);
m_list->SetItemImage(listitem, icon, icon);
m_list->SetItem(listitem);

if (m_modified == false)
{
m_modified = true;
UpdateTitle();
}
}
7 changes: 7 additions & 0 deletions poedit/src/edframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class poEditFrame : public wxFrame
/// Updates menu -- disables and enables items.
void UpdateMenu();

/// Updates the editable nature of the comment window
void UpdateCommentWindowEditable();

/// Returns popup menu for given catalog entry.
wxMenu *GetPopupMenu(size_t item);

Expand Down Expand Up @@ -159,6 +162,7 @@ class poEditFrame : public wxFrame
void OnFind(wxCommandEvent& event);
void OnEditComment(wxCommandEvent& event);
void OnManager(wxCommandEvent& event);
void OnCommentWindowText(wxCommandEvent& event);
#ifdef USE_TRANSMEM
void OnAutoTranslate(wxCommandEvent& event);
void OnAutoTranslateAll(wxCommandEvent& event);
Expand All @@ -167,10 +171,13 @@ class poEditFrame : public wxFrame

void OnExport(wxCommandEvent& event);
bool ExportCatalog(const wxString& filename);

void UpdateDisplayCommentWin();

DECLARE_EVENT_TABLE()

private:
bool m_commentWindowEditable;
Catalog *m_catalog;
wxString m_fileName;

Expand Down
Loading

0 comments on commit da4372c

Please sign in to comment.