<commit_before>//#define MEMORYCHECK
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Bloom.Book;
using Bloom.CollectionTab;
using Bloom.ImageProcessing;
using Bloom.Properties;
using Bloom.Api;
using Bloom.web.controllers;
using Bloom.Workspace;
using L10NSharp;
using SIL.Progress;
using SIL.Reporting;
using SIL.Windows.Forms.ClearShare;
using SIL.Windows.Forms.ImageToolbox;
using SIL.Windows.Forms.Miscellaneous;
using Gecko;
using TempFile = SIL.IO.TempFile;
using Gecko.DOM;
using SIL.IO;
using SIL.Windows.Forms.ImageToolbox.ImageGallery;
using SIL.Windows.Forms.Widgets;
using System.Globalization;
using Bloom.web;
using ICSharpCode.SharpZipLib.Zip;
using SIL.Extensions;

namespace Bloom.Edit
{
	public partial class EditingView : UserControl, IBloomTabArea, IZoomManager
	{
		private readonly EditingModel _model;
		private PageListView _pageListView;
		private readonly CutCommand _cutCommand;
		private readonly CopyCommand _copyCommand;
		private readonly PasteCommand _pasteCommand;
		private readonly UndoCommand _undoCommand;
		private readonly DuplicatePageCommand _duplicatePageCommand;
		private readonly DeletePageCommand _deletePageCommand;
		private readonly SignLanguageApi _signLanguageApi;
		private Action _pendingMessageHandler;
		private bool _updatingDisplay;
		private Color _enabledToolbarColor = Palette.DarkTextAgainstBackgroundColor;
		private Color _disabledToolbarColor = Color.FromArgb(114, 74, 106);
		private bool _visible;
		private BloomWebSocketServer _webSocketServer;
		private ZoomControl _zoomControl;
		private PageListApi _pageListApi;

		public delegate EditingView Factory(); //autofac uses this

		public EditingView(EditingModel model, PageListView pageListView, CutCommand cutCommand, CopyCommand copyCommand,
			PasteCommand pasteCommand, UndoCommand undoCommand, DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand, NavigationIsolator isolator, ControlKeyEvent controlKeyEvent,
			SignLanguageApi signLanguageApi, CommonApi commonApi, EditingViewApi editingViewApi, PageListApi pageListApi)
		{
			_model = model;
			_pageListView = pageListView;
			_cutCommand = cutCommand;
			_copyCommand = copyCommand;
			_pasteCommand = pasteCommand;
			_undoCommand = undoCommand;
			_duplicatePageCommand = duplicatePageCommand;
			_deletePageCommand = deletePageCommand;
			_webSocketServer = model.EditModelSocketServer;
			_pageListApi = pageListApi;
			InitializeComponent();

			this._splitContainer2.BackColor = Palette.GeneralBackground;
			SetupThumnailLists();
			_model.SetView(this);
			// We will need to handle this in another way if we ever have multiple projects open and thus
			// multiple models and views.
			_signLanguageApi = signLanguageApi;
			signLanguageApi.Model = _model;
			signLanguageApi.View = this;
			editingViewApi.View = this;
			commonApi.Model = _model;
			_browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand);

			_browser1.GeckoReady += new EventHandler(OnGeckoReady);

			_browser1.ControlKeyEvent = controlKeyEvent;

			if(SIL.PlatformUtilities.Platform.IsMono)
			{
				RepositionButtonsForMono();
				BackgroundColorsForLinux();
			}

			controlKeyEvent.Subscribe(HandleControlKeyEvent);

			// Adding this renderer prevents a white line from showing up under the components.
			// BL-5071 We don't want a hover border on the items either.
			_menusToolStrip.Renderer = new NoBorderToolStripRenderer();

			//we're giving it to the parent control through the TopBarControls property
			Controls.Remove(_topBarPanel);
			SetupBrowserContextMenu();
#if __MonoCS__
// The inactive button images look garishly pink on Linux/Mono, but look okay on Windows.
// Merely introducing an "identity color matrix" to the image attributes appears to fix
// this problem.  (The active form looks okay with or without this fix.)
// See http://issues.bloomlibrary.org/youtrack/issue/BL-3714.
			float[][] colorMatrixElements = {
				new float[] {1,  0,  0,  0,  0},		// red scaling factor of 1
				new float[] {0,  1,  0,  0,  0},		// green scaling factor of 1
				new float[] {0,  0,  1,  0,  0},		// blue scaling factor of 1
				new float[] {0,  0,  0,  1,  0},		// alpha scaling factor of 1
				new float[] {0,  0,  0,  0,  1}};		// three translations of 0.0
			var colorMatrix = new ColorMatrix(colorMatrixElements);
			_undoButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_cutButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_pasteButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_copyButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

			// Prevent the layout choices and book language dropdown menus from closing
			// immediately in Linux/Gnome (default for ubuntu 18.04 aka bionic).
			_layoutChoices.DropDown.Closing += DropDown_Closing;
			_contentLanguagesDropdown.DropDown.Closing += DropDown_Closing;
			_layoutChoices.DropDown.Opening += DropDown_Opening;
			_contentLanguagesDropdown.DropDown.Opening += DropDown_Opening;<commit_msg>BL-9133 Get Edit View to update pagelist on title chg<commit_after>//#define MEMORYCHECK
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Bloom.Book;
using Bloom.CollectionTab;
using Bloom.ImageProcessing;
using Bloom.Properties;
using Bloom.Api;
using Bloom.web.controllers;
using Bloom.Workspace;
using L10NSharp;
using SIL.Progress;
using SIL.Reporting;
using SIL.Windows.Forms.ClearShare;
using SIL.Windows.Forms.ImageToolbox;
using SIL.Windows.Forms.Miscellaneous;
using Gecko;
using TempFile = SIL.IO.TempFile;
using Gecko.DOM;
using SIL.IO;
using SIL.Windows.Forms.ImageToolbox.ImageGallery;
using SIL.Windows.Forms.Widgets;
using System.Globalization;
using Bloom.web;
using ICSharpCode.SharpZipLib.Zip;
using SIL.Extensions;

namespace Bloom.Edit
{
	public partial class EditingView : UserControl, IBloomTabArea, IZoomManager
	{
		private readonly EditingModel _model;
		private PageListView _pageListView;
		private readonly CutCommand _cutCommand;
		private readonly CopyCommand _copyCommand;
		private readonly PasteCommand _pasteCommand;
		private readonly UndoCommand _undoCommand;
		private readonly DuplicatePageCommand _duplicatePageCommand;
		private readonly DeletePageCommand _deletePageCommand;
		private readonly SignLanguageApi _signLanguageApi;
		private Action _pendingMessageHandler;
		private bool _updatingDisplay;
		private Color _enabledToolbarColor = Palette.DarkTextAgainstBackgroundColor;
		private Color _disabledToolbarColor = Color.FromArgb(114, 74, 106);
		private bool _visible;
		private BloomWebSocketServer _webSocketServer;
		private ZoomControl _zoomControl;
		private PageListApi _pageListApi;

		public delegate EditingView Factory(); //autofac uses this

		public EditingView(EditingModel model, PageListView pageListView, CutCommand cutCommand, CopyCommand copyCommand,
			PasteCommand pasteCommand, UndoCommand undoCommand, DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand, NavigationIsolator isolator, ControlKeyEvent controlKeyEvent,
			SignLanguageApi signLanguageApi, CommonApi commonApi, EditingViewApi editingViewApi, PageListApi pageListApi, BookRenamedEvent bookRenamedEvent)
		{
			_model = model;
			_pageListView = pageListView;
			_cutCommand = cutCommand;
			_copyCommand = copyCommand;
			_pasteCommand = pasteCommand;
			_undoCommand = undoCommand;
			_duplicatePageCommand = duplicatePageCommand;
			_deletePageCommand = deletePageCommand;
			_webSocketServer = model.EditModelSocketServer;
			_pageListApi = pageListApi;
			InitializeComponent();

			this._splitContainer2.BackColor = Palette.GeneralBackground;
			SetupThumnailLists();
			_model.SetView(this);
			// We will need to handle this in another way if we ever have multiple projects open and thus
			// multiple models and views.
			_signLanguageApi = signLanguageApi;
			signLanguageApi.Model = _model;
			signLanguageApi.View = this;
			editingViewApi.View = this;
			commonApi.Model = _model;
			_browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand);

			_browser1.GeckoReady += new EventHandler(OnGeckoReady);

			_browser1.ControlKeyEvent = controlKeyEvent;

			if(SIL.PlatformUtilities.Platform.IsMono)
			{
				RepositionButtonsForMono();
				BackgroundColorsForLinux();
			}

			controlKeyEvent.Subscribe(HandleControlKeyEvent);

			// Adding this renderer prevents a white line from showing up under the components.
			// BL-5071 We don't want a hover border on the items either.
			_menusToolStrip.Renderer = new NoBorderToolStripRenderer();

			//we're giving it to the parent control through the TopBarControls property
			Controls.Remove(_topBarPanel);
			SetupBrowserContextMenu();
			bookRenamedEvent.Subscribe((book) =>
			{
				UpdatePageList(true);
			});
#if __MonoCS__
// The inactive button images look garishly pink on Linux/Mono, but look okay on Windows.
// Merely introducing an "identity color matrix" to the image attributes appears to fix
// this problem.  (The active form looks okay with or without this fix.)
// See http://issues.bloomlibrary.org/youtrack/issue/BL-3714.
			float[][] colorMatrixElements = {
				new float[] {1,  0,  0,  0,  0},		// red scaling factor of 1
				new float[] {0,  1,  0,  0,  0},		// green scaling factor of 1
				new float[] {0,  0,  1,  0,  0},		// blue scaling factor of 1
				new float[] {0,  0,  0,  1,  0},		// alpha scaling factor of 1
				new float[] {0,  0,  0,  0,  1}};		// three translations of 0.0
			var colorMatrix = new ColorMatrix(colorMatrixElements);
			_undoButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_cutButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_pasteButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
			_copyButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

			// Prevent the layout choices and book language dropdown menus from closing
			// immediately in Linux/Gnome (default for ubuntu 18.04 aka bionic).
			_layoutChoices.DropDown.Closing += DropDown_Closing;
			_contentLanguagesDropdown.DropDown.Closing += DropDown_Closing;
			_layoutChoices.DropDown.Opening += DropDown_Opening;
			_contentLanguagesDropdown.DropDown.Opening += DropDown_Opening;
{'fraction_non_alphanumeric': 0.07621417380886554, 'fraction_numerical': 0.01087457377200258, 'mean_word_length': 5.0490523968784835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428161', 'n_tokens_mistral': 3526, 'n_tokens_neox': 3106, 'n_words': 874}