Files
duplicati/Duplicati/GUI/HelperControls/DurationEditor.cs
T
kenneth.skovhede@gmail.com 52af0476ab Update issue #317
Status: Fixed

Turns out it was a more generic problem than I first assumed.
The problem was that there are two similar controls on the page (the duration editors),
and their internal controls are named the same, so it applied the setting from the top control to the lower,
and the top control was set to "each day".

The other problem "system is slow" is also fixed, although I'm unsure why it happened in the first place.

git-svn-id: https://duplicati.googlecode.com/svn/trunk@630 59da171f-624f-0410-aa54-27559c288bec
2010-12-12 12:15:19 +00:00

124 lines
4.3 KiB
C#

#region Disclaimer / License
// Copyright (C) 2010, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Duplicati.GUI.HelperControls
{
public partial class DurationEditor : UserControl
{
private string[] m_values = { "1D", "1W", "2W", "1M", "" };
public DurationEditor()
{
InitializeComponent();
this.HandleCreated += new EventHandler(EasyDuration_SelectedIndexChanged);
}
public event EventHandler ValueChanged;
/// <summary>
/// Sets the available intervals
/// </summary>
/// <param name="values">A dictionary where the key is the string to display and the value is the duplicity time string</param>
public void SetIntervals(List<KeyValuePair<string, string>> values)
{
EasyDuration.Items.Clear();
if (values[values.Count - 1].Value != "")
values.Add(new KeyValuePair<string, string>(Strings.DurationEditor.CustomDuration, ""));
m_values = new string[values.Count];
for (int i = 0; i < values.Count; i++)
{
m_values[i] = values[i].Value;
EasyDuration.Items.Add(values[i].Key);
}
}
private void EasyDuration_SelectedIndexChanged(object sender, EventArgs e)
{
//To prevent some flickering when creating the control, we must wait until the handle is created
if (this.IsHandleCreated)
{
CustomDuration.Visible = (EasyDuration.SelectedIndex == EasyDuration.Items.Count - 1);
if (EasyDuration.SelectedIndex == EasyDuration.Items.Count - 1)
CustomDuration.Text = m_values[EasyDuration.Items.Count - 1];
if (ValueChanged != null)
ValueChanged(sender, e);
}
}
private void CustomDuration_TextChanged(object sender, EventArgs e)
{
try
{
Duplicati.Library.Utility.Timeparser.ParseTimeSpan(CustomDuration.Text);
}
catch (Exception ex)
{
errorProvider.SetError(CustomDuration, ex.Message);
return;
}
errorProvider.SetError(CustomDuration, "");
m_values[EasyDuration.Items.Count - 1] = CustomDuration.Text;
if (ValueChanged != null)
ValueChanged(sender, e);
}
public string Value
{
get
{
if (EasyDuration.SelectedIndex < 0)
return "";
else
return m_values[EasyDuration.SelectedIndex];
}
set
{
for (int i = 0; i < m_values.Length - 1; i++)
if (m_values[i] == value)
{
EasyDuration.SelectedIndex = i;
return;
}
m_values[EasyDuration.Items.Count - 1] = value;
EasyDuration.SelectedIndex = EasyDuration.Items.Count - 1;
CustomDuration.Text = m_values[EasyDuration.Items.Count - 1];
if (ValueChanged != null)
ValueChanged(this, null);
}
}
}
}