summaryrefslogtreecommitdiffstats
path: root/sfx2/inc/autoredactdialog.hxx
blob: 5af176a6f7ce51bfa4e6bbd6a0c910a02d27aab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
#define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX

#include <memory>
#include <sal/config.h>
#include <sfx2/dllapi.h>
#include <sfx2/basedlgs.hxx>
#include <sfx2/objsh.hxx>

#include <vcl/idle.hxx>
#include <o3tl/typed_flags_set.hxx>

#include <svtools/simptabl.hxx>

enum RedactionTargetType
{
    REDACTION_TARGET_TEXT,
    REDACTION_TARGET_REGEX,
    REDACTION_TARGET_PREDEFINED,
    REDACTION_TARGET_UNKNOWN
};

/// Keeps information for a single redaction target
struct RedactionTarget
{
    OUString sName;
    RedactionTargetType sType;
    OUString sContent;
    bool bCaseSensitive;
    bool bWholeWords;
    sal_uInt32 nID;
};

/// Used to display the targets list
class TargetsTable : public SvSimpleTable
{
    SvTreeListEntry* GetRowByTargetName(const OUString& sName);

public:
    TargetsTable(SvSimpleTableContainer& rParent);
    void InsertTarget(RedactionTarget* pTarget);
    void SelectByName(const OUString& sName);
    RedactionTarget* GetTargetByName(const OUString& sName);
    OUString GetNameProposal();
};

namespace sfx2
{
class FileDialogHelper;
}

enum class StartFileDialogType
{
    Open,
    SaveAs
};

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;

    VclPtr<SvSimpleTableContainer> m_pTargetsContainer;
    VclPtr<TargetsTable> m_pTargetsBox;
    VclPtr<FixedText> m_pRedactionTargetsLabel;
    VclPtr<PushButton> m_pLoadBtn;
    VclPtr<PushButton> m_pSaveBtn;
    VclPtr<PushButton> m_pAddBtn;
    VclPtr<PushButton> m_pEditBtn;
    VclPtr<PushButton> m_pDeleteBtn;

    DECL_LINK(Load, Button*, void);
    DECL_LINK(Save, Button*, void);
    DECL_LINK(AddHdl, 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
    void clearTargets();

public:
    SfxAutoRedactDialog(vcl::Window* pParent);
    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.
     */
    bool getTargets(std::vector<std::pair<RedactionTarget*, OUString>>& r_aTargets);
};

class SfxAddTargetDialog : public SfxModalDialog
{
private:
    VclPtr<Edit> m_pName;
    VclPtr<ListBox> m_pType;
    VclPtr<FixedText> m_pLabelContent;
    VclPtr<Edit> m_pContent;
    VclPtr<FixedText> m_pLabelPredefContent;
    VclPtr<ListBox> m_pPredefContent;
    VclPtr<CheckBox> m_pCaseSensitive;
    VclPtr<CheckBox> m_pWholeWords;

    DECL_LINK(SelectTypeHdl, ListBox&, void);

public:
    SfxAddTargetDialog(vcl::Window* pWindow, const OUString& rName);
    SfxAddTargetDialog(vcl::Window* pWindow, const OUString& sName,
                       const RedactionTargetType& eTargetType, const OUString& sContent,
                       const bool& bCaseSensitive, const bool& bWholeWords);
    virtual ~SfxAddTargetDialog() override;
    virtual void dispose() override;

    OUString getName() const { return m_pName->GetText(); }
    RedactionTargetType getType() const;
    OUString getContent() const;
    bool isCaseSensitive() const { return m_pCaseSensitive->GetState() == TriState::TRISTATE_TRUE; }
    bool isWholeWords() const { return m_pWholeWords->GetState() == TriState::TRISTATE_TRUE; }
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */