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

        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
                            LanguageSettings languageSettings,
                            TemplateInsertionCommand templateInsertionCommand,
                            PageListChangedEvent pageListChangedEvent,
                            RelocatePageEvent relocatePageEvent,
                            BookRefreshEvent bookRefreshEvent,
                            DuplicatePageCommand duplicatePageCommand,
                            DeletePageCommand deletePageCommand,
                            SelectedTabChangedEvent selectedTabChangedEvent,
                            SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                            LibraryClosing libraryClosingEvent,
                            LocalizationChangedEvent localizationChangedEvent,
                            CollectionSettings collectionSettings,
                            SendReceiver sendReceiver,
                            EnhancedImageServer server)
        {
            _bookSelection        = bookSelection;
            _pageSelection        = pageSelection;
            _languageSettings     = languageSettings;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand    = deletePageCommand;
            _collectionSettings   = collectionSettings;
            _sendReceiver         = sendReceiver;
            _server = server;

            bookSelection.SelectionChanged      += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged      += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer    = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o => SaveNow());
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                    _view.UpdateTemplateList();
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List <ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
            _server.CurrentBook = CurrentBook;
        }
Example #2
0
        //autofac uses this
        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
			LanguageSettings languageSettings,
			TemplateInsertionCommand templateInsertionCommand,
			PageListChangedEvent pageListChangedEvent,
			RelocatePageEvent relocatePageEvent,
			BookRefreshEvent bookRefreshEvent,
			DeletePageCommand deletePageCommand,
			SelectedTabChangedEvent selectedTabChangedEvent,
			SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
			LibraryClosing libraryClosingEvent,
			CollectionSettings collectionSettings,
			SendReceiver sendReceiver)
        {
            _bookSelection = bookSelection;
            _pageSelection = pageSelection;
            _languageSettings = languageSettings;
            _deletePageCommand = deletePageCommand;
            _collectionSettings = collectionSettings;
            _sendReceiver = sendReceiver;

            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            deletePageCommand.Implementer=OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o=>SaveNow());
            _contentLanguages = new List<ContentLanguage>();
        }
Example #3
0
        public delegate EditingModel Factory();        //autofac uses this

        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
                            LanguageSettings languageSettings,
                            TemplateInsertionCommand templateInsertionCommand,
                            PageListChangedEvent pageListChangedEvent,
                            RelocatePageEvent relocatePageEvent,
                            BookRefreshEvent bookRefreshEvent,
                            DeletePageCommand deletePageCommand,
                            SelectedTabChangedEvent selectedTabChangedEvent,
                            SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                            LibraryClosing libraryClosingEvent,
                            CollectionSettings collectionSettings,
                            SendReceiver sendReceiver)
        {
            _bookSelection      = bookSelection;
            _pageSelection      = pageSelection;
            _languageSettings   = languageSettings;
            _deletePageCommand  = deletePageCommand;
            _collectionSettings = collectionSettings;
            _sendReceiver       = sendReceiver;

            bookSelection.SelectionChanged      += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged      += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            deletePageCommand.Implementer = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o => SaveNow());
            _contentLanguages = new List <ContentLanguage>();
        }
Example #4
0
        public Shell(Func<WorkspaceView> projectViewFactory,
												CollectionSettings collectionSettings,
												BookDownloadStartingEvent bookDownloadStartingEvent,
												LibraryClosing libraryClosingEvent,
												QueueRenameOfCollection queueRenameOfCollection,
												ControlKeyEvent controlKeyEvent)
        {
            queueRenameOfCollection.Subscribe(newName => _nameToChangeCollectionUponClosing = newName.Trim().SanitizeFilename('-'));
            _collectionSettings = collectionSettings;
            _libraryClosingEvent = libraryClosingEvent;
            _controlKeyEvent = controlKeyEvent;
            InitializeComponent();

            //bring the application to the front (will normally be behind the user's web browser)
            bookDownloadStartingEvent.Subscribe((x) =>
            {
                try
                {
                    this.Invoke((Action)this.Activate);
                }
                catch (Exception e)
                {
                    Debug.Fail("(Debug Only) Can't bring to front in the current state: " + e.Message);
                    //swallow... so we were in some state that we couldn't come to the front... that's ok.
                }
            });

            #if DEBUG
            WindowState = FormWindowState.Normal;
            //this.FormBorderStyle = FormBorderStyle.None;  //fullscreen

            Size = new Size(1024,720);
            #else
            // We only want this screen size context menu in Debug mode
            ContextMenuStrip = null;
            #endif
            _workspaceView = projectViewFactory();
            _workspaceView.CloseCurrentProject += ((x, y) =>
                                                    {
                                                        UserWantsToOpenADifferentProject = true;
                                                        Close();
                                                    });

            _workspaceView.ReopenCurrentProject += ((x, y) =>
            {
                UserWantsToOpeReopenProject = true;
                Close();
            });

            _workspaceView.BackColor =
                System.Drawing.Color.FromArgb(64,64,64);
                                        _workspaceView.Dock = System.Windows.Forms.DockStyle.Fill;

            this.Controls.Add(this._workspaceView);

            SetWindowText(null);
        }
Example #5
0
        public Shell(Func<WorkspaceView> projectViewFactory, CollectionSettings collectionSettings, LibraryClosing libraryClosingEvent, QueueRenameOfCollection queueRenameOfCollection, Sparkle _sparkle)
        {
            queueRenameOfCollection.Subscribe(newName => _nameToChangeCollectionUponClosing = newName.Trim().SanitizeFilename('-'));
            _collectionSettings = collectionSettings;
            _libraryClosingEvent = libraryClosingEvent;
            InitializeComponent();

            #if DEBUG
            WindowState = FormWindowState.Normal;
            //this.FormBorderStyle = FormBorderStyle.None;  //fullscreen

            Size = new Size(1024,720);
            #endif
            _workspaceView = projectViewFactory();
            _workspaceView.CloseCurrentProject += ((x, y) =>
                                                    {
                                                        UserWantsToOpenADifferentProject = true;
                                                        Close();
                                                    });

            _sparkle.AboutToExitForInstallerRun += ((x, cancellable) =>
            {
                cancellable.Cancel = false;
                QuitForVersionUpdate = true;
                Close();
            });

            _workspaceView.ReopenCurrentProject += ((x, y) =>
            {
                UserWantsToOpeReopenProject = true;
                Close();
            });

            SystemEvents.SessionEnding += ((x,y)=>
            {
                QuitForSystemShutdown=true;
                Close();
            });

            _workspaceView.BackColor =
                System.Drawing.Color.FromArgb(64,64,64);
                                        _workspaceView.Dock = System.Windows.Forms.DockStyle.Fill;

            this.Controls.Add(this._workspaceView);

            SetWindowText();
        }
        public TeamCollectionManager(string localCollectionPath, BloomWebSocketServer webSocketServer,
                                     BookRenamedEvent bookRenamedEvent, BookStatusChangeEvent bookStatusChangeEvent,
                                     BookSelection bookSelection, LibraryClosing libraryClosingEvent)
        {
            _webSocketServer       = webSocketServer;
            _bookStatusChangeEvent = bookStatusChangeEvent;
            _localCollectionFolder = Path.GetDirectoryName(localCollectionPath);
            BookSelection          = bookSelection;
            libraryClosingEvent?.Subscribe((x) =>
            {
                // When closing the collection...especially if we're restarting due to
                // changed settings!...we need to save any settings changes to the repo.
                // In such cases we can't safely wait for the change watcher to write things,
                // because (a) if we're shutting down for good, we just might not detect the
                // change before everything shuts down; and (b) if we're reopening the collection,
                // we might overwrite the change with current collection settings before we
                // save the new ones.
                if (CurrentCollection != null)
                {
                    CurrentCollection.SyncLocalAndRepoCollectionFiles(false);
                }
                else if (Settings.HaveEnterpriseFeatures && CurrentCollectionEvenIfDisconnected != null &&
                         CurrentCollectionEvenIfDisconnected is DisconnectedTeamCollection disconnectedTC && disconnectedTC.DisconnectedBecauseNoEnterprise)
                {
                    // We were disconnected because of Enterprise being off, but now the user has
                    // turned Enterprise on again. We really need to save that, even though we usually don't
                    // save settings changes when disconnected. Otherwise, restarting will restore the
                    // no-enterprise state, and we will be stuck.
                    // Note: We don't need to check for admin privileges here. If the user isn't an admin,
                    // he could not have made any changes to settings, including turning on enterprise.
                    var tempCollectionLinkPath = GetTcLinkPathFromLcPath(_localCollectionFolder);
                    if (RobustFile.Exists(tempCollectionLinkPath))
                    {
                        try
                        {
                            var repoFolderPath        = RepoFolderPathFromLinkPath(tempCollectionLinkPath);
                            var tempCollection        = new FolderTeamCollection(this, _localCollectionFolder, repoFolderPath);
                            var problemWithConnection = tempCollection.CheckConnection();
                            if (problemWithConnection == null)
                            {
                                tempCollection.SyncLocalAndRepoCollectionFiles(false);
                            }
                            else
                            {
                                NonFatalProblem.Report(ModalIf.All, PassiveIf.All, "Bloom could not save your settings to the Team Collection: " + problemWithConnection.TextForDisplay,
                                                       null, null, true);
                            }
                        }
                        catch (Exception ex)
                        {
                            NonFatalProblem.Report(ModalIf.All, PassiveIf.All, "Bloom could not save your settings to the Team Collection",
                                                   null, ex, true);
                        }
                    }
                    // What if there's NOT a TC link file? Then it would be pathological to have a CurrentCollectionEvenIfDisconnected.
                    // It's no longer a TC, so we don't need to save the settings to the TC. For now I'm just not going to do anything.
                }
            });
            bookRenamedEvent.Subscribe(pair =>
            {
                CurrentCollectionEvenIfDisconnected?.HandleBookRename(Path.GetFileName(pair.Key), Path.GetFileName(pair.Value));
            });
            var impersonatePath = Path.Combine(_localCollectionFolder, "impersonate.txt");

            if (RobustFile.Exists(impersonatePath))
            {
                var lines = RobustFile.ReadAllLines(impersonatePath);
                _overrideCurrentUser = lines.FirstOrDefault();
                if (lines.Length > 1)
                {
                    _overrideMachineName = lines[1];
                }
                if (lines.Length > 2)
                {
                    _overrideCurrentUserFirstName = lines[2];
                }
                if (lines.Length > 3)
                {
                    _overrideCurrentUserSurname = lines[3];
                }
            }

            var localCollectionLinkPath = GetTcLinkPathFromLcPath(_localCollectionFolder);

            if (RobustFile.Exists(localCollectionLinkPath))
            {
                try
                {
                    var repoFolderPath = RepoFolderPathFromLinkPath(localCollectionLinkPath);
                    CurrentCollection = new FolderTeamCollection(this, _localCollectionFolder, repoFolderPath);                     // will be replaced if CheckConnection fails
                    if (CheckConnection())
                    {
                        CurrentCollectionEvenIfDisconnected = CurrentCollection;
                        CurrentCollection.SocketServer      = SocketServer;
                        CurrentCollection.TCManager         = this;
                        // Later, we will sync everything else, but we want the current collection settings before
                        // we create the CollectionSettings object.
                        if (ForceNextSyncToLocal)
                        {
                            ForceNextSyncToLocal = false;
                            CurrentCollection.CopyRepoCollectionFilesToLocal(_localCollectionFolder);
                        }
                        else
                        {
                            CurrentCollection.SyncLocalAndRepoCollectionFiles();
                        }
                    }
                    // else CheckConnection has set up a DisconnectedRepo if that is relevant.
                }
                catch (Exception ex)
                {
                    NonFatalProblem.Report(ModalIf.All, PassiveIf.All, "Bloom found Team Collection settings but could not process them", null, ex, true);
                    CurrentCollection = null;
                    CurrentCollectionEvenIfDisconnected = null;
                }
            }
        }
Example #7
0
        //autofac uses this
        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
			TemplateInsertionCommand templateInsertionCommand,
			PageListChangedEvent pageListChangedEvent,
			RelocatePageEvent relocatePageEvent,
			BookRefreshEvent bookRefreshEvent,
			PageRefreshEvent pageRefreshEvent,
			DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand,
			SelectedTabChangedEvent selectedTabChangedEvent,
			SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
			LibraryClosing libraryClosingEvent,
			LocalizationChangedEvent localizationChangedEvent,
			CollectionSettings collectionSettings,
			//SendReceiver sendReceiver,
			EnhancedImageServer server,
			BloomWebSocketServer webSocketServer)
        {
            _bookSelection = bookSelection;
            _pageSelection = pageSelection;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand = deletePageCommand;
            _collectionSettings = collectionSettings;
            //_sendReceiver = sendReceiver;
            _server = server;
            _webSocketServer = webSocketServer;
            _templatePagesDict = null;

            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged += new EventHandler(OnPageSelectionChanged);
            pageSelection.SelectionChanging += OnPageSelectionChanging;
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            pageRefreshEvent.Subscribe((PageRefreshEvent.SaveBehavior behavior) =>
            {
                switch (behavior)
                {
                    case PageRefreshEvent.SaveBehavior.SaveBeforeRefresh:
                        RethinkPageAndReloadIt(null);
                        break;

                    case PageRefreshEvent.SaveBehavior.JustRedisplay:
                        RefreshDisplayOfCurrentPage();
                        break;
                }
            });

            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o =>
            {
                if (Visible)
                    SaveNow();
            });
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List<ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
        }