Make sure that when the directory change happens, any open posts save to the correct location.

This commit is contained in:
Scott Lovegrove 2016-01-24 12:55:44 +00:00
parent 6b2d2a079b
commit f5633a88e4
5 changed files with 37 additions and 5 deletions

View File

@ -558,7 +558,7 @@ namespace OpenLiveWriter.CoreServices
{
get
{
return PreferencesSettingsRoot.GetSubSettings("PostEditor").GetString("PostsDirectory", null); ;
return PreferencesSettingsRoot.GetSubSettings("PostEditor").GetString("PostsDirectory", null);
}
}

View File

@ -698,6 +698,7 @@ namespace OpenLiveWriter.PostEditor
/// the current editing state
/// </summary>
/// <param name="editingContext">editing conext</param>
/// <param name="isNewPost">if set to <c>true</c> [is new post].</param>
private void DispatchEditPost(IBlogPostEditingContext editingContext, bool isNewPost)
{
// calcluate whether the user has a "blank" unsaved post
@ -754,7 +755,7 @@ namespace OpenLiveWriter.PostEditor
else if (saveChangesResult == DialogResult.Yes && editingContext.LocalFile.Equals(LocalFile))
{
EditPostWithPostCloseEvent(LocalFile.Load());
break; ;
break;
}
}

View File

@ -206,10 +206,30 @@ namespace OpenLiveWriter.PostEditor
private PostEditorFile(DirectoryInfo targetDirectory)
{
TargetDirectory = targetDirectory;
ListenForDirectoryChanges();
}
private void ListenForDirectoryChanges()
{
var preferences = PostEditorPreferences.Instance;
preferences.PreferencesChanged -= PreferencesOnPreferencesChanged;
preferences.PreferencesChanged += PreferencesOnPreferencesChanged;
}
private void PreferencesOnPreferencesChanged(object sender, EventArgs e)
{
if (TargetDirectory?.FullName != PostEditorSettings.AutoSaveDirectory)
{
TargetDirectory = new DirectoryInfo(PostEditorPreferences.Instance.WeblogPostsFolder);
}
}
private PostEditorFile(FileInfo file)
{
TargetFile = file;
ListenForDirectoryChanges();
}
// auto-create drafts and recent-posts directories

View File

@ -1,12 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
using OpenLiveWriter.ApplicationFramework.Preferences;
using System;
namespace OpenLiveWriter.PostEditor
{
public class PostEditorPreferences : OpenLiveWriter.ApplicationFramework.Preferences.Preferences
{
private static PostEditorPreferences _instance;
public static PostEditorPreferences Instance => _instance ?? (_instance = new PostEditorPreferences());
public PostEditorPreferences() : base("Writer")
{
}
@ -74,6 +78,11 @@ namespace OpenLiveWriter.PostEditor
}
private string _weblogPostsFolder;
public void Changed()
{
OnPreferencesChanged(EventArgs.Empty);
}
protected override void LoadPreferences()
{
PostWindowBehavior = PostEditorSettings.PostWindowBehavior;

View File

@ -76,7 +76,7 @@ namespace OpenLiveWriter.PostEditor
PanelBitmap = ResourceHelper.LoadAssemblyResourceBitmap("Images.PreferencesOther.png");
_postEditorPreferences = new PostEditorPreferences();
_postEditorPreferences = PostEditorPreferences.Instance;
_postEditorPreferences.PreferencesModified += _writerPreferences_PreferencesModified;
switch (_postEditorPreferences.PostWindowBehavior)
@ -160,7 +160,7 @@ namespace OpenLiveWriter.PostEditor
Directory.CreateDirectory(destinationRecentPosts);
Directory.CreateDirectory(destinationDrafts);
if (String.Compare(_originalFolder, _postEditorPreferences.WeblogPostsFolder, true) != 0)
if (string.Compare(_originalFolder, _postEditorPreferences.WeblogPostsFolder, true, CultureInfo.CurrentUICulture) != 0)
{
string message = "You have updated the default location for your blog posts, would you like to move any existing posts?";
string caption = "Move existing posts";
@ -175,6 +175,8 @@ namespace OpenLiveWriter.PostEditor
MovePosts(Path.Combine(_originalFolder + @"\\Drafts\\"), destinationDrafts);
}
_postEditorPreferences.Changed();
}
if (_postEditorPreferences.IsModified())