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

MenuBar and IDE shortcuts in Linux

Ivan Safrin 13 лет назад
Родитель
Сommit
09520ea3ab

+ 1 - 1
Core/Contents/Include/PolyInputKeys.h

@@ -286,4 +286,4 @@ namespace Polycode {
 	} PolyKEY;
 
 };
-	
+	

+ 8 - 8
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -123,15 +123,15 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	menuBar = new UIMenuBar(100, globalMenu);
 
 	UIMenuBarEntry *fileEntry = menuBar->addMenuBarEntry("File");
-	fileEntry->addItem("New File", "new_file");
-	fileEntry->addItem("New Project", "new_project");
-	fileEntry->addItem("New Folder", "new_folder");
-	fileEntry->addItem("Open Project", "open_project");
-	fileEntry->addItem("Close Project", "close_project");
+	fileEntry->addItem("New File", "new_file", KEY_n);
+	fileEntry->addItem("New Project", "new_project", KEY_LSHIFT, KEY_n);
+	fileEntry->addItem("New Folder", "new_folder", KEY_LSHIFT, KEY_f);
+	fileEntry->addItem("Open Project", "open_project", KEY_LSHIFT, KEY_o);
+	fileEntry->addItem("Close Project", "close_project", KEY_LSHIFT, KEY_w);
 	fileEntry->addItem("Remove File", "remove_file");
 	fileEntry->addItem("Refresh Project", "refresh_project");
-	fileEntry->addItem("Save File", "save_file");
-	fileEntry->addItem("Browse Examples", "browse_examples");
+	fileEntry->addItem("Save File", "save_file", KEY_s);
+	fileEntry->addItem("Browse Examples", "browse_examples", KEY_LSHIFT, KEY_e);
 	fileEntry->addItem("Quit", "quit");
 
 	UIMenuBarEntry *editEntry = menuBar->addMenuBarEntry("Edit");
@@ -141,7 +141,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	editEntry->addItem("Copy", "copy");
 
 	UIMenuBarEntry *projectEntry = menuBar->addMenuBarEntry("Project");
-	projectEntry->addItem("Run Project", "run_project");
+	projectEntry->addItem("Run Project", "run_project", KEY_r);
 	projectEntry->addItem("Publish Project", "export_project");
 
 	UIMenuBarEntry *helpEntry = menuBar->addMenuBarEntry("Help");

+ 9 - 0
IDE/Contents/Source/PolycodeProjectManager.cpp

@@ -162,5 +162,14 @@ void PolycodeProjectManager::exportProject(PolycodeProject *project, String expo
 		CoreServices::getInstance()->getCore()->copyDiskItem(polyappPath, appPath+"/Contents/Resources/main.polyapp");
 		
 	}
+
+	if(linux) {
+		PolycodeConsole::print("Exporting Linux version to "+exportPath+"/Linux \n");
+		CoreServices::getInstance()->getCore()->copyDiskItem(publishPath+"/Linux", exportPath);
+		CoreServices::getInstance()->getCore()->copyDiskItem(publishPath+"/Linux", exportPath);
+		CoreServices::getInstance()->getCore()->moveDiskItem(exportPath+"/Linux/StandalonePlayer", exportPath+"/Linux/"+project->getProjectName());
+		CoreServices::getInstance()->getCore()->removeDiskItem(exportPath+"/Linux/main.polyapp");
+		CoreServices::getInstance()->getCore()->copyDiskItem(polyappPath, exportPath+"/Linux/main.polyapp");
+	}
 }
 

+ 8 - 2
Modules/Contents/UI/Include/PolyUIMenuBar.h

@@ -35,16 +35,22 @@ namespace Polycode {
 
 	class UIMenuBarEntryItem {
 		public:
-			UIMenuBarEntryItem(String name, String code) { this->name = name; this->code = code; }
+			UIMenuBarEntryItem(String name, String code, PolyKEY shortCut1, PolyKEY shortCut2);
 			String name;	
 			String code;
+
+			bool checkShortCut(PolyKEY shortCut);
+
+			PolyKEY shortCut1;
+			PolyKEY shortCut2;
+
 	};
 
 	class _PolyExport UIMenuBarEntry : public UIElement {
 		public:
 			UIMenuBarEntry(String name);
 			~UIMenuBarEntry();		
-			void addItem(String name, String code);
+			void addItem(String name, String code, PolyKEY shortCut1 = KEY_UNKNOWN, PolyKEY shortCut2 = KEY_UNKNOWN);
 
 			void Select();
 			void Deselect();

+ 52 - 2
Modules/Contents/UI/Source/PolyUIMenuBar.cpp

@@ -1,9 +1,40 @@
 
 #include "PolyUIMenuBar.h"
 #include "PolyLabel.h"
+#include <PolyCoreServices.h>
+#include <PolyCore.h>
 
 using namespace Polycode;
 
+UIMenuBarEntryItem::UIMenuBarEntryItem(String name, String code, PolyKEY shortCut1, PolyKEY shortCut2) {
+	this->name = name;
+	this->code = code;
+	this->shortCut1 = shortCut1;
+	this->shortCut2 = shortCut2;
+}
+
+bool UIMenuBarEntryItem::checkShortCut(PolyKEY shortCut) {
+	if(shortCut1 == KEY_UNKNOWN && shortCut2 == KEY_UNKNOWN)
+		return false;
+
+	if(CoreServices::getInstance()->getCore()->getInput()->getKeyState(KEY_RCTRL) || CoreServices::getInstance()->getCore()->getInput()->getKeyState(KEY_LCTRL)) {
+		if(shortCut1 != KEY_UNKNOWN && shortCut2 != KEY_UNKNOWN) {
+			if(shortCut == shortCut1 && CoreServices::getInstance()->getCore()->getInput()->getKeyState(shortCut2)) {
+				return true;
+			}
+			if(shortCut == shortCut2 && CoreServices::getInstance()->getCore()->getInput()->getKeyState(shortCut1)) {
+				return true;
+			}
+		} else {
+			if(shortCut == shortCut1) {
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
 UIMenuBarEntry::UIMenuBarEntry(String name): UIElement() {
 	
 	label = new ScreenLabel(name, 14, "sans");
@@ -25,8 +56,8 @@ void UIMenuBarEntry::Deselect() {
 	bg->color.setColorHex(0xce5a1600);
 }
 
-void UIMenuBarEntry::addItem(String name, String code) {
-	items.push_back(UIMenuBarEntryItem(name,code));
+void UIMenuBarEntry::addItem(String name, String code, PolyKEY shortCut1, PolyKEY shortCut2) {
+	items.push_back(UIMenuBarEntryItem(name,code, shortCut1, shortCut2));
 }
 
 UIMenuBarEntry::~UIMenuBarEntry() {
@@ -48,6 +79,8 @@ UIMenuBar::UIMenuBar(int width, UIGlobalMenu *globalMenu) : UIElement() {
 	dropMenu = NULL;
 
 	holdingMouse = false;
+
+	CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
 }
 
 UIMenuBarEntry *UIMenuBar::addMenuBarEntry(String name) {
@@ -87,6 +120,23 @@ String UIMenuBar::getSelectedItem() {
 }
 
 void UIMenuBar::handleEvent(Event *event) {
+
+	if(event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {
+		InputEvent *inputEvent = (InputEvent*) event;
+		if(event->getEventCode() == InputEvent::EVENT_KEYDOWN) {
+			for(int i=0; i < entries.size(); i++) {
+				UIMenuBarEntry *entry = entries[i];
+				for(int j=0; j < entry->items.size(); j++) {
+					if(entry->items[j].checkShortCut(inputEvent->key)) {
+						selectedItem = entry->items[j].code;
+						dispatchEvent(new UIEvent(), UIEvent::OK_EVENT);
+						break;
+					}
+				}
+			}
+		}
+	}
+
 	if(event->getDispatcher() == dropMenu) {
 		if(event->getEventCode() == UIEvent::OK_EVENT) {
 			selectedItem = dropMenu->getSelectedItem()->_id;