Ivan Safrin 12 лет назад
Родитель
Сommit
87a85e1651

+ 8 - 2
IDE/Contents/Include/PolycodeFrame.h

@@ -233,6 +233,8 @@ class PolycodeTabButton : public UIElement {
 		PolycodeProjectTab *tab;
 		UIRect *bgRect;
 		UILabel *tabLabel;
+		
+		UIImageButton *closeButton;
 	
 };
 
@@ -246,7 +248,10 @@ class PolycodeProjectFrame : public UIElement {
 		PolycodeProjectTab *addNewTab();
 		
 		void showTab(PolycodeProjectTab *tab);
+		void closeTab(PolycodeProjectTab *tab);
 		
+		void Update();
+								
 		PolycodeProjectTab *getActiveTab();
 		void handleEvent(Event *event);
 		
@@ -260,14 +265,15 @@ class PolycodeProjectFrame : public UIElement {
 	
 		PolycodeProject *project;
 		
-		UIElement *tabButtonAnchor;
-		
+		UIElement *tabButtonAnchor;		
 		UIImageButton *newTabButton;
 	
 		PolycodeEditorManager *editorManager;
 		PolycodeProjectTab *activeTab;
 		std::vector<PolycodeProjectTab*> tabs;		
 		std::vector<PolycodeTabButton*> tabButtons;
+		
+		PolycodeProjectTab *tabToClose;
 };
 
 

BIN
IDE/Contents/Resources/Images/tab_close_button.png


+ 68 - 12
IDE/Contents/Source/PolycodeFrame.cpp

@@ -900,9 +900,19 @@ PolycodeTabButton::PolycodeTabButton(PolycodeProjectTab *tab) : UIElement() {
 	tabLabel = new UILabel(tab->getTabName().toUpperCase(), 16, "section");
 	tabLabel->setPosition((getWidth()-tabLabel->getWidth())/2.0, ((getHeight()-tabLabel->getHeight())/2.0) - 3.0);
 	addChild(tabLabel);
+	
+	closeButton = new UIImageButton("Images/tab_close_button.png");
+	closeButton->setPosition(4.0, floor((30.0 - closeButton->getHeight()) / 2.0));
+	addChild(closeButton);
+	closeButton->blockMouseInput = true;
+	closeButton->addEventListener(this, UIEvent::CLICK_EVENT);
 }
 
 void PolycodeTabButton::handleEvent(Event *event) {
+	if(event->getDispatcher() == closeButton) {
+		dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);		
+	}
+	
 	if(event->getDispatcher() == bgRect) {
 		dispatchEvent(new Event(), Event::SELECT_EVENT);
 	}
@@ -926,6 +936,7 @@ PolycodeTabButton::~PolycodeTabButton() {
 }
 
 PolycodeProjectFrame::PolycodeProjectFrame(PolycodeProject *project, PolycodeEditorManager *editorManager) {
+	tabToClose = NULL;
 	this->editorManager = editorManager;
 	this->project = project;
 	lastActiveEditorHolder = NULL;
@@ -953,10 +964,50 @@ PolycodeProjectTab *PolycodeProjectFrame::addNewTab() {
 	tabButtonAnchor->addChild(newTabButton);
 	tabButtons.push_back(newTabButton);
 	newTabButton->addEventListener(this, Event::SELECT_EVENT);
+	newTabButton->addEventListener(this, UIEvent::CLOSE_EVENT);		
 	showTab(newTab);
 	return newTab;
 }
 
+void PolycodeProjectFrame::Update() {
+	if(tabToClose) {
+	
+		// can't close the last tab
+		if(tabs.size() == 1) {
+			tabToClose = NULL;
+			return;
+		}
+		
+		for(int i=0; i < tabs.size(); i++) {
+			if(tabs[i] == tabToClose) {
+				tabs.erase(tabs.begin()+i);
+				break;
+			}
+		}
+		
+		for(int i=0; i < tabButtons.size(); i++) {
+			if(tabButtons[i]->getTab() == tabToClose) {
+				tabButtonAnchor->removeChild(tabButtons[i]);
+				delete tabButtons[i];
+				tabButtons.erase(tabButtons.begin()+i);
+				break;
+			}
+		}
+		
+		if(tabToClose == activeTab) {
+			showTab(tabs[0]);
+		}
+		
+		delete tabToClose;
+		tabToClose = NULL;
+		restructTabs();
+	}
+}
+
+void PolycodeProjectFrame::closeTab(PolycodeProjectTab *tab) {
+	tabToClose = tab;
+}
+
 void PolycodeProjectFrame::showTab(PolycodeProjectTab *tab) {
 	if(activeTab) {
 		activeTab->setActive(false);
@@ -984,18 +1035,24 @@ void PolycodeProjectFrame::restructTabs() {
 }
 
 void PolycodeProjectFrame::handleEvent(Event *event) {
-	if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
-		dispatchEvent(new UIEvent, UIEvent::CLOSE_EVENT);
+	for(int i=0; i < tabs.size(); i++) {
+		if(event->getDispatcher() == tabs[i] && event->getEventCode() == UIEvent::CLOSE_EVENT) {
+			dispatchEvent(new UIEvent, UIEvent::CLOSE_EVENT);
+			return;
+		 } 
+	}
+	
+	if(event->getDispatcher() == newTabButton) {
+		addNewTab();
 	} else {
-		if(event->getDispatcher() == newTabButton) {
-			addNewTab();
-		} else {
-			for(int i=0; i < tabButtons.size(); i++) {
-				if(event->getDispatcher() == tabButtons[i]) {
-					if(event->getEventCode() == Event::SELECT_EVENT) {
-						showTab(tabButtons[i]->getTab());
-						break;
-					}
+		for(int i=0; i < tabButtons.size(); i++) {
+			if(event->getDispatcher() == tabButtons[i]) {
+				if(event->getEventCode() == Event::SELECT_EVENT) {
+					showTab(tabButtons[i]->getTab());
+					break;
+				} else 	if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
+					closeTab(tabButtons[i]->getTab());
+					break;
 				}
 			}
 		}
@@ -1271,7 +1328,6 @@ void PolycodeFrame::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == activeProjectFrame) {
 		if(event->getEventCode() == Event::CHANGE_EVENT) {
-			printf("WOOP\n");
 			dispatchEvent(new Event(), Event::CHANGE_EVENT);
 		}
 	}

+ 0 - 1
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -616,7 +616,6 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == frame) {
 		if(event->getEventCode() == Event::CHANGE_EVENT) {
-			printf("HOPHOP\n");
 			if(frame->getCurrentProjectBrowser()) {
 				frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this);
 			}