Selaa lähdekoodia

Added support for editors to add their own config to the user state file, text editor will now reopen to the line it was closed on

Ivan Safrin 12 vuotta sitten
vanhempi
sitoutus
c5884954d5

+ 3 - 0
IDE/Contents/Include/PolycodeEditor.h

@@ -77,6 +77,9 @@ public:
 
 	virtual void handleDroppedFile(OSFileEntry file, Number x, Number y) {};
 	
+	virtual ObjectEntry *getEditorConfig() { return NULL; }
+	virtual void applyEditorConfig(ObjectEntry *configEntry) {}
+	
 	void setFilePath(String newPath);
 	String getFilePath() { return filePath; }
 	

+ 3 - 0
IDE/Contents/Include/PolycodeTextEditor.h

@@ -92,6 +92,9 @@ public:
 	void Resize(int x, int y);
 	void saveFile();
 	
+	ObjectEntry *getEditorConfig();
+	void applyEditorConfig(ObjectEntry *configEntry);
+		
 	void handleEvent(Event *event);
 	
 	void hideFindBar();

+ 8 - 0
IDE/Contents/Source/PolycodeFrame.cpp

@@ -554,6 +554,10 @@ ObjectEntry *EditorHolder::getEditorHolderConfig() {
 		configEntry->addChild("split", "none");	
 		if(currentEditor) {
 			configEntry->addChild("file_name", 	currentEditor->getFilePath());
+			ObjectEntry *editorConfig = currentEditor->getEditorConfig();
+			if(editorConfig) {
+				configEntry->addChild(editorConfig)->name = "editor_config";
+			}			
 		}
 
 	}
@@ -570,6 +574,10 @@ void EditorHolder::applyConfig(ObjectEntry *entry) {
 				PolycodeEditor *editor = globalEditorManager->openFile(file);
 				if(editor) {
 					setEditor(editor);
+					ObjectEntry *editorConfig = (*entry)["editor_config"];
+					if(editorConfig) {
+						editor->applyEditorConfig(editorConfig);
+					}
 				}	
 			}
 		} else {

+ 15 - 0
IDE/Contents/Source/PolycodeTextEditor.cpp

@@ -510,6 +510,21 @@ bool PolycodeTextEditor::openFile(OSFileEntry filePath) {
 	return true;
 }
 
+ObjectEntry *PolycodeTextEditor::getEditorConfig() {
+	ObjectEntry *configEntry = new ObjectEntry();
+		
+	configEntry->addChild("scroll_offset", textInput->getScrollContainer()->getVScrollBar()->getScrollValue());
+			
+	return configEntry;
+}
+
+void PolycodeTextEditor::applyEditorConfig(ObjectEntry *configEntry) {
+	ObjectEntry *scrollEntry = (*configEntry)["scroll_offset"];
+	if(scrollEntry) {
+		textInput->getScrollContainer()->setScrollValue(0.0, scrollEntry->NumberVal);
+	}
+}
+
 void PolycodeTextEditor::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == textInput && event->getEventType() == "UIEvent") {