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

feature: Implement Search Settings Ability #416

Merged
merged 16 commits into from Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/settings-view/lib/rich-title.js
@@ -0,0 +1,12 @@
const _ = require("underscore-plus")

module.exports = {
getSettingTitle (keyPath, name) {
if (name == null) {
name = ''
}
const schema = atom.config.getSchema(keyPath)
const title = schema != null ? schema.title : null
return title || _.uncamelcase(name).split('.').map(_.capitalize).join(' ')
}
}
104 changes: 104 additions & 0 deletions packages/settings-view/lib/search-setting-view.js
@@ -0,0 +1,104 @@
/** @babel */
/** @jsx etch.dom */

import etch from 'etch'
import { shell } from 'electron'
import { Disposable, CompositeDisposable } from 'atom'
import { getSettingTitle } from './rich-title'

export default class SearchSettingView {
constructor(setting, settingsView) {
this.settingsView = settingsView
this.setting = setting
this.disposables = new CompositeDisposable()

etch.initialize(this)

this.handleButtonEvents()
}

render () {
const title = this.setting.title ?? getSettingTitle(this.setting.path, this.setting.path.split(".")[1]);
const path = atom.config.get("settings-view.searchSettingsMetadata") ? this.setting.path + ": " : "";
const description = this.setting.description ?? "";
const packageName = this.setting.path.split(".")[0];
const icon = this.getIcon(packageName);
const score = atom.config.get("settings-view.searchSettingsMetadata") ? this.setting.rank.totalScore.toFixed(2) + " Search Score" : "";

return (
<div className='search-result col-lg-8'>
<span className='search-package-name pull-right'>
<span className={icon}></span>
{packageName}
</span>
<div className='body'>
<h4 className='card-name'>
<a ref='settingLink'>
<span className='search-name'>{title}</span>
<span className='search-id'>{path}{score}</span>
</a>
</h4>
<span className='search-description'>{description}</span>

</div>

</div>
)
}

update () {}

destroy () {
this.disposables.dispose()
return etch.destroy(this)
}

getIcon(namespace) {
// Takes a setting namespace and returns the appropriate icon for it.
switch(namespace) {
case "core":
return "icon icon-settings search-result-icon";
break;
case "editor":
return "icon icon-code search-result-icon";
break;
default:
return "icon icon-package search-result-icon";
break;
}
}

handleButtonEvents () {
const settingsClickHandler = (event) => {
event.stopPropagation()

// Lets check if the setting we want to open is built in or from a package
const settingLocation = this.setting.path.split(".")[0]
// The above is the location where the setting exists, such as Core, or a packages name

switch(settingLocation) {
case "core":
// There are some special cases of settings broken off into other panels
let settingName = this.setting.path.split(".")[1]
if (settingName === 'uriHandlerRegistration') {
// the URI handler doesn't have any registered uri to actually reach it
// funnily enough. So we will prompt a notification to go there
atom.notifications.addInfo("Sorry, Pulsar is unable to link to this setting. Please select 'URI Handling' on the sidebar.")
} else {
atom.workspace.open("atom://config/core")
}
break;
case "editor":
atom.workspace.open("atom://config/editor")
break;
default:
// The handling for any packages name
atom.workspace.open(`atom://config/packages/${settingLocation}`)
Copy link
Contributor

@icecream17 icecream17 Mar 8, 2023

Choose a reason for hiding this comment

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

is there a difference between builtin packages and installed packages that makes installed packages not work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Surprisingly the URI for the settings page of all packages is exactly the same. Made sure this functioned for either the core packages or community packages.

Only thing not explicitly tested for is Git installed packages, but I'd imagine they should work as well, especially since the settings-view showPackage() function is written identically.

But of course anyone with Git installed packages on their system could double check by navigating to this URI format in the browser and letting it open up Pulsar

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I've been using the package-settings package for ages in order to jump quickly to a given package's settings, and this is the exact method that package uses. Never observed it not to work, no matter how a package is installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I got confused, that's relieving. I think for clarity, the packages caveat means:

  • Does not search for the names of any packages

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I got confused, that's relieving. I think for clarity, the packages caveat means:

  • Does not search for the names of any packages

Ahh I see how that can be confusing. Yeah just means it's not the search that's available on the "Packages" pane, as in it won't accomplish the same thing.

(Although technically you could search by package name to help bring your package up, but it will only show results for packages that have settings. As the name of the package is considered when doing a search. But this makes the whole thing a little confusing, so though it was easier to say it doesn't search for packages)

break;
}
}

this.refs.settingLink.addEventListener('click', settingsClickHandler)
this.disposables.add(new Disposable(() => { this.refs.settingLink.removeEventListener('click', settingsClickHandler) }))
}
}