Skip to content

Commit

Permalink
Merge pull request #1380 from KeyWorksRW/selection
Browse files Browse the repository at this point in the history
Improve node selection handling in language panels
  • Loading branch information
Randalphwa authored Jan 15, 2024
2 parents 0da74ba + 28d4c5b commit 23fcaa8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 7 deletions.
89 changes: 88 additions & 1 deletion src/panels/code_display.cpp
Original file line number Diff line number Diff line change
@@ -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
/////////////////////////////////////////////////////////////////////////////

Expand All @@ -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
Expand Down Expand Up @@ -594,6 +596,17 @@ void CodeDisplay::CodeGenerationComplete()

void CodeDisplay::OnNodeSelected(Node* node)
{
if (node->isGen(gen_embedded_image))
{
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))
{
Expand Down Expand Up @@ -736,3 +749,77 @@ void CodeDisplay::OnNodeSelected(Node* node)
// Unlike GetLineVisible(), this function does ensure that the line is visible.
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))
{
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;
}
}
}
}
15 changes: 9 additions & 6 deletions src/panels/code_display.h
Original file line number Diff line number Diff line change
@@ -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
/////////////////////////////////////////////////////////////////////////////

Expand All @@ -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
{
Expand All @@ -38,9 +39,11 @@ class CodeDisplay : public CodeDisplayBase, public WriteCode
wxStyledTextCtrl* GetTextCtrl() { return m_scintilla; };

protected:
void OnRibbonToolSelected(Node* node);
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;

Expand Down

0 comments on commit 23fcaa8

Please # to comment.