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

Ask before closing #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions source/StopWatch/UI/IssueControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public string IssueKey
}
}

public string Summary
{
get;
private set;
}


public WatchTimer WatchTimer { get; private set; }

Expand Down Expand Up @@ -209,7 +215,11 @@ private void UpdateSummary()
{
summary = jiraClient.GetIssueSummary(key, settings.IncludeProjectName);
this.InvokeIfRequired(
() => lblSummary.Text = summary
() =>
{
lblSummary.Text = summary;
Summary = summary;
}
);
}
catch (RequestDeniedException)
Expand Down Expand Up @@ -574,9 +584,9 @@ private void btnPostAndReset_Click(object sender, EventArgs e)
PostAndReset();
}

public void PostAndReset()
public DialogResult PostAndReset()
{
using (var worklogForm = new WorklogForm(WatchTimer.GetInitialStartTime(), WatchTimer.TimeElapsedNearestMinute, Comment, EstimateUpdateMethod, EstimateUpdateValue))
using (var worklogForm = new WorklogForm(this))
{
UpdateRemainingEstimate(worklogForm);
var formResult = worklogForm.ShowDialog(this);
Expand All @@ -595,6 +605,7 @@ public void PostAndReset()
EstimateUpdateValue = worklogForm.EstimateValue;
UpdateOutput();
}
return formResult;
}
}

Expand Down
1 change: 1 addition & 0 deletions source/StopWatch/UI/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions source/StopWatch/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ private void pbSettings_Click(object sender, EventArgs e)
}


private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
List<IssueControl> unsubmittedControls = new List<IssueControl>();
foreach (var issueControl in this.issueControls)
{
if (issueControl.WatchTimer.GetState().TotalTime.TotalMinutes > 0)
unsubmittedControls.Add(issueControl);
}

if (unsubmittedControls.Count > 0)
{
switch ( MessageBox.Show("Submit tracked time before closing?", "", MessageBoxButtons.YesNoCancel) ) {
case DialogResult.Cancel:
e.Cancel = true;
return;
case DialogResult.Yes:
foreach (var issueControl in unsubmittedControls)
if (issueControl.PostAndReset() == DialogResult.Cancel)
{
e.Cancel = true;
return;
}
return;
}
}
}


private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
SaveSettingsAndIssueStates();
Expand Down
27 changes: 13 additions & 14 deletions source/StopWatch/UI/WorklogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

namespace StopWatch
{
public partial class WorklogForm : Form
internal partial class WorklogForm : Form
{
#region public members
public string Comment
Expand Down Expand Up @@ -89,21 +89,18 @@ public int RemainingEstimateSeconds


#region public methods
public WorklogForm(DateTimeOffset startTime, TimeSpan TimeElapsed, string comment, EstimateUpdateMethods estimateUpdateMethod, string estimateUpdateValue)
{
this.TimeElapsed = TimeElapsed;
DateTimeOffset initialStartTime;
if (startTime == null)
public WorklogForm(IssueControl issueControl)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's good practice to increase coupling.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to not make the already long signature of the constructor even longer. Because all the arguments only really make sense if they stem from the same IssueControl object I thought the cleaner signature makes clearer what's going on.

It's not a big deal to change that back, though – if this PR has any chance of being accepted by @carstengehling.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with you. Repository looks abandoned...

{
this.TimeElapsed = issueControl.WatchTimer.TimeElapsedNearestMinute;
DateTimeOffset initialStartTime = issueControl.WatchTimer.GetInitialStartTime();
if (initialStartTime == null)
{
initialStartTime = DateTimeOffset.UtcNow.Subtract(TimeElapsed);
}else
{
initialStartTime = startTime;
}
InitializeComponent();
if (!String.IsNullOrEmpty(comment))
if (!String.IsNullOrEmpty(issueControl.Comment))
{
tbComment.Text = String.Format("{0}{0}{1}", Environment.NewLine, comment);
tbComment.Text = String.Format("{0}{0}{1}", Environment.NewLine, issueControl.Comment);
tbComment.SelectionStart = 0;
}

Expand All @@ -113,7 +110,7 @@ public WorklogForm(DateTimeOffset startTime, TimeSpan TimeElapsed, string commen
this.startDatePicker.Value = localInitialStartTime;
this.startTimePicker.Value = localInitialStartTime;

switch ( estimateUpdateMethod ) {
switch ( issueControl.EstimateUpdateMethod ) {
case EstimateUpdateMethods.Auto:
rdEstimateAdjustAuto.Checked = true;
break;
Expand All @@ -122,13 +119,15 @@ public WorklogForm(DateTimeOffset startTime, TimeSpan TimeElapsed, string commen
break;
case EstimateUpdateMethods.SetTo:
rdEstimateAdjustSetTo.Checked = true;
tbSetTo.Text = estimateUpdateValue;
tbSetTo.Text = issueControl.EstimateUpdateValue;
break;
case EstimateUpdateMethods.ManualDecrease:
rdEstimateAdjustManualDecrease.Checked = true;
tbReduceBy.Text = estimateUpdateValue;
tbReduceBy.Text = issueControl.EstimateUpdateValue;
break;
}

this.Text = "Submit worklog for " + issueControl.IssueKey + ": " + issueControl.Summary;
}
#endregion

Expand Down