Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Adds a context-sensitive menu item to import stock variables when right-clicking on a Godley icon, enabling users to quickly import matching columns from other Godley tables.

Changes

  • Menu item placement: Added "Import stock variables" between "Copy stock variables" and "Export as" in the Godley icon context menu
  • Coordinate transformation: Transforms canvas coordinates to Godley-local coordinates to determine the column at the click position
  • Direct submenu building: Builds submenu directly from godley.editor.matchingTableColumnsByCol() with items that call godley.editor.importStockVarByCol()
  • Dynamic enablement: Menu item is always present but disabled when there are no matching import options available

Implementation

// Build stock import menu for this column
const stockImportMenuItems=[];
{
  let x=this.x-await godley.x()+0.5*await godley.width();
  let col=await godley.editor.colXZoomed(x);
  let importOptions=await godley.editor.matchingTableColumnsByCol(col);
  for (let v of importOptions) 
    stockImportMenuItems.push({
      label: v,
      click: (item) => {
        godley.editor.importStockVarByCol(item.label, col);
      },
    });
}

// Menu item with submenu
new MenuItem({
  label: 'Import stock variables',
  enabled: stockImportMenuItems.length>0,
  submenu: Menu.buildFromTemplate(stockImportMenuItems),
})

Notes

Uses godley.editor (GodleyTableEditor) for coordinate calculations and import operations. The coordinate transformation accounts for the Godley icon's position and width to correctly map canvas coordinates to table columns.

Reference: https://sourceforge.net/p/minsky/tickets/1890/

Original prompt

Modify ContextMenuManager to add an "Import stock variables" context-menu item for Godley icons. The item should be enabled only when the mouse is over a stock column header cell, determined from the mouse coordinates via godley.editor helpers. When clicked it must call the existing GodleyMenuManager.importStock helper with the editor and column index.

Files to change:

  • gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts

Required changes (detailed & actionable):

  1. Add an import for GodleyMenuManager at the top of ContextMenuManager.ts:
    import { GodleyMenuManager } from './GodleyMenuManager';

  2. In the private static async buildContextMenuForGodleyIcon(itemInfo: CanvasItem) function, insert logic to determine whether the mouse is over a stock column header and obtain the column index. Use the godley.editor helpers already available on the GodleyIcon wrapper:

    • const editorClickType = await godley.editor.clickTypeZoomed(this.x, this.y);
    • if editorClickType === 'row0' then enabled = true and importCol = await godley.editor.colXZoomed(this.x);
    • If any error occurs, keep the menu item disabled and log the error via electron-log.
  3. Insert a new MenuItem into the menuItems array (near Copy stock variables and Export as items) with:

    • label: 'Import stock variables'
    • enabled: importEnabled
    • click: async () => { if (!importEnabled || importCol===null) return; await GodleyMenuManager.importStock(godley.editor, importCol); }
    • wrap call in try/catch and log failures using log.error
  4. Keep behavior consistent with existing code style and patterns used in ContextMenuManager: use await where necessary, and use this.x / this.y (the canvas coordinates) to determine column. Ensure to not open the Godley popup; reuse GodleyMenuManager.importStock which will present the submenu of matching columns the same way it does elsewhere.

  5. Add small defensive logging: when calculating editorClickType or colXZoomed, catch errors and call log.debug(...) to record inability to determine column.

Notes:

  • GodleyMenuManager.importStock signature in the codebase is: static async importStock(window: GodleyTableWindow, c, event?: IpcMainInvokeEvent)
  • godley.editor is an appropriate object (editor / GodleyTableWindow) that exposes clickTypeZoomed and colXZoomed used elsewhere.
  • Only modify ContextMenuManager.ts.
  • Reference: ticket https://sourceforge.net/p/minsky/tickets/1890/

Include in PR:

  • A clear commit message describing the change and referencing the ticket.
  • One file changed: ContextMenuManager.ts

Please create a PR branch, commit the change, and open the pull request in repository highperformancecoder/minsky. Do not include unrelated changes.

This pull request was created as a result of the following prompt from Copilot chat.

Modify ContextMenuManager to add an "Import stock variables" context-menu item for Godley icons. The item should be enabled only when the mouse is over a stock column header cell, determined from the mouse coordinates via godley.editor helpers. When clicked it must call the existing GodleyMenuManager.importStock helper with the editor and column index.

Files to change:

  • gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts

Required changes (detailed & actionable):

  1. Add an import for GodleyMenuManager at the top of ContextMenuManager.ts:
    import { GodleyMenuManager } from './GodleyMenuManager';

  2. In the private static async buildContextMenuForGodleyIcon(itemInfo: CanvasItem) function, insert logic to determine whether the mouse is over a stock column header and obtain the column index. Use the godley.editor helpers already available on the GodleyIcon wrapper:

    • const editorClickType = await godley.editor.clickTypeZoomed(this.x, this.y);
    • if editorClickType === 'row0' then enabled = true and importCol = await godley.editor.colXZoomed(this.x);
    • If any error occurs, keep the menu item disabled and log the error via electron-log.
  3. Insert a new MenuItem into the menuItems array (near Copy stock variables and Export as items) with:

    • label: 'Import stock variables'
    • enabled: importEnabled
    • click: async () => { if (!importEnabled || importCol===null) return; await GodleyMenuManager.importStock(godley.editor, importCol); }
    • wrap call in try/catch and log failures using log.error
  4. Keep behavior consistent with existing code style and patterns used in ContextMenuManager: use await where necessary, and use this.x / this.y (the canvas coordinates) to determine column. Ensure to not open the Godley popup; reuse GodleyMenuManager.importStock which will present the submenu of matching columns the same way it does elsewhere.

  5. Add small defensive logging: when calculating editorClickType or colXZoomed, catch errors and call log.debug(...) to record inability to determine column.

Notes:

  • GodleyMenuManager.importStock signature in the codebase is: static async importStock(window: GodleyTableWindow, c, event?: IpcMainInvokeEvent)
  • godley.editor is an appropriate object (editor / GodleyTableWindow) that exposes clickTypeZoomed and colXZoomed used elsewhere.
  • Only modify ContextMenuManager.ts.
  • Reference: ticket https://sourceforge.net/p/minsky/tickets/1890/

Include in PR:

  • A clear commit message describing the change and referencing the ticket.
  • One file changed: ContextMenuManager.ts

Please create a PR branch, commit the change, and open the pull request in repository highperformancecoder/minsky. Do not include unrelated changes.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added "Import stock variables" submenu to Godley context menus, enabling column-specific stock variable imports when available.
  • Style

    • Removed pulldown indicator symbols from Godley table header.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Two distinct enhancements across the application stack: the UI layer now provides a dynamic stock variable import submenu in Godley table context menus based on column calculations, while the rendering layer disables pulldown indicator symbols and associated width accounting in table headers.

Changes

Cohort / File(s) Summary
Stock Import Submenu
gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts
Added import of GodleyMenuManager; introduced dynamic "Import stock variables" submenu in Godley context menus calculated from node position and width; each submenu item wires to importStockVarByCol with corresponding column index
Pulldown Indicator Removal
model/godleyTableWindow.cc
Disabled rendering of pulldown indicator (▼ symbol) in table headers via code comments; removed width offset calculation (pulldownHot) from column width computation

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as ContextMenuManager
    participant Calc as Column Calculator
    participant Menu as Menu Builder
    participant Handler as Stock Import Handler

    User->>UI: Right-click on Godley table
    UI->>Calc: Compute columns from node position & width
    Calc->>Calc: Filter matching columns
    Calc-->>UI: Return column list
    
    UI->>Menu: Build submenu items
    Note over Menu: Create item per column<br/>if list non-empty
    Menu-->>UI: Stock import submenu
    
    UI->>UI: Enable submenu if items exist
    UI-->>User: Display context menu
    
    User->>Handler: Click submenu item
    Handler->>Handler: importStockVarByCol(columnIndex)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • ContextMenuManager changes involve straightforward menu construction logic with column filtering; review focus on verifying column calculation correctness and menu wiring
  • godleyTableWindow.cc changes are purely cosmetic (rendering removal); verify no unintended layout side effects from removing pulldownHot width offset

Poem

🐰 A submenu springs to life so bright,
Stock variables import with a click—right!
The pulldown symbols fade away,
Cleaner headers greet the day! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Add 'Import stock variables' context menu item for Godley icons" accurately and specifically describes the primary objective of the pull request, which is to introduce a context-sensitive menu item for importing stock variables in Godley icons. The title is clear, concise, and directly reflects the main feature addition visible in ContextMenuManager.ts. While the changeset also includes modifications to godleyTableWindow.cc that disable pulldown indicator rendering, the PR's core objective focuses on the menu item feature, and it is reasonable for the title not to enumerate every detail or file change.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits October 27, 2025 03:33
- Added import for GodleyMenuManager
- Detect if mouse is over stock column header (row0) using godley.popup.clickTypeZoomed
- Get column index using godley.popup.colXZoomed
- Added "Import stock variables" menu item enabled only when over row0
- Click handler calls GodleyMenuManager.importStock with godley.popup and column
- Added defensive error logging for column detection

Reference: https://sourceforge.net/p/minsky/tickets/1890/

Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
The menu item is already disabled when importEnabled is false, so checking it again in the click handler is redundant.

Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
Keep both importEnabled and importCol checks for logical consistency and defensive programming, even though disabled menu items shouldn't be clickable.

Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
Copilot AI changed the title [WIP] Add 'Import stock variables' context-menu item for Godley icons Add "Import stock variables" context menu item for Godley icons Oct 27, 2025
@highperformancecoder
Copy link
Owner

@CodeRabbit review

@highperformancecoder
Copy link
Owner

@copilot review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
model/godleyTableWindow.cc (2)

288-288: Commented code: remove or restore the pulldownHot width accounting.

The commented portion suggests the pulldown indicator width is no longer factored into column width calculations. If the indicator is permanently removed, delete the commented code. If it may be restored, document why it's temporarily disabled.

Apply this diff to clean up:

-            colWidth=max(colWidth,pango.width() /* + (row==0? pulldownHot:0)*/);
+            colWidth=max(colWidth,pango.width());

305-307: Remove commented code for the last column's pulldown rendering.

If the pulldown indicator is permanently removed, delete these commented lines to keep the codebase clean.

Apply this diff:

-//    cairo_move_to(cairo,x-pulldownHot,topTableOffset);
-//    pango.setMarkup("▼");
-//    pango.show();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 294759c and 3fe0c9a.

📒 Files selected for processing (2)
  • gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts (3 hunks)
  • model/godleyTableWindow.cc (3 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeQL
gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts

[notice] 9-9: Unused variable, import, function or class
Unused import GodleyMenuManager.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: copilot
  • GitHub Check: ubuntu-20.04
  • GitHub Check: ubuntu-20.04
  • GitHub Check: ubuntu-20.04
  • GitHub Check: ubuntu-20.04
🔇 Additional comments (2)
gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts (1)

716-720: LGTM with minor suggestion.

The "Import stock variables" menu item is correctly positioned between "Copy stock variables" and "Export as" as specified in the PR objectives. However, the enabled state depends only on stockImportMenuItems.length>0. Once the row0 check is added (see previous comment), this will work correctly.

model/godleyTableWindow.cc (1)

206-211: Remove commented code and clean up line 326; verify colWidgets provides adequate visual feedback for column import feature.

The pulldown indicator (▼) rendering was removed, but this appears to be part of a refactoring where column header interactions now use colWidgets (ButtonWidget objects) instead. These button widgets are actively drawn (line 203) and handle column interactions. However, line 326 contains orphaned cursor positioning code (cairo_move_to(cairo,x-pulldownHot,topTableOffset);) with no rendering—this should be removed as part of the cleanup. The import feature itself remains functional through importStockVar() and importStockVarByCol() functions. Verify that the colWidgets button UI provides sufficient visual indication to users about where to interact for importing stock variables.

import { BrowserWindow, Menu, MenuItem, IpcMainEvent } from 'electron';
import { BookmarkManager } from './BookmarkManager';
import { CommandsManager } from './CommandsManager';
import { GodleyMenuManager } from './GodleyMenuManager';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove unused import.

GodleyMenuManager is imported but never used. The PR description mentions using GodleyMenuManager.importStock(), but the implementation directly calls godley.editor.importStockVarByCol().

Apply this diff if GodleyMenuManager won't be used:

-import { GodleyMenuManager } from './GodleyMenuManager';

Alternatively, if the PR intended to use GodleyMenuManager.importStock(), update the click handlers at lines 666 and 1269 accordingly.

Based on learnings

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { GodleyMenuManager } from './GodleyMenuManager';
🧰 Tools
🪛 GitHub Check: CodeQL

[notice] 9-9: Unused variable, import, function or class
Unused import GodleyMenuManager.

🤖 Prompt for AI Agents
In gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts around
line 9, the GodleyMenuManager import is unused; remove the import line to clean
up unused code (or if you intended to use GodleyMenuManager, replace the direct
calls to godley.editor.importStockVarByCol() at the click handlers around lines
666 and 1269 with calls to GodleyMenuManager.importStock(...) and adjust
parameters accordingly so the manager is actually used).

Comment on lines +655 to +669
// build stock import menu for this column

const stockImportMenuItems=[];
{
let x=this.x-await godley.x()+0.5*await godley.width();
let col=await godley.editor.colXZoomed(x);
let importOptions=await godley.editor.matchingTableColumnsByCol(col);
for (let v of importOptions)
stockImportMenuItems.push({
label: v,
click: (item) => {
godley.editor.importStockVarByCol(item.label, col);
},
});
}
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing row0 check: menu should only be enabled when clicking on stock column headers.

According to the PR objectives, the "Import stock variables" menu should be "enabled only when right-clicking over a Godley icon's stock column header." The current code builds the import menu for any click location on the GodleyIcon without verifying the user clicked on row0 (the stock variable header row).

Consider checking the click type before building the menu:

     const editorModeChecked = await godley.editorMode();
 
-    // build stock import menu for this column
-
     const stockImportMenuItems=[];
-    {
+    // Only build import menu if clicking on row0 (stock column header)
+    const clickType = await godley.editor.clickTypeZoomed(this.x - await godley.x() + 0.5 * await godley.width(), 
+                                                          this.y - await godley.y() + 0.5 * await godley.height());
+    if (clickType === "row0") {
       let x=this.x-await godley.x()+0.5*await godley.width();
       let col=await godley.editor.colXZoomed(x);
       let importOptions=await godley.editor.matchingTableColumnsByCol(col);
       for (let v of importOptions) 
         stockImportMenuItems.push({
           label: v,
           click: (item) => {
             godley.editor.importStockVarByCol(item.label, col);
           },
         });
     }

This ensures the menu is context-sensitive as intended.

Committable suggestion skipped: line range outside the PR's diff.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practical testing, so long as the import menu item was restricted to columns rather than just row 0, it was fine, since it is a context menu, rather than a right mouse click action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@highperformancecoder, thank you for the clarification and for testing this! I understand now—since this is a context menu for the entire Godley icon (not a row0-specific right-click), restricting the import functionality by column is sufficient and provides the appropriate context-sensitive behavior. Your practical testing confirms this works well.

I appreciate you explaining the distinction between a context menu approach and a right-click action. This makes sense given the overall UI design.


✏️ Learnings added
Learnt from: highperformancecoder
PR: highperformancecoder/minsky#575
File: gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts:654-668
Timestamp: 2025-10-27T05:57:05.870Z
Learning: For Godley icon context menus in `gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts`, the "Import stock variables" menu item is restricted by column (using the clicked x-coordinate to determine the column) rather than being limited to row0 clicks only. This column-based restriction is sufficient for the context menu approach, as confirmed by practical testing.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot review

The implementation looks good! The coordinate transformation and direct submenu building are improvements over my initial approach. A few observations:

Positives:

  • Uses godley.editor as originally specified ✓
  • Coordinate transformation correctly accounts for Godley icon position ✓
  • Direct submenu building is more efficient ✓
  • Always shows menu item (disabled when no options) for better UX ✓

Suggestions for robustness:

  1. Add error handling around the coordinate/column calculations to prevent crashes if calculations fail
  2. The GodleyMenuManager import on line 9 can be removed since it's no longer used
  3. Consider adding defensive logging (log.debug) for error cases as originally specified

The core functionality is solid and the build passes successfully.

@highperformancecoder
Copy link
Owner

@copilot - the calls to colX etc are guaranteed not to throw, which is why I removed the try/catch statements.

….com:highperformancecoder/minsky into copilot/add-import-stock-variables-menu-item
@highperformancecoder highperformancecoder marked this pull request as ready for review October 27, 2025 06:37
Copilot AI review requested due to automatic review settings October 27, 2025 06:37
@highperformancecoder highperformancecoder merged commit 5840cc4 into master Oct 27, 2025
7 checks passed
@highperformancecoder highperformancecoder deleted the copilot/add-import-stock-variables-menu-item branch October 27, 2025 06:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a context menu item "Import stock variables" to Godley icons, enabling users to import matching stock variable columns from other Godley tables. The implementation builds a dynamic submenu based on available import options for the column at the click position.

  • Added "Import stock variables" menu item with dynamic submenu to Godley icon context menu
  • Implemented coordinate transformation to map canvas coordinates to Godley table columns
  • Removed pulldown indicator symbols (▼) from Godley table headers in the C++ rendering code

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts Adds "Import stock variables" menu item with coordinate-to-column mapping and dynamic submenu generation
model/godleyTableWindow.cc Removes pulldown indicator symbols from Godley table header rendering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// build stock import menu for this column

const stockImportMenuItems=[];
{
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coordinate transformation lacks explanation. Add a comment describing why 0.5*width is added (presumably to adjust from icon center to left edge) to clarify the mathematical relationship between canvas and Godley-local coordinates.

Suggested change
{
{
// Convert from canvas coordinates (where this.x is relative to the icon center)
// to Godley-local coordinates (where 0 is the left edge of the icon).
// Adding 0.5*width shifts the origin from the center to the left edge.

Copilot uses AI. Check for mistakes.

// build stock import menu for this column

const stockImportMenuItems=[];
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after '=' operator. Should be 'const stockImportMenuItems = [];' to follow consistent spacing conventions.

Suggested change
const stockImportMenuItems=[];
const stockImportMenuItems = [];

Copilot uses AI. Check for mistakes.
{
let x=this.x-await godley.x()+0.5*await godley.width();
let col=await godley.editor.colXZoomed(x);
let importOptions=await godley.editor.matchingTableColumnsByCol(col);
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around '=' operators. Should be 'let x = ...', 'let col = ...', and 'let importOptions = ...' for consistent code formatting.

Suggested change
let importOptions=await godley.editor.matchingTableColumnsByCol(col);
let importOptions = await godley.editor.matchingTableColumnsByCol(col);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants