public static void CustomAutosaveCmd() { if (Application.DocumentManager.Count == 0) { return; } var doc = Application.DocumentManager.MdiActiveDocument; if (!doc.IsReadOnly) { Autosave1.Save(ref doc); } }
public static void CustomAutosaveSettingsCmd() { var s = new SettingsForm(); Autosave1.ReadSettings(); s.checkBox1.Checked = Autosave1.AutosaveOn; s.checkBox4.Checked = Autosave1.RestartAutosaveCycleOnDocSave; s.checkBox3.Checked = Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly; for (int i1 = 1; i1 < 61; i1++) { s.comboBox1.Items.Add(i1.ToString()); } int AutosaveCycleTimeMin = -1; int.TryParse(((double)Autosave1.AutosaveCycleTime / 60000).ToString(), out AutosaveCycleTimeMin); if (AutosaveCycleTimeMin != -1) { s.comboBox1.Text = AutosaveCycleTimeMin.ToString(); } for (int i1 = 1; i1 < 31; i1++) { s.comboBox2.Items.Add(i1.ToString()); } s.comboBox2.Text = Autosave1.StorageTime.ToString(); s.textBox1.Text = Autosave1.DirName; s.checkBox2.Checked = Autosave1.CreateDir; s.textBox2.Text = Autosave1.DirPath; var dr = s.ShowDialog(); if (dr != DialogResult.OK) { s.shouldStop = true; return; } if (!Autosave1.AutosaveOn && s.checkBox1.Checked) { AutosaveCycle.Start(); } else if (Autosave1.AutosaveOn && !s.checkBox1.Checked) { AutosaveCycle.Stop(); } Autosave1.AutosaveOn = s.checkBox1.Checked; if (!Autosave1.RestartAutosaveCycleOnDocSave && s.checkBox4.Checked) { Application.DocumentManager.DocumentActivated += Autosave1.DcDocumentActivated; Application.DocumentManager.DocumentToBeDeactivated += Autosave1.DcDocumentToBeDeactivated; var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; db.SaveComplete += new DatabaseIOEventHandler(Autosave1.DbSaveComplete); } else if (Autosave1.RestartAutosaveCycleOnDocSave && !s.checkBox4.Checked) { Application.DocumentManager.DocumentActivated -= Autosave1.DcDocumentActivated; Application.DocumentManager.DocumentToBeDeactivated -= Autosave1.DcDocumentToBeDeactivated; var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; db.SaveComplete -= new DatabaseIOEventHandler(Autosave1.DbSaveComplete); } Autosave1.RestartAutosaveCycleOnDocSave = s.checkBox4.Checked; if (!Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly && s.checkBox3.Checked) { Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(Autosave1.DcDocumentCreated); } else if (Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly && !s.checkBox3.Checked) { Application.DocumentManager.DocumentCreated -= new DocumentCollectionEventHandler(Autosave1.DcDocumentCreated); } Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly = s.checkBox3.Checked; int.TryParse(s.comboBox1.Text, out Autosave1.AutosaveCycleTime); Autosave1.AutosaveCycleTime = Autosave1.AutosaveCycleTime * 60000; int.TryParse(s.comboBox2.Text, out Autosave1.StorageTime); Autosave1.DirName = s.textBox1.Text; Autosave1.CreateDir = s.checkBox2.Checked; Autosave1.DirPath = s.textBox2.Text; Autosave1.WriteSettings(); s.shouldStop = true; }
public static void ReOpenDocReadOnlyCmd() { if (Application.DocumentManager.Count == 0) { return; } var doc = Application.DocumentManager.MdiActiveDocument; if (!doc.IsReadOnly) { return; } var db = doc.Database; var ed = doc.Editor; var hs = HostApplicationServices.Current; string DocPath = hs.FindFile(doc.Name, db, FindFileHint.Default); string FileNameToAutosave = null; if (!string.IsNullOrEmpty(DocPath)) { FileNameToAutosave = Autosave1.GetFilenameToAutosave(DocPath, ref ed); } doc.CloseAndDiscard(); //doc.SendStringToExecute("CLOSE ", false, false, true); if (string.IsNullOrEmpty(FileNameToAutosave)) { return; } foreach (Document doc0 in Application.DocumentManager) { string DocPath0 = hs.FindFile(doc0.Name, doc0.Database, FindFileHint.Default); if (DocPath0 == FileNameToAutosave) { doc0.CloseAndDiscard(); } } if (File.Exists(FileNameToAutosave)) { try { File.Delete(FileNameToAutosave); } catch {} } try { File.Copy(DocPath, FileNameToAutosave); } catch { return; } Application.DocumentManager.Open(FileNameToAutosave, true); }