Skip to content

Commit

Permalink
Place unsupported languages in conditional blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Randalphwa committed Jan 11, 2025
1 parent 384dcfc commit c9ddeee
Show file tree
Hide file tree
Showing 32 changed files with 1,691 additions and 1,506 deletions.
113 changes: 80 additions & 33 deletions src/customprops/eventhandler_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,30 @@ extern const char* g_rust_keywords;
#define SCI_SETKEYWORDS 4005
#endif

constexpr size_t EVENT_PAGE_CPP = 0;
constexpr size_t EVENT_PAGE_PYTHON = 1;
constexpr size_t EVENT_PAGE_RUBY = 2;
constexpr size_t EVENT_PAGE_FORTRAN = 3;
constexpr size_t EVENT_PAGE_HASKELL = 4;
constexpr size_t EVENT_PAGE_LUA = 5;
constexpr size_t EVENT_PAGE_PERL = 6;
constexpr size_t EVENT_PAGE_RUST = 7;
constexpr int EVENT_PAGE_CPP = 0;
constexpr int EVENT_PAGE_PERL = 1;
constexpr int EVENT_PAGE_PYTHON = 2;
constexpr int EVENT_PAGE_RUBY = 3;
constexpr int EVENT_PAGE_RUST = 4;

// Keep these even if !GENERATE_NEW_LANG_CODE so that they can be removed
constexpr int EVENT_PAGE_FORTRAN = 5;
constexpr int EVENT_PAGE_HASKELL = 6;
constexpr int EVENT_PAGE_LUA = 7;

EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHandlerDlgBase(parent), m_event(event)
{
// Page numbers can be reduced if the language before it was removed
m_perl_page = EVENT_PAGE_PERL;
m_python_page = EVENT_PAGE_PYTHON;
m_ruby_page = EVENT_PAGE_RUBY;
m_rust_page = EVENT_PAGE_RUST;

#if GENERATE_NEW_LANG_CODE
m_fortran_page = EVENT_PAGE_FORTRAN;
m_haskell_page = EVENT_PAGE_HASKELL;
m_lua_page = EVENT_PAGE_LUA;
m_perl_page = EVENT_PAGE_PERL;
m_rust_page = EVENT_PAGE_RUST;
#endif // GENERATE_NEW_LANG_CODE

m_gen_languages = Project.getGenerateLanguages();
m_is_cpp_enabled = (m_gen_languages & GEN_LANG_CPLUSPLUS);
Expand All @@ -64,42 +69,76 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand

// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they are
// here in case they do get supported in the future.

#if GENERATE_NEW_LANG_CODE
m_is_fortran_enabled = (m_gen_languages & GEN_LANG_FORTRAN);
m_is_haskell_enabled = (m_gen_languages & GEN_LANG_HASKELL);
m_is_lua_enabled = (m_gen_languages & GEN_LANG_LUA);
#endif // GENERATE_NEW_LANG_CODE

m_code_preference = Project.getCodePreference(event->getNode());

if (!m_is_cpp_enabled)
{
m_notebook->RemovePage(EVENT_PAGE_CPP);
m_perl_page--;
m_python_page--;
m_ruby_page--;
m_rust_page--;

#if GENERATE_NEW_LANG_CODE
m_fortran_page--;
m_haskell_page--;
m_lua_page--;
m_perl_page--;
#endif // GENERATE_NEW_LANG_CODE
}
if (!m_is_perl_enabled)
{
m_notebook->RemovePage(m_perl_page);
m_python_page--;
m_ruby_page--;
m_rust_page--;

#if GENERATE_NEW_LANG_CODE
m_fortran_page--;
m_haskell_page--;
m_lua_page--;
#endif // GENERATE_NEW_LANG_CODE
}
if (!m_is_python_enabled)
{
m_notebook->RemovePage(m_python_page);
m_ruby_page--;
m_rust_page--;

#if GENERATE_NEW_LANG_CODE
m_fortran_page--;
m_haskell_page--;
m_lua_page--;
m_perl_page--;
m_rust_page--;
#endif // GENERATE_NEW_LANG_CODE
}
if (!m_is_ruby_enabled)
{
m_notebook->RemovePage(m_ruby_page);
m_rust_page--;

#if GENERATE_NEW_LANG_CODE
m_fortran_page--;
m_haskell_page--;
m_lua_page--;
m_perl_page--;
m_rust_page--;
#endif // GENERATE_NEW_LANG_CODE
}
if (!m_is_rust_enabled)
{
m_notebook->RemovePage(m_rust_page);

#if GENERATE_NEW_LANG_CODE
m_fortran_page--;
m_haskell_page--;
m_lua_page--;
#endif // GENERATE_NEW_LANG_CODE
}

#if GENERATE_NEW_LANG_CODE
if (!m_is_fortran_enabled)
{
m_notebook->RemovePage(m_fortran_page);
Expand All @@ -121,16 +160,7 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand
m_perl_page--;
m_rust_page--;
}
if (!m_is_perl_enabled)
{
m_notebook->RemovePage(m_perl_page);
m_rust_page--;
}
if (!m_is_rust_enabled)
{
m_notebook->RemovePage(m_rust_page);
}

#endif
m_value = event->get_value().make_wxString();

if (m_is_cpp_enabled)
Expand Down Expand Up @@ -184,6 +214,7 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand
// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they are
// here in case they do get supported in the future.

#if GENERATE_NEW_LANG_CODE
if (m_is_fortran_enabled)
{
m_fortran_stc_lambda->SetLexer(wxSTC_LEX_FORTRAN);
Expand Down Expand Up @@ -216,6 +247,7 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand
m_lua_stc_lambda->StyleSetForeground(wxSTC_LUA_WORD, UserPrefs.get_LuaKeywordColour());
m_lua_stc_lambda->StyleSetForeground(wxSTC_LUA_WORD2, UserPrefs.get_LuaColour());
}
#endif // GENERATE_NEW_LANG_CODE

auto form = event->getNode()->getForm();
if (form)
Expand Down Expand Up @@ -278,6 +310,7 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand

// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they
// are here in case they do get supported in the future.
#if GENERATE_NEW_LANG_CODE

if (m_is_fortran_enabled)
{
Expand All @@ -294,6 +327,7 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand
m_lua_stc_lambda->SetLexer(wxSTC_LEX_LUA);
m_lua_stc_lambda->SendMsg(SCI_SETKEYWORDS, 0, (wxIntPtr) g_lua_keywords);
}
#endif // GENERATE_NEW_LANG_CODE
}

if (m_code_preference == GEN_LANG_CPLUSPLUS)
Expand All @@ -310,18 +344,27 @@ EventHandlerDlg::EventHandlerDlg(wxWindow* parent, NodeEvent* event) : EventHand
// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they are
// here in case they do get supported in the future.

#if GENERATE_NEW_LANG_CODE
else if (m_code_preference == GEN_LANG_FORTRAN)
m_notebook->SetSelection(m_fortran_page);
else if (m_code_preference == GEN_LANG_HASKELL)
m_notebook->SetSelection(m_haskell_page);
else if (m_code_preference == GEN_LANG_LUA)
m_notebook->SetSelection(m_lua_page);
#endif // GENERATE_NEW_LANG_CODE
}

void EventHandlerDlg::OnInit(wxInitDialogEvent& WXUNUSED(event))
{
m_static_bind_text->SetLabel(wxEmptyString);

#if !GENERATE_NEW_LANG_CODE
// Remove in reverse order so prevent positions from changing
m_notebook->RemovePage(EVENT_PAGE_LUA);
m_notebook->RemovePage(EVENT_PAGE_HASKELL);
m_notebook->RemovePage(EVENT_PAGE_FORTRAN);
#endif // !GENERATE_NEW_LANG_CODE

if (m_value.empty())
{
if (auto default_name = s_EventNames.find(m_event->get_name()); default_name != s_EventNames.end())
Expand Down Expand Up @@ -664,7 +707,7 @@ void EventHandlerDlg::OnPageChanged(wxBookCtrlEvent& event)
// once and been corrected, then further changes work fine. I have not been able to figure
// out why this is happening, but this code works around it.

if (m_is_python_enabled && event.GetSelection() == (to_int) m_python_page)
if (m_is_python_enabled && event.GetSelection() == m_python_page)
{
if (m_is_python_lambda)
{
Expand All @@ -678,7 +721,7 @@ void EventHandlerDlg::OnPageChanged(wxBookCtrlEvent& event)
m_is_cpp_lambda = m_cpp_radio_use_lambda->GetValue();
m_is_ruby_lambda = m_ruby_radio_use_lambda->GetValue();
}
else if (m_is_cpp_enabled && event.GetSelection() == (to_int) EVENT_PAGE_CPP)
else if (m_is_cpp_enabled && event.GetSelection() == EVENT_PAGE_CPP)
{
if (m_is_cpp_lambda)
{
Expand All @@ -692,7 +735,7 @@ void EventHandlerDlg::OnPageChanged(wxBookCtrlEvent& event)
m_is_python_lambda = m_py_radio_use_lambda->GetValue();
m_is_ruby_lambda = m_ruby_radio_use_lambda->GetValue();
}
else if (m_is_ruby_enabled && event.GetSelection() == (to_int) m_ruby_page)
else if (m_is_ruby_enabled && event.GetSelection() == m_ruby_page)
{
if (m_is_ruby_lambda)
{
Expand All @@ -706,7 +749,7 @@ void EventHandlerDlg::OnPageChanged(wxBookCtrlEvent& event)
m_is_cpp_lambda = m_cpp_radio_use_lambda->GetValue();
m_is_python_lambda = m_py_radio_use_lambda->GetValue();
}
else if (m_is_rust_enabled && event.GetSelection() == (to_int) m_rust_page)
else if (m_is_rust_enabled && event.GetSelection() == m_rust_page)
{
if (m_is_rust_lambda)
{
Expand Down Expand Up @@ -750,12 +793,14 @@ void EventHandlerDlg::OnNone(wxCommandEvent& WXUNUSED(event))

// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they are
// here in case they do get supported in the future.
#if GENERATE_NEW_LANG_CODE
else if (m_is_fortran_enabled && m_notebook->GetCurrentPage() == m_fortran_bookpage)
m_fortran_text_function->SetValue("none");
else if (m_is_haskell_enabled && m_notebook->GetCurrentPage() == m_haskell_bookpage)
m_haskell_text_function->SetValue("none");
else if (m_is_lua_enabled && m_notebook->GetCurrentPage() == m_lua_bookpage)
m_lua_text_function->SetValue("none");
#endif // GENERATE_NEW_LANG_CODE
}

void EventHandlerDlg::OnDefault(wxCommandEvent& WXUNUSED(event))
Expand Down Expand Up @@ -783,23 +828,25 @@ void EventHandlerDlg::OnDefault(wxCommandEvent& WXUNUSED(event))

// REVIEW: [Randalphwa - 01-09-2025] Support for these is not currently planned, but they are
// here in case they do get supported in the future.
#if GENERATE_NEW_LANG_CODE
else if (m_is_fortran_enabled && m_notebook->GetCurrentPage() == m_fortran_bookpage)
m_fortran_text_function->SetValue(value);
else if (m_is_haskell_enabled && m_notebook->GetCurrentPage() == m_haskell_bookpage)
m_haskell_text_function->SetValue(value);
else if (m_is_lua_enabled && m_notebook->GetCurrentPage() == m_lua_bookpage)
m_lua_text_function->SetValue(value);
#endif // GENERATE_NEW_LANG_CODE
}

void EventHandlerDlg::FormatBindText()
{
auto page = m_notebook->GetSelection();
GenLang language;
if (m_is_cpp_enabled && page == (to_int) EVENT_PAGE_CPP)
if (m_is_cpp_enabled && page == EVENT_PAGE_CPP)
language = GEN_LANG_CPLUSPLUS;
else if (m_is_python_enabled && page == (to_int) m_python_page)
else if (m_is_python_enabled && page == m_python_page)
language = GEN_LANG_PYTHON;
else if (m_is_ruby_enabled && page == (to_int) m_ruby_page)
else if (m_is_ruby_enabled && page == m_ruby_page)
language = GEN_LANG_RUBY;
else
return;
Expand Down
32 changes: 20 additions & 12 deletions src/customprops/eventhandler_dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,41 @@ class EventHandlerDlg : public EventHandlerDlgBase
private:
NodeEvent* m_event;

size_t m_fortran_page;
size_t m_haskell_page;
size_t m_lua_page;
size_t m_perl_page;
size_t m_python_page;
size_t m_ruby_page;
size_t m_rust_page;
int m_perl_page;
int m_python_page;
int m_ruby_page;
int m_rust_page;

#if GENERATE_NEW_LANG_CODE
int m_fortran_page;
int m_haskell_page;
int m_lua_page;
#endif // GENERATE_NEW_LANG_CODE

size_t m_gen_languages; // set by Project.getGenerateLanguages()
GenLang m_code_preference; // This will be one of the GEN_LANG values

bool m_is_cpp_enabled { false };
bool m_is_fortran_enabled { false };
bool m_is_haskell_enabled { false };
bool m_is_lua_enabled { false };
bool m_is_perl_enabled { false };
bool m_is_python_enabled { false };
bool m_is_ruby_enabled { false };
bool m_is_rust_enabled { false };

#if GENERATE_NEW_LANG_CODE
bool m_is_fortran_enabled { false };
bool m_is_haskell_enabled { false };
bool m_is_lua_enabled { false };
#endif // GENERATE_NEW_LANG_CODE

bool m_is_cpp_lambda { false };
bool m_is_perl_lambda { false };
bool m_is_python_lambda { false };
bool m_is_ruby_lambda { false };
bool m_is_rust_lambda { false };

#if GENERATE_NEW_LANG_CODE
bool m_is_fortran_lambda { false };
bool m_is_haskell_lambda { false };
bool m_is_lua_lambda { false };
bool m_is_perl_lambda { false };
bool m_is_rust_lambda { false };
#endif // GENERATE_NEW_LANG_CODE
};
7 changes: 4 additions & 3 deletions src/file_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ set (file_list

generate/gen_cpp.cpp # Generate C++ code
generate/gen_derived.cpp # Generate C++ Derived code
generate/gen_fortran.cpp # Generate wxFortran code
generate/gen_haskell.cpp # Generate wxHaskell code
generate/gen_lua.cpp # Generate wxLua/wxLuaJIT code
generate/gen_perl.cpp # Generate wxPerl code
generate/gen_python.cpp # Generate wxPython code
generate/gen_ruby.cpp # Generate wxRuby3 code
generate/gen_rust.cpp # Generate wxRust code
generate/gen_xrc.cpp # Generate XRC

# generate/gen_fortran.cpp # Generate wxFortran code
# generate/gen_haskell.cpp # Generate wxHaskell code
# generate/gen_lua.cpp # Generate wxLua/wxLuaJIT code

# Generators are responsible for displaying the widget in the Mockup window,
# and generating both C++, Python, Ruby and XRC code. If the generated object
# can be used in a Dialog or Frame, then the generator must also be able to
Expand Down
11 changes: 7 additions & 4 deletions src/generate/base_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,20 +929,23 @@ std::optional<tt_string> BaseGenerator::isLanguagePropSupported(Node* node, GenL
{
switch (language)
{
case GEN_LANG_LUA:
return "persist is not supported in Lua";
case GEN_LANG_PERL:
return "persist is not supported in Perl";
case GEN_LANG_RUST:
return "persist is not supported in Rust";
case GEN_LANG_PYTHON:
return "persist is not supported in Python";
case GEN_LANG_XRC:
return "persist is not supported in XRC";

#if GENERATE_NEW_LANG_CODE
case GEN_LANG_FORTRAN:
return "persist is not supported in Fortran";
case GEN_LANG_HASKELL:
return "persist is not supported in Haskell";
case GEN_LANG_XRC:
return "persist is not supported in XRC";
case GEN_LANG_LUA:
return "persist is not supported in Lua";
#endif // GENERATE_NEW_LANG_CODE
default:
return {};
}
Expand Down
Loading

0 comments on commit c9ddeee

Please sign in to comment.