Skip to content

Commit

Permalink
Made save and load function use file dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
dannypas00 committed Jun 7, 2020
1 parent a4d1216 commit 7fbd7af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 6 additions & 4 deletions DrawingApp/CommandPattern/CommandLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Shapes;
using DrawingApp.CompositePattern;
using DrawingApp.DecoratorPattern;
using Microsoft.Win32;

namespace DrawingApp.CommandPattern
{
Expand All @@ -25,9 +26,10 @@ public void Execute()
{
//Set up variables
//Set up the path to the save file TODO: Make this path selectable in runtime
string pathWithEnv = @"%USERPROFILE%\Pictures\DrawingApp\save.txt";
string filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);
string[] fileLines = File.ReadAllLines(filePath);
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Save file (*.sav)|*.sav";
if (openFileDialog.ShowDialog() != true) return;
string[] fileLines = File.ReadAllLines(openFileDialog.FileName);
int lineNr = 0;
Dictionary<int, Group> lineGroupmap = new Dictionary<int, Group>();
List<CaptionDecorator> nextCaptions = new List<CaptionDecorator>();
Expand Down Expand Up @@ -113,7 +115,7 @@ public void Execute()
lineGroupmap.Add(lineNr, (Group)invoker.GroupMap[(ListBoxItem)invoker.MainWindow.groups.SelectedItem]);
break;
case "ornament":
nextCaptions.Add(new CaptionDecorator(new DecoratorContext(default, splitted[1 + depth * 4], null, splitted[2] + depth * 4)));
//nextCaptions.Add(new CaptionDecorator(new DecoratorContext(default, splitted[1 + depth * 4], null, splitted[2] + depth * 4)));
break;
default:
continue;
Expand Down
15 changes: 11 additions & 4 deletions DrawingApp/CommandPattern/CommandSave.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Shapes;
using DrawingApp.CompositePattern;
using DrawingApp.VisitorPattern;
using Microsoft.Win32;

namespace DrawingApp.CommandPattern
{
Expand All @@ -21,10 +23,15 @@ public CommandSave()

public void Execute()
{

string pathWithEnv = @"%USERPROFILE%\Pictures\DrawingApp\save.txt";
string filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);
invoker.GroupMap.Values.ToArray()[0].Accept(new SaveVisitor(filePath, (Group) invoker.GroupMap.Values.ToArray()[0]));
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Save file (*.sav)|*.sav";
if (saveFileDialog.ShowDialog() == true && invoker.GroupMap.Values.Count > 0)
{
string pathWithEnv = saveFileDialog.FileName;
string filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);
invoker.GroupMap.Values.ToArray()[0]
.Accept(new SaveVisitor(filePath, (Group) invoker.GroupMap.Values.ToArray()[0]));
}
}

public void Redo()
Expand Down

0 comments on commit 7fbd7af

Please sign in to comment.