Kaydet (Commit) 85fc36b9 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ManageLanguageDialog

Change-Id: I03dfa49f4a8b269408d9037feb9c5c984f6c3c52
Reviewed-on: https://gerrit.libreoffice.org/67511
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst cb22fb0c
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <com/sun/star/i18n/Boundary.hpp> #include <com/sun/star/i18n/Boundary.hpp>
#include <com/sun/star/i18n/WordType.hpp> #include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp> #include <com/sun/star/i18n/XBreakIterator.hpp>
#include <comphelper/sequence.hxx>
#include <editeng/unolingu.hxx> #include <editeng/unolingu.hxx>
#include <sfx2/bindings.hxx> #include <sfx2/bindings.hxx>
#include <svtools/langtab.hxx> #include <svtools/langtab.hxx>
...@@ -146,13 +147,13 @@ void ManageLanguageDialog::ClearLanguageBox() ...@@ -146,13 +147,13 @@ void ManageLanguageDialog::ClearLanguageBox()
IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, Button*, void) IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, Button*, void)
{ {
VclPtr< SetDefaultLanguageDialog > pDlg = VclPtr<SetDefaultLanguageDialog>::Create(this, m_xLocalizationMgr); std::shared_ptr<SetDefaultLanguageDialog> xDlg(new SetDefaultLanguageDialog(GetFrameWeld(), m_xLocalizationMgr));
pDlg->StartExecuteAsync([pDlg,this](sal_Int32 nResult) weld::DialogController::runAsync(xDlg, [xDlg,this](sal_Int32 nResult)
{ {
if (!nResult ) if (!nResult )
return; return;
// add new locales // add new locales
Sequence< Locale > aLocaleSeq = pDlg->GetLocales(); Sequence< Locale > aLocaleSeq = xDlg->GetLocales();
m_xLocalizationMgr->handleAddLocales( aLocaleSeq ); m_xLocalizationMgr->handleAddLocales( aLocaleSeq );
// update listbox // update listbox
ClearLanguageBox(); ClearLanguageBox();
...@@ -224,31 +225,34 @@ IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl, ListBox&, void) ...@@ -224,31 +225,34 @@ IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl, ListBox&, void)
// class SetDefaultLanguageDialog ----------------------------------------------- // class SetDefaultLanguageDialog -----------------------------------------------
SetDefaultLanguageDialog::SetDefaultLanguageDialog(vcl::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr) SetDefaultLanguageDialog::SetDefaultLanguageDialog(weld::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr)
: ModalDialog(pParent, "DefaultLanguageDialog", "modules/BasicIDE/ui/defaultlanguage.ui") : GenericDialogController(pParent, "modules/BasicIDE/ui/defaultlanguage.ui", "DefaultLanguageDialog")
, m_pCheckLangLB(nullptr)
, m_xLocalizationMgr(xLMgr) , m_xLocalizationMgr(xLMgr)
, m_xLanguageFT(m_xBuilder->weld_label("defaultlabel"))
, m_xLanguageLB(m_xBuilder->weld_tree_view("entries"))
, m_xCheckLangFT(m_xBuilder->weld_label("checkedlabel"))
, m_xCheckLangLB(m_xBuilder->weld_tree_view("checkedentries"))
, m_xDefinedFT(m_xBuilder->weld_label("defined"))
, m_xAddedFT(m_xBuilder->weld_label("added"))
, m_xAltTitle(m_xBuilder->weld_label("alttitle"))
, m_xLanguageCB(new LanguageBox(m_xBuilder->weld_combo_box("hidden")))
{ {
get(m_pLanguageLB, "entries"); m_xLanguageLB->set_size_request(-1, m_xLanguageLB->get_height_rows(10));
get(m_pCheckLangLB, "checkedentries"); m_xCheckLangLB->set_size_request(-1, m_xCheckLangLB->get_height_rows(10));
get(m_pDefinedFT, "defined"); std::vector<int> aWidths;
get(m_pAddedFT, "added"); aWidths.push_back(m_xCheckLangLB->get_approximate_digit_width() * 3 + 6);
get(m_pLanguageFT, "defaultlabel"); m_xCheckLangLB->set_column_fixed_widths(aWidths);
get(m_pCheckLangFT, "checkedlabel");
m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
m_pCheckLangLB->set_height_request(m_pCheckLangLB->GetTextHeight() * 10);
if (m_xLocalizationMgr->isLibraryLocalized()) if (m_xLocalizationMgr->isLibraryLocalized())
{ {
// change to "Add Interface Language" mode // change to "Add Interface Language" mode
m_pLanguageLB->Hide(); m_xLanguageLB->set_visible(false);
m_pCheckLangLB->Show(); m_xCheckLangLB->set_visible(true);
SetText(get<FixedText>("alttitle")->GetText()); m_xDialog->set_title(m_xAltTitle->get_label());
m_pLanguageFT->Hide(); m_xLanguageFT->set_visible(false);
m_pCheckLangFT->Show(); m_xCheckLangFT->set_visible(true);
m_pDefinedFT->Hide(); m_xDefinedFT->set_visible(false);
m_pAddedFT->Show(); m_xAddedFT->set_visible(true);
} }
FillLanguageBox(); FillLanguageBox();
...@@ -256,72 +260,73 @@ SetDefaultLanguageDialog::SetDefaultLanguageDialog(vcl::Window* pParent, std::sh ...@@ -256,72 +260,73 @@ SetDefaultLanguageDialog::SetDefaultLanguageDialog(vcl::Window* pParent, std::sh
SetDefaultLanguageDialog::~SetDefaultLanguageDialog() SetDefaultLanguageDialog::~SetDefaultLanguageDialog()
{ {
disposeOnce();
}
void SetDefaultLanguageDialog::dispose()
{
m_pLanguageFT.clear();
m_pLanguageLB.clear();
m_pCheckLangFT.clear();
m_pCheckLangLB.clear();
m_pDefinedFT.clear();
m_pAddedFT.clear();
ModalDialog::dispose();
} }
void SetDefaultLanguageDialog::FillLanguageBox() void SetDefaultLanguageDialog::FillLanguageBox()
{ {
// fill list with all languages // fill list with all languages
m_pLanguageLB->SetLanguageList( SvxLanguageListFlags::ALL, false ); m_xLanguageCB->SetLanguageList(SvxLanguageListFlags::ALL, false);
if ( m_xLocalizationMgr->isLibraryLocalized() ) if (m_xLocalizationMgr->isLibraryLocalized())
{ {
// remove the already localized languages // remove the already localized languages
Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales(); Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
const Locale* pLocale = aLocaleSeq.getConstArray(); const Locale* pLocale = aLocaleSeq.getConstArray();
const sal_Int32 nCountLoc = aLocaleSeq.getLength(); const sal_Int32 nCountLoc = aLocaleSeq.getLength();
for ( sal_Int32 i = 0; i < nCountLoc; ++i ) for ( sal_Int32 i = 0; i < nCountLoc; ++i )
m_pLanguageLB->RemoveLanguage( LanguageTag::convertToLanguageType( pLocale[i] ) ); m_xLanguageCB->remove_id(LanguageTag::convertToLanguageType(pLocale[i]));
// fill checklistbox if not in default mode // fill checklistbox if not in default mode
const sal_Int32 nCountLang = m_pLanguageLB->GetEntryCount(); const sal_Int32 nCountLang = m_xLanguageCB->get_count();
for ( sal_Int32 j = 0; j < nCountLang; ++j ) for (sal_Int32 j = 0; j < nCountLang; ++j)
{ {
m_pCheckLangLB->InsertEntry( LanguageType eLang = m_xLanguageCB->get_id(j);
m_pLanguageLB->GetEntry(j), LISTBOX_APPEND, m_pLanguageLB->GetEntryData(j) ); m_xCheckLangLB->insert(nullptr, -1, nullptr, nullptr, nullptr,
nullptr, nullptr, false);
const int nRow = m_xCheckLangLB->n_children() - 1;
m_xCheckLangLB->set_toggle(nRow, false, 0);
m_xCheckLangLB->set_text(nRow, m_xLanguageCB->get_text(j), 1);
m_xCheckLangLB->set_id(nRow, OUString::number(eLang.get()));
} }
m_pLanguageLB = nullptr; m_xLanguageCB.reset();
m_xLanguageLB.reset();
} }
else else
{
const sal_Int32 nCountLang = m_xLanguageCB->get_count();
for (sal_Int32 j = 0; j < nCountLang; ++j)
{
LanguageType eLang = m_xLanguageCB->get_id(j);
m_xLanguageLB->append(OUString::number(eLang.get()), m_xLanguageCB->get_text(j));
}
m_xLanguageCB.reset();
// preselect current UI language // preselect current UI language
m_pLanguageLB->SelectLanguage( Application::GetSettings().GetUILanguageTag().getLanguageType() ); m_xLanguageLB->select_id(OUString::number(Application::GetSettings().GetUILanguageTag().getLanguageType().get()));
}
} }
Sequence< Locale > SetDefaultLanguageDialog::GetLocales() const Sequence< Locale > SetDefaultLanguageDialog::GetLocales() const
{ {
bool bNotLocalized = !m_xLocalizationMgr->isLibraryLocalized(); bool bNotLocalized = !m_xLocalizationMgr->isLibraryLocalized();
sal_Int32 nSize = bNotLocalized ? 1 : m_pCheckLangLB->GetCheckedEntryCount(); if (bNotLocalized)
Sequence< Locale > aLocaleSeq( nSize );
if ( bNotLocalized )
{ {
aLocaleSeq[0] = LanguageTag( m_pLanguageLB->GetSelectedLanguage() ).getLocale(); LanguageType eType = LanguageType(m_xLanguageLB->get_selected_id().toUInt32());
Sequence<Locale> aLocaleSeq(1);
aLocaleSeq[0] = LanguageTag(eType).getLocale();
return aLocaleSeq;
} }
else std::vector<Locale> aLocaleSeq;
const sal_Int32 nCount = m_xCheckLangLB->n_children();
for (sal_Int32 i = 0; i < nCount; ++i)
{ {
const sal_Int32 nCount = m_pCheckLangLB->GetEntryCount(); if (m_xCheckLangLB->get_toggle(i, 0))
sal_Int32 j = 0;
for ( sal_Int32 i = 0; i < nCount; ++i )
{ {
if ( m_pCheckLangLB->IsChecked(i) ) LanguageType eType = LanguageType(m_xCheckLangLB->get_id(i).toUInt32());
{ aLocaleSeq.push_back(LanguageTag::convertToLocale(eType));
LanguageType eType = LanguageType( reinterpret_cast<sal_uLong>(m_pCheckLangLB->GetEntryData(i)) );
aLocaleSeq[j++] = LanguageTag::convertToLocale( eType );
}
} }
DBG_ASSERT( nSize == j, "SetDefaultLanguageDialog::GetLocales(): invalid indexes" );
} }
return aLocaleSeq; return comphelper::containerToSequence(aLocaleSeq);
} }
} // namespace basctl } // namespace basctl
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <vcl/dialog.hxx> #include <vcl/dialog.hxx>
#include <vcl/fixed.hxx> #include <vcl/fixed.hxx>
class SvxLanguageBox; class LanguageBox;
namespace basctl namespace basctl
{ {
...@@ -74,24 +74,25 @@ public: ...@@ -74,24 +74,25 @@ public:
virtual void dispose() override; virtual void dispose() override;
}; };
class SetDefaultLanguageDialog : public ModalDialog class SetDefaultLanguageDialog : public weld::GenericDialogController
{ {
private: private:
VclPtr<FixedText> m_pLanguageFT;
VclPtr<SvxLanguageBox> m_pLanguageLB;
VclPtr<FixedText> m_pCheckLangFT;
VclPtr<SvxCheckListBox> m_pCheckLangLB;
VclPtr<FixedText> m_pDefinedFT;
VclPtr<FixedText> m_pAddedFT;
std::shared_ptr<LocalizationMgr> m_xLocalizationMgr; std::shared_ptr<LocalizationMgr> m_xLocalizationMgr;
void FillLanguageBox(); void FillLanguageBox();
std::unique_ptr<weld::Label> m_xLanguageFT;
std::unique_ptr<weld::TreeView> m_xLanguageLB;
std::unique_ptr<weld::Label> m_xCheckLangFT;
std::unique_ptr<weld::TreeView> m_xCheckLangLB;
std::unique_ptr<weld::Label> m_xDefinedFT;
std::unique_ptr<weld::Label> m_xAddedFT;
std::unique_ptr<weld::Label> m_xAltTitle;
std::unique_ptr<::LanguageBox> m_xLanguageCB;
public: public:
SetDefaultLanguageDialog(vcl::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr); SetDefaultLanguageDialog(weld::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr);
virtual ~SetDefaultLanguageDialog() override; virtual ~SetDefaultLanguageDialog() override;
virtual void dispose() override;
css::uno::Sequence< css::lang::Locale > GetLocales() const; css::uno::Sequence< css::lang::Locale > GetLocales() const;
}; };
......
...@@ -174,10 +174,13 @@ public: ...@@ -174,10 +174,13 @@ public:
bool get_visible() const { return m_xControl->get_visible(); } bool get_visible() const { return m_xControl->get_visible(); }
LanguageType get_active_id() const; LanguageType get_active_id() const;
int find_id(const LanguageType eLangType) const; int find_id(const LanguageType eLangType) const;
LanguageType get_id(int nPos) const;
void set_id(int nPos, const LanguageType eLangType); void set_id(int nPos, const LanguageType eLangType);
void remove_id(const LanguageType eLangType); void remove_id(const LanguageType eLangType);
void append(const LanguageType eLangType, const OUString& rStr); void append(const LanguageType eLangType, const OUString& rStr);
int find_text(const OUString& rStr) const { return m_xControl->find_text(rStr); } int find_text(const OUString& rStr) const { return m_xControl->find_text(rStr); }
OUString get_text(int nPos) const { return m_xControl->get_text(nPos); }
int get_count() const { return m_xControl->get_count(); }
const weld::ComboBox* get_widget() const { return m_xControl.get(); } const weld::ComboBox* get_widget() const { return m_xControl.get(); }
}; };
......
...@@ -477,6 +477,11 @@ void LanguageBox::set_id(int pos, const LanguageType eLangType) ...@@ -477,6 +477,11 @@ void LanguageBox::set_id(int pos, const LanguageType eLangType)
m_xControl->set_id(pos, OUString::number(static_cast<sal_uInt16>(eLangType))); m_xControl->set_id(pos, OUString::number(static_cast<sal_uInt16>(eLangType)));
} }
LanguageType LanguageBox::get_id(int pos) const
{
return LanguageType(m_xControl->get_id(pos).toInt32());
}
void LanguageBox::remove_id(const LanguageType eLangType) void LanguageBox::remove_id(const LanguageType eLangType)
{ {
m_xControl->remove_id(OUString::number(static_cast<sal_uInt16>(eLangType))); m_xControl->remove_id(OUString::number(static_cast<sal_uInt16>(eLangType)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment