Kaydet (Commit) 9170c8ee authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ManageLanguageDialog

Change-Id: I70cabe6c028cdfae06d0f677979937f18249917a
Reviewed-on: https://gerrit.libreoffice.org/67513
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 70ab6ff7
...@@ -742,8 +742,8 @@ void Shell::ExecuteGlobal( SfxRequest& rReq ) ...@@ -742,8 +742,8 @@ void Shell::ExecuteGlobal( SfxRequest& rReq )
{ {
std::shared_ptr<SfxRequest> pRequest(new SfxRequest(rReq)); std::shared_ptr<SfxRequest> pRequest(new SfxRequest(rReq));
rReq.Ignore(); // the 'old' request is not relevant any more rReq.Ignore(); // the 'old' request is not relevant any more
auto pDlg = VclPtr<ManageLanguageDialog>::Create(pCurWin, m_pCurLocalizationMgr); std::shared_ptr<ManageLanguageDialog> xDlg(new ManageLanguageDialog(pCurWin ? pCurWin->GetFrameWeld() : nullptr, m_pCurLocalizationMgr));
pDlg->StartExecuteAsync([=](sal_Int32 /*nResult*/){ weld::DialogController::runAsync(xDlg, [=](sal_Int32 /*nResult*/){
pRequest->Done(); pRequest->Done();
}); });
} }
......
...@@ -56,37 +56,27 @@ bool localesAreEqual( const Locale& rLocaleLeft, const Locale& rLocaleRight ) ...@@ -56,37 +56,27 @@ bool localesAreEqual( const Locale& rLocaleLeft, const Locale& rLocaleRight )
return bRet; return bRet;
} }
ManageLanguageDialog::ManageLanguageDialog(vcl::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr) ManageLanguageDialog::ManageLanguageDialog(weld::Window* pParent, std::shared_ptr<LocalizationMgr> const & xLMgr)
: ModalDialog(pParent, "ManageLanguagesDialog", "modules/BasicIDE/ui/managelanguages.ui") : GenericDialogController(pParent, "modules/BasicIDE/ui/managelanguages.ui", "ManageLanguagesDialog")
, m_xLocalizationMgr(xLMgr) , m_xLocalizationMgr(xLMgr)
, m_sDefLangStr(IDEResId(RID_STR_DEF_LANG)) , m_sDefLangStr(IDEResId(RID_STR_DEF_LANG))
, m_sCreateLangStr(IDEResId(RID_STR_CREATE_LANG)) , m_sCreateLangStr(IDEResId(RID_STR_CREATE_LANG))
, m_xLanguageLB(m_xBuilder->weld_tree_view("treeview"))
, m_xAddPB(m_xBuilder->weld_button("add"))
, m_xDeletePB(m_xBuilder->weld_button("delete"))
, m_xMakeDefPB(m_xBuilder->weld_button("default"))
{ {
get(m_pLanguageLB, "treeview"); m_xLanguageLB->set_size_request(m_xLanguageLB->get_approximate_digit_width() * 42,
m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10); m_xLanguageLB->get_height_rows(10));
m_pLanguageLB->set_width_request(m_pLanguageLB->approximate_char_width() * 50);
get(m_pAddPB, "add");
get(m_pDeletePB, "delete");
get(m_pMakeDefPB, "default");
Init(); Init();
FillLanguageBox(); FillLanguageBox();
SelectHdl( *m_pLanguageLB ); SelectHdl( *m_xLanguageLB );
} }
ManageLanguageDialog::~ManageLanguageDialog() ManageLanguageDialog::~ManageLanguageDialog()
{
disposeOnce();
}
void ManageLanguageDialog::dispose()
{ {
ClearLanguageBox(); ClearLanguageBox();
m_pLanguageLB.clear();
m_pAddPB.clear();
m_pDeletePB.clear();
m_pMakeDefPB.clear();
ModalDialog::dispose();
} }
void ManageLanguageDialog::Init() void ManageLanguageDialog::Init()
...@@ -95,16 +85,16 @@ void ManageLanguageDialog::Init() ...@@ -95,16 +85,16 @@ void ManageLanguageDialog::Init()
Shell* pShell = GetShell(); Shell* pShell = GetShell();
const OUString& sLibName = pShell->GetCurLibName(); const OUString& sLibName = pShell->GetCurLibName();
// set dialog title with library name // set dialog title with library name
OUString sText = GetText(); OUString sText = m_xDialog->get_title();
sText = sText.replaceAll("$1", sLibName); sText = sText.replaceAll("$1", sLibName);
SetText( sText ); m_xDialog->set_title(sText);
// set handler // set handler
m_pAddPB->SetClickHdl( LINK( this, ManageLanguageDialog, AddHdl ) ); m_xAddPB->connect_clicked( LINK( this, ManageLanguageDialog, AddHdl ) );
m_pDeletePB->SetClickHdl( LINK( this, ManageLanguageDialog, DeleteHdl ) ); m_xDeletePB->connect_clicked( LINK( this, ManageLanguageDialog, DeleteHdl ) );
m_pMakeDefPB->SetClickHdl( LINK( this, ManageLanguageDialog, MakeDefHdl ) ); m_xMakeDefPB->connect_clicked( LINK( this, ManageLanguageDialog, MakeDefHdl ) );
m_pLanguageLB->SetSelectHdl( LINK( this, ManageLanguageDialog, SelectHdl ) ); m_xLanguageLB->connect_changed( LINK( this, ManageLanguageDialog, SelectHdl ) );
m_pLanguageLB->EnableMultiSelection( true ); m_xLanguageLB->set_selection_mode(SelectionMode::Multiple);
} }
void ManageLanguageDialog::FillLanguageBox() void ManageLanguageDialog::FillLanguageBox()
...@@ -126,28 +116,28 @@ void ManageLanguageDialog::FillLanguageBox() ...@@ -126,28 +116,28 @@ void ManageLanguageDialog::FillLanguageBox()
{ {
sLanguage += " " + m_sDefLangStr; sLanguage += " " + m_sDefLangStr;
} }
const sal_Int32 nPos = m_pLanguageLB->InsertEntry( sLanguage ); LanguageEntry* pEntry = new LanguageEntry(pLocale[i], bIsDefault);
m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( pLocale[i], bIsDefault ) ); m_xLanguageLB->append(OUString::number(reinterpret_cast<sal_Int64>(pEntry)), sLanguage);
} }
} }
else else
m_pLanguageLB->InsertEntry( m_sCreateLangStr ); m_xLanguageLB->append_text(m_sCreateLangStr);
} }
void ManageLanguageDialog::ClearLanguageBox() void ManageLanguageDialog::ClearLanguageBox()
{ {
const sal_Int32 nCount = m_pLanguageLB->GetEntryCount(); const sal_Int32 nCount = m_xLanguageLB->n_children();
for ( sal_Int32 i = 0; i < nCount; ++i ) for (sal_Int32 i = 0; i < nCount; ++i)
{ {
LanguageEntry* pEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData(i)); LanguageEntry* pEntry = reinterpret_cast<LanguageEntry*>(m_xLanguageLB->get_id(i).toInt64());
delete pEntry; delete pEntry;
} }
m_pLanguageLB->Clear(); m_xLanguageLB->clear();
} }
IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, Button*, void) IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, weld::Button&, void)
{ {
std::shared_ptr<SetDefaultLanguageDialog> xDlg(new SetDefaultLanguageDialog(GetFrameWeld(), m_xLocalizationMgr)); std::shared_ptr<SetDefaultLanguageDialog> xDlg(new SetDefaultLanguageDialog(m_xDialog.get(), m_xLocalizationMgr));
weld::DialogController::runAsync(xDlg, [xDlg,this](sal_Int32 nResult) weld::DialogController::runAsync(xDlg, [xDlg,this](sal_Int32 nResult)
{ {
if (!nResult ) if (!nResult )
...@@ -164,20 +154,21 @@ IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, Button*, void) ...@@ -164,20 +154,21 @@ IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl, Button*, void)
}); });
} }
IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl, Button*, void) IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl, weld::Button&, void)
{ {
std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/BasicIDE/ui/deletelangdialog.ui")); std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), "modules/BasicIDE/ui/deletelangdialog.ui"));
std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog("DeleteLangDialog")); std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog("DeleteLangDialog"));
if (xQBox->run() == RET_OK) if (xQBox->run() == RET_OK)
{ {
sal_Int32 nCount = m_pLanguageLB->GetSelectedEntryCount(); std::vector<int> aSelection = m_xLanguageLB->get_selected_rows();
sal_Int32 nPos = m_pLanguageLB->GetSelectedEntryPos(); int nCount = aSelection.size();
int nPos = m_xLanguageLB->get_selected_index();
// remove locales // remove locales
Sequence< Locale > aLocaleSeq( nCount ); Sequence< Locale > aLocaleSeq( nCount );
for ( sal_Int32 i = 0; i < nCount; ++i ) for (int i = 0; i < nCount; ++i)
{ {
const sal_Int32 nSelPos = m_pLanguageLB->GetSelectedEntryPos(i); const sal_Int32 nSelPos = aSelection[i];
LanguageEntry* pEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData( nSelPos )); LanguageEntry* pEntry = reinterpret_cast<LanguageEntry*>(m_xLanguageLB->get_id(nSelPos).toInt64());
if ( pEntry ) if ( pEntry )
aLocaleSeq[i] = pEntry->m_aLocale; aLocaleSeq[i] = pEntry->m_aLocale;
} }
...@@ -186,19 +177,19 @@ IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl, Button*, void) ...@@ -186,19 +177,19 @@ IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl, Button*, void)
ClearLanguageBox(); ClearLanguageBox();
FillLanguageBox(); FillLanguageBox();
// reset selection // reset selection
nCount = m_pLanguageLB->GetEntryCount(); nCount = m_xLanguageLB->n_children();
if ( nCount <= nPos ) if (nCount <= nPos)
nPos = nCount - 1; nPos = nCount - 1;
m_pLanguageLB->SelectEntryPos( nPos ); m_xLanguageLB->select(nPos);
SelectHdl( *m_pLanguageLB ); SelectHdl( *m_xLanguageLB );
} }
} }
IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl, Button*, void) IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl, weld::Button&, void)
{ {
const sal_Int32 nPos = m_pLanguageLB->GetSelectedEntryPos(); const sal_Int32 nPos = m_xLanguageLB->get_selected_index();
LanguageEntry* pSelectEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData( nPos )); LanguageEntry* pSelectEntry = reinterpret_cast<LanguageEntry*>(m_xLanguageLB->get_id(nPos).toInt64());
if ( pSelectEntry && !pSelectEntry->m_bIsDefault ) if (pSelectEntry && !pSelectEntry->m_bIsDefault)
{ {
// set new default entry // set new default entry
m_xLocalizationMgr->handleSetDefaultLocale( pSelectEntry->m_aLocale ); m_xLocalizationMgr->handleSetDefaultLocale( pSelectEntry->m_aLocale );
...@@ -206,21 +197,21 @@ IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl, Button*, void) ...@@ -206,21 +197,21 @@ IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl, Button*, void)
ClearLanguageBox(); ClearLanguageBox();
FillLanguageBox(); FillLanguageBox();
// reset selection // reset selection
m_pLanguageLB->SelectEntryPos( nPos ); m_xLanguageLB->select(nPos);
SelectHdl( *m_pLanguageLB ); SelectHdl( *m_xLanguageLB );
} }
} }
IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl, ListBox&, void) IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl, weld::TreeView&, void)
{ {
const sal_Int32 nCount = m_pLanguageLB->GetEntryCount(); const sal_Int32 nCount = m_xLanguageLB->n_children();
bool bEmpty = ( !nCount || bool bEmpty = ( !nCount ||
m_pLanguageLB->GetEntryPos( m_sCreateLangStr ) != LISTBOX_ENTRY_NOTFOUND ); m_xLanguageLB->find_text(m_sCreateLangStr) != -1 );
bool bSelect = ( m_pLanguageLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND ); bool bSelect = ( m_xLanguageLB->get_selected_index() != -1 );
bool bEnable = !bEmpty && bSelect; bool bEnable = !bEmpty && bSelect;
m_pDeletePB->Enable(bEnable); m_xDeletePB->set_sensitive(bEnable);
m_pMakeDefPB->Enable(bEnable && nCount > 1 && m_pLanguageLB->GetSelectedEntryCount() == 1); m_xMakeDefPB->set_sensitive(bEnable && nCount > 1 && m_xLanguageLB->count_selected_rows() == 1);
} }
// class SetDefaultLanguageDialog ----------------------------------------------- // class SetDefaultLanguageDialog -----------------------------------------------
......
...@@ -46,32 +46,31 @@ struct LanguageEntry ...@@ -46,32 +46,31 @@ struct LanguageEntry
extern bool localesAreEqual( const css::lang::Locale& rLocaleLeft, extern bool localesAreEqual( const css::lang::Locale& rLocaleLeft,
const css::lang::Locale& rLocaleRight ); const css::lang::Locale& rLocaleRight );
class ManageLanguageDialog : public ModalDialog class ManageLanguageDialog : public weld::GenericDialogController
{ {
private: private:
VclPtr<ListBox> m_pLanguageLB;
VclPtr<PushButton> m_pAddPB;
VclPtr<PushButton> m_pDeletePB;
VclPtr<PushButton> m_pMakeDefPB;
std::shared_ptr<LocalizationMgr> m_xLocalizationMgr; std::shared_ptr<LocalizationMgr> m_xLocalizationMgr;
OUString m_sDefLangStr; OUString m_sDefLangStr;
OUString m_sCreateLangStr; OUString m_sCreateLangStr;
std::unique_ptr<weld::TreeView> m_xLanguageLB;
std::unique_ptr<weld::Button> m_xAddPB;
std::unique_ptr<weld::Button> m_xDeletePB;
std::unique_ptr<weld::Button> m_xMakeDefPB;
void Init(); void Init();
void FillLanguageBox(); void FillLanguageBox();
void ClearLanguageBox(); void ClearLanguageBox();
DECL_LINK(AddHdl, Button*, void); DECL_LINK(AddHdl, weld::Button&, void);
DECL_LINK(DeleteHdl, Button*, void); DECL_LINK(DeleteHdl, weld::Button&, void);
DECL_LINK(MakeDefHdl, Button*, void); DECL_LINK(MakeDefHdl, weld::Button&, void);
DECL_LINK(SelectHdl, ListBox&, void); DECL_LINK(SelectHdl, weld::TreeView&, void);
public: public:
ManageLanguageDialog( vcl::Window* pParent, std::shared_ptr<LocalizationMgr> const & _pLMgr ); ManageLanguageDialog(weld::Window* pParent, std::shared_ptr<LocalizationMgr> const & _pLMgr);
virtual ~ManageLanguageDialog() override; virtual ~ManageLanguageDialog() override;
virtual void dispose() override;
}; };
class SetDefaultLanguageDialog : public weld::GenericDialogController class SetDefaultLanguageDialog : public weld::GenericDialogController
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 --> <!-- Generated with glade 3.22.1 -->
<interface domain="basctl"> <interface domain="basctl">
<requires lib="gtk+" version="3.18"/> <requires lib="gtk+" version="3.18"/>
<object class="GtkTreeStore" id="liststore1">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="ManageLanguagesDialog"> <object class="GtkDialog" id="ManageLanguagesDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes" context="managelanguages|ManageLanguagesDialog">Manage User Interface Languages [$1]</property> <property name="title" translatable="yes" context="managelanguages|ManageLanguagesDialog">Manage User Interface Languages [$1]</property>
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">normal</property> <property name="type_hint">normal</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1"> <object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property> <property name="can_focus">False</property>
...@@ -65,10 +77,10 @@ ...@@ -65,10 +77,10 @@
<object class="GtkLabel" id="label1"> <object class="GtkLabel" id="label1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="managelanguages|label1">Present languages:</property> <property name="label" translatable="yes" context="managelanguages|label1">Present languages:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">treeview:border</property> <property name="mnemonic_widget">treeview</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -79,10 +91,10 @@ ...@@ -79,10 +91,10 @@
<object class="GtkLabel" id="label2"> <object class="GtkLabel" id="label2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="managelanguages|label2">The default language is used if no localization for a user interface locale is present. Furthermore all strings from the default language are copied to resources of newly added languages.</property> <property name="label" translatable="yes" context="managelanguages|label2">The default language is used if no localization for a user interface locale is present. Furthermore all strings from the default language are copied to resources of newly added languages.</property>
<property name="wrap">True</property> <property name="wrap">True</property>
<property name="max_width_chars">68</property> <property name="max_width_chars">68</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -153,14 +165,38 @@ ...@@ -153,14 +165,38 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkTreeView" id="treeview:border"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="show_expanders">False</property> <property name="shadow_type">in</property>
<child internal-child="selection"> <child>
<object class="GtkTreeSelection" id="treeview-selection1"/> <object class="GtkTreeView" id="treeview">
<property name="width_request">-1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_visible">False</property>
<property name="search_column">1</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="Macro Library List-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child> </child>
</object> </object>
<packing> <packing>
......
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