Browse Source

frontend-tools: Add context menu to Scripts list

Matt Gajownik 5 years ago
parent
commit
c39aef03fe

+ 1 - 0
UI/frontend-plugins/frontend-tools/data/locale/en-US.ini

@@ -32,6 +32,7 @@ AddScripts="Add Scripts"
 RemoveScripts="Remove Scripts"
 ReloadScripts="Reload Scripts"
 LoadedScripts="Loaded Scripts"
+Reload="Reload"
 PythonSettings="Python Settings"
 PythonSettings.PythonInstallPath32bit="Python Install Path (32bit)"
 PythonSettings.PythonInstallPath64bit="Python Install Path (64bit)"

+ 3 - 0
UI/frontend-plugins/frontend-tools/forms/scripts.ui

@@ -41,6 +41,9 @@
          </item>
          <item>
           <widget class="QListWidget" name="scripts">
+           <property name="contextMenuPolicy">
+            <enum>Qt::CustomContextMenu</enum>
+           </property>
            <property name="sortingEnabled">
             <bool>true</bool>
            </property>

+ 25 - 0
UI/frontend-plugins/frontend-tools/scripts.cpp

@@ -16,6 +16,7 @@
 #include <QResizeEvent>
 #include <QAction>
 #include <QMessageBox>
+#include <QMenu>
 #include <QUrl>
 #include <QDesktopServices>
 
@@ -389,6 +390,30 @@ void ScriptsTool::on_reloadScripts_clicked()
 	on_scripts_currentRowChanged(ui->scripts->currentRow());
 }
 
+void ScriptsTool::on_scripts_customContextMenuRequested(const QPoint &pos)
+{
+
+	QListWidgetItem *item = ui->scripts->itemAt(pos);
+
+	QMenu popup(this);
+
+	obs_frontend_push_ui_translation(obs_module_get_string);
+
+	popup.addAction(tr("Add"), this, SLOT(on_addScripts_clicked()));
+
+	if (item) {
+		popup.addSeparator();
+		popup.addAction(obs_module_text("Reload"), this,
+				SLOT(on_reloadScripts_clicked()));
+		popup.addSeparator();
+		popup.addAction(tr("Remove"), this,
+				SLOT(on_removeScripts_clicked()));
+	}
+	obs_frontend_pop_ui_translation();
+
+	popup.exec(QCursor::pos());
+}
+
 void ScriptsTool::on_scriptLog_clicked()
 {
 	scriptLogWindow->show();

+ 1 - 0
UI/frontend-plugins/frontend-tools/scripts.hpp

@@ -54,4 +54,5 @@ public slots:
 
 private slots:
 	void on_description_linkActivated(const QString &link);
+	void on_scripts_customContextMenuRequested(const QPoint &pos);
 };