Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade WindowPlacementSettings on version change #1787

Merged
merged 3 commits into from
Feb 5, 2015

Conversation

punker76
Copy link
Member

@punker76 punker76 commented Feb 5, 2015

  • Added a UpgradeSettings property to IWindowPlacementSettings, which defaults to true
  • Added a void Upgrade() method to IWindowPlacementSettings, which is implemeneted by ApplicationSettingsBase

Closes #1736

- Added a UpgradeSettings property to IWindowPlacementSettings, which
defaults to true
- Added a `void Upgrade()` method to IWindowPlacementSettings, which is
implemeneted by ApplicationSettingsBase
@punker76
Copy link
Member Author

punker76 commented Feb 5, 2015

@mike-ward is this what you need? is this enough?

@punker76 punker76 added this to the 1.1.0 milestone Feb 5, 2015
@mike-ward
Copy link

I think the Upgrade method is all that is really needed. It's typical for apps to have their own UpgradeSettings property.

@punker76
Copy link
Member Author

punker76 commented Feb 5, 2015

@mike-ward so the others (at th einterface) too much?

@mike-ward
Copy link

Probably. I can't think of a use case where I would want to reset or reload those settings. For my use case, Upgrade is sufficent.

@punker76
Copy link
Member Author

punker76 commented Feb 5, 2015

@mike-ward ok, you're right. i removed the reset method.

punker76 added a commit that referenced this pull request Feb 5, 2015
Upgrade WindowPlacementSettings on version change
@punker76 punker76 merged commit 63e4f42 into master Feb 5, 2015
@flagbug
Copy link
Member

flagbug commented Feb 5, 2015

Hm, that's a breaking change, but I guess it's alright

@punker76 punker76 deleted the 1736-UpgradeSettings branch February 17, 2015 16:24
@mike-ward
Copy link

Upgraded to 1.1.0. Could I get a quick tutorial on how to upgrade settings? Here is what I've tried.

In App.xaml.cs, OnStartup()

var windowPlacementSettings = mainWindow.GetWindowPlacementSettings();

if (windowPlacementSettings.UpgradeSettings)
{
    windowPlacementSettings.Upgrade();
    windowPlacementSettings.UpgradeSettings = false;
    windowPlacementSettings.Save();
}

UpgradeSettings is always false. I must be missing something else where?

@punker76
Copy link
Member Author

it's a mistake with DefaultValue(true) and auto property, i'll fix this
tomorrow and publish a 1.1.1 version
Am 25.02.2015 00:56 schrieb "Mike Ward" [email protected]:

Upgraded to 1.1.0. Could I get a quick tutorial on how to upgrade
settings? Here is what I've tried.

In App.xaml.cs, OnStartup()

var windowPlacementSettings = mainWindow.GetWindowPlacementSettings();

if (windowPlacementSettings.UpgradeSettings)
{
windowPlacementSettings.Upgrade();
windowPlacementSettings.UpgradeSettings = false;
windowPlacementSettings.Save();
}

UpgradeSettings is always false. I must be missing something else where?


Reply to this email directly or view it on GitHub
#1787 (comment)
.

@mike-ward
Copy link

Cool beans! The window snap restore thing is working nicely.

On Tue, Feb 24, 2015 at 7:03 PM, Jan Karger [email protected]
wrote:

it's a mistake with DefaultValue(true) and auto property, i'll fix this
tomorrow and publish a 1.1.1 version
Am 25.02.2015 00:56 schrieb "Mike Ward" [email protected]:

Upgraded to 1.1.0. Could I get a quick tutorial on how to upgrade
settings? Here is what I've tried.

In App.xaml.cs, OnStartup()

var windowPlacementSettings = mainWindow.GetWindowPlacementSettings();

if (windowPlacementSettings.UpgradeSettings)
{
windowPlacementSettings.Upgrade();
windowPlacementSettings.UpgradeSettings = false;
windowPlacementSettings.Save();
}

UpgradeSettings is always false. I must be missing something else where?


Reply to this email directly or view it on GitHub
<
https://github.com/MahApps/MahApps.Metro/pull/1787#issuecomment-75877532>

.


Reply to this email directly or view it on GitHub
#1787 (comment)
.

@punker76
Copy link
Member Author

@mike-ward UpgradeSettings should now work :-D 509bd77

@mike-ward
Copy link

Different problem. Using code from above, UpgradeSettings is always true now.

@punker76
Copy link
Member Author

@mike-ward to clarify this, i will change the implementation to this

        /// <summary>
        /// Upgrades the application settings on loading.
        /// </summary>
        [UserScopedSetting]
        public bool UpgradeSettings
        {
            get
            {
                if (this["UpgradeSettings"] != null)
                {
                    return (bool)this["UpgradeSettings"];
                }
                return true;
            }
            set { this["UpgradeSettings"] = value; }
        }

with the result

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MahApps.Metro.Controls.WindowApplicationSettings.MetroDemo.ExampleWindows.FlyoutDemo" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <MahApps.Metro.Controls.WindowApplicationSettings.MetroDemo.ExampleWindows.FlyoutDemo>
            <setting name="UpgradeSettings" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="Placement" serializeAs="Xml">
                <value>
                    <WINDOWPLACEMENT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <length>44</length>
                        <flags>0</flags>
                        <showCmd>1</showCmd>
                        <minPosition>
                            <X>-1</X>
                            <Y>-1</Y>
                        </minPosition>
                        <maxPosition>
                            <X>-1</X>
                            <Y>-1</Y>
                        </maxPosition>
                        <normalPosition>
                            <left>1028</left>
                            <top>418</top>
                            <right>1903</right>
                            <bottom>1043</bottom>
                        </normalPosition>
                    </WINDOWPLACEMENT>
                </value>
            </setting>
        </MahApps.Metro.Controls.WindowApplicationSettings.MetroDemo.ExampleWindows.FlyoutDemo>
    </userSettings>
</configuration>

is this what you want?

@mike-ward
Copy link

Yep, I think that will work. Thanks for doing this.

@punker76
Copy link
Member Author

@mike-ward np, but can you give me a reason why a user want change this property in this file? i don't see the benefit, maybe i'm blind ;-)

@mike-ward
Copy link

You only want to upgrade the settings once per version bump. The suggested
way to do this is:

http://blog.johnsworkshop.net/automatically-upgrading-user-settings-after-an-application-version-change/

It doesn't matter to me if I keep a flag in my user settings or use the
MahApp supplied flag. If you decide not to persist the flag then I would
suggest removing it.

On Wed, Feb 25, 2015 at 5:55 PM, Jan Karger [email protected]
wrote:

@mike-ward https://github.com/mike-ward np, but can you give me a
reason why a user want change this property in this file? i don't see the
benefit, maybe i'm blind ;-)


Reply to this email directly or view it on GitHub
#1787 (comment)
.

punker76 added a commit that referenced this pull request Feb 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants