Преглед на файлове

settings are now written to file

Isak Andersson преди 12 години
родител
ревизия
d02c9cdd98
променени са 2 файла, в които са добавени 23 реда и са изтрити 4 реда
  1. 20 3
      IDE/Contents/Source/PolycodeIDEApp.cpp
  2. 3 1
      IDE/Contents/Source/SettingsWindow.cpp

+ 20 - 3
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -821,9 +821,20 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 	}	
 	}	
 
 
     if(event->getDispatcher() == frame->settingsWindow) {
     if(event->getDispatcher() == frame->settingsWindow) {
-        if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
-            printf("Event handled!\n");
-            frame->hideModal();
+        if(event->getEventType() == "UIEvent") {
+            Config *config = CoreServices::getInstance()->getConfig();
+            SettingsWindow *settingsWindow = frame->settingsWindow;
+
+            if(event->getEventCode() == UIEvent::OK_EVENT) {
+                config->setStringValue("Polycode", "useExternalTextEditor", settingsWindow->useExternalTextEditorBox->isChecked() ? "true" : "false");
+                config->setStringValue("Polycode", "externalTextEditorCommand", settingsWindow->externalTextEditorCommand->getText());
+            
+                frame->hideModal();
+            }
+            if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
+                settingsWindow->useExternalTextEditorBox->setChecked(config->getStringValue("Polycode", "useExternalTextEditor") == "true");
+                settingsWindow->externalTextEditorCommand->setText(config->getStringValue("Polycode", "externalTextEditorCommand"));
+            }
         }
         }
     }
     }
 
 
@@ -879,6 +890,7 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 }
 }
 
 
 void PolycodeIDEApp::saveConfigFile() {
 void PolycodeIDEApp::saveConfigFile() {
+    Config *config = CoreServices::getInstance()->getConfig();
 	Object configFile;
 	Object configFile;
 	configFile.root.name = "config";
 	configFile.root.name = "config";
 	configFile.root.addChild("open_projects");
 	configFile.root.addChild("open_projects");
@@ -890,6 +902,11 @@ void PolycodeIDEApp::saveConfigFile() {
 		projectEntry->addChild("path", project->getProjectFile());
 		projectEntry->addChild("path", project->getProjectFile());
 	}
 	}
 
 
+    configFile.root.addChild("settings");
+    ObjectEntry *textEditorEntry = configFile.root["settings"]->addChild("text_editor");
+    textEditorEntry->addChild("use_external", config->getStringValue("Polycode", "useExternalTextEditor"));
+    textEditorEntry->addChild("command", config->getStringValue("Polycode", "externalTextEditorCommand"));
+
 #if defined(__APPLE__) && defined(__MACH__)
 #if defined(__APPLE__) && defined(__MACH__)
 	core->createFolder(core->getUserHomeDirectory()+"/Library/Application Support/Polycode");
 	core->createFolder(core->getUserHomeDirectory()+"/Library/Application Support/Polycode");
 	configFile.saveToXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");	
 	configFile.saveToXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");	

+ 3 - 1
IDE/Contents/Source/SettingsWindow.cpp

@@ -19,6 +19,7 @@
 #include "SettingsWindow.h"
 #include "SettingsWindow.h"
 
 
 SettingsWindow::SettingsWindow() : UIWindow(L"Settings", SETTINGS_WINDOW_WIDTH, SETTINGS_WINDOW_HEIGHT) {
 SettingsWindow::SettingsWindow() : UIWindow(L"Settings", SETTINGS_WINDOW_WIDTH, SETTINGS_WINDOW_HEIGHT) {
+    Config *config = CoreServices::getInstance()->getConfig();
     
     
     closeOnEscape = true;
     closeOnEscape = true;
 
 
@@ -29,7 +30,7 @@ SettingsWindow::SettingsWindow() : UIWindow(L"Settings", SETTINGS_WINDOW_WIDTH,
     label->setPosition(padding, 50);
     label->setPosition(padding, 50);
 
 
 
 
-    useExternalTextEditorBox = new UICheckBox("Use external text editor?", false);
+    useExternalTextEditorBox = new UICheckBox("Use external text editor?", config->getStringValue("Polycode", "useExternalTextEditor") == "true");
     addChild(useExternalTextEditorBox); 
     addChild(useExternalTextEditorBox); 
     useExternalTextEditorBox->setPosition(padding, 85);
     useExternalTextEditorBox->setPosition(padding, 85);
 
 
@@ -40,6 +41,7 @@ SettingsWindow::SettingsWindow() : UIWindow(L"Settings", SETTINGS_WINDOW_WIDTH,
 
 
     externalTextEditorCommand = new UITextInput(false, SETTINGS_WINDOW_WIDTH - (padding*2 + BUTTON_WIDTH + BUTTON_PADDING/2), TEXTBOX_HEIGHT);
     externalTextEditorCommand = new UITextInput(false, SETTINGS_WINDOW_WIDTH - (padding*2 + BUTTON_WIDTH + BUTTON_PADDING/2), TEXTBOX_HEIGHT);
     addChild(externalTextEditorCommand);
     addChild(externalTextEditorCommand);
+    externalTextEditorCommand->setText(config->getStringValue("Polycode", "externalTextEditorCommand"));
     externalTextEditorCommand->setPosition(padding, EDITOR_BROWSE_POS);
     externalTextEditorCommand->setPosition(padding, EDITOR_BROWSE_POS);
 
 
     browseButton = new UIButton("Browse...", BUTTON_WIDTH);
     browseButton = new UIButton("Browse...", BUTTON_WIDTH);