Skip to content

Commit 7a1ae09

Browse files
committed
Impplement minimal project info settings
1 parent fc15d3b commit 7a1ae09

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

data/io.elementary.code.gschema.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@
244244
<description>Opened folders that should be restored in startup.</description>
245245
</key>
246246
</schema>
247+
248+
<!--Relocatable schema for per project info-->
249+
<schema id="io.elementary.code.Projects">
250+
<key name="expanded" type="b">
251+
<default>false</default>
252+
<summary>Project Folder expanded</summary>
253+
<description>Whether the project folder in the sidebar should be expanded on loading</description>
254+
</key>
255+
</schema>
256+
247257
</schemalist>

src/FolderManager/ProjectFolderItem.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ namespace Scratch.FolderManager {
7878
checkout_local_branch_action.activate.connect (handle_checkout_local_branch_action);
7979
checkout_remote_branch_action.activate.connect (handle_checkout_remote_branch_action);
8080
}
81+
82+
ProjectInfoManager.get_project_info (this);
8183
}
8284

8385
private void branch_or_name_changed () {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2026 elementary, Inc. <https://elementary.io>
4+
*
5+
* Authored by: Jeremy Wootten <jeremywootten@gmail.com>
6+
*/
7+
8+
// Using static methods unless we find we require singleton
9+
// We keep a separate list of project infos for future use in e.g. recently closed project list
10+
// and for re-opening projects without recreating info object
11+
public class Scratch.FolderManager.ProjectInfoManager : Object {
12+
private class ProjectInfo : Object {
13+
const string PROJECT_INFO_SCHEMA_ID = "io.elementary.code.Projects";
14+
const string PROJECT_INFO_SCHEMA_PATH_PREFIX = "/io/elementary/code/Projects/";
15+
public string path {
16+
owned get {
17+
return project.path;
18+
}
19+
}
20+
21+
public ProjectFolderItem project { get; construct; }
22+
private Settings settings;
23+
24+
public ProjectInfo (ProjectFolderItem project) {
25+
Object (
26+
project: project
27+
);
28+
}
29+
30+
construct {
31+
var settings_path = PROJECT_INFO_SCHEMA_PATH_PREFIX +
32+
schema_name_from_path (path) +
33+
Path.DIR_SEPARATOR_S;
34+
35+
settings = new Settings.with_path (
36+
PROJECT_INFO_SCHEMA_ID,
37+
settings_path
38+
);
39+
40+
settings.bind ("expanded", project, "expanded", DEFAULT);
41+
}
42+
43+
//Combine basename and parent folder name and convert to camelcase
44+
private string schema_name_from_path (string path) {
45+
var dir = Path.get_basename (Path.get_dirname (path)).normalize ();
46+
var basename = Path.get_basename (path).normalize ();
47+
var name = dir.substring (0, 1).up () +
48+
dir.substring (1, -1).down () +
49+
basename.substring (0, 1).up () +
50+
basename.substring (1, -1).down ();
51+
52+
return name;
53+
}
54+
}
55+
56+
private static Gee.HashMap<string, ProjectInfo>? map = null;
57+
private static Gee.HashMap<string, ProjectInfo> project_info_map {
58+
get {
59+
if (map == null) {
60+
map = new Gee.HashMap<string, ProjectInfo> ();
61+
}
62+
63+
return map;
64+
}
65+
}
66+
67+
//Called when folder created
68+
public static void get_project_info (ProjectFolderItem project_folder) {
69+
var info = project_info_map[project_folder.path];
70+
if (info == null) {
71+
info = new ProjectInfo (project_folder);
72+
project_info_map[project_folder.path] = info;
73+
}
74+
}
75+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ code_files = files(
3131
'FolderManager/FolderItem.vala',
3232
'FolderManager/Item.vala',
3333
'FolderManager/ProjectFolderItem.vala',
34+
'FolderManager/ProjectInfoManager.vala',
3435
'Services/CommentToggler.vala',
3536
'Services/Document.vala',
3637
'Services/DocumentManager.vala',

0 commit comments

Comments
 (0)