Skip to content

[API] Add set_name() and name() methods to the base Sheet class #3826

@OdatNurd

Description

@OdatNurd

Problem description

Instances of HTMLSheet don't have a property that allows you to distinguish them from other HTMLSheet instances except for the sheet's id.

This makes finding and reusing an existing sheet problematic; if you lose the reference to the original instance returned by window.new_html_sheet() the only thing you can rely on is the id, but because the sheet id changes across sessions it's not possible in a general sense to be sure you're selecting the correct instance if there is more than one.

In contrast, an ImageSheet responds to file_name() to tell you the filename of the image, and TextSheet instances report their view, from which you can determine the required information.

Preferred solution

If the underlying Sheet class had set_name() and name() methods natively, it would be possible to distinguish and work with sheets in a safer manner; this would be an extension to the existing logic already in place:

  1. TextSheet wraps a View, and View has set_name() and name(), so it could defer these methods directly to it's view with the current logic.
  2. ImageSheet wraps an image and is not generally modifiable via the API. A name() method would allow you to open an image and alter it's display name in the tab; get_name() could report the file_name() if no custom name was set.
  3. HtmlSheet has a set_name() method, but no corresponding name() method, which seems like an oversight.

Alternatives

None that I can think of, except having HTMLSheet instances that are restored from session information keep the same sheet ID they originally had (or maybe do that generically for all restored sheets), but this seems problematic and probably not a good idea.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions