[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
Muhammet Kara (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 23 19:36:28 UTC 2019
sfx2/inc/autoredactdialog.hxx | 14 ----
sfx2/source/doc/autoredactdialog.cxx | 120 ++++++++++++++---------------------
2 files changed, 52 insertions(+), 82 deletions(-)
New commits:
commit 16772ff18d04af5b91d00075841b967597fae595
Author: Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Fri Aug 23 20:29:37 2019 +0300
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Fri Aug 23 21:35:27 2019 +0200
AutoRedaction: Adapt EditHdl
And do some clean-up
[NO-FORWARD-PORT]
Change-Id: I8fec2acd38e0f160b22db20f6d9adc585b67c13c
Reviewed-on: https://gerrit.libreoffice.org/78039
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
Tested-by: Muhammet Kara <muhammet.kara at collabora.com>
diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx
index 5af176a6f7ce..90e5ec6ad3d5 100644
--- a/sfx2/inc/autoredactdialog.hxx
+++ b/sfx2/inc/autoredactdialog.hxx
@@ -48,7 +48,7 @@ class TargetsTable : public SvSimpleTable
public:
TargetsTable(SvSimpleTableContainer& rParent);
void InsertTarget(RedactionTarget* pTarget);
- void SelectByName(const OUString& sName);
+ void InsertTargetAtPos(RedactionTarget* pTarget, const sal_uLong& nPos);
RedactionTarget* GetTargetByName(const OUString& sName);
OUString GetNameProposal();
};
@@ -67,7 +67,6 @@ enum class StartFileDialogType
class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog
{
SfxObjectShellLock m_xDocShell;
- //std::vector<std::pair<RedactionTarget*, OUString>> m_aTableTargets;
std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
bool m_bIsValidState;
bool m_bTargetsCopied;
@@ -84,16 +83,14 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog
DECL_LINK(Load, Button*, void);
DECL_LINK(Save, Button*, void);
DECL_LINK(AddHdl, Button*, void);
- //DECL_LINK(EditHdl, Button*, void);
+ DECL_LINK(EditHdl, Button*, void);
DECL_LINK(DeleteHdl, Button*, void);
DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void);
DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void);
void StartFileDialog(StartFileDialogType nType, const OUString& rTitle);
- /// Carry out proper addition both to the targets box, and to the tabletargets vector.
- /*void addTarget(RedactionTarget* pTarget);*/
- /// Clear all targets both visually and from the targets vector
+ /// Clear all targets both visually and from the memory
void clearTargets();
public:
@@ -101,11 +98,6 @@ public:
virtual ~SfxAutoRedactDialog() override;
virtual void dispose() override;
- /// Check if the dialog has any valid redaction targets.
- //bool hasTargets() const;
- /// Check if the dialog is in a valid state.
- //bool isValidState() const { return m_bIsValidState; }
-
/** Copies targets vector
* Does a shallow copy.
* Returns true if successful.
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 040fb3a9dacc..cbeb8a8705a1 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -150,13 +150,34 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget)
InsertEntryToColumn(sColumnData, TREELIST_APPEND, 0xffff, pTarget);
}
-void TargetsTable::SelectByName(const OUString& sName)
+void TargetsTable::InsertTargetAtPos(RedactionTarget* pTarget, const sal_uLong& nPos)
{
- SvTreeListEntry* pEntry = GetRowByTargetName(sName);
- if (!pEntry)
+ if (!pTarget)
+ {
+ SAL_WARN("sfx.doc", "pTarget is null in TargetsTable::InsertTarget()");
return;
+ }
+
+ // Check if the name is empty or invalid (clashing with another entry's name)
+ if (pTarget->sName.isEmpty() || GetRowByTargetName(pTarget->sName) != nullptr)
+ {
+ SAL_WARN("sfx.doc", "Repetitive or empty target name in TargetsTable::InsertTarget()");
+ pTarget->sName = GetNameProposal();
+ }
+
+ OUString sContent = pTarget->sContent;
+
+ if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED)
+ {
+ //selection_num;selection_name
+ sContent = sContent.getToken(1, ';');
+ }
- Select(pEntry);
+ OUString sColumnData = pTarget->sName + "\t" + getTypeName(pTarget->sType) + "\t" + sContent
+ + "\t" + (pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"))
+ + "\t" + (pTarget->bWholeWords ? OUString("Yes") : OUString("No"));
+
+ InsertEntryToColumn(sColumnData, nPos, 0xffff, pTarget);
}
RedactionTarget* TargetsTable::GetTargetByName(const OUString& sName)
@@ -191,23 +212,6 @@ OUString TargetsTable::GetNameProposal()
return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1);
}
-/*void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarget)
-{
- OUString sContent = pTarget->sContent;
-
- if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED)
- {
- //selection_num;selection_name
- sContent = sContent.getToken(1, ';');
- }
-
- m_xControl->set_text(nRowIndex, pTarget->sName, 0);
- m_xControl->set_text(nRowIndex, getTypeName(pTarget->sType), 1);
- m_xControl->set_text(nRowIndex, sContent, 2);
- m_xControl->set_text(nRowIndex, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3);
- m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4);
-}*/
-
IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, Button*, void)
{
//Load a targets list from a previously saved file (a json file?)
@@ -260,41 +264,38 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void)
m_pTargetsBox->InsertTarget(redactiontarget);
}
-/*IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, Button*, void)
+IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, Button*, void)
{
- sal_Int32 nSelectedRow = m_xTargetsBox->get_selected_index();
+ SvTreeListEntry* pEntry = m_pTargetsBox->FirstSelected();
// No selection, nothing to edit
- if (nSelectedRow < 0)
+ if (pEntry == nullptr)
return;
// Only one entry should be selected for editing
- if (m_xTargetsBox->get_selected_rows().size() > 1)
+ if (m_pTargetsBox->GetSelectionCount() > 1)
{
OUString sMsg(
"You have selected multiple targets, but only one target can be edited at once.");
//Warn the user about multiple selections
- std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
- getDialog(), VclMessageType::Error, VclButtonsType::Ok, sMsg));
- xBox->run();
+ ScopedVclPtrInstance<WarningBox>(this, MessBoxStyle::Ok, sMsg)->Execute();
return;
}
- // Get the redaction target to be edited
- RedactionTarget* pTarget
- = reinterpret_cast<RedactionTarget*>(m_xTargetsBox->get_id(nSelectedRow).toInt64());
+ // Get the redaction target to be edited, and its position
+ RedactionTarget* pTarget = static_cast<RedactionTarget*>(pEntry->GetUserData());
+ sal_uLong nPos = m_pTargetsBox->GetEntryPos(pEntry);
// Construct and run the edit target dialog
- SfxAddTargetDialog aEditTargetDialog(getDialog(), pTarget->sName, pTarget->sType,
- pTarget->sContent, pTarget->bCaseSensitive,
- pTarget->bWholeWords);
+ SfxAddTargetDialog aEditTargetDialog(this, pTarget->sName, pTarget->sType, pTarget->sContent,
+ pTarget->bCaseSensitive, pTarget->bWholeWords);
bool bIncomplete;
do
{
bIncomplete = false;
- if (aEditTargetDialog.run() != RET_OK)
+ if (aEditTargetDialog.Execute() != RET_OK)
return;
if (aEditTargetDialog.getName().isEmpty()
@@ -302,19 +303,16 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void)
|| aEditTargetDialog.getContent().isEmpty())
{
bIncomplete = true;
- std::unique_ptr<weld::MessageDialog> xBox(
- Application::CreateMessageDialog(getDialog(), VclMessageType::Warning,
- VclButtonsType::Ok, "All fields are required"));
- xBox->run();
+ ScopedVclPtrInstance<WarningBox>(this, MessBoxStyle::Ok, "All fields are required")
+ ->Execute();
}
else if (aEditTargetDialog.getName() != pTarget->sName
- && m_xTargetsBox->GetTargetByName(aEditTargetDialog.getName()))
+ && m_pTargetsBox->GetTargetByName(aEditTargetDialog.getName()))
{
bIncomplete = true;
- std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
- getDialog(), VclMessageType::Warning, VclButtonsType::Ok,
- "There is already a target with this name"));
- xBox->run();
+ ScopedVclPtrInstance<WarningBox>(this, MessBoxStyle::Ok,
+ "There is already a target with this name")
+ ->Execute();
}
} while (bIncomplete);
@@ -327,8 +325,12 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void)
pTarget->bWholeWords = aEditTargetDialog.isWholeWords();
// And sync the targets box row with the actual target data
- m_xTargetsBox->setRowData(nSelectedRow, pTarget);
-}*/
+ m_pTargetsBox->RemoveEntry(pEntry);
+ m_pTargetsBox->InsertTargetAtPos(pTarget, nPos);
+
+ m_pTargetsBox->SelectAll(false);
+ m_pTargetsBox->SelectRow(nPos);
+}
IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, Button*, void)
{
@@ -520,24 +522,6 @@ void SfxAutoRedactDialog::StartFileDialog(StartFileDialogType nType, const OUStr
m_pFileDlg->StartExecuteModal(aDlgClosedLink);
}
-/*void SfxAutoRedactDialog::addTarget(RedactionTarget* pTarget)
-{
- // Only the visual/display part
- m_xTargetsBox->InsertTarget(pTarget);
-
- // Actually add to the targets vector
- if (m_xTargetsBox->GetTargetByName(pTarget->sName))
- m_aTableTargets.emplace_back(pTarget, pTarget->sName);
- else
- {
- std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
- getDialog(), VclMessageType::Warning, VclButtonsType::Ok,
- "An error occurred while adding new target. Please report this incident."));
- xBox->run();
- delete pTarget;
- }
-}*/
-
void SfxAutoRedactDialog::clearTargets()
{
SvTreeListEntry* pEntry = m_pTargetsBox->First();
@@ -573,6 +557,7 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(vcl::Window* pParent)
m_pSaveBtn->SetClickHdl(LINK(this, SfxAutoRedactDialog, Save));
m_pDeleteBtn->SetClickHdl(LINK(this, SfxAutoRedactDialog, DeleteHdl));
m_pAddBtn->SetClickHdl(LINK(this, SfxAutoRedactDialog, AddHdl));
+ m_pEditBtn->SetClickHdl(LINK(this, SfxAutoRedactDialog, EditHdl));
// Can be used to remmeber the last set of redaction targets?
/*OUString sExtraData;
@@ -614,13 +599,6 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(vcl::Window* pParent)
//TODO: Warn the user with a message box
}
}*/
-
- // Handler connections
- /*m_xLoadBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, Load));
- m_xSaveBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, Save));
- m_xAddBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, AddHdl));
- m_xEditBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, EditHdl));
- m_xDeleteBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, DeleteHdl));*/
}
SfxAutoRedactDialog::~SfxAutoRedactDialog()
More information about the Libreoffice-commits
mailing list