/// ------------------------------------------------------------------------------------ /// <summary> /// Display the project properties dialog /// </summary> /// <param name="args"></param> /// ------------------------------------------------------------------------------------ protected virtual bool OnFileProjectProperties(object args) { // Disabling the main window circumvents the usual mechanisms for switching keyboards, // so we manually switch to the default keyboard here so that the Project Properties // dialog displays the default keyboard. When we're all done we switch back to the // keyboard we had recently. (TE-4683) var oldWsd = Keyboard.Controller.ActiveKeyboard; Keyboard.Controller.ActivateDefaultKeyboard(); // Disable windows on cache to prevent painting when fonts for writing system are changed m_app.EnableMainWindows(false); bool fDbRenamed = false; bool fFilesMoved = false; string sProject = m_cache.ProjectId.Name; string sOrigLinkedFilesRootDir = m_cache.LangProject.LinkedFilesRootDir; try { using (var dlg = new FwProjPropertiesDlg(m_cache, m_app, m_app, m_StyleSheet)) { if (dlg.ShowDialog(this) != DialogResult.OK) return true; using (new WaitCursor(this)) { fDbRenamed = dlg.ProjectNameChanged(); if (fDbRenamed) sProject = dlg.ProjectName; if (dlg.LinkedFilesChanged()) fFilesMoved = m_app.UpdateExternalLinks(sOrigLinkedFilesRootDir); if (!fDbRenamed) { // rename works only if other programs (like Flex) are not // running. In which case, the Sync operation isn't needed. // Note: We handle this here since Flex does full refresh and we don't want // this happening first. if (dlg.WritingSystemsChanged()) { using (var undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null, "kstidUndoRedoProjectProperties")) { var undoAction = new SyncUndoAction(m_app, SyncMsg.ksyncWs); undoAction.Do(); m_cache.DomainDataByFlid.GetActionHandler().AddAction(undoAction); undoHelper.RollBack = false; } } } } } } finally { m_app.EnableMainWindows(true); if (!fDbRenamed && !fFilesMoved) // no need for refresh when total shutdown & reopen { // Make sure windows for this cache are now enabled. // if the dialog merged two writing systems it will close/dispose this FwMainWnd. // if so, don't try to access any properties like EditingHelper or we'll crash (TE-7297). if (!IsDisposed) { // Restore the previous keyboard if (oldWsd != null) oldWsd.Activate(); } } } if (fDbRenamed) m_app.FwManager.RenameProject(sProject, m_app); return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Launches the proj properties DLG. /// </summary> /// <param name="startOnWSPage">if set to <c>true</c> [start on WS page].</param> /// ------------------------------------------------------------------------------------ private void LaunchProjPropertiesDlg(bool startOnWSPage) { FdoCache cache = Cache; bool fDbRenamed = false; string sServer = cache.ServerName; string sDatabase = cache.DatabaseName; string sProject = cache.LangProject.Name.UserDefaultWritingSystem; if (sProject != sDatabase) { cache.LangProject.Name.UserDefaultWritingSystem = sDatabase; sProject = sDatabase; } string sExtLinkRootDir = cache.LangProject.ExternalLinkRootDir; using (FwProjPropertiesDlg dlg = new FwProjPropertiesDlg(cache, FwApp.App, FwApp.App, FwApp.App, Logger.Stream, cache.LangProject.Hvo, HvoAppRootObject, cache.DefaultUserWs, FontHeightAdjuster.StyleSheetFromMediator(Mediator))) { if (startOnWSPage) dlg.StartWithWSPage(); if (dlg.ShowDialog(this) != DialogResult.Abort) { fDbRenamed = dlg.ProjectNameChanged(); if (fDbRenamed) { sProject = cache.LangProject.Name.UserDefaultWritingSystem; } bool fFilesMoved = false; if (dlg.ExternalLinkChanged()) { fFilesMoved = FwApp.UpdateExternalLinks(sExtLinkRootDir, cache.LangProject); } // no need for any of these refreshes if entire window has been/will be // destroyed and recreated. if (!fDbRenamed && !fFilesMoved) { bool fDidRefresh = false; if (dlg.NewRenderingNeeded() && FwApp.App is FwXApp) { Mediator.BroadcastMessage("MasterRefresh", null); // Part of fixing LT-2339: redisplay with changes. fDidRefresh = true; } if (dlg.WritingSystemsChanged()) { // Since we are going to do a full refresh, we don't want to sync the writing systems here as that // adds several more seconds updating everything prior to doing the full refresh. If we really need // to notify other apps of this change, we need some better approach, or sync a full refresh (but I // (KZ) tried this and it runs into the same huge delay as calling OnMasterRefresh directly. Also, it // doesn't appear that a call to Synchronize gets a sync message to the database anyway. It just // does the work immediately on the local copy). //FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncWs, 0, 0), cache); // JohnT: So many things depend on the current list of writing systems...for example, // everywhere we display all writing systems, or best writing system, or default writing system... if (!fDidRefresh && FwApp.App is FwXApp) { Mediator.BroadcastMessage("MasterRefresh", null); // Note: calling OnMasterRefresh directly takes many minutes reloading and painting // everything in the process of removing the browse control in WarmBootPart1. //(FwApp.App as FwXApp).OnMasterRefresh(null); fDidRefresh = true; } } if (!fDidRefresh && dlg.SortChanged() && FwApp.App is FwXApp) Mediator.BroadcastMessage("MasterRefresh", null); Mediator.PropertyTable.SetProperty("DocumentName", cache.ProjectName()); Mediator.PropertyTable.SetPropertyPersistence("DocumentName", false); SetWindowLabel(); } } } if (fDbRenamed) { string oldFilenamePrefix = String.Format("db${0}$", sDatabase); string newFilenamePrefix = String.Format("db${0}$", sProject); //Make a copy all the settings files to match the new project name. DirectoryInfo di = new DirectoryInfo(Mediator.PropertyTable.UserSettingDirectory); string findOldFilenames = String.Format("db${0}$*", sDatabase); System.IO.FileInfo[] fi = di.GetFiles(findOldFilenames); foreach (System.IO.FileInfo f in fi) { string newname = CreateNewFileName(f.FullName, oldFilenamePrefix, newFilenamePrefix); File.Copy(f.FullName, newname, true); } // The file db$ProjectName$Settings.xml cannot just be copied because the PropertyTable // settings have to be renamed to reflect the new project name. // Therefore before renaming the database we need to save the project specific PropertyTable settings // to a new file using the new project name in the filename and property names. Mediator.PropertyTable.SaveLocalSettingsForNewProjectName(sDatabase, sProject); bool fRenameSucceeded = false; fRenameSucceeded = FwApp.App.RenameProject(sServer, sDatabase, sProject); if (fRenameSucceeded) { //Now delete all old settings files. foreach (System.IO.FileInfo f in fi) { if (File.Exists(f.FullName)) File.Delete(f.FullName); } } else { //delete the new settings files since the database rename failed foreach (System.IO.FileInfo f in fi) { string newname = CreateNewFileName(f.FullName, oldFilenamePrefix, newFilenamePrefix); if (File.Exists(newname)) File.Delete(newname); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the project properties dialog /// </summary> /// <param name="args"></param> /// ------------------------------------------------------------------------------------ protected virtual bool OnFileProjectProperties(object args) { // Disabling the main window circumvents the usual mechanisms for switching keyboards, // so we manually switch to the default keyboard here so that the Project Properties // dialog displays the default keyboard. When we're all done we switch back to the // keyboard we had recently. (TE-4683) int oldWs = 0; if (EditingHelper != null) // JohnT: guard against e.g. TE-6543. oldWs = EditingHelper.SetKeyboardForWs(-1); // Disable windows on cache to prevent painting when fonts for writing system are // changed FwApp.App.EnableSameProjectWindows(m_cache, false); bool fDbRenamed = false; bool fFilesMoved = false; string sServer = m_cache.ServerName; string sDatabase = m_cache.DatabaseName; string sProject = m_cache.LangProject.Name.UserDefaultWritingSystem; string sOrigExtLinkRootDir = m_cache.LangProject.ExternalLinkRootDir; try { using (FwProjPropertiesDlg dlg = new FwProjPropertiesDlg(m_cache, FwApp.App, FwApp.App, FwApp.App, Logger.Stream, m_cache.LangProject.Hvo, HvoAppRootObject, m_cache.DefaultUserWs, FontHeightAdjuster.StyleSheetFromMediator(Mediator))) { using (new UndoTaskHelper(m_cache.MainCacheAccessor, null, "kstidUndoRedoProjectProperties")) { if (dlg.ShowDialog(this) != DialogResult.OK) return true; using (new WaitCursor(this)) { fDbRenamed = dlg.ProjectNameChanged(); if (fDbRenamed) sProject = m_cache.LangProject.Name.UserDefaultWritingSystem; if (dlg.ExternalLinkChanged()) fFilesMoved = FwApp.UpdateExternalLinks(sOrigExtLinkRootDir, m_cache.LangProject); if (!fDbRenamed) { // rename works only if other programs (like Flex) are not // running. In which case, the Sync operation isn't needed. // Note: We handle this here since Flex does full refresh and we don't want // this happening first. if (dlg.WritingSystemsChanged()) { SyncUndoAction undoAction = new SyncUndoAction(m_cache, FwApp.App, new SyncInfo(SyncMsg.ksyncWs, 0, 0)); undoAction.Do(); m_cache.ActionHandlerAccessor.AddAction(undoAction); } } } } } } finally { if (!fDbRenamed && !fFilesMoved) // no need for refresh when total shutdown & reopen { // Make sure windows for this cache are now enabled. FwApp.App.EnableSameProjectWindows(m_cache, true); // if the dialog merged two writing systems it will close/dispose this FwMainWnd. // if so, don't try to access any properties like EditingHelper or we'll crash (TE-7297). if (!this.IsDisposed) { // Restore the previous keyboard if (oldWs != 0 && EditingHelper != null) EditingHelper.SetKeyboardForWs(oldWs); } } } if (fDbRenamed) FwApp.App.RenameProject(sServer, sDatabase, sProject); return true; }