From 12adf9b7a0e6c96ea7ae9911c780990f7b3c49c2 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Fri, 8 May 2015 16:01:36 -0400 Subject: [PATCH] Generate language menu --- Mac-compatibility-build.md | 1 - README.md | 2 +- Windows-Build.md | 2 +- src/TyroApp.cpp | 6 ++---- src/definitions.h | 2 +- src/settings/LangConfig.cpp | 21 ++++++++++++++++++++- src/settings/LangConfig.h | 1 + src/settings/ThemeConfig.cpp | 5 ++++- src/widgets/EditPane.cpp | 16 ++++++++++------ src/widgets/EditPane.h | 2 -- src/widgets/MainFrame.cpp | 2 +- src/widgets/MainFrame.h | 4 ---- src/widgets/TabContainer.h | 2 -- src/widgets/TyroMenu.cpp | 26 +++++++++++++++++--------- src/widgets/TyroMenu.h | 10 ++++------ src/widgets/widget.h | 12 ++++++++++++ 16 files changed, 74 insertions(+), 40 deletions(-) diff --git a/Mac-compatibility-build.md b/Mac-compatibility-build.md index 0217d8a..cc4c866 100644 --- a/Mac-compatibility-build.md +++ b/Mac-compatibility-build.md @@ -16,7 +16,6 @@ Use [this script](http://devernay.free.fr/hacks/xcodelegacy/) to install older S ## Recommended flags for development/debugging (Assuming OS X > 10.7) * --enable-debug_gdb * --enable-profile -* --enable-arttango * --disable-compat28 * --disable-shared * --without-webviewwebkit diff --git a/README.md b/README.md index 3c757cf..421d742 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ steps should work fine for a local build. 1. Download the latest wxWidgets source 2. Make a new directory in the source tree, like `wxmac` -3. Run `../configure --disable-shared --disable-webviewwebkit` in the new directory +3. Run `../configure --disable-shared --disable-webviewwebkit --disable-compat28` in the new directory 4. Run `make && make install` Install libssh2 (Using homebrew): diff --git a/Windows-Build.md b/Windows-Build.md index 408153e..f458c4e 100644 --- a/Windows-Build.md +++ b/Windows-Build.md @@ -21,7 +21,7 @@ In order to keep a consistent build system, Tyro is built with MinGW and Msys. T 1. Download the windows [installer](https://www.wxwidgets.org/downloads/) for version 3 2. Use the MSyS prompt to navigate to the wxWidgets directory 3. Make a new folder, eg. msw-debug, and cd into it. -4. Run `../configure --disable-shared --enable-debug` in that new directory. +4. Run `../configure --disable-shared --enable-debug --disable-compat28 --enable-arttango` in that new directory. 5. After configure finishes, run `make && make install` in the same folder. diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index cd50c79..af2df74 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -3,9 +3,9 @@ */ #include "wx_common.h" +#include "widgets/widget.h" #include -#include #include class TyroApp : public wxApp @@ -17,14 +17,12 @@ public: private: }; -wxConfigBase *Config; - //************************************************************** -#include "widgets/widget.h" IMPLEMENT_APP(TyroApp); // Some global stuff +wxConfigBase *Config; TyroMenu *mbar; MainFrame *main_frame; diff --git a/src/definitions.h b/src/definitions.h index 4475a8d..8c88cc7 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -30,7 +30,7 @@ enum myMenuIds { myHELP_MENU }; -// Menu ids +// General Menu ids enum myMenuItemIds { myID_VIEW_WHITESPACE = wxID_HIGHEST, myID_VIEW_LINE_ENDINGS, diff --git a/src/settings/LangConfig.cpp b/src/settings/LangConfig.cpp index 80f7a9b..331cf44 100644 --- a/src/settings/LangConfig.cpp +++ b/src/settings/LangConfig.cpp @@ -13,7 +13,10 @@ LangConfig::LangConfig() this->lang = ""; } -LangConfig::~LangConfig() {} +LangConfig::~LangConfig() +{ + wxLogDebug("Called LangConfig Destructor"); +} /** * Determine the format of the current file by @@ -99,4 +102,20 @@ void LangConfig::SetLang(string lang) string LangConfig::GetLang() { return this->lang; +} + +StringMap LangConfig::GetLangList() +{ + JsonValue langList = this->GetRoot(); + JsonValue::iterator it; + + StringMap outputList; + + for (it = langList.begin(); it != langList.end(); ++it) + { + JsonValue langObj = *it; + outputList[it.key().asString()] = langObj.get("name", JsonValue()).asString(); + } + + return outputList; } \ No newline at end of file diff --git a/src/settings/LangConfig.h b/src/settings/LangConfig.h index 1354dfc..f6b1a67 100644 --- a/src/settings/LangConfig.h +++ b/src/settings/LangConfig.h @@ -13,6 +13,7 @@ public: string GetLangByFile(wxFileName &fileName); JsonValue GetKeywordList(string lang="none"); JsonValue GetLexerMap(string lang="none"); + StringMap GetLangList(); private: string lang; }; diff --git a/src/settings/ThemeConfig.cpp b/src/settings/ThemeConfig.cpp index ad9da25..a7081f2 100644 --- a/src/settings/ThemeConfig.cpp +++ b/src/settings/ThemeConfig.cpp @@ -11,7 +11,10 @@ ThemeConfig::ThemeConfig() this->SetTheme("Solarized"); } -ThemeConfig::~ThemeConfig() {} +ThemeConfig::~ThemeConfig() +{ + wxLogDebug("Called ThemeConfig Destructor"); +} void ThemeConfig::SetTheme(string theme_name) { diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index c272483..8a1e8d5 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -77,6 +77,7 @@ EditPane::EditPane( EditPane::~EditPane() { + wxLogDebug("Called EditPane Destructor"); delete lang_config; delete theme_config; } @@ -143,14 +144,17 @@ void EditPane::ApplyTheme(string lang, string theme) } else { - string typeMap[] = {"null", "int", "unsigned int", "double", "string", "boolean", "array", "object"}; - stringstream output; + if (lang != "") + { + string typeMap[] = {"null", "int", "unsigned int", "double", "string", "boolean", "array", "object"}; + stringstream output; - output << "current lang is:" << lang << endl; - output << "keywords array is not an array" << endl; - output << "keyword array is a " << typeMap[keywords_array.type()] << endl; + output << "current lang is:" << lang << endl; + output << "keywords array is not an array" << endl; + output << "keyword array is a " << typeMap[keywords_array.type()] << endl; - wxLogDebug(output.str().c_str()); + wxLogDebug(output.str().c_str()); + } } // Do the appropriate mappings to load the selected theme diff --git a/src/widgets/EditPane.h b/src/widgets/EditPane.h index 07a2587..5af6c11 100644 --- a/src/widgets/EditPane.h +++ b/src/widgets/EditPane.h @@ -4,8 +4,6 @@ #include "../settings/LangConfig.h" #include "../settings/ThemeConfig.h" -#include - class EditPane: public wxStyledTextCtrl { public: diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 94f6c74..90fa30a 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -45,7 +45,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title) MainFrame::~MainFrame() { wxLogDebug("Main Frame Destructor Called."); - //delete notebook; + delete notebook; } void MainFrame::SetupStatusBar() diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index e61cf89..1358780 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -5,10 +5,6 @@ #ifndef TYROMAIN_H #define TYROMAIN_H -#include -#include -#include -#include #include "TabContainer.h" class MainFrame: public wxFrame diff --git a/src/widgets/TabContainer.h b/src/widgets/TabContainer.h index 7a01c49..1af4c1c 100644 --- a/src/widgets/TabContainer.h +++ b/src/widgets/TabContainer.h @@ -7,8 +7,6 @@ #include "EditPane.h" #include "MainFrame.h" -#include -#include static long tab_style = wxBORDER_NONE | wxAUI_NB_TAB_SPLIT |wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index e08d34e..468a98c 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -1,4 +1,7 @@ #include "widget.h" +#include "../settings/LangConfig.h" + +static LangConfig *lang_config; TyroMenu::TyroMenu() { @@ -7,8 +10,11 @@ TyroMenu::TyroMenu() viewMenu = new wxMenu(); langMenu = new wxMenu(); helpMenu = new wxMenu(); - + + lang_config = new LangConfig(); + this->SetupMainMenus(); + this->SetupLangMenu(); // Add the menus to the menubar this->Insert(myFILE_MENU, fileMenu, "&File"); @@ -21,12 +27,6 @@ TyroMenu::TyroMenu() TyroMenu::~TyroMenu() { wxLogDebug("TyroMenu Destructor Called."); - - //delete fileMenu; - //delete editMenu; - //delete viewMenu; - //delete langMenu; - //delete helpMenu; } void TyroMenu::SetupMainMenus() @@ -66,7 +66,15 @@ void TyroMenu::SetupMainMenus() void TyroMenu::SetupLangMenu() { + StringMap langs = lang_config->GetLangList(); + StringMap::iterator it; + StringMap::iterator last = langs.end(); + + for (it = langs.begin(); it != last; ++it) + { + langMenu->Append(wxID_ANY, it->second, "Hightlight file as " + it->second, wxITEM_CHECK); + } } void TyroMenu::EnableEditControls(bool enable) @@ -95,11 +103,11 @@ void TyroMenu::EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable) { // Toggle the top of the menu this->EnableTop(menuId, enable); - + // Toggle the rest of the items in the menu wxMenuItemList list = menu->GetMenuItems(); wxMenuItemList::iterator iter; - + for(iter = list.begin(); iter != list.end(); ++iter) { wxMenuItem *current = *iter; diff --git a/src/widgets/TyroMenu.h b/src/widgets/TyroMenu.h index a9e2b54..fd86659 100644 --- a/src/widgets/TyroMenu.h +++ b/src/widgets/TyroMenu.h @@ -1,13 +1,11 @@ -/* - * File: TyroMenu.h - * Author: twarren - * - * Created on May 7, 2015, 3:10 PM +/** + * Main Menu class */ - #ifndef TYRO_MENU_H #define TYRO_MENU_H +#include "widget.h" + class TyroMenu : public wxMenuBar { public: TyroMenu(); diff --git a/src/widgets/widget.h b/src/widgets/widget.h index 071f0d5..7c24e3c 100644 --- a/src/widgets/widget.h +++ b/src/widgets/widget.h @@ -8,7 +8,19 @@ #ifndef TYRO_WIDGET_H #define TYRO_WIDGET_H +// Common wxWidgets stuff #include "../wx_common.h" + +// Base widgets +#include +#include +#include +#include +#include +#include +#include + +// Tyro includes #include "TyroMenu.h" #include "EditPane.h" #include "TabContainer.h"