Просмотр исходного кода

Added function list dropdown to IDE text editor

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

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

@@ -53,6 +53,7 @@ class FindBar : public UIElement {
 		UIImageButton *closeButton;		
 		
 		UIButton *replaceAllButton;
+		UIComboBox *functionList;
 		
 	protected:
 		ScreenShape *barBg;

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


+ 36 - 2
IDE/Contents/Source/PolycodeTextEditor.cpp

@@ -23,6 +23,7 @@
 #include "PolycodeTextEditor.h"
 
 extern SyntaxHighlightTheme *globalSyntaxTheme;
+extern UIGlobalMenu *globalMenu;
 
 void SyntaxHighlightTheme::loadFromFile(String themeName) {
 	String filePath = "SyntaxThemes/"+themeName+".xml";
@@ -486,7 +487,8 @@ bool PolycodeTextEditor::openFile(OSFileEntry filePath) {
 			
 	findBar->closeButton->addEventListener(this, UIEvent::CLICK_EVENT);
 	findBar->replaceAllButton->addEventListener(this, UIEvent::CLICK_EVENT);
-		
+	findBar->functionList->addEventListener(this, UIEvent::CHANGE_EVENT);
+			
 	syntaxHighligher = NULL;
 	
 	if(filePath.extension == "lua" || filePath.extension == "vert" || filePath.extension == "frag") {
@@ -517,6 +519,13 @@ void PolycodeTextEditor::handleEvent(Event *event) {
 		}
 	}
 
+	if(event->getDispatcher() == findBar->functionList) {
+		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
+			FindMatch *match = (FindMatch*)findBar->functionList->getSelectedItem()->data;
+			textInput->showLine(match->lineNumber, true);
+		}		
+	}
+
 	if(event->getDispatcher() == findBar->replaceAllButton) {
 		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
 			textInput->replaceAll(findBar->findInput->getText(), findBar->replaceInput->getText());
@@ -573,6 +582,22 @@ void PolycodeTextEditor::showFindBar() {
 	findBar->focusChild(findBar->findInput);
 	findBar->findInput->selectAll();
 	lastFindString = "";
+	
+	for(int i=0; i < findBar->functionList->getNumItems(); i++) {
+		FindMatch *match = (FindMatch*)findBar->functionList->getItemAtIndex(i)->data;
+		findBar->functionList->getItemAtIndex(i)->data = NULL;
+		delete match;
+	}
+	
+	findBar->functionList->clearItems();
+	
+	std::vector<FindMatch> functionMatches = textInput->getFindMatches("function ");
+	for(int i=0; i < functionMatches.size(); i++) {
+		FindMatch *match = new FindMatch();
+		(*match) = functionMatches[i];
+		findBar->functionList->addComboItem(textInput->getLineText(functionMatches[i].lineNumber).replace("function ", ""), (void*) match);
+	}
+	
 	Resize(editorSize.x, editorSize.y);
 }
 
@@ -630,7 +655,7 @@ FindBar::FindBar() : UIElement() {
 	addChild(replaceLabel);
 	replaceLabel->setColor(1.0, 1.0, 1.0, 0.6);
 	replaceLabel->setPosition(200,3);
-
+	
 	processInputEvents = true;
 	
 	findInput = new UITextInput(false, 120, 12);
@@ -644,7 +669,15 @@ FindBar::FindBar() : UIElement() {
 	replaceAllButton = new UIButton("Replace All", 100);
 	addChild(replaceAllButton);
 	replaceAllButton->setPosition(420, 3);
+
+	ScreenImage *functionIcon = new ScreenImage("Images/function_icon.png");
+	addChild(functionIcon);
+	functionIcon->setPosition(540, 5);	
 	
+	functionList = new UIComboBox(globalMenu, 200);
+	addChild(functionList);
+	functionList->setPosition(560, 4);	
+		
 	closeButton = new UIImageButton("Images/barClose.png");
 	addChild(closeButton);
 }
@@ -670,4 +703,5 @@ FindBar::~FindBar(){
 void FindBar::setBarWidth(int width) {
 	barBg->setShapeSize(width, 30);
 	closeButton->setPosition(width - 30, 5);
+	functionList->Resize(width-560-60, functionList->getHeight());
 }

+ 2 - 0
Modules/Contents/UI/Include/PolyUITextInput.h

@@ -295,6 +295,8 @@ namespace Polycode {
 			 */
 			void findString(String stringToFind, bool replace=false, String replaceString="");
 
+			std::vector<FindMatch> getFindMatches(String stringToFind);
+
 			/**
 			 * Set the current find result to the next one in the result list and select it
 			 * in the text field.

+ 12 - 10
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -1123,14 +1123,10 @@ void UITextInput::replaceAll(String what, String withWhat) {
 	}
 }
 
-void UITextInput::findString(String stringToFind, bool replace, String replaceString) {
-
-	clearSelection();
-	findMatches.clear();
+std::vector<FindMatch> UITextInput::getFindMatches(String stringToFind) {
+	std::vector<FindMatch> findMatches;
 	
 	for(int i=0; i < lines.size(); i++) {
-
-
 		String lineText = lines[i].text;
 		
 		int offset = 0;				
@@ -1145,11 +1141,17 @@ void UITextInput::findString(String stringToFind, bool replace, String replaceSt
 				findMatches.push_back(match);		
 				offset = retVal + stringToFind.length();
 			}			
-		} while(retVal != -1);
-		
+		} while(retVal != -1);		
 	}
-	
-	
+	return findMatches;
+}
+
+void UITextInput::findString(String stringToFind, bool replace, String replaceString) {
+
+	clearSelection();
+	findMatches.clear();		
+	findMatches = getFindMatches(stringToFind);
+		
 	if(findMatches.size() > 0) {
 
 		if(replace) {