提交 07a26b17 编写于 作者: J jp9000

libobs: Add more editable list types

(Note: This commit also modifies the UI)

The editable list only had two types: A type that allows both files and
URLS, and a type that only allows strings.

This changes it so the editable list can have a "files only" type, a
"files and URLs" type, and a "strings only" type.
上级 8d002fb6
......@@ -62,7 +62,7 @@ struct list_data {
};
struct editable_list_data {
bool allow_files;
enum obs_editable_list_type type;
char *filter;
char *default_path;
};
......@@ -503,7 +503,7 @@ obs_property_t *obs_properties_add_font(obs_properties_t *props,
obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
const char *name, const char *desc,
bool allow_files, const char *filter,
enum obs_editable_list_type type, const char *filter,
const char *default_path)
{
if (!props || has_prop(props, name)) return NULL;
......@@ -511,7 +511,7 @@ obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
OBS_PROPERTY_EDITABLE_LIST);
struct editable_list_data *data = get_property_data(p);
data->allow_files = allow_files;
data->type = type;
data->filter = bstrdup(filter);
data->default_path = bstrdup(default_path);
return p;
......@@ -863,11 +863,11 @@ double obs_property_list_item_float(obs_property_t *p, size_t idx)
data->items.array[idx].d : 0.0;
}
bool obs_property_editable_list_allow_files(obs_property_t *p)
enum obs_editable_list_type obs_property_editable_list_type(obs_property_t *p)
{
struct editable_list_data *data = get_type_data(p,
OBS_PROPERTY_EDITABLE_LIST);
return data ? data->allow_files : false;
return data ? data->type : OBS_EDITABLE_LIST_TYPE_STRINGS;
}
const char *obs_property_editable_list_filter(obs_property_t *p)
......
......@@ -70,6 +70,12 @@ enum obs_combo_type {
OBS_COMBO_TYPE_LIST,
};
enum obs_editable_list_type {
OBS_EDITABLE_LIST_TYPE_STRINGS,
OBS_EDITABLE_LIST_TYPE_FILES,
OBS_EDITABLE_LIST_TYPE_FILES_AND_URLS
};
enum obs_path_type {
OBS_PATH_FILE,
OBS_PATH_FILE_SAVE,
......@@ -202,7 +208,7 @@ EXPORT obs_property_t *obs_properties_add_font(obs_properties_t *props,
EXPORT obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
const char *name, const char *description,
bool allow_files, const char *filter,
enum obs_editable_list_type type, const char *filter,
const char *default_path);
EXPORT obs_property_t *obs_properties_add_frame_rate(obs_properties_t *props,
......@@ -281,7 +287,7 @@ EXPORT const char *obs_property_list_item_string(obs_property_t *p, size_t idx);
EXPORT long long obs_property_list_item_int(obs_property_t *p, size_t idx);
EXPORT double obs_property_list_item_float(obs_property_t *p, size_t idx);
EXPORT bool obs_property_editable_list_allow_files(obs_property_t *p);
EXPORT enum obs_editable_list_type obs_property_editable_list_type(obs_property_t *p);
EXPORT const char *obs_property_editable_list_filter(obs_property_t *p);
EXPORT const char *obs_property_editable_list_default_path(obs_property_t *p);
......
......@@ -1765,12 +1765,19 @@ public:
void WidgetInfo::EditListAdd()
{
bool allow_files = obs_property_editable_list_allow_files(property);
if (!allow_files) {
enum obs_editable_list_type type = obs_property_editable_list_type(
property);
if (type == OBS_EDITABLE_LIST_TYPE_STRINGS) {
EditListAddText();
return;
} else if (type == OBS_EDITABLE_LIST_TYPE_FILES) {
EditListAddFiles();
return;
}
/* Files and URLs */
QMenu popup(view->window());
QAction *action;
......@@ -1843,7 +1850,8 @@ void WidgetInfo::EditListRemove()
void WidgetInfo::EditListEdit()
{
QListWidget *list = reinterpret_cast<QListWidget*>(widget);
bool allow_files = obs_property_editable_list_allow_files(property);
enum obs_editable_list_type type = obs_property_editable_list_type(
property);
const char *desc = obs_property_description(property);
const char *filter = obs_property_editable_list_filter(property);
QList<QListWidgetItem*> selectedItems = list->selectedItems();
......@@ -1852,8 +1860,21 @@ void WidgetInfo::EditListEdit()
return;
QListWidgetItem *item = selectedItems[0];
EditableItemDialog dialog(widget->window(), item->text(), allow_files,
filter);
if (type == OBS_EDITABLE_LIST_TYPE_FILES) {
QString path = QFileDialog::getOpenFileName(
App()->GetMainWindow(), QTStr("Browse"),
item->text(), QT_UTF8(filter));
if (path.isEmpty())
return;
item->setText(path);
EditableListChanged();
return;
}
EditableItemDialog dialog(widget->window(), item->text(),
type != OBS_EDITABLE_LIST_TYPE_STRINGS, filter);
auto title = QTStr("Basic.PropertiesWindow.EditEditableListEntry").arg(
QT_UTF8(desc));
dialog.setWindowTitle(title);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册