diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-04-13 11:31:02 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-04-13 14:21:37 +0200 |
commit | a8b096cba3a49732bfec608b4b7e7b90badb31c3 (patch) | |
tree | 7cc2b3c83c4d75b1c37bd75aae3c7824f0c42a5e | |
parent | f17a04df424dac553195c1922a4e4aa1f4ad5b9d (diff) |
weld SfxTemplateCategoryDialog
Change-Id: I7462102797e3b0f552aec97f6cbae919e89e7099
Reviewed-on: https://gerrit.libreoffice.org/52820
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/sfx2/templatedlg.hxx | 24 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 109 | ||||
-rw-r--r-- | sfx2/uiconfig/ui/templatecategorydlg.ui | 60 |
3 files changed, 105 insertions, 88 deletions
diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index 40d735d8231b..7f730c50161d 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -18,6 +18,7 @@ #include <vcl/dialog.hxx> #include <vcl/button.hxx> #include <vcl/fixed.hxx> +#include <vcl/weld.hxx> #include <com/sun/star/frame/XDesktop2.hpp> #include <sfx2/templatelocalview.hxx> @@ -146,21 +147,21 @@ protected: // class SfxTemplateCategoryDialog ------------------------------------------------------------------- -class SFX2_DLLPUBLIC SfxTemplateCategoryDialog : public ModalDialog +class SFX2_DLLPUBLIC SfxTemplateCategoryDialog : public weld::GenericDialogController { private: - VclPtr<ListBox> mpLBCategory; - VclPtr<FixedText> mpSelectLabel; - VclPtr<Edit> mpNewCategoryEdit; - VclPtr<FixedText> mpCreateLabel; - VclPtr<PushButton> mpOKButton; - OUString msSelectedCategory; bool mbIsNewCategory; + std::unique_ptr<weld::TreeView> mxLBCategory; + std::unique_ptr<weld::Label> mxSelectLabel; + std::unique_ptr<weld::Entry> mxNewCategoryEdit; + std::unique_ptr<weld::Label> mxCreateLabel; + std::unique_ptr<weld::Button> mxOKButton; + public: - DECL_LINK(NewCategoryEditHdl, Edit&, void); - DECL_LINK(SelectCategoryHdl, ListBox&, void); + DECL_LINK(NewCategoryEditHdl, weld::Entry&, void); + DECL_LINK(SelectCategoryHdl, weld::TreeView&, void); void SetCategoryLBEntries(std::vector<OUString> names); @@ -171,7 +172,7 @@ public: }; void SetSelectLabelText(OUString const & sText) const { - mpSelectLabel->SetText(sText); + mxSelectLabel->set_label(sText); }; bool IsNewCategoryCreated() const { @@ -180,10 +181,9 @@ public: public: - explicit SfxTemplateCategoryDialog(); + explicit SfxTemplateCategoryDialog(weld::Window* pParent); virtual ~SfxTemplateCategoryDialog() override; - virtual void dispose() override; }; diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 03459cd9cfff..8317b8c139f3 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -570,16 +570,15 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, OkClickHdl, Button*, void) IMPL_LINK_NOARG(SfxTemplateManagerDlg, MoveClickHdl, Button*, void) { // modal dialog to select templates category - ScopedVclPtrInstance<SfxTemplateCategoryDialog> aDlg; - aDlg->SetCategoryLBEntries(mpLocalView->getFolderNames()); + SfxTemplateCategoryDialog aDlg(GetFrameWeld()); + aDlg.SetCategoryLBEntries(mpLocalView->getFolderNames()); size_t nItemId = 0; - if (aDlg->Execute() == RET_OK) + if (aDlg.run() == RET_OK) { - OUString sCategory = aDlg->GetSelectedCategory(); - bool bIsNewCategory = aDlg->IsNewCategoryCreated(); - aDlg.disposeAndClear(); + OUString sCategory = aDlg.GetSelectedCategory(); + bool bIsNewCategory = aDlg.IsNewCategoryCreated(); if(bIsNewCategory) { if (!sCategory.isEmpty()) @@ -612,14 +611,13 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, ExportClickHdl, Button*, void) IMPL_LINK_NOARG(SfxTemplateManagerDlg, ImportClickHdl, Button*, void) { //Modal Dialog to select Category - ScopedVclPtrInstance<SfxTemplateCategoryDialog> aDlg; - aDlg->SetCategoryLBEntries(mpLocalView->getFolderNames()); + SfxTemplateCategoryDialog aDlg(GetFrameWeld()); + aDlg.SetCategoryLBEntries(mpLocalView->getFolderNames()); - if (aDlg->Execute() == RET_OK) + if (aDlg.run() == RET_OK) { - OUString sCategory = aDlg->GetSelectedCategory(); - bool bIsNewCategory = aDlg->IsNewCategoryCreated(); - aDlg.disposeAndClear(); + OUString sCategory = aDlg.GetSelectedCategory(); + bool bIsNewCategory = aDlg.IsNewCategoryCreated(); if(bIsNewCategory) { if(mpLocalView->createRegion(sCategory)) @@ -1168,16 +1166,15 @@ void SfxTemplateManagerDlg::OnCategoryRename() void SfxTemplateManagerDlg::OnCategoryDelete() { - ScopedVclPtrInstance< SfxTemplateCategoryDialog > aDlg; - aDlg->SetCategoryLBEntries(mpLocalView->getFolderNames()); - aDlg->HideNewCategoryOption(); - aDlg->SetText(SfxResId(STR_CATEGORY_DELETE)); - aDlg->SetSelectLabelText(SfxResId(STR_CATEGORY_SELECT)); + SfxTemplateCategoryDialog aDlg(GetFrameWeld()); + aDlg.SetCategoryLBEntries(mpLocalView->getFolderNames()); + aDlg.HideNewCategoryOption(); + aDlg.set_title(SfxResId(STR_CATEGORY_DELETE)); + aDlg.SetSelectLabelText(SfxResId(STR_CATEGORY_SELECT)); - if (aDlg->Execute() == RET_OK) + if (aDlg.run() == RET_OK) { - OUString sCategory = aDlg->GetSelectedCategory(); - aDlg.disposeAndClear(); + OUString sCategory = aDlg.GetSelectedCategory(); std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QMSG_SEL_FOLDER_DELETE))); if (popupDlg->run() != RET_YES) @@ -1319,69 +1316,57 @@ static std::vector<OUString> lcl_getAllFactoryURLs () // Class SfxTemplateCategoryDialog -------------------------------------------------- -SfxTemplateCategoryDialog::SfxTemplateCategoryDialog(): - ModalDialog(nullptr, "TemplatesCategoryDialog", "sfx/ui/templatecategorydlg.ui"), - msSelectedCategory(OUString()), - mbIsNewCategory(false) +SfxTemplateCategoryDialog::SfxTemplateCategoryDialog(weld::Window* pParent) + : weld::GenericDialogController(pParent, "sfx/ui/templatecategorydlg.ui", "TemplatesCategoryDialog") + , msSelectedCategory(OUString()) + , mbIsNewCategory(false) + , mxLBCategory(m_xBuilder->weld_tree_view("categorylb")) + , mxSelectLabel(m_xBuilder->weld_label("select_label")) + , mxNewCategoryEdit(m_xBuilder->weld_entry("category_entry")) + , mxCreateLabel(m_xBuilder->weld_label("create_label")) + , mxOKButton(m_xBuilder->weld_button("ok")) { - get(mpLBCategory, "categorylb"); - get(mpNewCategoryEdit, "category_entry"); - get(mpOKButton, "ok"); - get(mpSelectLabel, "select_label"); - get(mpCreateLabel, "create_label"); - - mpNewCategoryEdit->SetModifyHdl(LINK(this, SfxTemplateCategoryDialog, NewCategoryEditHdl)); - mpLBCategory->SetSelectHdl(LINK(this, SfxTemplateCategoryDialog, SelectCategoryHdl)); - - mpOKButton->Disable(); + mxNewCategoryEdit->connect_changed(LINK(this, SfxTemplateCategoryDialog, NewCategoryEditHdl)); + mxLBCategory->set_size_request(mxLBCategory->get_approximate_digit_width() * 32, + mxLBCategory->get_height_rows(8)); + mxLBCategory->connect_changed(LINK(this, SfxTemplateCategoryDialog, SelectCategoryHdl)); + mxOKButton->set_sensitive(false); } SfxTemplateCategoryDialog::~SfxTemplateCategoryDialog() { - disposeOnce(); -} - -void SfxTemplateCategoryDialog::dispose() -{ - mpLBCategory.clear(); - mpNewCategoryEdit.clear(); - mpOKButton.clear(); - mpSelectLabel.clear(); - mpCreateLabel.clear(); - - ModalDialog::dispose(); } -IMPL_LINK_NOARG(SfxTemplateCategoryDialog, NewCategoryEditHdl, Edit&, void) +IMPL_LINK_NOARG(SfxTemplateCategoryDialog, NewCategoryEditHdl, weld::Entry&, void) { - OUString sParam = comphelper::string::strip(mpNewCategoryEdit->GetText(), ' '); - mpLBCategory->Enable(sParam.isEmpty()); + OUString sParam = comphelper::string::strip(mxNewCategoryEdit->get_text(), ' '); + mxLBCategory->set_sensitive(sParam.isEmpty()); if(!sParam.isEmpty()) { msSelectedCategory = sParam; mbIsNewCategory = true; - mpOKButton->Enable(); + mxOKButton->set_sensitive(true); } else { - SelectCategoryHdl(*mpLBCategory); + SelectCategoryHdl(*mxLBCategory); mbIsNewCategory = false; } } -IMPL_LINK_NOARG(SfxTemplateCategoryDialog, SelectCategoryHdl, ListBox&, void) +IMPL_LINK_NOARG(SfxTemplateCategoryDialog, SelectCategoryHdl, weld::TreeView&, void) { - if(mpLBCategory->GetSelectedEntryPos() == 0) + if (mxLBCategory->get_selected_index() == 0) { msSelectedCategory = OUString(); - mpOKButton->Disable(); - mpNewCategoryEdit->Enable(); + mxOKButton->set_sensitive(false); + mxNewCategoryEdit->set_sensitive(true); } else { - msSelectedCategory = mpLBCategory->GetSelectedEntry(); - mpNewCategoryEdit->Disable(); - mpOKButton->Enable(); + msSelectedCategory = mxLBCategory->get_selected(); + mxNewCategoryEdit->set_sensitive(false); + mxOKButton->set_sensitive(true); } mbIsNewCategory = false; @@ -1392,15 +1377,15 @@ void SfxTemplateCategoryDialog::SetCategoryLBEntries(std::vector<OUString> aFold if (!aFolderNames.empty()) { for (size_t i = 0, n = aFolderNames.size(); i < n; ++i) - mpLBCategory->InsertEntry(aFolderNames[i], i+1); + mxLBCategory->append_text(aFolderNames[i]); } - mpLBCategory->SelectEntryPos(0); + mxLBCategory->select(0); } void SfxTemplateCategoryDialog::HideNewCategoryOption() { - mpCreateLabel->Hide(); - mpNewCategoryEdit->Hide(); + mxCreateLabel->hide(); + mxNewCategoryEdit->hide(); } // SfxTemplateSelectionDialog ----------------------------------------------------------------- diff --git a/sfx2/uiconfig/ui/templatecategorydlg.ui b/sfx2/uiconfig/ui/templatecategorydlg.ui index 13012b48cb2f..908120a62908 100644 --- a/sfx2/uiconfig/ui/templatecategorydlg.ui +++ b/sfx2/uiconfig/ui/templatecategorydlg.ui @@ -1,11 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> +<!-- Generated with glade 3.20.4 --> <interface domain="sfx"> <requires lib="gtk+" version="3.18"/> - <requires lib="LibreOffice" version="1.0"/> <object class="GtkListStore" id="categorylist"> <columns> - <!-- column-name gchararray1 --> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name id --> <column type="gchararray"/> </columns> <data> @@ -19,6 +20,8 @@ <property name="border_width">6</property> <property name="title" translatable="yes" context="templatecategorydlg|TemplatesCategoryDialog">Select Category</property> <property name="modal">True</property> + <property name="default_width">0</property> + <property name="default_height">0</property> <property name="type_hint">normal</property> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> @@ -87,20 +90,24 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="margin_bottom">6</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> <property name="row_spacing">12</property> <property name="column_spacing">12</property> <child> <object class="GtkBox" id="box1"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> <property name="orientation">vertical</property> <property name="spacing">6</property> <child> <object class="GtkLabel" id="select_label"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="templatecategorydlg|select_label">Select from Existing Category</property> + <property name="xalign">0</property> <attributes> <attribute name="weight" value="normal"/> </attributes> @@ -112,15 +119,36 @@ </packing> </child> <child> - <object class="GtkTreeView" id="categorylb:border"> - <property name="height_request">150</property> - <property name="width_request">300</property> + <object class="GtkScrolledWindow"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="border_width">2</property> - <property name="model">categorylist</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="treeview-selection1"/> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTreeView" id="categorylb"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="vexpand">True</property> + <property name="model">categorylist</property> + <property name="headers_visible">False</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> + <property name="show_expanders">False</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="treeview-selection1"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + </object> </child> </object> <packing> @@ -139,14 +167,15 @@ <object class="GtkBox" id="box2"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="hexpand">True</property> <property name="orientation">vertical</property> <property name="spacing">6</property> <child> <object class="GtkLabel" id="create_label"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="templatecategorydlg|create_label">or Create a New Category</property> + <property name="xalign">0</property> <attributes> <attribute name="weight" value="normal"/> </attributes> @@ -160,8 +189,8 @@ <child> <object class="GtkEntry" id="category_entry"> <property name="visible">True</property> - <property name="width_request">300</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> </object> <packing> <property name="expand">False</property> @@ -189,5 +218,8 @@ <action-widget response="-5">ok</action-widget> <action-widget response="-6">cancel</action-widget> </action-widgets> + <child> + <placeholder/> + </child> </object> </interface> |