cui/inc/dlgname.hxx                       |    9 +
 cui/source/dialogs/MacroManagerDialog.cxx |  139 +++++++++++++++---------------
 cui/source/dialogs/dlgname.cxx            |    3 
 3 files changed, 83 insertions(+), 68 deletions(-)

New commits:
commit cda4965ea65ff9fa0e63e53344f46aeac91848a9
Author:     bruh <randomfores...@gmail.com>
AuthorDate: Sun Feb 2 02:42:40 2025 +0530
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Feb 3 07:39:00 2025 +0100

    tdf#158280 Replace usage of InputDialog with SvxNameDialog
    
    Change-Id: I02309ea7c01369429de08be0b2bd78725602a837
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181002
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/cui/inc/dlgname.hxx b/cui/inc/dlgname.hxx
index d12b8edb1bea..366f57454917 100644
--- a/cui/inc/dlgname.hxx
+++ b/cui/inc/dlgname.hxx
@@ -29,6 +29,7 @@ private:
     std::unique_ptr<weld::Entry> m_xEdtName;
     std::unique_ptr<weld::Label> m_xFtDescription;
     std::unique_ptr<weld::Button> m_xBtnOK;
+    std::function<bool(OUString)> m_aCheckName;
 
     Link<SvxNameDialog&, bool> m_aCheckNameHdl;
     Link<SvxNameDialog&, OUString> m_aCheckNameTooltipHdl;
@@ -41,6 +42,8 @@ public:
 
     OUString GetName() const { return m_xEdtName->get_text(); }
 
+    void SetCheckName(const std::function<bool(OUString)>& rFunc) { 
m_aCheckName = rFunc; }
+
     /** add a callback Link that is called whenever the content of the edit
         field is changed.  The Link result determines whether the OK
         Button is enabled (> 0) or disabled (== 0).
@@ -60,6 +63,12 @@ public:
         m_xBtnOK->set_tooltip_text(rLink.Call(*this));
     }
 
+    void SetNameText(const OUString& aName)
+    {
+        m_xEdtName->set_text(aName);
+        m_xEdtName->set_position(-1);
+    }
+
     void SetEditHelpId(const OUString& aHelpId) { 
m_xEdtName->set_help_id(aHelpId); }
 };
 
diff --git a/cui/source/dialogs/MacroManagerDialog.cxx 
b/cui/source/dialogs/MacroManagerDialog.cxx
index ebc07902dcb3..26d1eba324b1 100644
--- a/cui/source/dialogs/MacroManagerDialog.cxx
+++ b/cui/source/dialogs/MacroManagerDialog.cxx
@@ -28,7 +28,6 @@
 #include <osl/file.hxx>
 #include <sfx2/app.hxx>
 #include <sfx2/dispatch.hxx>
-#include <sfx2/inputdlg.hxx>
 #include <sfx2/minfitem.hxx>
 #include <sfx2/request.hxx>
 #include <sfx2/sfxsids.hrc>
@@ -41,6 +40,7 @@
 #include <unotools/viewoptions.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/weldutils.hxx>
+#include <dlgname.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XEnumerationAccess.hpp>
@@ -1228,11 +1228,12 @@ void 
MacroManagerDialog::BasicScriptsCreateLibrary(const basctl::ScriptDocument&
          aLibName = CuiResId(STR_LIBRARY) + OUString::number(++i))
         ;
 
-    InputDialog aInputDlg(m_xDialog.get(), 
CuiResId(STR_INPUTDIALOG_NEWLIBRARYLABEL));
-    aInputDlg.set_title(CuiResId(STR_INPUTDIALOG_NEWLIBRARYTITLE));
-    aInputDlg.SetEntryText(aLibName);
-    aInputDlg.HideHelpBtn();
-    aInputDlg.setCheckEntry([&](OUString sNewName) {
+    OUString aDesc = CuiResId(STR_INPUTDIALOG_NEWLIBRARYLABEL);
+
+    SvxNameDialog aNameDialog(m_xDialog.get(), aLibName, aDesc,
+                              CuiResId(STR_INPUTDIALOG_NEWLIBRARYTITLE));
+
+    aNameDialog.SetCheckName([&](OUString sNewName) -> bool {
         if (sNewName.isEmpty() || rDocument.hasLibrary(basctl::E_SCRIPTS, 
sNewName)
             || rDocument.hasLibrary(basctl::E_DIALOGS, sNewName) || 
sNewName.getLength() > 30
             || !basctl::IsValidSbxName(sNewName))
@@ -1240,10 +1241,10 @@ void 
MacroManagerDialog::BasicScriptsCreateLibrary(const basctl::ScriptDocument&
         return true;
     });
 
-    if (!aInputDlg.run())
+    if (aNameDialog.run() != RET_OK)
         return;
 
-    aLibName = aInputDlg.GetEntryText();
+    aLibName = aNameDialog.GetName();
 
     try
     {
@@ -1295,21 +1296,22 @@ void MacroManagerDialog::BasicScriptsCreateModule(const 
basctl::ScriptDocument&
          aModName = CuiResId(STR_MODULE) + OUString::number(++i))
         ;
 
-    InputDialog aInputDlg(m_xDialog.get(), 
CuiResId(STR_INPUTDIALOG_NEWMODULELABEL));
-    aInputDlg.set_title(CuiResId(STR_INPUTDIALOG_NEWMODULETITLE));
-    aInputDlg.SetEntryText(aModName);
-    aInputDlg.HideHelpBtn();
-    aInputDlg.setCheckEntry([&](OUString sNewName) {
+    OUString aDesc = CuiResId(STR_INPUTDIALOG_NEWMODULELABEL);
+
+    SvxNameDialog aNameDialog(m_xDialog.get(), aModName, aDesc,
+                              CuiResId(STR_INPUTDIALOG_NEWMODULETITLE));
+
+    aNameDialog.SetCheckName([&](OUString sNewName) -> bool {
         if (sNewName.isEmpty() || rDocument.hasModule(aLibName, sNewName)
             || sNewName.getLength() > 30 || !basctl::IsValidSbxName(sNewName))
             return false;
         return true;
     });
 
-    if (!aInputDlg.run())
+    if (!aNameDialog.run())
         return;
 
-    aModName = aInputDlg.GetEntryText();
+    aModName = aNameDialog.GetName();
 
     OUString sModuleCode;
     if (!rDocument.createModule(aLibName, aModName, true /*create main sub*/, 
sModuleCode))
@@ -1339,21 +1341,22 @@ void MacroManagerDialog::BasicScriptsCreateDialog(const 
basctl::ScriptDocument&
          sDialogName = CuiResId(STR_DIALOG) + OUString::number(++i))
         ;
 
-    InputDialog aInputDlg(m_xDialog.get(), 
CuiResId(STR_INPUTDIALOG_NEWDIALOGLABEL));
-    aInputDlg.set_title(CuiResId(STR_INPUTDIALOG_NEWDIALOGTITLE));
-    aInputDlg.SetEntryText(sDialogName);
-    aInputDlg.HideHelpBtn();
-    aInputDlg.setCheckEntry([&](OUString sNewName) {
+    OUString aDesc = CuiResId(STR_INPUTDIALOG_NEWDIALOGLABEL);
+
+    SvxNameDialog aNameDialog(m_xDialog.get(), sDialogName, aDesc,
+                              CuiResId(STR_INPUTDIALOG_NEWDIALOGTITLE));
+
+    aNameDialog.SetCheckName([&](OUString sNewName) -> bool {
         if (sNewName.isEmpty() || rDocument.hasDialog(aLibName, sNewName)
             || sNewName.getLength() > 30 || !basctl::IsValidSbxName(sNewName))
             return false;
         return true;
     });
 
-    if (!aInputDlg.run())
+    if (!aNameDialog.run())
         return;
 
-    sDialogName = aInputDlg.GetEntryText();
+    sDialogName = aNameDialog.GetName();
 
     try
     {
@@ -1744,11 +1747,12 @@ void 
MacroManagerDialog::BasicScriptsLibraryModuleDialogRename(
 
     if (rTreeView.get_iter_depth(*xSelectedIter) == 2) // library
     {
-        InputDialog aInputDlg(m_xDialog.get(), 
CuiResId(STR_INPUTDIALOG_RENAMELIBRARYLABEL));
-        aInputDlg.HideHelpBtn();
-        aInputDlg.set_title(CuiResId(STR_INPUTDIALOG_RENAMELIBRARYTITLE));
-        aInputDlg.SetEntryText(sOldName);
-        aInputDlg.setCheckEntry([&](OUString sNewName) {
+        OUString aDesc = CuiResId(STR_INPUTDIALOG_RENAMELIBRARYLABEL);
+
+        SvxNameDialog aNameDialog(m_xDialog.get(), sOldName, aDesc,
+                                  
CuiResId(STR_INPUTDIALOG_RENAMELIBRARYTITLE));
+
+        aNameDialog.SetCheckName([&](OUString sNewName) -> bool {
             if (sNewName != sOldName
                 && (sNewName.isEmpty() || 
rDocument.hasLibrary(basctl::E_SCRIPTS, sNewName)
                     || rDocument.hasLibrary(basctl::E_DIALOGS, sNewName)
@@ -1757,10 +1761,10 @@ void 
MacroManagerDialog::BasicScriptsLibraryModuleDialogRename(
             return true;
         });
 
-        if (!aInputDlg.run())
+        if (!aNameDialog.run())
             return;
 
-        OUString sNewName = aInputDlg.GetEntryText();
+        OUString sNewName = aNameDialog.GetName();
         if (sNewName == sOldName)
             return;
 
@@ -1799,15 +1803,16 @@ void 
MacroManagerDialog::BasicScriptsLibraryModuleDialogRename(
         OUString aLibName = 
m_xScriptContainersListBox->GetSelectedEntryContainerName(
             ScriptContainerType::LIBRARY);
 
-        InputDialog aInputDlg(m_xDialog.get(), 
CuiResId(pScriptContainerInfo->pBrowseNode
-                                                            ? 
STR_INPUTDIALOG_RENAMEMODULELABEL
-                                                            : 
STR_INPUTDIALOG_RENAMEDIALOGLABEL));
-        aInputDlg.HideHelpBtn();
-        aInputDlg.set_title(CuiResId(pScriptContainerInfo->pBrowseNode
-                                         ? STR_INPUTDIALOG_RENAMEMODULETITLE
-                                         : STR_INPUTDIALOG_RENAMEMODULETITLE));
-        aInputDlg.SetEntryText(sOldName);
-        aInputDlg.setCheckEntry([&](OUString sNewName) {
+        OUString aDesc
+            = CuiResId(pScriptContainerInfo->pBrowseNode ? 
STR_INPUTDIALOG_RENAMEMODULELABEL
+                                                         : 
STR_INPUTDIALOG_RENAMEDIALOGLABEL);
+
+        SvxNameDialog aNameDialog(m_xDialog.get(), sOldName, aDesc,
+                                  CuiResId(pScriptContainerInfo->pBrowseNode
+                                               ? 
STR_INPUTDIALOG_RENAMEMODULETITLE
+                                               : 
STR_INPUTDIALOG_RENAMEMODULETITLE));
+
+        aNameDialog.SetCheckName([&](OUString sNewName) -> bool {
             if (sNewName != sOldName
                 && (sNewName.isEmpty() || sNewName.getLength() > 30
                             || !basctl::IsValidSbxName(sNewName)
@@ -1818,10 +1823,10 @@ void 
MacroManagerDialog::BasicScriptsLibraryModuleDialogRename(
             return true;
         });
 
-        if (!aInputDlg.run())
+        if (!aNameDialog.run())
             return;
 
-        OUString sNewName = aInputDlg.GetEntryText();
+        OUString sNewName = aNameDialog.GetName();
         if (sNewName == sOldName)
             return;
 
@@ -2051,29 +2056,27 @@ void 
MacroManagerDialog::ScriptingFrameworkScriptsRenameEntry(weld::TreeView& rT
             aNewName = aNewName.copy(0, extnPos);
         }
 
-        InputDialog aInputDlg(m_xDialog.get(),
-                              xBrowseNode->getType()
-                                      == 
css::script::browse::BrowseNodeTypes::CONTAINER
-                                  ? 
CuiResId(STR_INPUTDIALOG_RENAMELIBRARYLABEL)
-                                  : 
CuiResId(STR_INPUTDIALOG_RENAMEMACROLABEL));
-        aInputDlg.set_title(xBrowseNode->getType()
-                                    == 
css::script::browse::BrowseNodeTypes::CONTAINER
-                                ? CuiResId(STR_INPUTDIALOG_RENAMELIBRARYTITLE)
-                                : CuiResId(STR_INPUTDIALOG_RENAMEMACROTITLE));
-        aInputDlg.SetEntryText(aNewName);
-        aInputDlg.HideHelpBtn();
-        // doesn't check if the name already exists, that will be caught below 
by invoke
-        aInputDlg.setCheckEntry([](OUString sNewName) {
+        OUString aDesc = xBrowseNode->getType() == 
css::script::browse::BrowseNodeTypes::CONTAINER
+                             ? CuiResId(STR_INPUTDIALOG_RENAMELIBRARYLABEL)
+                             : CuiResId(STR_INPUTDIALOG_RENAMEMACROLABEL);
+
+        SvxNameDialog aNameDialog(m_xDialog.get(), aNewName, aDesc,
+                                  xBrowseNode->getType()
+                                          == 
css::script::browse::BrowseNodeTypes::CONTAINER
+                                      ? 
CuiResId(STR_INPUTDIALOG_RENAMELIBRARYTITLE)
+                                      : 
CuiResId(STR_INPUTDIALOG_RENAMEMACROTITLE));
+
+        aNameDialog.SetCheckName([](OUString sNewName) -> bool {
             if (sNewName.isEmpty() || sNewName.getLength() > 30
                 || !basctl::IsValidSbxName(sNewName))
                 return false;
             return true;
         });
 
-        if (!aInputDlg.run())
+        if (!aNameDialog.run())
             return;
 
-        aNewName = aInputDlg.GetEntryText();
+        aNewName = aNameDialog.GetName();
 
         css::uno::Sequence<css::uno::Any> args{ css::uno::Any(aNewName) };
         css::uno::Sequence<css::uno::Any> outArgs;
@@ -2301,19 +2304,19 @@ void 
MacroManagerDialog::ScriptingFrameworkScriptsCreateEntry(InputDialogMode eI
             }
         }
 
-        InputDialog aInputDlg(m_xDialog.get(), eInputDialogMode == 
InputDialogMode::NEWLIB
-                                                   ? 
CuiResId(STR_INPUTDIALOG_NEWLIBRARYLABEL)
-                                                   : 
CuiResId(STR_INPUTDIALOG_NEWMACROLABEL));
-        aInputDlg.set_title(eInputDialogMode == InputDialogMode::NEWLIB
-                                ? CuiResId(STR_INPUTDIALOG_NEWLIBRARYTITLE)
-                                : CuiResId(STR_INPUTDIALOG_NEWMACROTITLE));
-        aInputDlg.SetEntryText(aNewName);
-        aInputDlg.HideHelpBtn();
+        OUString aDesc = eInputDialogMode == InputDialogMode::NEWLIB
+                             ? CuiResId(STR_INPUTDIALOG_NEWLIBRARYLABEL)
+                             : CuiResId(STR_INPUTDIALOG_NEWMACROLABEL);
+
+        SvxNameDialog aNameDialog(m_xDialog.get(), aNewName, aDesc,
+                                  eInputDialogMode == InputDialogMode::NEWLIB
+                                      ? 
CuiResId(STR_INPUTDIALOG_NEWLIBRARYTITLE)
+                                      : 
CuiResId(STR_INPUTDIALOG_NEWMACROTITLE));
 
-        // setCheckEntry doesn't check if the name already exists. It is 
checked after the dialog
+        // SetCheckName doesn't check if the name already exists. It is 
checked after the dialog
         // in the Creatable invocation call - this could be improved by 
including a check for
         // existing name
-        aInputDlg.setCheckEntry([](OUString sNewName) {
+        aNameDialog.SetCheckName([](OUString sNewName) -> bool {
             if (sNewName.isEmpty() || sNewName.getLength() > 30
                 || !basctl::IsValidSbxName(sNewName))
                 return false;
@@ -2322,9 +2325,9 @@ void 
MacroManagerDialog::ScriptingFrameworkScriptsCreateEntry(InputDialogMode eI
 
         do
         {
-            if (aInputDlg.run())
+            if (aNameDialog.run())
             {
-                OUString aUserSuppliedName = aInputDlg.GetEntryText();
+                OUString aUserSuppliedName = aNameDialog.GetName();
                 bValid = true;
                 for (const 
css::uno::Reference<css::script::browse::XBrowseNode>& n : childNodes)
                 {
@@ -2340,7 +2343,7 @@ void 
MacroManagerDialog::ScriptingFrameworkScriptsCreateEntry(InputDialogMode eI
                                                              
VclButtonsType::Ok, aError));
                         
xErrorBox->set_title(CuiResId(RID_CUISTR_CREATEFAILED_TITLE));
                         xErrorBox->run();
-                        aInputDlg.SetEntryText(aNewName);
+                        aNameDialog.SetNameText(aNewName);
                         break;
                     }
                 }
diff --git a/cui/source/dialogs/dlgname.cxx b/cui/source/dialogs/dlgname.cxx
index 5e0cdacbf599..d49c5fa28579 100644
--- a/cui/source/dialogs/dlgname.cxx
+++ b/cui/source/dialogs/dlgname.cxx
@@ -33,6 +33,7 @@ SvxNameDialog::SvxNameDialog(weld::Window* pParent, const 
OUString& rName, const
     , m_xEdtName(m_xBuilder->weld_entry(u"name_entry"_ustr))
     , m_xFtDescription(m_xBuilder->weld_label(u"description_label"_ustr))
     , m_xBtnOK(m_xBuilder->weld_button(u"ok"_ustr))
+    , m_aCheckName(nullptr)
 {
     m_xFtDescription->set_label(rDesc);
     m_xEdtName->set_text(rName);
@@ -49,6 +50,8 @@ IMPL_LINK_NOARG(SvxNameDialog, ModifyHdl, weld::Entry&, void)
     bool bEnable;
     if (m_aCheckNameHdl.IsSet())
         bEnable = m_aCheckNameHdl.Call(*this);
+    else if (m_aCheckName)
+        bEnable = m_aCheckName(m_xEdtName->get_text());
     else
         bEnable = !m_xEdtName->get_text().isEmpty();
     m_xBtnOK->set_sensitive(bEnable);

Reply via email to