Skip to content

UI IVIB integration - #287

Draft
jschnet wants to merge 16 commits into
uniconproject:masterfrom
jschnet:uivib
Draft

jschnet wants to merge 16 commits into
uniconproject:masterfrom
jschnet:uivib

Conversation

@jschnet

@jschnet jschnet commented Nov 7, 2022 •

Copy link
Copy Markdown
Contributor

This PR integrates IVIB into Unicon ide as one unified tool.

@Jafaral

Jafaral commented Oct 30, 2026

Copy link
Copy Markdown
Member

@greptile review

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect IVIB users and the IDE’s file-save workflow.

The PR should not merge while an untrusted layout can still close the IDE and lose unsaved work.

Findings

  1. P1 Security Layout comments close the IDE ▶
Fix with agent prompt
### Issue 1
uni/ide/ivibtab.icn:1026-1028
Opening an untrusted source file while Files/IVIB is shown can close the IDE without asking about unsaved work. A layout containing `### Ivib-v2 layout ##` followed by `#class|exit|` reaches `lang::decode()`. Its `Decode.decode_class()` resolves `exit` and calls it with no arguments before the `Canvas` check runs.

Use a decoder that allows only the expected layout classes and rejects other names before calling them.

**How this was verified:** Layout comments reach a decoder that calls the named procedure, and `exit()` defaults to closing the process successfully.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Integrates IVIB into the IDE beside the source editor.

  • The IDE shows IVIB beside the editor and keeps a canvas for each tab.
  • Generated UI code becomes one undoable edit in the editor.
  • Saving an editor tab includes its pending IVIB layout.
  • Closing the last file leaves a fresh IDE tab.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Tab[Source tab] --> Layout[Read saved layout]
  Layout --> Canvas[Per-tab canvas]
  Canvas --> Generate[Generate code]
  Generate --> Editor[Undoable editor change]
  Editor --> Save[Save source file]
  Editor --> Undo[Undo or redo]
  Undo --> Reload[Rebuild or drop cached canvas]
  Reload --> Canvas
Loading

Reviews (8) · Last reviewed commit: "ide: stop a layout comment from calling ..." · Reviewed by Greptile

Comment thread uni/ide/ide.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ide.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
jschnet and others added 14 commits October 30, 2026 00:05
The integration commits reformatted ~100 ivib and gui files (trailing
whitespace, tab/space changes, file modes) without changing them.
Restore those files to master and keep only the functional hunks, so
the series is reviewable. Also drop the committed xpmtoims binary and
the unused bigsave/medsave icons, and revert the stray
'package ivib' in canvastablecolumn.icn, which renamed the class and
broke loading of layouts containing tables.

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
The integration made the canvas reach its owner through self.parent
instead of self.parent_dialog, but left several paths broken:

- gui: revert the hooks added to Dialog.resize_win/handle_resize; they
  referenced ui's uidlog from the generic GUI library (a runtime error
  in any other program) and the tooltip padding change.  ui now
  handles this itself.
- ivib/main: revert the layout hacks that hid standalone ivib's menu
  bar and clipped its tool bar, and the half-done "Unicon IDE"
  (Ctrl-i) menu item whose handler did not exist.  Set the canvas
  parent when a file is loaded from the command line; standalone ivib
  crashed on start with a file argument.
- The component dialogs read parent_dialog.last_icon_dir, which is
  the IDE dialog when embedded: a runtime error on Browse.  Use parent.
- Canvas: keep the temporary window size positive while the canvas is
  positioned outside the dialog; only retitle the window, and only use
  the CommonDialog attribs, when standalone (the IDE's title became
  "Ivib"); restore dup()'s copy of parent_dialog.

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
Fix the crashes and data-loss cases in the Files/IVIB integration:

- Edit > Undo/Redo in the editor were also connected to ivib's undo
  and crashed with an empty undo list; the ivib undo/redo menu items
  were locals shadowing the fields, and their shading tests were
  inverted.  Ivib undo/redo now fail cleanly when empty.
- on_save_btn used || (string concatenation) instead of |, a runtime
  error once a canvas was new and unmodified.
- Saving any file ran ivib's code generation on it, writing to disk
  behind the editor (output_code() overwrote new files with a
  skeleton); it also crashed through ivib/code.icn's unset global
  ivib_maindialog.
- Load errors returned a TextList instead of failing, so the caller
  used it as a canvas; error messages were passed to set_contents()
  as strings.
- Ctrl-key handlers (dead in a Component) called op_open_file() with
  no file and referenced undefined undo/redo fields.
- Every tab switch reloaded the canvas from disk, discarding layout
  changes and asking to append a layout even while the panel was
  hidden; declining once disabled loading for all files.
- The tool bar wrapped only once, pushing "Generate UI Code" off
  screen, and the new toolbar button overlapped the search toggle.
- Popup menus opened away from the pointer.

How the panel works now:

- Each editor tab has its own canvas and undo history, loaded from the
  layout at the end of that tab's buffer when the Files/IVIB view is
  shown, and kept when switching tabs.
- "Generate UI Code" writes the code and layout into the editor
  buffer (appending a dialog class if there is none) instead of the
  file on disk.  Modifying the layout marks the tab modified; saving
  it generates the pending changes first.
- The Canvas/Selection/Objects menus are built in Mainbar.IvibMenus()
  from the panel's object list, and are shaded unless the panel is
  shown.
- File > Ivib launches standalone ivib as before.
- The Makefile relinks ui when the ivib ucode it links changes.

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
Comment thread uni/ide/ide.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
@github-actions github-actions Bot added the gui label Oct 31, 2026
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Comment thread uni/ide/ivibtab.icn Resolved
Closing the IDE and choosing Save replaced the last tab with Untitled,
so the exit loop never finished.  A save also ignored a failed generate,
skipped canvases stored while the panel was hidden, and treated any
setup() method as an IVIB dialog.  Scratch files were created in a
shared temp directory.

Stop replacing tabs while exiting, and leave the tab open when saving
fails.  Generate a stored canvas before writing its buffer, and rewrite
a file only when it already has an IVIB layout marker.  Save All selects
each modified tab first, so the write and any pending layout use that
tab's buffer.  Save As keeps the modified mark unless generation and the
write both succeed.  Record the generated text as an editor undo step,
so earlier source edits remain.  Put scratch files in a private 0700
directory and remember its absolute path, so a later chdir still finds
it.  Wrap the toolbar so the icons fit in half of a 1024-wide IDE window.

Arrow keys reached the canvas even when the editor had them, and any
other keystroke cleared a run of arrow moves.  Forward keys to the canvas
only while it has the keyboard.  A later generate rewrote every class
before the first setup() and dropped source after the layout encoding.
Rewrite only the dialog class, and keep the rest of the buffer.

Counting initially as its own block left the class open, because the
class end closes the initializer too, so the next generation appended
a second dialog.  Joining the saved encoding stripped trailing spaces,
but the encoder splits inside field names that contain spaces, so
reopening a layout could change a label.  Do not count initially, and
keep every character of an encoded line except a trailing carriage
return.

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
Comment thread uni/ide/ivibtab.icn Outdated
Comment on lines +1026 to +1028
c := lang::decode(t) | return alert_error("Invalid ivib layout")

instanceof(c, "Canvas") | return alert_error("Invalid ivib layout")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Layout comments close the IDE

Opening an untrusted source file while Files/IVIB is shown can close the IDE without asking about unsaved work. A layout containing ### Ivib-v2 layout ## followed by #class|exit| reaches lang::decode(). Its Decode.decode_class() resolves exit and calls it with no arguments before the Canvas check runs.

Use a decoder that allows only the expected layout classes and rejects other names before calling them.

How this was verified: Layout comments reach a decoder that calls the named procedure, and exit() defaults to closing the process successfully.

Prompt To Fix With AI
This is a comment left during a code review.
Path: uni/ide/ivibtab.icn
Line: 1026-1028

Comment:
**Layout comments close the IDE**

Opening an untrusted source file while Files/IVIB is shown can close the IDE without asking about unsaved work. A layout containing `### Ivib-v2 layout ##` followed by `#class|exit|` reaches `lang::decode()`. Its `Decode.decode_class()` resolves `exit` and calls it with no arguments before the `Canvas` check runs.

Use a decoder that allows only the expected layout classes and rejects other names before calling them.

**How this was verified:** Layout comments reach a decoder that calls the named procedure, and `exit()` defaults to closing the process successfully.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread uni/ide/ivibtab.icn Resolved
lang::decode() called whatever procedure a layout named, so a comment
of the form class|exit| closed the IDE while opening a file, a
component, or the config.  Decode those with an allowlist of the
classes a real layout contains, and never call a builtin.

Undoing a generate restored the source and left the new controls on
the canvas, so the next save wrote them back.  Undo and redo of that
step rebuild the canvas from the restored text, and drop a canvas
cached for another tab.

Signed-off-by: Jafar Al-Gharaibeh <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants