LibreOffice Module sw (master) 1
AnnotationMenuButton.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <AnnotationWin.hxx>
21#include <strings.hrc>
22
24
25#include <vcl/event.hxx>
26
27#include <cmdid.h>
28
29#include <swtypes.hxx>
30
31namespace sw::annotation {
32
33IMPL_LINK(SwAnnotationWin, SelectHdl, const OString&, rIdent, void)
34{
35 if (rIdent.isEmpty())
36 return;
37
38 // tdf#136682 ensure this is the currently active sidebar win so the command
39 // operates in an active sidebar context
40 bool bSwitchedFocus = SetActiveSidebarWin();
41
42 if (rIdent == "reply")
43 ExecuteCommand(FN_REPLY);
44 if (rIdent == "resolve" || rIdent == "unresolve")
45 ExecuteCommand(FN_RESOLVE_NOTE);
46 else if (rIdent == "resolvethread" || rIdent == "unresolvethread")
47 ExecuteCommand(FN_RESOLVE_NOTE_THREAD);
48 else if (rIdent == "delete")
49 ExecuteCommand(FN_DELETE_COMMENT);
50 else if (rIdent == "deletethread")
51 ExecuteCommand(FN_DELETE_COMMENT_THREAD);
52 else if (rIdent == "deleteby")
53 ExecuteCommand(FN_DELETE_NOTE_AUTHOR);
54 else if (rIdent == "deleteall")
55 ExecuteCommand(FN_DELETE_ALL_NOTES);
56 else if (rIdent == "formatall")
57 ExecuteCommand(FN_FORMAT_ALL_NOTES);
58
59 if (bSwitchedFocus)
60 UnsetActiveSidebarWin();
61 GrabFocusToDocument();
62}
63
65{
66 if (!mxMenuButton->get_active())
67 return;
68
69 bool bReplyVis = true;
70
71 bool bReadOnly = IsReadOnly();
72 if (bReadOnly)
73 {
74 mxMenuButton->set_item_visible("reply", false);
75 bReplyVis = false;
76 mxMenuButton->set_item_visible("resolve", false);
77 mxMenuButton->set_item_visible("unresolve", false);
78 mxMenuButton->set_item_visible("resolvethread", false);
79 mxMenuButton->set_item_visible("unresolvethread", false);
80 mxMenuButton->set_item_visible("delete", false );
81 }
82 else
83 {
84 mxMenuButton->set_item_visible("resolve", !IsResolved());
85 mxMenuButton->set_item_visible("unresolve", IsResolved());
86 mxMenuButton->set_item_visible("resolvethread", !IsThreadResolved());
87 mxMenuButton->set_item_visible("unresolvethread", IsThreadResolved());
88 mxMenuButton->set_item_visible("delete", !IsProtected());
89 }
90
91 mxMenuButton->set_item_visible("deletethread", !bReadOnly);
92 mxMenuButton->set_item_visible("deleteby", !bReadOnly);
93 mxMenuButton->set_item_visible("deleteall", !bReadOnly);
94 mxMenuButton->set_item_visible("formatall", !bReadOnly);
95
96 if (IsProtected())
97 {
98 mxMenuButton->set_item_visible("reply", false);
99 bReplyVis = false;
100 }
101 else
102 {
103 SvtUserOptions aUserOpt;
104 OUString sAuthor;
105 if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
106 {
107 if ((sAuthor = aUserOpt.GetID()).isEmpty())
108 {
109 sAuthor = SwResId(STR_REDLINE_UNKNOWN_AUTHOR);
110 }
111 }
112 // do not allow to reply to ourself and no answer possible if this note is in a protected section
113 bReplyVis = sAuthor != GetAuthor();
114 mxMenuButton->set_item_visible("reply", bReplyVis);
115 }
116 mxMenuButton->set_item_visible("sep1", bReplyVis);
117}
118
119IMPL_LINK(SwAnnotationWin, KeyInputHdl, const KeyEvent&, rKeyEvt, bool)
120{
121 const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
122 if (rKeyCode.GetCode() == KEY_TAB)
123 {
124 ActivatePostIt();
125 GrabFocus();
126 return true;
127 }
128 return false;
129}
130
131} // end of namespace sw::annotation
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetFullName() const
OUString GetID() const
sal_uInt16 GetCode() const
#define FN_RESOLVE_NOTE
Definition: cmdid.h:776
#define FN_REPLY
Definition: cmdid.h:774
#define FN_DELETE_NOTE_AUTHOR
Definition: cmdid.h:767
#define FN_DELETE_ALL_NOTES
Definition: cmdid.h:768
#define FN_DELETE_COMMENT
Definition: cmdid.h:773
#define FN_DELETE_COMMENT_THREAD
Definition: cmdid.h:778
#define FN_RESOLVE_NOTE_THREAD
Definition: cmdid.h:777
#define FN_FORMAT_ALL_NOTES
Definition: cmdid.h:775
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
bool bReadOnly
constexpr sal_uInt16 KEY_TAB
IMPL_LINK(SwAnnotationWin, SelectHdl, const OString &, rIdent, void)
IMPL_LINK_NOARG(SwAnnotationWin, ToggleHdl, weld::Toggleable &, void)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165