compiler/libec: (#341, #351, #644, #771) Improved enum type matching and type handlin...
[sdk] / ide / src / IDESettings.ec
index e9aea97..b13c0f5 100644 (file)
@@ -1,3 +1,10 @@
+#if defined(__WIN32__)
+#define MessageBox _MessageBox
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#undef MessageBox
+#endif
+
 #ifdef ECERE_STATIC
 public import static "ecere"
 #else
@@ -101,7 +108,7 @@ char * CopyValidateMakefilePath(char * path)
    if(path)
    {
       int len;
-      len = strlen(path);
+      len = (int)strlen(path);
       copy = CopyString(path);
       if(len)
       {
@@ -181,7 +188,7 @@ void ValidPathBufCopy(char *output, char *input)
 void RemoveTrailingPathSeparator(char *path)
 {
    int len;
-   len = strlen(path);
+   len = (int)strlen(path);
    if(len>1 && path[len-1] == DIR_SEP)
       path[--len] = '\0';
 }
@@ -279,30 +286,26 @@ private:
 
    void OnAskReloadSettings()
    {
-      /*if(MessageBox { type = YesNo, master = this,
-            text = "Global Settings Modified Externally",
-            contents = "The global settings were modified by another instance.\n"
-            "Would you like to reload them?" }.Modal() == Yes)*/
+      FileSize newSettingsFileSize;
+
+      if(OpenAndLock(&newSettingsFileSize))
       {
-         double o, n;
-         FileSize newSettingsFileSize;
-         FileGetSize(settingsFilePath, &newSettingsFileSize);
-         o = settingsFileSize;
-         n = newSettingsFileSize;
-         if(o - n < 2048)
+         if((double)settingsFileSize - (double)newSettingsFileSize < 2048)
             Load();
          else
          {
             GuiApplication app = ((GuiApplication)__thisModule.application);
             Window w;
             for(w = app.desktop.firstChild; w && (!w.created || !w.visible); w = w.next);
-            MessageBox { master = w, type = ok,
+
+            CloseAndMonitor();
+
+            MessageBox { master = w, type = ok, isModal = true,
                   text = "Global Settings Modified Externally",
                   contents = "The global settings were modified by another process and a drastic shrinking of the settings file was detected.\n"
                   "The new settings will not be loaded to prevent loss of your ide settings.\n"
                   "Please check your settings file and make sure to save this IDE's global settings if your settings file has been compromised."
                   }.Create();
-            //Save();
          }
       }
    }
@@ -522,6 +525,7 @@ private:
       delete projectDefaultIntermediateObjDir;
       delete compilerConfigsDir;
       delete defaultCompiler;
+      delete language;
 
       delete ideFileDialogLocation;
       delete ideProjectFileDialogLocation;
@@ -758,7 +762,7 @@ public enum CompilerType
       {
          if(value)
          {
-            Platform c;
+            CompilerType c;
             for(c = firstCompilerType; c <= lastCompilerType; c++)
                if(!strcmpi(value, compilerTypeNames[c]))
                   return c;
@@ -1154,11 +1158,30 @@ Array<LanguageOption> languages
 
 String GetLanguageString()
 {
-   String language = getenv("LANGUAGE");
+   char * dot, * colon;
+   static char lang[256];
+   String language = getenv("ECERE_LANGUAGE");
+   if(!language) language = getenv("LANGUAGE");
    if(!language) language = getenv("LC_ALL");
    if(!language) language = getenv("LC_MESSAGES");
    if(!language) language = getenv("LANG");
    if(!language) language = "";
+   if(language && (colon = strchr(language, ':')))
+   {
+      if(lang != language)
+         strncpy(lang, language, sizeof(lang));
+      lang[sizeof(lang)-1] = 0;
+      lang[colon - language] = 0;
+      language = lang;
+   }
+   if(language && (dot = strchr(language, '.')))
+   {
+      if(lang != language)
+         strncpy(lang, language, sizeof(lang));
+      lang[sizeof(lang)-1] = 0;
+      lang[dot - language] = 0;
+      language = lang;
+   }
    return language;
 }
 
@@ -1166,7 +1189,7 @@ bool LanguageRestart(char * code, Application app, IDESettings settings, IDESett
 {
    bool restart = true;
    String command = null;
-   int arg0Len = strlen(app.argv[0]);
+   int arg0Len = (int)strlen(app.argv[0]);
    int len = arg0Len;
    int j;
    char ch;
@@ -1259,7 +1282,7 @@ bool LanguageRestart(char * code, Application app, IDESettings settings, IDESett
                      strcat(command, " ");
                      len++;
                      ReplaceSpaces(command + len, name);
-                     len = strlen(command);
+                     len = (int)strlen(command);
                   }
                }
             }
@@ -1275,6 +1298,25 @@ bool LanguageRestart(char * code, Application app, IDESettings settings, IDESett
       {
          settings.language = code;
          settingsContainer.Save();
+
+#if defined(__WIN32__)
+         // Set LANGUAGE environment variable
+         {
+            HKEY key = null;
+            uint16 wLanguage[256];
+            HRESULT status;
+            wLanguage[0] = 0;
+
+            RegCreateKeyEx(HKEY_CURRENT_USER, "Environment", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, null, &key, &status);
+            if(key)
+            {
+               UTF8toUTF16Buffer(code, wLanguage, sizeof(wLanguage) / sizeof(uint16));
+               RegSetValueExW(key, L"ECERE_LANGUAGE", 0, REG_EXPAND_SZ, (byte *)wLanguage, (uint)(wcslen(wLanguage)+1) * 2);
+               RegCloseKey(key);
+            }
+         }
+#endif
+
          if(eClass_IsDerived(app._class, class(GuiApplication)))
          {
             GuiApplication guiApp = (GuiApplication)app;
@@ -1301,13 +1343,13 @@ bool LanguageRestart(char * code, Application app, IDESettings settings, IDESett
          strcat(command, " ");
          len++;
          ReplaceSpaces(command + len, app.argv[i]);
-         len = strlen(command);
+         len = (int)strlen(command);
       }
    }
 
    if(restart)
    {
-      SetEnvironment("LANGUAGE", code);
+      SetEnvironment("ECERE_LANGUAGE", code);
       if(wait)
          ExecuteWait(command);
       else