ssg: advanced config saving
This commit is contained in:
parent
3a1502dd4f
commit
406a63cc82
|
@ -33,7 +33,7 @@ namespace OpenLiveWriter.ApplicationFramework.Preferences
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The PreferencesPanel list.
|
/// The PreferencesPanel list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private ArrayList preferencesPanelList = new ArrayList();
|
protected ArrayList preferencesPanelList = new ArrayList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A value which indicates whether the form is initialized.
|
/// A value which indicates whether the form is initialized.
|
||||||
|
@ -391,7 +391,7 @@ namespace OpenLiveWriter.ApplicationFramework.Preferences
|
||||||
/// Helper method to save Preferences.
|
/// Helper method to save Preferences.
|
||||||
/// Returns true if saved successfully.
|
/// Returns true if saved successfully.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool SavePreferences()
|
protected virtual bool SavePreferences()
|
||||||
{
|
{
|
||||||
TabSwitcher tabSwitcher = new TabSwitcher(sideBarControl);
|
TabSwitcher tabSwitcher = new TabSwitcher(sideBarControl);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ using OpenLiveWriter.BlogClient;
|
||||||
using OpenLiveWriter.PostEditor;
|
using OpenLiveWriter.PostEditor;
|
||||||
using OpenLiveWriter.ApplicationFramework.Preferences;
|
using OpenLiveWriter.ApplicationFramework.Preferences;
|
||||||
using OpenLiveWriter.PostEditor.Configuration.Wizard;
|
using OpenLiveWriter.PostEditor.Configuration.Wizard;
|
||||||
|
using OpenLiveWriter.BlogClient.Clients.StaticSite;
|
||||||
|
|
||||||
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
{
|
{
|
||||||
|
@ -94,12 +95,42 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
set => textBoxImagesPath.Text = value;
|
set => textBoxImagesPath.Text = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthoringPanel(StaticSitePreferencesController controller, TemporaryBlogSettings blogSettings)
|
public AuthoringPanel(StaticSitePreferencesController controller)
|
||||||
: base(controller, blogSettings)
|
: base(controller)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadConfig()
|
||||||
|
{
|
||||||
|
PostsPath = _controller.Config.PostsPath;
|
||||||
|
DraftsEnabled = _controller.Config.DraftsEnabled;
|
||||||
|
DraftsPath = _controller.Config.DraftsPath;
|
||||||
|
PagesEnabled = _controller.Config.PagesEnabled;
|
||||||
|
PagesPath = _controller.Config.PagesPath;
|
||||||
|
PagesStoredInRoot = _controller.Config.PagesPath == ".";
|
||||||
|
ImagesEnabled = _controller.Config.ImagesEnabled;
|
||||||
|
ImagesPath = _controller.Config.ImagesPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ValidateConfig()
|
||||||
|
=> _controller.Config.Validator
|
||||||
|
.ValidatePostsPath()
|
||||||
|
.ValidateDraftsPath()
|
||||||
|
.ValidatePagesPath()
|
||||||
|
.ValidateImagesPath();
|
||||||
|
|
||||||
|
public override void Save()
|
||||||
|
{
|
||||||
|
_controller.Config.PostsPath = PostsPath;
|
||||||
|
_controller.Config.DraftsEnabled = DraftsEnabled;
|
||||||
|
_controller.Config.DraftsPath = DraftsPath;
|
||||||
|
_controller.Config.PagesEnabled = PagesEnabled;
|
||||||
|
_controller.Config.PagesPath = PagesStoredInRoot ? "." : PagesPath;
|
||||||
|
_controller.Config.ImagesEnabled = ImagesEnabled;
|
||||||
|
_controller.Config.ImagesPath = ImagesPath;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
|
@ -46,19 +46,6 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// private System.ComponentModel.Container components = null;
|
// private System.ComponentModel.Container components = null;
|
||||||
|
|
||||||
public BuildPublishPanel(StaticSitePreferencesController controller, TemporaryBlogSettings blogSettings)
|
|
||||||
: base(controller, blogSettings)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
numericUpDownCmdTimeout.Maximum = int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
|
||||||
{
|
|
||||||
base.OnLoad(e);
|
|
||||||
RecomputeEnabledStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowCmdWindows
|
public bool ShowCmdWindows
|
||||||
{
|
{
|
||||||
get => checkBoxShowCommandWindows.Checked;
|
get => checkBoxShowCommandWindows.Checked;
|
||||||
|
@ -113,6 +100,45 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
set => textBoxPublishCommand.Text = value;
|
set => textBoxPublishCommand.Text = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BuildPublishPanel(StaticSitePreferencesController controller)
|
||||||
|
: base(controller)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
numericUpDownCmdTimeout.Maximum = int.MaxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadConfig()
|
||||||
|
{
|
||||||
|
ShowCmdWindows = _controller.Config.ShowCmdWindows;
|
||||||
|
CmdTimeoutMs = _controller.Config.CmdTimeoutMs;
|
||||||
|
BuildingEnabled = _controller.Config.BuildingEnabled;
|
||||||
|
BuildCommand = _controller.Config.BuildCommand;
|
||||||
|
OutputPath = _controller.Config.OutputPath;
|
||||||
|
PublishCommand = _controller.Config.PublishCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ValidateConfig()
|
||||||
|
=> _controller.Config.Validator
|
||||||
|
.ValidateBuildCommand()
|
||||||
|
.ValidateOutputPath()
|
||||||
|
.ValidatePublishCommand();
|
||||||
|
|
||||||
|
public override void Save()
|
||||||
|
{
|
||||||
|
_controller.Config.ShowCmdWindows = ShowCmdWindows;
|
||||||
|
_controller.Config.CmdTimeoutMs = CmdTimeoutMs;
|
||||||
|
_controller.Config.BuildingEnabled = BuildingEnabled;
|
||||||
|
_controller.Config.BuildCommand = BuildCommand;
|
||||||
|
_controller.Config.OutputPath = OutputPath;
|
||||||
|
_controller.Config.PublishCommand = PublishCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLoad(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLoad(e);
|
||||||
|
RecomputeEnabledStates();
|
||||||
|
}
|
||||||
|
|
||||||
#region Component Designer generated code
|
#region Component Designer generated code
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
|
|
|
@ -40,12 +40,26 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
private Label labelSubtitle;
|
private Label labelSubtitle;
|
||||||
private Dictionary<KeyIdentifier, DataGridViewRow> _keyRowMap = new Dictionary<KeyIdentifier, DataGridViewRow>();
|
private Dictionary<KeyIdentifier, DataGridViewRow> _keyRowMap = new Dictionary<KeyIdentifier, DataGridViewRow>();
|
||||||
|
|
||||||
public FrontMatterPanel(StaticSitePreferencesController controller, TemporaryBlogSettings blogSettings)
|
public FrontMatterPanel(StaticSitePreferencesController controller)
|
||||||
: base(controller, blogSettings)
|
: base(controller)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadConfig()
|
||||||
|
{
|
||||||
|
Keys = _controller.Config.FrontMatterKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ValidateConfig()
|
||||||
|
{
|
||||||
|
// No validator for FrontMatterKeys yet
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Save()
|
||||||
|
{
|
||||||
|
_controller.Config.FrontMatterKeys = Keys;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLayout(LayoutEventArgs e)
|
protected override void OnLayout(LayoutEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@ using OpenLiveWriter.BlogClient;
|
||||||
using OpenLiveWriter.PostEditor;
|
using OpenLiveWriter.PostEditor;
|
||||||
using OpenLiveWriter.ApplicationFramework.Preferences;
|
using OpenLiveWriter.ApplicationFramework.Preferences;
|
||||||
using OpenLiveWriter.PostEditor.Configuration.Wizard;
|
using OpenLiveWriter.PostEditor.Configuration.Wizard;
|
||||||
|
using OpenLiveWriter.BlogClient.Clients.StaticSite;
|
||||||
|
|
||||||
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
{
|
{
|
||||||
|
@ -62,12 +63,29 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
set => textBoxLocalSitePath.Text = value;
|
set => textBoxLocalSitePath.Text = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeneralPanel(StaticSitePreferencesController controller, TemporaryBlogSettings blogSettings)
|
public GeneralPanel(StaticSitePreferencesController controller)
|
||||||
: base(controller, blogSettings)
|
: base(controller)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadConfig()
|
||||||
|
{
|
||||||
|
SiteTitle = _controller.Config.SiteTitle;
|
||||||
|
SiteUrl = _controller.Config.SiteUrl;
|
||||||
|
LocalSitePath = _controller.Config.LocalSitePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ValidateConfig()
|
||||||
|
=> _controller.Config.Validator.ValidateLocalSitePath();
|
||||||
|
|
||||||
|
public override void Save()
|
||||||
|
{
|
||||||
|
_controller.Config.SiteTitle = SiteTitle;
|
||||||
|
_controller.Config.SiteUrl = SiteUrl;
|
||||||
|
_controller.Config.LocalSitePath = LocalSitePath;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
|
@ -17,9 +17,11 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
{
|
{
|
||||||
public class StaticSitePreferencesController
|
public class StaticSitePreferencesController
|
||||||
{
|
{
|
||||||
private TemporaryBlogSettings _temporarySettings;
|
public StaticSiteConfig Config { get; set; }
|
||||||
private PreferencesForm _form;
|
|
||||||
|
|
||||||
|
private TemporaryBlogSettings _temporarySettings;
|
||||||
|
|
||||||
|
private StaticSitePreferencesForm formPreferences;
|
||||||
private GeneralPanel panelGeneral;
|
private GeneralPanel panelGeneral;
|
||||||
private AuthoringPanel panelAuthoring;
|
private AuthoringPanel panelAuthoring;
|
||||||
private FrontMatterPanel panelFrontMatter;
|
private FrontMatterPanel panelFrontMatter;
|
||||||
|
@ -28,46 +30,69 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
public StaticSitePreferencesController(TemporaryBlogSettings blogSettings)
|
public StaticSitePreferencesController(TemporaryBlogSettings blogSettings)
|
||||||
{
|
{
|
||||||
_temporarySettings = blogSettings;
|
_temporarySettings = blogSettings;
|
||||||
_form = new PreferencesForm();
|
LoadConfigFromBlogSettings();
|
||||||
|
|
||||||
panelGeneral = new GeneralPanel(this, blogSettings);
|
panelGeneral = new GeneralPanel(this);
|
||||||
panelAuthoring = new AuthoringPanel(this, blogSettings);
|
panelAuthoring = new AuthoringPanel(this);
|
||||||
panelFrontMatter = new FrontMatterPanel(this, blogSettings);
|
panelFrontMatter = new FrontMatterPanel(this);
|
||||||
panelBuildPublish = new BuildPublishPanel(this, blogSettings);
|
panelBuildPublish = new BuildPublishPanel(this);
|
||||||
|
|
||||||
|
LoadConfigIntoPanels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadConfigFromBlogSettings()
|
||||||
|
=> Config = StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings);
|
||||||
|
|
||||||
|
public void LoadConfigIntoPanels()
|
||||||
|
{
|
||||||
|
panelGeneral.LoadConfig();
|
||||||
|
panelAuthoring.LoadConfig();
|
||||||
|
panelFrontMatter.LoadConfig();
|
||||||
|
panelBuildPublish.LoadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save the StaticSiteConfig to an arbitrary TemporaryBlogSettings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="settings">the TemporaryBlogSettings object</param>
|
||||||
|
private void SaveConfigToBlogSettings(TemporaryBlogSettings settings)
|
||||||
|
{
|
||||||
|
Config.SaveToCredentials(settings.Credentials);
|
||||||
|
settings.BlogName = Config.SiteTitle;
|
||||||
|
settings.HomepageUrl = Config.SiteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool EditWeblogTemporarySettings(IWin32Window owner)
|
private bool EditWeblogTemporarySettings(IWin32Window owner)
|
||||||
{
|
{
|
||||||
LoadFromStaticSiteConfig(StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings));
|
LoadConfigFromBlogSettings();
|
||||||
|
LoadConfigIntoPanels();
|
||||||
|
|
||||||
// Show form
|
// Show form
|
||||||
using (var preferencesForm = new StaticSitePreferencesForm())
|
using (formPreferences = new StaticSitePreferencesForm(this))
|
||||||
{
|
{
|
||||||
using (BlogClientUIContextScope uiContextScope = new BlogClientUIContextScope(preferencesForm))
|
using (BlogClientUIContextScope uiContextScope = new BlogClientUIContextScope(formPreferences))
|
||||||
{
|
{
|
||||||
// Customize form title and behavior
|
// Customize form title and behavior
|
||||||
preferencesForm.Text = $"Static Site Configuration for '{_temporarySettings.BlogName}'"; //TODO use strings
|
formPreferences.Text = $"Static Site Configuration for '{_temporarySettings.BlogName}'"; //TODO use strings
|
||||||
preferencesForm.HideApplyButton();
|
formPreferences.HideApplyButton();
|
||||||
|
|
||||||
// Add panels
|
// Add panels
|
||||||
int iPanel = 0;
|
int iPanel = 0;
|
||||||
preferencesForm.SetEntry(iPanel++, panelGeneral);
|
formPreferences.SetEntry(iPanel++, panelGeneral);
|
||||||
preferencesForm.SetEntry(iPanel++, panelAuthoring);
|
formPreferences.SetEntry(iPanel++, panelAuthoring);
|
||||||
preferencesForm.SetEntry(iPanel++, panelFrontMatter);
|
formPreferences.SetEntry(iPanel++, panelFrontMatter);
|
||||||
preferencesForm.SetEntry(iPanel++, panelBuildPublish);
|
formPreferences.SetEntry(iPanel++, panelBuildPublish);
|
||||||
|
|
||||||
preferencesForm.SelectedIndex = 0;
|
formPreferences.SelectedIndex = 0;
|
||||||
|
|
||||||
// Show the dialog
|
// Show the dialog
|
||||||
var result = preferencesForm.ShowDialog(owner);
|
var result = formPreferences.ShowDialog(owner);
|
||||||
|
|
||||||
if(result == DialogResult.OK)
|
if(result == DialogResult.OK)
|
||||||
{
|
{
|
||||||
// Create a static site config
|
|
||||||
var ssgConfig = StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings);
|
|
||||||
SaveToStaticSiteConfig(ssgConfig);
|
|
||||||
// All panels should be validated by this point, so save the settings
|
// All panels should be validated by this point, so save the settings
|
||||||
|
|
||||||
|
SaveConfigToBlogSettings(_temporarySettings);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,75 +102,26 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadFromStaticSiteConfig(StaticSiteConfig config)
|
|
||||||
{
|
|
||||||
// General
|
|
||||||
panelGeneral.SiteTitle = config.SiteTitle;
|
|
||||||
panelGeneral.SiteUrl = config.SiteUrl;
|
|
||||||
panelGeneral.LocalSitePath = config.LocalSitePath;
|
|
||||||
|
|
||||||
// Authoring
|
|
||||||
panelAuthoring.PostsPath = config.PostsPath;
|
|
||||||
panelAuthoring.DraftsEnabled = config.DraftsEnabled;
|
|
||||||
panelAuthoring.DraftsPath = config.DraftsPath;
|
|
||||||
panelAuthoring.PagesEnabled = config.PagesEnabled;
|
|
||||||
panelAuthoring.PagesPath = config.PagesPath;
|
|
||||||
panelAuthoring.PagesStoredInRoot = config.PagesPath == ".";
|
|
||||||
panelAuthoring.ImagesEnabled = config.ImagesEnabled;
|
|
||||||
panelAuthoring.ImagesPath = config.ImagesPath;
|
|
||||||
|
|
||||||
// Front Matter
|
|
||||||
panelFrontMatter.Keys = config.FrontMatterKeys;
|
|
||||||
|
|
||||||
// Building and Publishing
|
|
||||||
panelBuildPublish.ShowCmdWindows = config.ShowCmdWindows;
|
|
||||||
panelBuildPublish.CmdTimeoutMs = config.CmdTimeoutMs;
|
|
||||||
panelBuildPublish.BuildingEnabled = config.BuildingEnabled;
|
|
||||||
panelBuildPublish.BuildCommand = config.BuildCommand;
|
|
||||||
panelBuildPublish.OutputPath = config.OutputPath;
|
|
||||||
panelBuildPublish.PublishCommand = config.PublishCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveToStaticSiteConfig(StaticSiteConfig config)
|
|
||||||
{
|
|
||||||
// General
|
|
||||||
config.SiteTitle = panelGeneral.SiteTitle;
|
|
||||||
config.SiteUrl = panelGeneral.SiteUrl;
|
|
||||||
config.LocalSitePath = panelGeneral.LocalSitePath;
|
|
||||||
|
|
||||||
// Authoring
|
|
||||||
config.PostsPath = panelAuthoring.PostsPath;
|
|
||||||
config.DraftsEnabled = panelAuthoring.DraftsEnabled;
|
|
||||||
config.DraftsPath = panelAuthoring.DraftsPath;
|
|
||||||
config.PagesEnabled = panelAuthoring.PagesEnabled;
|
|
||||||
config.PagesPath = panelAuthoring.PagesStoredInRoot ? "." : panelAuthoring.PagesPath;
|
|
||||||
config.ImagesEnabled = panelAuthoring.ImagesEnabled;
|
|
||||||
config.ImagesPath = panelAuthoring.ImagesPath;
|
|
||||||
|
|
||||||
// Front Matter
|
|
||||||
config.FrontMatterKeys = panelFrontMatter.Keys;
|
|
||||||
|
|
||||||
// Building and Publishing
|
|
||||||
config.ShowCmdWindows = panelBuildPublish.ShowCmdWindows;
|
|
||||||
config.CmdTimeoutMs = panelBuildPublish.CmdTimeoutMs;
|
|
||||||
config.BuildingEnabled = panelBuildPublish.BuildingEnabled;
|
|
||||||
config.BuildCommand = panelBuildPublish.BuildCommand;
|
|
||||||
config.OutputPath = panelBuildPublish.OutputPath;
|
|
||||||
config.PublishCommand = panelBuildPublish.PublishCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void GeneralPanel_RunAccountWizard()
|
public void GeneralPanel_RunAccountWizard()
|
||||||
{
|
{
|
||||||
WeblogConfigurationWizardController.EditTemporarySettings(_form, _temporarySettings);
|
var settingsCopy = TemporaryBlogSettings.CreateNew();
|
||||||
// Reload the settings into the form
|
settingsCopy.CopyFrom(_temporarySettings);
|
||||||
LoadFromStaticSiteConfig(StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings));
|
SaveConfigToBlogSettings(settingsCopy);
|
||||||
|
|
||||||
|
var result = WeblogConfigurationWizardController.EditTemporarySettings(formPreferences, settingsCopy);
|
||||||
|
|
||||||
|
// If wizard is successful, load the new settings back into the form.
|
||||||
|
if(result)
|
||||||
|
{
|
||||||
|
_temporarySettings.CopyFrom(settingsCopy);
|
||||||
|
Config = StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings);
|
||||||
|
LoadConfigIntoPanels();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GeneralPanel_RunAutoDetect()
|
public void GeneralPanel_RunAutoDetect()
|
||||||
{
|
{
|
||||||
var ssgConfig = StaticSiteConfig.LoadConfigFromBlogSettings(_temporarySettings);
|
var result = StaticSiteConfigDetector.AttmeptAutoDetect(Config);
|
||||||
var result = StaticSiteConfigDetector.AttmeptAutoDetect(ssgConfig);
|
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
|
@ -156,7 +132,7 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
MessageBoxButtons.OK,
|
MessageBoxButtons.OK,
|
||||||
MessageBoxIcon.Information);
|
MessageBoxIcon.Information);
|
||||||
|
|
||||||
LoadFromStaticSiteConfig(ssgConfig);
|
LoadConfigIntoPanels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,5 +10,32 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
{
|
{
|
||||||
public class StaticSitePreferencesForm : PreferencesForm
|
public class StaticSitePreferencesForm : PreferencesForm
|
||||||
{
|
{
|
||||||
|
private StaticSitePreferencesController _controller;
|
||||||
|
|
||||||
|
public StaticSitePreferencesForm(StaticSitePreferencesController controller)
|
||||||
|
{
|
||||||
|
_controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override bool SavePreferences()
|
||||||
|
{
|
||||||
|
// We need to save all the results before validating them, as the validity of some settings are dependant on others,
|
||||||
|
// eg. PostPath is dependant on LocalSitePath
|
||||||
|
|
||||||
|
// Clone the existing config in-case of validation failure
|
||||||
|
var originalConfig = _controller.Config.Clone();
|
||||||
|
|
||||||
|
foreach (StaticSitePreferencesPanel preferencesPanel in preferencesPanelList)
|
||||||
|
{
|
||||||
|
preferencesPanel.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// On succesful validation, hand control back to controller
|
||||||
|
if (base.SavePreferences()) return true;
|
||||||
|
// Otherwise, reset settings to pre-validation state and return false
|
||||||
|
_controller.Config = originalConfig;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,37 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
using OpenLiveWriter.ApplicationFramework.Preferences;
|
using OpenLiveWriter.ApplicationFramework.Preferences;
|
||||||
|
using OpenLiveWriter.BlogClient.Clients.StaticSite;
|
||||||
|
|
||||||
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
|
||||||
{
|
{
|
||||||
public abstract class StaticSitePreferencesPanel : PreferencesPanel
|
public abstract class StaticSitePreferencesPanel : PreferencesPanel
|
||||||
{
|
{
|
||||||
protected StaticSitePreferencesController _controller;
|
protected StaticSitePreferencesController _controller;
|
||||||
protected TemporaryBlogSettings _blogSettings;
|
|
||||||
|
|
||||||
public StaticSitePreferencesPanel(StaticSitePreferencesController controller, TemporaryBlogSettings blogSettings) : base()
|
public StaticSitePreferencesPanel(StaticSitePreferencesController controller) : base()
|
||||||
{
|
{
|
||||||
_controller = controller;
|
_controller = controller;
|
||||||
_blogSettings = blogSettings;
|
}
|
||||||
|
|
||||||
|
public abstract void LoadConfig();
|
||||||
|
public abstract void ValidateConfig();
|
||||||
|
|
||||||
|
public override bool PrepareSave(SwitchToPanel switchToPanel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ValidateConfig();
|
||||||
|
}
|
||||||
|
catch (StaticSiteConfigValidationException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Text, ex.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
switchToPanel();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue