Skip to content

Commit

Permalink
add search field to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Oct 1, 2023
1 parent c7e810a commit c011387
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
46 changes: 46 additions & 0 deletions javascript/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let settingsExcludeTabsFromShowAll = {
settings_tab_defaults: 1,
settings_tab_sysinfo: 1,
settings_tab_actions: 1,
settings_tab_licenses: 1,
};

function settingsShowAllTabs() {
gradioApp().querySelectorAll('#settings > div').forEach(function(elem) {
if (settingsExcludeTabsFromShowAll[elem.id]) return;

elem.style.display = "block";
});
}

function settingsShowOneTab() {
gradioApp().querySelector('#settings_show_one_page').click();
}

onUiLoaded(function() {
var edit = gradioApp().querySelector('#settings_search');
var editTextarea = gradioApp().querySelector('#settings_search > label > input');
var buttonShowAllPages = gradioApp().getElementById('settings_show_all_pages');
var settings_tabs = gradioApp().querySelector('#settings div');

onEdit('settingsSearch', editTextarea, 250, function() {
var searchText = (editTextarea.value || "").trim();

gradioApp().querySelectorAll('#settings > div[id^=settings_] div[id^=column_settings_] > *').forEach(function(elem) {
var visible = elem.textContent.trim().indexOf(searchText) != -1;
elem.style.display = visible ? "" : "none";
});

if (searchText != "") {
settingsShowAllTabs();
} else {
settingsShowOneTab();
}
});

settings_tabs.insertBefore(edit, settings_tabs.firstChild);
settings_tabs.appendChild(buttonShowAllPages);


buttonShowAllPages.addEventListener("click", settingsShowAllTabs);
});
2 changes: 1 addition & 1 deletion javascript/token-counters.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function setupTokenCounting(id, id_counter, id_button) {
prompt.parentElement.insertBefore(counter, prompt);
prompt.parentElement.style.position = "relative";

func = onEdit(id, textarea, 800, function() {
var func = onEdit(id, textarea, 800, function() {
gradioApp().getElementById(id_button)?.click();
});
promptTokenCountUpdateFunctions[id] = func;
Expand Down
15 changes: 0 additions & 15 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,6 @@ onAfterUiUpdate(function() {
json_elem.parentElement.style.display = "none";

setupTokenCounters();

var show_all_pages = gradioApp().getElementById('settings_show_all_pages');
var settings_tabs = gradioApp().querySelector('#settings div');
if (show_all_pages && settings_tabs) {
settings_tabs.appendChild(show_all_pages);
show_all_pages.onclick = function() {
gradioApp().querySelectorAll('#settings > div').forEach(function(elem) {
if (elem.id == "settings_tab_licenses") {
return;
}

elem.style.display = "block";
});
};
}
});

onOptionsChanged(function() {
Expand Down
16 changes: 14 additions & 2 deletions modules/ui_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class UiSettings:
quicksettings_list = None
quicksettings_names = None
text_settings = None
show_all_pages = None
show_one_page = None
search_input = None

def run_settings(self, *args):
changed = []
Expand Down Expand Up @@ -136,7 +139,7 @@ def create_ui(self, loadsave, dummy_component):
gr.Group()
current_tab = gr.TabItem(elem_id=f"settings_{elem_id}", label=text)
current_tab.__enter__()
current_row = gr.Column(variant='compact')
current_row = gr.Column(elem_id=f"column_settings_{elem_id}", variant='compact')
current_row.__enter__()

previous_section = item.section
Expand Down Expand Up @@ -183,7 +186,11 @@ def create_ui(self, loadsave, dummy_component):
with gr.TabItem("Licenses", id="licenses", elem_id="settings_tab_licenses"):
gr.HTML(shared.html("licenses.html"), elem_id="licenses")

gr.Button(value="Show all pages", elem_id="settings_show_all_pages")
self.show_all_pages = gr.Button(value="Show all pages", elem_id="settings_show_all_pages")
self.show_one_page = gr.Button(value="Show only one page", elem_id="settings_show_one_page", visible=False)
self.show_one_page.click(lambda: None)

self.search_input = gr.Textbox(value="", elem_id="settings_search", max_lines=1, placeholder="Search...", show_label=False)

self.text_settings = gr.Textbox(elem_id="settings_json", value=lambda: opts.dumpjson(), visible=False)

Expand Down Expand Up @@ -313,3 +320,8 @@ def get_settings_values():
outputs=[self.component_dict[k] for k in component_keys],
queue=False,
)

def search(self, text):
print(text)

return [gr.update(visible=text in (comp.label or "")) for comp in self.components]
2 changes: 2 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ div#extras_scale_to_tab div.form{
#settings > div{
border: none;
margin-left: 10em;
padding: 0 var(--spacing-xl);
}

#settings > div.tab-nav{
Expand All @@ -437,6 +438,7 @@ div#extras_scale_to_tab div.form{
border: none;
text-align: left;
white-space: initial;
padding: 4px;
}

#settings_result{
Expand Down

0 comments on commit c011387

Please sign in to comment.