Kaynağa Gözat

Setting window caption in UIWindow, confirmation for file removal in IDE, name popup for new folder

Ivan Safrin 13 yıl önce
ebeveyn
işleme
1deeee0ebc

+ 1 - 0
IDE/Contents/Include/PolycodeFrame.h

@@ -179,6 +179,7 @@ public:
 	AssetBrowser *assetBrowser;
 	
 	TextInputPopup *textInputPopup;
+	YesNoPopup *yesNoPopup;
 	
 	ScreenEntity *welcomeEntity;	
 	PolycodeProjectBrowser *projectBrowser;

+ 2 - 0
IDE/Contents/Include/PolycodeIDEApp.h

@@ -64,9 +64,11 @@ public:
 	// menu commands
 	void renameFile();
 	void removeFile();
+	void doRemoveFile();
 	void browseExamples();
 	void newProject();
 	void newFile();	
+	
 	void newGroup();
 	void openProject();
 	void closeProject();	

+ 22 - 1
IDE/Contents/Include/ToolWindows.h

@@ -34,15 +34,36 @@ class TextInputPopup : public UIWindow {
 		TextInputPopup();
 		~TextInputPopup();
 		
+		void setCaption(String caption);
 		void setValue(String value);
 		String getValue();
 		void handleEvent(Event *event);
 		
+		String action;
+				
 	protected:
 	
 		UITextInput *textInput;
 	
 		UIButton *cancelButton;
-		UIButton *okButton;
+		UIButton *okButton;	
+};
+
+class YesNoPopup : public UIWindow {
+	public:
+		YesNoPopup();
+		~YesNoPopup();
+		
+		void setCaption(String caption);
+		void handleEvent(Event *event);
+		
+		String action;
+		
+	protected:
 	
+		ScreenLabel *captionLabel;
+	
+		ScreenEntity *buttonAnchor;
+		UIButton *cancelButton;
+		UIButton *okButton;	
 };

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

@@ -224,7 +224,7 @@ EditCurve::EditCurve(BezierCurve *targetCurve, Color curveColor) : UIElement() {
 	
 	visMesh->lineSmooth = true;
 	visMesh->lineWidth = 2.0;
-	
+
 	addChild(visMesh);
 	visMesh->setPosition(0, 254);	
 	visMesh->color = curveColor;
@@ -584,6 +584,8 @@ PolycodeFrame::PolycodeFrame() : ScreenEntity() {
 	textInputPopup = new TextInputPopup();
 	textInputPopup->visible = false;
 	
+	yesNoPopup = new YesNoPopup();
+	yesNoPopup->visible = false;
 	
 	isDragging  = false;
 	dragLabel = new ScreenLabel("NONE", 11, "sans");

+ 45 - 15
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -68,6 +68,8 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	frame->console->backtraceWindow->addEventListener(this, BackTraceEvent::EVENT_BACKTRACE_SELECTED);
 
 	frame->textInputPopup->addEventListener(this, UIEvent::OK_EVENT);	
+	frame->yesNoPopup->addEventListener(this, UIEvent::OK_EVENT);
+	
 	frame->newProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
 	frame->exportProjectWindow->addEventListener(this, UIEvent::OK_EVENT);
 	frame->newFileWindow->addEventListener(this, UIEvent::OK_EVENT);	
@@ -110,12 +112,14 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 
 void PolycodeIDEApp::renameFile() {
 	if(projectManager->selectedFile != "") {
+		frame->textInputPopup->action = "renameFile";
+		frame->textInputPopup->setCaption("Enter new filename");
 		frame->textInputPopup->setValue(projectManager->selectedFileEntry.name);
 		frame->showModal(frame->textInputPopup);
 	}
 }
 
-void PolycodeIDEApp::removeFile() {
+void PolycodeIDEApp::doRemoveFile() {
 	if(projectManager->selectedFile != "") {
 		core->removeDiskItem(projectManager->selectedFile);
 		if(projectManager->getActiveProject()) {
@@ -124,6 +128,14 @@ void PolycodeIDEApp::removeFile() {
 	}
 }
 
+void PolycodeIDEApp::removeFile() {
+	if(projectManager->selectedFile != "") {
+		frame->yesNoPopup->setCaption("Are you sure you want to remove this file?");
+		frame->yesNoPopup->action = "removeFile";
+		frame->showModal(frame->yesNoPopup);
+	}
+}
+
 void PolycodeIDEApp::newProject() {
 	frame->newProjectWindow->ResetForm();
 	frame->showModal(frame->newProjectWindow);
@@ -152,10 +164,10 @@ void PolycodeIDEApp::closeProject() {
 
 void PolycodeIDEApp::newGroup() {
 	if(projectManager->activeFolder != "") {
-		core->createFolder(projectManager->activeFolder+"/New Folder");
-		if(projectManager->getActiveProject()) {
-			frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
-		}
+		frame->textInputPopup->action = "newGroup";
+		frame->textInputPopup->setCaption("New folder name");
+		frame->textInputPopup->setValue("New Folder");
+		frame->showModal(frame->textInputPopup);	
 	}
 }
 
@@ -376,23 +388,41 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 		}
 	}
 
+	if(event->getDispatcher() == frame->yesNoPopup) {
+		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
+			if(frame->yesNoPopup->action == "removeFile") {
+				doRemoveFile();
+			}
+			frame->hideModal();
+			frame->yesNoPopup->action = "";
+		}
+	}
 	
 	if(event->getDispatcher() == frame->textInputPopup) {
 		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
-			core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());			
-			if(projectManager->getActiveProject()) {
-				frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
+						
+			if(frame->textInputPopup->action == "newGroup") {	
+				core->createFolder(projectManager->activeFolder+"/"+frame->textInputPopup->getValue());
+				if(projectManager->getActiveProject()) {
+					frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
+				}			
 			}
 			
-			PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath);
-			if(editor) {
-				editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());
+			if(frame->textInputPopup->action == "renameFile") {		
+				core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());			
+				if(projectManager->getActiveProject()) {
+					frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
+				}
+				
+				PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath);
+				if(editor) {
+					editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());
+				}
+				
+				projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue();
+				projectManager->selectedFileEntry.name = frame->textInputPopup->getValue();				
 			}
 			
-			projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue();
-			projectManager->selectedFileEntry.name = frame->textInputPopup->getValue();
-			
-			
 			frame->hideModal();			
 		}
 	}	

+ 59 - 4
IDE/Contents/Source/ToolWindows.cpp

@@ -22,26 +22,30 @@
  
 #include "ToolWindows.h"
 
-TextInputPopup::TextInputPopup() : UIWindow(L"", 300, 95) {
+TextInputPopup::TextInputPopup() : UIWindow(L"", 300, 80) {
 	
-	textInput = new UITextInput(false, 300-(padding*3.0), 12);	
+	textInput = new UITextInput(false, 300, 12);	
 	addChild(textInput);
 	textInput->setPosition(padding, 35);
 		
 	cancelButton = new UIButton(L"Cancel", 100);
 	cancelButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	addChild(cancelButton);
-	cancelButton->setPosition(300-100-padding-100-10, 60);		
+	cancelButton->setPosition(padding+300-100-100-10, 64);		
 	
 	okButton = new UIButton(L"OK", 100);
 	okButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	addChild(okButton);
-	okButton->setPosition(300-100-padding, 60);
+	okButton->setPosition(padding+300-100, 64);
 	
 	closeOnEscape = true;
 
 }
 
+void TextInputPopup::setCaption(String caption) {
+	setWindowCaption(caption);
+}
+
 String TextInputPopup::getValue() {
 	return textInput->getText();
 }
@@ -69,4 +73,55 @@ void TextInputPopup::handleEvent(Event *event) {
 
 TextInputPopup::~TextInputPopup() {
 	
+}
+
+YesNoPopup::YesNoPopup() : UIWindow(L"", 300, 80) {
+	
+	captionLabel = new ScreenLabel("This is a caption", 12);	
+	addChild(captionLabel);
+	captionLabel->setPosition(padding, 35);
+		
+	buttonAnchor = new ScreenEntity();
+	buttonAnchor->processInputEvents = true;
+	addChild(buttonAnchor);
+			
+	cancelButton = new UIButton(L"No", 100);
+	cancelButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	buttonAnchor->addChild(cancelButton);
+	cancelButton->setPosition(0, 60);		
+	
+	okButton = new UIButton(L"Yes", 100);
+	okButton->addEventListener(this, UIEvent::CLICK_EVENT);
+	buttonAnchor->addChild(okButton);
+	okButton->setPosition(120, 60);
+	
+	closeOnEscape = true;
+
+}
+
+void YesNoPopup::setCaption(String caption) {
+	captionLabel->setText(caption);
+	setWindowSize(captionLabel->getWidth() + 50, 80);
+	captionLabel->setPosition(padding + (captionLabel->getWidth() + 50 - captionLabel->getWidth()) / 2.0, 35);
+	buttonAnchor->setPosition(padding + ((captionLabel->getWidth() + 50 - 220) / 2.0), 0);
+}
+
+void YesNoPopup::handleEvent(Event *event) {
+	if(event->getEventType() == "UIEvent") {
+		if(event->getEventCode() == UIEvent::CLICK_EVENT) {
+			if(event->getDispatcher() == okButton) {
+				dispatchEvent(new UIEvent(), UIEvent::OK_EVENT);						
+			}
+			
+			if(event->getDispatcher() == cancelButton) {
+				dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);				
+			}									
+		}
+	}
+	UIWindow::handleEvent(event);	
+}
+
+
+YesNoPopup::~YesNoPopup() {
+	
 }

+ 4 - 0
Modules/Contents/UI/Include/PolyUIWindow.h

@@ -48,6 +48,8 @@ namespace Polycode {
 			
 			void setWindowSize(Number w, Number h);
 			
+			void setWindowCaption(String caption);
+			
 			void onMouseDown(Number x, Number y);
 					
 			virtual void handleEvent(Event *event);
@@ -61,6 +63,8 @@ namespace Polycode {
 			
 			Number closeIconX;
 			Number closeIconY;
+			
+			ScreenLabel *titleLabel;
 		
 			Font *font;
 			Tween *windowTween;

+ 5 - 1
Modules/Contents/UI/Source/PolyUIWindow.cpp

@@ -65,7 +65,7 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntit
 	titlebarRect->processInputEvents = true;
 	addChild(titlebarRect);
 	
-	ScreenLabel *titleLabel = new ScreenLabel(windowName, fontSize, fontName, Label::ANTIALIAS_FULL);
+	titleLabel = new ScreenLabel(windowName, fontSize, fontName, Label::ANTIALIAS_FULL);
 	titleLabel->setPosition(conf->getNumericValue("Polycode", "uiWindowTitleX"),conf->getNumericValue("Polycode", "uiWindowTitleY"));
 	addChild(titleLabel);
 	
@@ -91,6 +91,10 @@ UIWindow::UIWindow(String windowName, Number width, Number height) : ScreenEntit
 	processInputEvents = true;
 }
 
+void UIWindow::setWindowCaption(String caption) {
+	titleLabel->setText(caption);
+}
+
 void UIWindow::setWindowSize(Number w, Number h) {
 	w = w+(padding*2.0);
 	h = h+topPadding;