Repository: nvaccess/nvda

Issue:
MS Outlook: reply all shortcut not always working

### Steps to reproduce:


1. Set NVDA language to French
2. Open an Outlook message
3. Press Control+shift+R to reply to all

### Actual behavior:

Nothing happens at step 3. and an error is found in the log (cf. log
[OutlookReplyAllError.log](https://github.com/nvaccess/nvda/files/4674368/OutlookReplyAllError.log)
)
Pressing NVDA+F2 before step 3. allows to get the expected behavior.

### Expected behavior:

A new message window open with the caret being in a message in edition and all e-meils of recipients in the To or Cc fields.

### Additional comments

* The issue occurs only with some messages, not all of them.
* Issue probably introduced by my own PR #10212.

### System configuration
#### NVDA installed/portable/running from source:
Installed 

#### NVDA version:
2020.1

#### Windows version:
Windows 10 1903

#### Name and version of other software in use when reproducing the issue:
MS Outlook 2016.

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your computer?
Yes

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
NVDA 2019.3.1: same issue.
NVDA 2019.2.1: no issue.

#### If addons are disabled, is your problem still occuring?
Yes

#### Did you try to run the COM registry fixing tool in NVDA menu / tools?
Yes.


Discussion:
Analysis:
The Control+shift+R in French NVDA (and French Office) is used by MS Word to toggle change tracking. It is binded to script_toggleChangeTracking of class WordDocument in the file NVDAOBjects\window\winword.py. This class is used either for Word as well as for Outlook.
However, this script should only apply to Word since change tracking is not available under Outlook.
Thus, I suggest to create a class inheriting from WordDocument that would be used only for Word, e.g. in a winword app module to be created. This class would be used to contain script_toggleChangeTracking, which seems to be the only script of WordDocument class that applies to Word specifically and not to Outlook.

Yet, I cannot explain the error, neither why it occurs only when replying to some message and not to others.


Resolving patch:
diff --git a/source/NVDAObjects/window/winword.py b/source/NVDAObjects/window/winword.py
--- a/source/NVDAObjects/window/winword.py
+++ b/source/NVDAObjects/window/winword.py
@@ -1372,24 +1372,6 @@ def script_increaseDecreaseFontSize(self,gesture):
 		# Translators: a message when increasing or decreasing font size in Microsoft Word
 		ui.message(_("{size:g} point font").format(size=val))
 
-	def script_toggleChangeTracking(self, gesture):
-		if not self.WinwordDocumentObject:
-			# We cannot fetch the Word object model, so we therefore cannot report the status change.
-			# The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
-			# or it's within Windows Defender Application Guard.
-			# In this case, just let the gesture through and don't report anything.
-			return gesture.send()
-		val = self._WaitForValueChangeForAction(
-			lambda: gesture.send(),
-			lambda: self.WinwordDocumentObject.TrackRevisions
-		)
-		if val:
-			# Translators: a message when toggling change tracking in Microsoft word
-			ui.message(_("Change tracking on"))
-		else:
-			# Translators: a message when toggling change tracking in Microsoft word
-			ui.message(_("Change tracking off"))
-
 	@script(gesture="kb:control+shift+8")
 	def script_toggleDisplayNonprintingCharacters(self, gesture):
 		if not self.WinwordWindowObject:
@@ -1514,7 +1496,6 @@ def initOverlayClass(self):
 		"kb:control+1":"changeLineSpacing",
 		"kb:control+2":"changeLineSpacing",
 		"kb:control+5":"changeLineSpacing",
-		"kb:control+shift+e": "toggleChangeTracking",
 		"kb:control+pageUp": "caret_moveByLine",
 		"kb:control+pageDown": "caret_moveByLine",
 	}
diff --git a/source/appModules/winword.py b/source/appModules/winword.py
new file mode 100644
--- /dev/null
+++ b/source/appModules/winword.py
@@ -0,0 +1,42 @@
+# A part of NonVisual Desktop Access (NVDA)
+# This file is covered by the GNU General Public License.
+# See the file COPYING for more details.
+# Copyright (C) 2019-2020 NV Access Limited, Cyrille Bougot
+
+""" App module for Microsoft Word.
+Word and Outlook share a lot of code and components. This app module gathers the code that is relevant for
+Microsoft Word only.
+"""
+
+import appModuleHandler
+from scriptHandler import script
+import ui
+from NVDAObjects.IAccessible.winword import WordDocument
+
+
+class AppModule(appModuleHandler.AppModule):
+
+	def chooseNVDAObjectOverlayClasses(self, obj, clsList):
+		if WordDocument in clsList:
+			clsList.insert(0, WinwordWordDocument)
+
+
+class WinwordWordDocument(WordDocument):
+
+	@script(gesture="kb:control+shift+e")
+	def script_toggleChangeTracking(self, gesture):
+		if not self.WinwordDocumentObject:
+			# We cannot fetch the Word object model, so we therefore cannot report the status change.
+			# The object model may be unavailable because it's within Windows Defender Application Guard.
+			# In this case, just let the gesture through and don't report anything.
+			return gesture.send()
+		val = self._WaitForValueChangeForAction(
+			lambda: gesture.send(),
+			lambda: self.WinwordDocumentObject.TrackRevisions
+		)
+		if val:
+			# Translators: a message when toggling change tracking in Microsoft word
+			ui.message(_("Change tracking on"))
+		else:
+			# Translators: a message when toggling change tracking in Microsoft word
+			ui.message(_("Change tracking off"))


Test patch: