added .gitignore for all to enjoy
[installer] / Settings.ec
1 #ifdef ECERE_STATIC
2 import static "ecere"
3 #else
4 import "ecere"
5 #endif
6
7 define MaxRecent = 9;
8
9 enum DirTypes { includes, libraries, executables };
10
11 char * settingsDirectoryNames[DirTypes] = 
12 {
13    "Include Files",
14    "Library Files",
15    "Executable Files"
16 };
17
18 class GlobalSettings : GlobalAppSettings
19 {
20    settingsName = "ecereIDE";
21
22    Window owner;
23    List systemDirs[DirTypes];
24    List recentFiles;
25    List recentProjects;
26
27    virtual void Window::UpdateRecentMenus();
28
29    ~GlobalSettings()
30    {
31       DirTypes c;
32       for(c = 0; c < DirTypes::enumSize; c++)
33          systemDirs[c].Free(Link::Free);
34       recentFiles.Free(Link::Free);
35       recentProjects.Free(Link::Free);
36    }
37
38    void OnAskReloadSettings()
39    {
40       /*if(MessageBox { type = YesNo, master = this, 
41             text = "Global Settings Modified Externally", 
42             contents = "The global settings were modified by another instance.\n"
43             "Would you like to reload them?" }.Modal() == Yes)*/
44       {
45          Load();
46       }
47    }
48
49    void Load()
50    {
51       if(GlobalAppSettings::Load())
52       {
53          DirTypes c;
54          // Load new settings
55          for(c = 0; c < DirTypes::enumSize; c++)
56          {
57             systemDirs[c].Free(Link::Free);
58             GetGlobalValue("Directories", settingsDirectoryNames[c], 
59                stringList, &systemDirs[c]);
60          }
61
62          recentFiles.Free(Link::Free);
63          GetGlobalValue("Recent", "Files", 
64             stringList, &recentFiles);
65
66          recentProjects.Free(Link::Free);
67          GetGlobalValue("Recent", "Projects", 
68             stringList, &recentProjects);
69
70          CloseAndMonitor();
71
72          UpdateRecentMenus(owner);
73       }
74    }
75
76    void Save()
77    {
78       if(GlobalAppSettings::Save())
79       {
80          DirTypes c;
81          for(c = 0; c < DirTypes::enumSize; c++)
82             PutGlobalValue("Directories", 
83                settingsDirectoryNames[c], stringList, &systemDirs[c]);
84          PutGlobalValue("Recent", "Files",
85             stringList, &recentFiles);
86          PutGlobalValue("Recent", "Projects",
87             stringList, &recentProjects);
88          CloseAndMonitor();
89       }
90    }
91
92    void AddRecentFile(char * fileName)
93    {
94       NamedItem recent, next;
95       for(recent = recentFiles.first; recent; recent = next)
96       {
97          next = recent.next;
98          if(recent.name && !strcmp(recent.name, fileName))
99          {
100             delete recent.name;
101             recentFiles.Delete(recent);
102          }
103       }
104       while(recentFiles.count >= MaxRecent)
105       {
106          recent = recentFiles.last;
107          if(recent.name)
108             delete recent.name;
109          recentFiles.Delete(recent);
110       }
111       recent = { name = CopyString(fileName) };
112       recentFiles.Insert(null, recent);
113       UpdateRecentMenus(owner);
114    }
115
116    void AddRecentProject(char * projectName)
117    {
118       NamedItem recent, next;
119       for(recent = recentProjects.first; recent; recent = next)
120       {
121          next = recent.next;
122          if(recent.name && !strcmp(recent.name, projectName))
123          {
124             delete recent.name;
125             recentProjects.Delete(recent);
126          }
127       }
128       while(recentProjects.count >= MaxRecent)
129       {
130          recent = recentProjects.last;
131          if(recent.name)
132             delete recent.name;
133          recentProjects.Delete(recent);
134       }
135       recent = { name = CopyString(projectName) };
136       recentProjects.Insert(null, recent);
137       UpdateRecentMenus(owner);
138    }
139 }