Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow webview panels to provide a custom icon #48864

Closed
mjbvz opened this issue Apr 27, 2018 · 8 comments · Fixed by #54912
Closed

Allow webview panels to provide a custom icon #48864

mjbvz opened this issue Apr 27, 2018 · 8 comments · Fixed by #54912
Assignees
Labels
api-proposal feature-request Request for new features or functionality on-testplan webview Webview issues
Milestone

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 27, 2018

Allow webview panels to set an icon. This should probably be done declaratively in the package.json, something like:

"contributes": {
    "webviews": [
      {
        "viewType": "markdown.preview",
        "icon": {
          "light": "./media/Preview.svg",
          "dark": "./media/Preview_inverse.svg"
        }
      }
    ]
  
}

/cc @jrieken

@mjbvz mjbvz added feature-request Request for new features or functionality webview Webview issues labels Apr 27, 2018
@mjbvz mjbvz self-assigned this Apr 27, 2018
@mjbvz mjbvz changed the title Allow webview panels to provide an custom icon Allow webview panels to provide a custom icon Apr 27, 2018
@eamodio
Copy link
Contributor

eamodio commented Apr 28, 2018

@mjbvz Since the title is provided dynamically in code, why not provide the icon there as well?

@jrieken
Copy link
Member

jrieken commented Apr 30, 2018

Yeah, it's little weird to now start mixing declarative and symbolic information... @mjbvz why isn't this a property like the title?

@mjbvz
Copy link
Collaborator Author

mjbvz commented Apr 30, 2018

The declarative approach has a few advantages:

  1. Makes it clearer that you need per theme icons
  2. We always know where to get the icon resource file from
  3. We don't have to save the old icon or old icon path when restoring a webview after vscode restarts (if an icons path changes, such as during an extension update, we also would handle the change properly)

mjbvz added a commit to mjbvz/vscode that referenced this issue May 11, 2018
Fixes microsoft#48864

Adds a new top level `webview` contribution point. Use this new contribution point to contribute the declarative part of a webviews, such as icons
mjbvz added a commit to mjbvz/vscode that referenced this issue May 11, 2018
Fixes microsoft#48864

Adds a new top level `webview` contribution point. Use this new contribution point to contribute the declarative part of a webviews, such as icons
@mjbvz mjbvz added this to the May 2018 milestone May 14, 2018
@jrieken
Copy link
Member

jrieken commented May 17, 2018

Discussion ended in agreeing to disagree. There is the declarative vs in-code approach, arguments for the declarative are listed above, concerns against it are: (1) it uses package.json/contributes in a new way, not describing parts of the UI before loading code, but augmenting parts of the UI after loading & executing code. (2) it won't be possible to use a ThemeIcon or dynamic icons, (3) it feels asymmetric to provide properties like title et al in code but icon not. Last, the icon challenge (caching, fetching, transmitting) is something we already have today (activity bar icons, decorations with icons, tree items) and something we need to solve anyways.

@eamodio
Copy link
Contributor

eamodio commented May 17, 2018

Probably not the best idea (because of the extra work, etc), but maybe support both? Support the declarative as spec'd above, which will be the default unless overridden in-code, where more features (ThemeIcon, dynamically changing) can be used. Maybe even add title to the declarative syntax for the same, so they are symmetric?

@mjbvz
Copy link
Collaborator Author

mjbvz commented May 25, 2018

I still think a static contribution is the correct design.

  1. The icon is used before code is loaded, for example after restarting vscode and a webview is first restored.

  2. I don't think we want dynamic icons. I'm also not sure ThemeIcon is a good fit for webviews, at least how ThemeIcon is being used currently. Rather, to support themable icons, we could add a top level "webviews" entry to the file theme json, something like:

"webviews": {
      "markdown.preview": "_markdown_preview"
}

In fact, I believe that this would be required even if we did use ThemeIcon for the webviews icons.

  1. The proposed package.json contribution is for a webview type: markdown preview, azure explorer, gitlens, and so on. The title and webview content on the other hand are instance properties on the panel itself. I believe the icon should be the same for all instances of a webview type, as this is consistent with how we display other "editor" types.

Two follow up ideas:

  • Change the contribution point to webviewIcons to make it very clear what the intended use case of it is

  • Move the contribution into themeIcons:

{
  "contributes": {
      "themeIcons": [
          {
              // no label or id, just always apply these icons but allow other icons themes to override them
               "path": "./icons/my-webview-icon-theme.json"
          }
      ]  
  }
}

with my-webview-icon-theme.json being something like:

{
  "iconDefinitions": {
     "_markdown_preview": { "iconPath": "..." }
  },
   "webviewPanels": {
        "markdown.preview": "_markdown.preview"
    }
}

/cc @sandy081

@sandy081
Copy link
Member

I agree that web-view icon contribution is not a good fit into views contribution point. Moving it out makes sense to me. I would wait for @jrieken 's opinion about static vs dynamic.

@mjbvz mjbvz modified the milestones: May 2018, June 2018 May 25, 2018
@mjbvz mjbvz modified the milestones: June 2018, July 2018 Jun 21, 2018
@eamodio
Copy link
Contributor

eamodio commented Jul 18, 2018

Any update on this?

mjbvz added a commit to mjbvz/vscode that referenced this issue Jul 23, 2018
Allows webviews to provide icons used in UI. Adds a new `WebviewPanel.iconPath` property for this.

Replaces the static contribution approach from microsoft#49657

Fixes microsoft#48864
mjbvz added a commit that referenced this issue Jul 24, 2018
* Add WebviewPanel.iconPath

Allows webviews to provide icons used in UI. Adds a new `WebviewPanel.iconPath` property for this.

Replaces the static contribution approach from #49657

Fixes #48864

* Fix doc

* Move icon into mainthreadwebview

* Cleaning up implementation

* Cleaning up implementation
@mjbvz mjbvz mentioned this issue Jul 27, 2018
3 tasks
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.