forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassWorkspace.cs
101 lines (90 loc) · 3.18 KB
/
ClassWorkspace.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace GitForce
{
/// <summary>
/// This class contains the code to load and save workspaces.
/// It also implements a set of last recently used workspace files.
/// </summary>
static class ClassWorkspace
{
/// <summary>
/// Return a set of last recently used workspace files
/// as a list of absolute file names.
/// </summary>
public static List<string> GetLRU()
{
List<string> lru = Properties.Settings.Default.WorkspaceLRU.
Split(("\t").ToCharArray(),
StringSplitOptions.RemoveEmptyEntries).ToList();
return lru;
}
/// <summary>
/// Add a file name to the list of last recently used files.
/// If a file is already in the set, it will be ignored.
/// </summary>
private static void AddLRU(string name)
{
List<string> lru = GetLRU();
// Add a name only if it already does not exist
if (!lru.Contains(name))
{
lru.Insert(0, name);
// Keep the number of recently used files down to a reasonable number
if (lru.Count >= 6)
lru.RemoveRange(5, lru.Count - 5);
string s = string.Join("\t", lru.ToArray());
Properties.Settings.Default.WorkspaceLRU = s;
}
}
/// <summary>
/// Load workspace given the file name.
/// If the file name is null, load default workspace.
/// </summary>
public static bool Load(string name)
{
// Initialize workspace file name, if this is a first run
if (string.IsNullOrEmpty(Properties.Settings.Default.WorkspaceFile))
Properties.Settings.Default.WorkspaceFile = Path.Combine(App.AppHome, "repos.giw");
if (name == null)
name = Properties.Settings.Default.WorkspaceFile;
App.PrintStatusMessage("Loading workspace: " + name);
if (App.Repos.Load(name))
{
AddLRU(name);
Properties.Settings.Default.WorkspaceFile = name;
return true;
}
return false;
}
/// <summary>
/// Save workspace given the file name.
/// If the file name is null, save the current workspace.
/// </summary>
public static bool Save(string name)
{
if (name == null)
name = Properties.Settings.Default.WorkspaceFile;
App.PrintStatusMessage("Saving workspace: " + name);
if (App.Repos.Save(name))
{
AddLRU(name);
Properties.Settings.Default.WorkspaceFile = name;
return true;
}
return false;
}
/// <summary>
/// Helper function that clears current workspace
/// </summary>
public static void Clear()
{
App.Repos.Repos.Clear();
App.Repos.Refresh();
App.DoRefresh();
}
}
}