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 OUString&, 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 bReadOnly = IsReadOnly();
70 if (bReadOnly)
71 {
72 mxMenuButton->set_item_visible("resolve", false);
73 mxMenuButton->set_item_visible("unresolve", false);
74 mxMenuButton->set_item_visible("resolvethread", false);
75 mxMenuButton->set_item_visible("unresolvethread", false);
76 mxMenuButton->set_item_visible("delete", false );
77 }
78 else
79 {
80 mxMenuButton->set_item_visible("resolve", !IsResolved());
81 mxMenuButton->set_item_visible("unresolve", IsResolved());
82 mxMenuButton->set_item_visible("resolvethread", !IsThreadResolved());
83 mxMenuButton->set_item_visible("unresolvethread", IsThreadResolved());
84 mxMenuButton->set_item_visible("delete", !IsReadOnlyOrProtected());
85 }
86
87 mxMenuButton->set_item_visible("deletethread", !bReadOnly);
88 mxMenuButton->set_item_visible("deleteby", !bReadOnly);
89 mxMenuButton->set_item_visible("deleteall", !bReadOnly);
90 mxMenuButton->set_item_visible("formatall", !bReadOnly);
91
92 bool bReplyVis = true;
93
94 // No answer possible if this note is in a protected section.
95 if (IsReadOnlyOrProtected())
96 {
97 mxMenuButton->set_item_visible("reply", false);
98 bReplyVis = false;
99 }
100 else
101 {
102 SvtUserOptions aUserOpt;
103 OUString sAuthor;
104 if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
105 {
106 if ((sAuthor = aUserOpt.GetID()).isEmpty())
107 {
108 sAuthor = SwResId(STR_REDLINE_UNKNOWN_AUTHOR);
109 }
110 }
111 // do not allow to reply to ourself
112 bReplyVis = sAuthor != GetAuthor();
113 }
114 mxMenuButton->set_item_visible("reply", bReplyVis);
115 mxMenuButton->set_item_visible("sep1", bReplyVis);
116}
117
118IMPL_LINK(SwAnnotationWin, KeyInputHdl, const KeyEvent&, rKeyEvt, bool)
119{
120 const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
121 if (rKeyCode.GetCode() == KEY_TAB)
122 {
123 ActivatePostIt();
124 GrabFocus();
125 return true;
126 }
127 return false;
128}
129
130} // end of namespace sw::annotation
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetFullName() const
OUString GetID() const
sal_uInt16 GetCode() const
#define FN_RESOLVE_NOTE
Definition: cmdid.h:795
#define FN_REPLY
Definition: cmdid.h:793
#define FN_DELETE_NOTE_AUTHOR
Definition: cmdid.h:786
#define FN_DELETE_ALL_NOTES
Definition: cmdid.h:787
#define FN_DELETE_COMMENT
Definition: cmdid.h:792
#define FN_DELETE_COMMENT_THREAD
Definition: cmdid.h:797
#define FN_RESOLVE_NOTE_THREAD
Definition: cmdid.h:796
#define FN_FORMAT_ALL_NOTES
Definition: cmdid.h:794
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
bool bReadOnly
constexpr sal_uInt16 KEY_TAB
IMPL_LINK(SwAnnotationWin, SelectHdl, const OUString &, rIdent, void)
IMPL_LINK_NOARG(SwAnnotationWin, ToggleHdl, weld::Toggleable &, void)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168