Made the "Drafts and Posts folder" configurable via the options page. It will take the current location of the "Drafts and Posts folder" location from the registry and make it part of the PostEditorSettings. After this it will always get the settings from PostEditor.

This should help resolve issue #29.
This commit is contained in:
Mark Downie 2015-12-12 23:18:00 -05:00
parent 6f6426e5e8
commit 14ff60770c
7 changed files with 136 additions and 19 deletions

View File

@ -105,17 +105,28 @@ namespace OpenLiveWriter.CoreServices
dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
}
_myWeblogPostsFolder = _userSettingsRoot.GetString("PostsDirectory", null);
if (string.IsNullOrEmpty(_myWeblogPostsFolder))
string postsDirectoryPostEditor = PreferencesSettingsRoot.GetSubSettings("PostEditor").GetString("PostsDirectory", null);
if (string.IsNullOrEmpty(postsDirectoryPostEditor))
{
if ((_productName == DefaultProductName) && (string.IsNullOrEmpty(dataPath)))
_myWeblogPostsFolder = _userSettingsRoot.GetString("PostsDirectory", null);
if (string.IsNullOrEmpty(_myWeblogPostsFolder))
{
throw new DirectoryException(MessageId.PersonalDirectoryFail);
}
else
{
_myWeblogPostsFolder = Path.Combine(dataPath, "My Weblog Posts");
if ((_productName == DefaultProductName) && (string.IsNullOrEmpty(dataPath)))
{
throw new DirectoryException(MessageId.PersonalDirectoryFail);
}
else
{
_myWeblogPostsFolder = Path.Combine(dataPath, "My Weblog Posts");
}
}
PreferencesSettingsRoot.GetSubSettings("PostEditor").SetString("PostsDirectory", _myWeblogPostsFolder);
}
else
{
_myWeblogPostsFolder = postsDirectoryPostEditor;
}
// initialize diagnostics
@ -547,7 +558,7 @@ namespace OpenLiveWriter.CoreServices
{
get
{
return _myWeblogPostsFolder;
return PreferencesSettingsRoot.GetSubSettings("PostEditor").GetString("PostsDirectory", null); ;
}
}

View File

@ -3852,6 +3852,10 @@ namespace OpenLiveWriter.Localization
/// </summary>
PostEditorPrefGeneral,
/// <summary>
/// Folder Location for Posts
/// </summary>
PostEditorPrefPostLocation,
/// <summary>
/// Preferences
/// </summary>
PostEditorPrefName,
@ -3896,6 +3900,10 @@ namespace OpenLiveWriter.Localization
/// </summary>
PostEditorPrefView,
/// <summary>
/// Browse for a folder
/// </summary>
PostEditorPrefBrowseFolder,
/// <summary>
/// Unexpected error occurred while accessing local post ({0})
///
/// {1}

View File

@ -3375,6 +3375,9 @@ Unimplemented Method: {2}</value>
<data name="PostEditorPrefGeneral" xml:space="preserve">
<value>General options</value>
</data>
<data name="PostEditorPrefPostLocation" xml:space="preserve">
<value>Local drafts and recent posts folder</value>
</data>
<data name="PostEditorPrefName" xml:space="preserve">
<value>Preferences</value>
</data>
@ -3408,6 +3411,9 @@ Unimplemented Method: {2}</value>
<data name="PostEditorPrefView" xml:space="preserve">
<value>&amp;View post after publishing</value>
</data>
<data name="PostEditorPrefBrowseFolder" xml:space="preserve">
<value>Browse</value>
</data>
<data name="PostEditorStorageExceptionMessage" xml:space="preserve">
<value>Unexpected error occurred while accessing local post ({0})

View File

@ -70,28 +70,25 @@ namespace OpenLiveWriter.PostEditor
{
get
{
return _mMyWeblogPostsFolder;
return new DirectoryInfo(ApplicationEnvironment.MyWeblogPostsFolder);
}
}
private static readonly DirectoryInfo _mMyWeblogPostsFolder = new DirectoryInfo(ApplicationEnvironment.MyWeblogPostsFolder);
public static DirectoryInfo DraftsFolder
{
get
{
return _draftsFolder;
return new DirectoryInfo(Path.Combine(MyWeblogPostsFolder.FullName, "Drafts"));
}
}
private static readonly DirectoryInfo _draftsFolder = new DirectoryInfo(Path.Combine(MyWeblogPostsFolder.FullName, "Drafts"));
public static DirectoryInfo RecentPostsFolder
{
get
{
return _recentPostsFolder;
return new DirectoryInfo(Path.Combine(MyWeblogPostsFolder.FullName, "Recent Posts"));
}
}
private static readonly DirectoryInfo _recentPostsFolder = new DirectoryInfo(Path.Combine(MyWeblogPostsFolder.FullName, "Recent Posts"));
public static PostInfo[] GetRecentPosts(DirectoryInfo directory, RecentPostRequest request)
{

View File

@ -67,6 +67,13 @@ namespace OpenLiveWriter.PostEditor
}
private int _autoSaveMinutes;
public string WeblogPostsFolder
{
get { return _weblogPostsFolder; }
set { _weblogPostsFolder = value; Modified(); }
}
private string _weblogPostsFolder;
protected override void LoadPreferences()
{
PostWindowBehavior = PostEditorSettings.PostWindowBehavior;
@ -77,6 +84,7 @@ namespace OpenLiveWriter.PostEditor
TagReminder = PostEditorSettings.TagReminder;
AutoSaveDrafts = PostEditorSettings.AutoSaveDrafts;
AutoSaveMinutes = PostEditorSettings.AutoSaveMinutes;
WeblogPostsFolder = PostEditorSettings.WeblogPostsFolder;
}
protected override void SavePreferences()
@ -89,6 +97,7 @@ namespace OpenLiveWriter.PostEditor
PostEditorSettings.TagReminder = TagReminder;
PostEditorSettings.AutoSaveDrafts = AutoSaveDrafts;
PostEditorSettings.AutoSaveMinutes = AutoSaveMinutes;
PostEditorSettings.WeblogPostsFolder = WeblogPostsFolder;
}
}

View File

@ -42,6 +42,11 @@ namespace OpenLiveWriter.PostEditor
private System.Windows.Forms.CheckBox checkBoxAutoSaveDrafts;
private System.Windows.Forms.GroupBox groupBoxGeneral;
private System.Windows.Forms.CheckBox checkBoxWordCount;
private System.Windows.Forms.GroupBox groupBoxWeblogPostsFolder;
private System.Windows.Forms.TextBox textBoxWeblogPostsFolder;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
private System.Windows.Forms.Button buttonBrowserDialog;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
private WordCountPreferences _wordCountPreferences;
public PostEditorPreferencesPanel()
@ -65,6 +70,7 @@ namespace OpenLiveWriter.PostEditor
checkBoxAutoSaveDrafts.Text = Res.Get(StringId.PostEditorPrefAuto);
checkBoxWordCount.Text = Res.Get(StringId.ShowRealTimeWordCount);
PanelName = Res.Get(StringId.PostEditorPrefName);
this.groupBoxWeblogPostsFolder.Text = Res.Get(StringId.PostEditorPrefPostLocation);
}
PanelBitmap = ResourceHelper.LoadAssemblyResourceBitmap("Images.PreferencesOther.png");
@ -93,6 +99,11 @@ namespace OpenLiveWriter.PostEditor
checkBoxCategoryReminder.Checked = _postEditorPreferences.CategoryReminder;
checkBoxTagReminder.Checked = _postEditorPreferences.TagReminder;
textBoxWeblogPostsFolder.Text = _postEditorPreferences.WeblogPostsFolder;
textBoxWeblogPostsFolder.TextChanged += TextBoxWeblogPostsFolder_TextChanged;
buttonBrowserDialog.MouseClick += ButtonBrowserDialog_MouseClick;
checkBoxAutoSaveDrafts.Checked = _postEditorPreferences.AutoSaveDrafts;
checkBoxAutoSaveDrafts.CheckedChanged += new EventHandler(checkBoxAutoSaveDrafts_CheckedChanged);
@ -114,6 +125,16 @@ namespace OpenLiveWriter.PostEditor
}
private void ButtonBrowserDialog_MouseClick(object sender, MouseEventArgs e)
{
DialogResult result = folderBrowserDialog.ShowDialog();
if (result == DialogResult.OK)
{
textBoxWeblogPostsFolder.Text = folderBrowserDialog.SelectedPath;
}
}
private bool _layedOut = false;
protected override void OnLoad(EventArgs e)
{
@ -124,7 +145,8 @@ namespace OpenLiveWriter.PostEditor
LayoutHelper.FixupGroupBox(this.groupBoxPostWindows);
LayoutHelper.FixupGroupBox(this.groupBoxPublishing);
LayoutHelper.FixupGroupBox(this.groupBoxGeneral);
LayoutHelper.NaturalizeHeightAndDistribute(8, groupBoxPostWindows, groupBoxPublishing, groupBoxGeneral);
LayoutHelper.FixupGroupBox(this.groupBoxWeblogPostsFolder);
LayoutHelper.NaturalizeHeightAndDistribute(8, groupBoxPostWindows, groupBoxPublishing, groupBoxGeneral, groupBoxWeblogPostsFolder);
_layedOut = true;
}
}
@ -136,8 +158,9 @@ namespace OpenLiveWriter.PostEditor
if (_wordCountPreferences.IsModified())
_wordCountPreferences.Save();
}
PostListCache.Update();
}
private void checkBoxViewWeblog_CheckedChanged(object sender, EventArgs e)
{
@ -199,6 +222,11 @@ namespace OpenLiveWriter.PostEditor
_wordCountPreferences.EnableRealTimeWordCount = checkBoxWordCount.Checked;
}
private void TextBoxWeblogPostsFolder_TextChanged(object sender, EventArgs e)
{
_postEditorPreferences.WeblogPostsFolder = textBoxWeblogPostsFolder.Text;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
@ -236,9 +264,16 @@ namespace OpenLiveWriter.PostEditor
this.groupBoxGeneral = new System.Windows.Forms.GroupBox();
this.checkBoxAutoSaveDrafts = new System.Windows.Forms.CheckBox();
this.checkBoxWordCount = new System.Windows.Forms.CheckBox();
this.groupBoxWeblogPostsFolder = new System.Windows.Forms.GroupBox();
this.textBoxWeblogPostsFolder = new TextBox();
this.folderBrowserDialog = new FolderBrowserDialog();
this.buttonBrowserDialog = new Button();
this.flowLayoutPanel = new FlowLayoutPanel();
this.flowLayoutPanel.SuspendLayout();
this.groupBoxPublishing.SuspendLayout();
this.groupBoxPostWindows.SuspendLayout();
this.groupBoxGeneral.SuspendLayout();
this.groupBoxWeblogPostsFolder.SuspendLayout();
this.SuspendLayout();
//
// groupBoxPublishing
@ -384,23 +419,68 @@ namespace OpenLiveWriter.PostEditor
this.checkBoxWordCount.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkBoxWordCount.UseVisualStyleBackColor = true;
//
// textBoxWeblogPostsFolder
//
this.textBoxWeblogPostsFolder.Name = "textBoxWeblogPostsFolder";
this.textBoxWeblogPostsFolder.Size = new System.Drawing.Size(238, 18);
this.textBoxWeblogPostsFolder.TabIndex = 1;
this.textBoxWeblogPostsFolder.Text = "Show default post save location";
this.textBoxWeblogPostsFolder.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
this.textBoxWeblogPostsFolder.Location = new System.Drawing.Point(0, 0);
//
// buttonBrowserDialog
//
this.buttonBrowserDialog.Name = "buttonBrowserDialog";
this.buttonBrowserDialog.Text = Res.Get(StringId.PostEditorPrefBrowseFolder);
this.buttonBrowserDialog.TabIndex = 2;
this.buttonBrowserDialog.Location = new System.Drawing.Point(280, 0);
//
// FolderBrowserDialog
//
this.folderBrowserDialog.Description = "Select the directory that you want to use as the default";
this.folderBrowserDialog.ShowNewFolderButton = true;
this.folderBrowserDialog.RootFolder = Environment.SpecialFolder.Personal;
//
// flowLayoutPanel
//
this.Name = "flowLayoutPanel";
this.flowLayoutPanel.Controls.Add(this.textBoxWeblogPostsFolder);
this.flowLayoutPanel.Controls.Add(this.buttonBrowserDialog);
this.flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight;
this.flowLayoutPanel.Location = new System.Drawing.Point(16, 21);
this.flowLayoutPanel.Size = new System.Drawing.Size(325, 40);
//
// groupBoxGeneral
//
this.groupBoxWeblogPostsFolder.Controls.Add(this.flowLayoutPanel);
this.groupBoxWeblogPostsFolder.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBoxWeblogPostsFolder.Location = new System.Drawing.Point(8, 154);
this.groupBoxWeblogPostsFolder.Name = "groupBoxFolderLocation";
this.groupBoxWeblogPostsFolder.Size = new System.Drawing.Size(345, 25);
this.groupBoxWeblogPostsFolder.TabIndex = 4;
this.groupBoxWeblogPostsFolder.TabStop = false;
this.groupBoxWeblogPostsFolder.Text = "Post Folder Location";
//
// PostEditorPreferencesPanel
//
this.AccessibleName = "Preferences";
this.Controls.Add(this.groupBoxPostWindows);
this.Controls.Add(this.groupBoxPublishing);
this.Controls.Add(this.groupBoxGeneral);
this.Controls.Add(this.groupBoxWeblogPostsFolder);
this.Name = "PostEditorPreferencesPanel";
this.PanelName = "Preferences";
this.Size = new System.Drawing.Size(370, 521);
this.Controls.SetChildIndex(this.groupBoxPublishing, 0);
this.Controls.SetChildIndex(this.groupBoxPostWindows, 0);
this.Controls.SetChildIndex(this.groupBoxGeneral, 0);
this.Controls.SetChildIndex(this.groupBoxWeblogPostsFolder, 0);
this.groupBoxPublishing.ResumeLayout(false);
this.groupBoxPostWindows.ResumeLayout(false);
this.groupBoxGeneral.ResumeLayout(false);
this.groupBoxWeblogPostsFolder.ResumeLayout(false);
this.flowLayoutPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion

View File

@ -20,7 +20,6 @@ namespace OpenLiveWriter.PostEditor
public class PostEditorSettings
{
public static bool ViewPostAfterPublish
{
get { return SettingsKey.GetBoolean(VIEW_POST_AFTER_PUBLISH, true); }
@ -174,6 +173,13 @@ namespace OpenLiveWriter.PostEditor
}
private const string AUTOMATION_MODE = "AutomationMode";
public static string WeblogPostsFolder
{
get { return SettingsKey.GetString(WEBLOG_POSTS_FOLDER, null); }
set { SettingsKey.SetString(WEBLOG_POSTS_FOLDER, value); }
}
private const string WEBLOG_POSTS_FOLDER = "PostsDirectory";
internal static SettingsPersisterHelper SettingsKey = ApplicationEnvironment.PreferencesSettingsRoot.GetSubSettings("PostEditor");
public static SettingsPersisterHelper RecentEmoticonsKey = SettingsKey.GetSubSettings("RecentEmoticons");
}