Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
Fixes #29 Main window title does not reflect that outstanding changes…
Browse files Browse the repository at this point in the history
… have been made when changes are made
  • Loading branch information
Jack Hughes committed Jul 28, 2015
1 parent d78ca63 commit 55cd887
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
59 changes: 46 additions & 13 deletions Dyna Application/DynaApp/ViewModels/MainWindowViewModel.cs
Expand Up @@ -149,22 +149,49 @@ public bool CanAddDomainExecute
}
}

/// <summary>
/// Gets the File|New command.
/// </summary>
public ICommand NewCommand { get; private set; }

/// <summary>
/// Gets the File|Open command.
/// </summary>
public ICommand OpenCommand { get; private set; }

/// <summary>
/// Gets the File|Save command.
/// </summary>
public ICommand SaveCommand { get; private set; }

/// <summary>
/// Gets the File|Save As command.
/// </summary>
public ICommand SaveAsCommand { get; private set; }

/// <summary>
/// Gets the File|Exit command.
/// </summary>
public ICommand ExitCommand { get; private set; }

/// <summary>
/// Gets the Model|Solve command
/// </summary>
public ICommand SolveCommand { get; private set; }

/// <summary>
/// Gets the Model|Add Variable command.
/// </summary>
public ICommand AddVariableCommand { get; private set; }

/// <summary>
/// Gets the Model|Add Constraint command.
/// </summary>
public ICommand AddConstraintCommand { get; private set; }

/// <summary>
/// Gets the Model|Add Domain command.
/// </summary>
public ICommand AddDomainCommand { get; private set; }

/// <summary>
Expand All @@ -175,7 +202,7 @@ public string Title
get { return this.title; }
set
{
title = value;
this.title = value;
OnPropertyChanged();
}
}
Expand All @@ -191,8 +218,8 @@ private void FileNewAction()
}

this.Workspace.Reset();

this.filename = string.Empty;
this.Workspace.IsDirty = false;
this.UpdateTitle();
}

Expand Down Expand Up @@ -233,6 +260,7 @@ private void FileOpenAction()
}

this.filename = openFileDialog.FileName;
this.Workspace.IsDirty = false;
this.UpdateTitle();
}

Expand Down Expand Up @@ -287,6 +315,7 @@ private void FileExitAction()
private void ModelSolveAction()
{
this.Workspace.SolveModel(Application.Current.MainWindow);
this.UpdateTitle();
}

/// <summary>
Expand All @@ -295,7 +324,8 @@ private void ModelSolveAction()
private void ModelAddVariableAction()
{
var newVariableLocation = Mouse.GetPosition(Application.Current.MainWindow);
this.Workspace.CreateVariable("New Variable", newVariableLocation);
this.Workspace.AddVariable("New Variable", newVariableLocation);
this.UpdateTitle();
}

/// <summary>
Expand All @@ -304,7 +334,8 @@ private void ModelAddVariableAction()
private void ModelAddConstraintAction()
{
var newConstraintLocation = Mouse.GetPosition(Application.Current.MainWindow);
this.Workspace.CreateConstraint("New Constraint", newConstraintLocation);
this.Workspace.AddConstraint("New Constraint", newConstraintLocation);
this.UpdateTitle();
}

/// <summary>
Expand All @@ -313,7 +344,8 @@ private void ModelAddConstraintAction()
private void ModelAddDomainAction()
{
var newDomainLocation = Mouse.GetPosition(Application.Current.MainWindow);
this.Workspace.CreateDomain("New Domain", newDomainLocation);
this.Workspace.AddDomain("New Domain", newDomainLocation);
this.UpdateTitle();
}

/// <summary>
Expand Down Expand Up @@ -374,6 +406,7 @@ private bool Save(string file)
}

this.filename = file;
this.Workspace.IsDirty = false;
UpdateTitle();

return true;
Expand All @@ -396,23 +429,23 @@ private void ShowError(string message)
/// </summary>
private void UpdateTitle()
{
var s = "Dyna Project" + " - ";
var newTitle = "Dyna Project" + " - ";

if (string.IsNullOrEmpty(this.filename))
{
s += "Untitled";
}
else
{
s += Path.GetFileName(this.filename);
newTitle += "Untitled";
this.Title = newTitle;
return;
}

newTitle += Path.GetFileName(this.filename);

if (this.Workspace.IsDirty)
{
s += " *";
newTitle += " *";
}

this.Title = s;
this.Title = newTitle;
}

/// <summary>
Expand Down
24 changes: 13 additions & 11 deletions Dyna Application/DynaApp/ViewModels/WorkspaceViewModel.cs
Expand Up @@ -134,7 +134,7 @@ public bool IsDirty
}

/// <summary>
/// Solve the model.
/// Solve the constraint model.
/// </summary>
public void SolveModel(Window parentWindow)
{
Expand All @@ -149,7 +149,7 @@ public void SolveModel(Window parentWindow)
/// <param name="newVariableName">New variable name.</param>
/// <param name="newVariableLocation">New variable location.</param>
/// <returns>New variable view model.</returns>
public VariableViewModel CreateVariable(string newVariableName, Point newVariableLocation)
public VariableViewModel AddVariable(string newVariableName, Point newVariableLocation)
{
var newVariable = new VariableViewModel(newVariableName, newVariableLocation);
this.Model.AddVariable(newVariable);
Expand All @@ -164,7 +164,7 @@ public VariableViewModel CreateVariable(string newVariableName, Point newVariabl
/// <param name="newDomainName">New domain name.</param>
/// <param name="newDomainLocation">New domain location.</param>
/// <returns>New domain view model.</returns>
public DomainViewModel CreateDomain(string newDomainName, Point newDomainLocation)
public DomainViewModel AddDomain(string newDomainName, Point newDomainLocation)
{
var newDomain = new DomainViewModel(newDomainName, newDomainLocation);
this.Model.AddDomain(newDomain);
Expand All @@ -179,7 +179,7 @@ public DomainViewModel CreateDomain(string newDomainName, Point newDomainLocatio
/// <param name="newConstraintName">New constraint name.</param>
/// <param name="newLocation">New constraint location.</param>
/// <returns>New constraint view model.</returns>
public ConstraintViewModel CreateConstraint(string newConstraintName, Point newLocation)
public ConstraintViewModel AddConstraint(string newConstraintName, Point newLocation)
{
var newConstraint = new ConstraintViewModel(newConstraintName, newLocation);
this.Model.AddConstraint(newConstraint);
Expand Down Expand Up @@ -208,12 +208,13 @@ public void DeleteVariable(VariableViewModel variable)
// Remove all connections attached to the variable.
//
foreach (var connectionViewModel in variable.AttachedConnections)
this.Model.Connections.Remove(connectionViewModel);
this.Model.DeleteConnection(connectionViewModel);

//
// Remove the variable from the network.
//
this.Model.Variables.Remove(variable);
this.Model.DeleteVariable(variable);
this.IsDirty = true;
}

/// <summary>
Expand All @@ -223,6 +224,7 @@ public void Reset()
{
this.Model.Reset();
this.Solution.Reset();
this.IsDirty = true;
}

/// <summary>
Expand Down Expand Up @@ -261,7 +263,7 @@ private void DeleteSelectedVariables()
{
if (variable.IsSelected)
{
DeleteVariable(variable);
this.DeleteVariable(variable);
}
}
}
Expand All @@ -275,7 +277,7 @@ private void DeleteSelectedDomains()
{
if (domain.IsSelected)
{
DeleteDomain(domain);
this.DeleteDomain(domain);
}
}
}
Expand All @@ -289,7 +291,7 @@ private void DeleteConstraints()
{
if (constraint.IsSelected)
{
DeleteConstraint(constraint);
this.DeleteConstraint(constraint);
}
}
}
Expand All @@ -299,15 +301,15 @@ private void DeleteDomain(DomainViewModel domain)
//
// Remove the variable from the network.
//
this.Model.Domains.Remove(domain);
this.Model.DeleteDomain(domain);
}

private void DeleteConstraint(ConstraintViewModel constraint)
{
//
// Remove the variable from the network.
//
this.Model.Constraints.Remove(constraint);
this.Model.DeleteConstraint(constraint);
}
}
}

0 comments on commit 55cd887

Please sign in to comment.