From 6ddc7c9b75e38d8f97332a4a1c05c9440983b698 Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Sun, 14 Jan 2024 17:49:06 -0800 Subject: [PATCH 1/2] Handle Image List selection For C++ panels, this will find the function used to load the image. For Python and Ruby panels, this will find the variable of the selected image. --- src/panels/code_display.cpp | 53 ++++++++++++++++++++++++++++++++++++- src/panels/code_display.h | 14 +++++----- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/panels/code_display.cpp b/src/panels/code_display.cpp index c511aae1e..5a47c604e 100644 --- a/src/panels/code_display.cpp +++ b/src/panels/code_display.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // Purpose: Display code in scintilla control // Author: Ralph Walden -// Copyright: Copyright (c) 2020-2023 KeyWorks Software (Ralph Walden) +// Copyright: Copyright (c) 2020-2024 KeyWorks Software (Ralph Walden) // License: Apache License -- see ../../LICENSE ///////////////////////////////////////////////////////////////////////////// @@ -13,12 +13,14 @@ #include "base_panel.h" // BasePanel -- Code generation panel #include "code.h" // Code -- Helper class for generating code +#include "image_handler.h" // ImageHandler class #include "mainframe.h" // MainFrame -- Main window frame #include "node.h" // Node class #include "node_creator.h" // NodeCreator -- Class used to create nodes #include "node_event.h" // NodeEvent and NodeEventInfo classes #include "preferences.h" // Prefs -- Set/Get wxUiEditor preferences #include "propgrid_panel.h" // PropGridPanel -- PropertyGrid class for node properties and events +#include "to_casts.h" // to_int, to_size_t, and to_char classes #include "utils.h" // Miscellaneous utility functions #ifndef SCI_SETKEYWORDS @@ -594,6 +596,12 @@ void CodeDisplay::CodeGenerationComplete() void CodeDisplay::OnNodeSelected(Node* node) { + if (node->isGen(gen_embedded_image)) + { + OnEmbedImageSelected(node); + return; + } + if (!node->hasProp(prop_var_name) && m_panel_type != GEN_LANG_XRC && !node->isGen(gen_ribbonTool) && !node->isGen(gen_ribbonButton)) { @@ -736,3 +744,46 @@ void CodeDisplay::OnNodeSelected(Node* node) // Unlike GetLineVisible(), this function does ensure that the line is visible. m_scintilla->ScrollToLine(line); } + +void CodeDisplay::OnEmbedImageSelected(Node* node) +{ + if (node->hasValue(prop_bitmap)) + { + auto func_name = ProjectImages.GetBundleFuncName(node->as_string(prop_bitmap)); + if (func_name.size()) + { + if (func_name.starts_with("wxue_img::")) + func_name.erase(0, sizeof("wxue_img::") - 1); + if (auto pos = func_name.find("("); pos != tt::npos) + func_name.erase(pos, tt::npos); + + if (auto line = (to_int) m_view.FindLineContaining(func_name); line >= 0) + { + m_scintilla->MarkerDeleteAll(node_marker); + m_scintilla->MarkerAdd(line, node_marker); + m_scintilla->ScrollToLine(line); + return; + } + + // For icons, there is no bundle, just an image_ function + func_name.Replace("bundle_", "image_"); + if (auto line = (to_int) m_view.FindLineContaining(func_name); line >= 0) + { + m_scintilla->MarkerDeleteAll(node_marker); + m_scintilla->MarkerAdd(line, node_marker); + m_scintilla->ScrollToLine(line); + return; + } + + // If all else fails, try just the name. This will also handle Python and Ruby panels + func_name.Replace("image_", ""); + if (auto line = (to_int) m_view.FindLineContaining(func_name); line >= 0) + { + m_scintilla->MarkerDeleteAll(node_marker); + m_scintilla->MarkerAdd(line, node_marker); + m_scintilla->ScrollToLine(line); + return; + } + } + } +} diff --git a/src/panels/code_display.h b/src/panels/code_display.h index 3c0f879cc..2ddef1433 100644 --- a/src/panels/code_display.h +++ b/src/panels/code_display.h @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // Purpose: Display code in scintilla control // Author: Ralph Walden -// Copyright: Copyright (c) 2020-2021 KeyWorks Software (Ralph Walden) +// Copyright: Copyright (c) 2020-2024 KeyWorks Software (Ralph Walden) // License: Apache License -- see ../../LICENSE ///////////////////////////////////////////////////////////////////////////// @@ -16,10 +16,11 @@ class wxFindDialogEvent; class Node; -// CodeDisplayBase creates and initializes a wxStyledTextCtrl (scintilla) control, and places it in a sizer. -// -// WriteCode expects a class to override the doWrite() method, which in this case sends the text to the scinitilla control -// created by CodeDisplayBase. +// CodeDisplayBase creates and initializes a wxStyledTextCtrl (scintilla) control, and places +// it in a sizer. + +// WriteCode expects a class to override the doWrite() method, which in this case sends the +// text to the scinitilla control created by CodeDisplayBase. class CodeDisplay : public CodeDisplayBase, public WriteCode { @@ -38,9 +39,10 @@ class CodeDisplay : public CodeDisplayBase, public WriteCode wxStyledTextCtrl* GetTextCtrl() { return m_scintilla; }; protected: + void OnEmbedImageSelected(Node* node); void OnFind(wxFindDialogEvent& event); - // The following two functions are required to inherit from WriteCode + // The following function is required to inherit from WriteCode void doWrite(tt_string_view code) override; From 28d4c5bb6a312e2a55df4c03c1e74501213ba121 Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Sun, 14 Jan 2024 18:52:29 -0800 Subject: [PATCH 2/2] Correctly select ribbon tools and buttons For Ribbon tools, this avoids selecting a wxToolBar tool by mistake if there is one in the same form with the same artwork. --- src/panels/code_display.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/panels/code_display.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/panels/code_display.cpp b/src/panels/code_display.cpp index 5a47c604e..ba6f58eee 100644 --- a/src/panels/code_display.cpp +++ b/src/panels/code_display.cpp @@ -601,6 +601,11 @@ void CodeDisplay::OnNodeSelected(Node* node) OnEmbedImageSelected(node); return; } + else if (node->isGen(gen_ribbonTool) || node->isGen(gen_ribbonButton)) + { + OnRibbonToolSelected(node); + return; + } if (!node->hasProp(prop_var_name) && m_panel_type != GEN_LANG_XRC && !node->isGen(gen_ribbonTool) && !node->isGen(gen_ribbonButton)) @@ -745,6 +750,37 @@ void CodeDisplay::OnNodeSelected(Node* node) m_scintilla->ScrollToLine(line); } +void CodeDisplay::OnRibbonToolSelected(Node* node) +{ + tt_string search; + if (auto parent = node->getParent(); parent) + { + if (parent->isGen(gen_wxRibbonButtonBar)) + { + search << '"' << node->as_string(prop_label) << '"'; + } + else if (parent->isGen(gen_wxRibbonToolBar)) + { + search << parent->as_string(prop_var_name) << "->AddTool(" << node->as_string(prop_id) << ","; + if (m_panel_type == GEN_LANG_PYTHON) + search.Replace("->", "."); + else if (m_panel_type == GEN_LANG_RUBY) + search.Replace("->AddTool(", ".add_tool($"); + } + } + + if (search.size()) + { + if (auto line = (to_int) m_view.FindLineContaining(search); line >= 0) + { + m_scintilla->MarkerDeleteAll(node_marker); + m_scintilla->MarkerAdd(line, node_marker); + m_scintilla->ScrollToLine(line); + } + return; + } +} + void CodeDisplay::OnEmbedImageSelected(Node* node) { if (node->hasValue(prop_bitmap)) diff --git a/src/panels/code_display.h b/src/panels/code_display.h index 2ddef1433..8298b74b9 100644 --- a/src/panels/code_display.h +++ b/src/panels/code_display.h @@ -39,6 +39,7 @@ class CodeDisplay : public CodeDisplayBase, public WriteCode wxStyledTextCtrl* GetTextCtrl() { return m_scintilla; }; protected: + void OnRibbonToolSelected(Node* node); void OnEmbedImageSelected(Node* node); void OnFind(wxFindDialogEvent& event);