-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recent projects, build & run, toolbar icons (#27)
- Loading branch information
1 parent
ba18582
commit 5e7c4f5
Showing
12 changed files
with
248 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using HaruhiChokuretsuLib.Util; | ||
|
||
namespace SerialLoops.Lib | ||
{ | ||
public class RecentProjects | ||
{ | ||
private const int MAX_RECENT_PROJECTS = 10; | ||
public string RecentProjectsPath { get; set; } | ||
public List<string> Projects { get; set; } | ||
|
||
public void Save(ILogger log) | ||
{ | ||
log.Log($"Saving recent projects to '{RecentProjectsPath}'..."); | ||
IO.WriteStringFile(RecentProjectsPath, JsonSerializer.Serialize(this), log); | ||
} | ||
|
||
public static RecentProjects LoadRecentProjects(ILogger log) | ||
{ | ||
string recentProjectsJson = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "recent_projects.json"); | ||
if (!File.Exists(recentProjectsJson)) | ||
{ | ||
log.Log($"Creating default recent projects cache at '{recentProjectsJson}'..."); | ||
RecentProjects defaultRecentProjects = GetDefault(); | ||
defaultRecentProjects.RecentProjectsPath = recentProjectsJson; | ||
IO.WriteStringFile(recentProjectsJson, JsonSerializer.Serialize(defaultRecentProjects), log); | ||
return defaultRecentProjects; | ||
} | ||
|
||
try | ||
{ | ||
RecentProjects recentProjects = JsonSerializer.Deserialize<RecentProjects>(File.ReadAllText(recentProjectsJson)); | ||
recentProjects.RecentProjectsPath = recentProjectsJson; | ||
return recentProjects; | ||
} | ||
catch (JsonException exc) | ||
{ | ||
log.LogError($"Exception occurred while parsing recent_projects.json!\n{exc.Message}\n\n{exc.StackTrace}"); | ||
RecentProjects defaultRecentProjects = GetDefault(); | ||
IO.WriteStringFile(recentProjectsJson, JsonSerializer.Serialize(defaultRecentProjects), log); | ||
return defaultRecentProjects; | ||
} | ||
} | ||
|
||
private static RecentProjects GetDefault() | ||
{ | ||
return new() | ||
{ | ||
Projects = new List<string>() | ||
}; | ||
} | ||
|
||
public void AddProject(string projectPath) | ||
{ | ||
if (Projects.Contains(projectPath)) | ||
{ | ||
Projects.Remove(projectPath); | ||
} | ||
if (Projects.Count >= MAX_RECENT_PROJECTS) | ||
{ | ||
Projects.RemoveAt(Projects.Count - 1); | ||
} | ||
Projects.Insert(0, projectPath); | ||
} | ||
|
||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.