Move LuaProgressDialog into "LuaDialog" namespace
Define class in header file Match C++ and Lua binding namespaces (for documentation)
This commit is contained in:
parent
487503cab8
commit
2d680f3061
|
@ -37,7 +37,7 @@
|
|||
|
||||
using namespace LuaDialog;
|
||||
|
||||
/*******************************************************************************
|
||||
/* *****************************************************************************
|
||||
* Simple Message Dialog
|
||||
*/
|
||||
Message::Message (std::string const& title, std::string const& msg, Message::MessageType mt, Message::ButtonType bt)
|
||||
|
@ -589,9 +589,10 @@ protected:
|
|||
Gtk::FileChooserWidget _fc;
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
/* *****************************************************************************
|
||||
* Lua Parameter Dialog
|
||||
*/
|
||||
|
||||
Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
|
||||
:_ad (title, true, false)
|
||||
, _title (title)
|
||||
|
@ -840,3 +841,49 @@ Dialog::table_size_alloc (Gtk::Allocation& allocation)
|
|||
_ad.set_size_request (-1, 512);
|
||||
}
|
||||
}
|
||||
|
||||
/* *****************************************************************************
|
||||
* Lua Progress Dialog
|
||||
*/
|
||||
|
||||
ProgressWindow::ProgressWindow (std::string const& title, bool allow_cancel)
|
||||
: ArdourDialog (title, true)
|
||||
, _canceled (false)
|
||||
{
|
||||
_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
|
||||
|
||||
set_border_width (12);
|
||||
get_vbox()->set_spacing (6);
|
||||
get_vbox()->pack_start (_bar, false, false);
|
||||
|
||||
if (allow_cancel) {
|
||||
using namespace Gtk;
|
||||
Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
||||
b->signal_clicked().connect (sigc::mem_fun (*this, &ProgressWindow::cancel_clicked));
|
||||
}
|
||||
|
||||
set_default_size (200, -1);
|
||||
show_all ();
|
||||
}
|
||||
|
||||
bool
|
||||
ProgressWindow::progress (float prog, std::string const& text)
|
||||
{
|
||||
if (!text.empty ()) {
|
||||
_bar.set_text (text);
|
||||
}
|
||||
if (prog < 0 || prog > 1) {
|
||||
std::cerr << "pulse\n";
|
||||
_bar.set_pulse_step(.1);
|
||||
_bar.pulse();
|
||||
} else {
|
||||
_bar.set_fraction (prog);
|
||||
}
|
||||
ARDOUR::GUIIdle ();
|
||||
return _canceled;
|
||||
}
|
||||
|
||||
void
|
||||
ProgressWindow::done () {
|
||||
Gtk::Dialog::response(_canceled ? Gtk::RESPONSE_CANCEL : Gtk::RESPONSE_OK);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <cassert>
|
||||
#include <gtkmm/table.h>
|
||||
#include <gtkmm/messagedialog.h>
|
||||
#include <gtkmm/progressbar.h>
|
||||
|
||||
#include "LuaBridge/LuaBridge.h"
|
||||
|
||||
|
@ -98,6 +99,49 @@ private:
|
|||
std::string _title;
|
||||
};
|
||||
|
||||
/** Synchronous GUI-thread Progress dialog
|
||||
*
|
||||
* This shows a modal progress dialog with an optional
|
||||
* "Cancel" button. Since it runs in the UI thread
|
||||
* the script needs to regularly call progress(),
|
||||
* as well as close the dialog, as needed.
|
||||
*/
|
||||
class ProgressWindow : public ArdourDialog
|
||||
{
|
||||
public:
|
||||
/** Create a new progress window.
|
||||
* @param title Window title
|
||||
* @param allow_cancel include a "Cancel" option
|
||||
*/
|
||||
ProgressWindow (std::string const& title, bool allow_cancel);
|
||||
|
||||
/** Report progress and update GUI.
|
||||
* @param prog progress in range 0..1 show a bar, values outside this range show a pulsing dialog.
|
||||
* @param text optional text to show on the progress-bar
|
||||
* @return true if cancel was clicked, false otherwise
|
||||
*/
|
||||
bool progress (float prog, std::string const& text = "");
|
||||
|
||||
bool canceled () const {
|
||||
return _canceled;
|
||||
}
|
||||
|
||||
/** Close and hide the dialog.
|
||||
*
|
||||
* This is required to be at the end, since the dialog
|
||||
* is modal and prevents other UI operations while visible.
|
||||
*/
|
||||
void done ();
|
||||
|
||||
private:
|
||||
void cancel_clicked () {
|
||||
_canceled = true;
|
||||
}
|
||||
|
||||
Gtk::ProgressBar _bar;
|
||||
bool _canceled;
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#include <cairomm/surface.h>
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#include <gtkmm/progressbar.h>
|
||||
#include <gtkmm/stock.h>
|
||||
|
||||
#include "pbd/file_utils.h"
|
||||
#include "pbd/strsplit.h"
|
||||
|
||||
|
@ -43,7 +40,6 @@
|
|||
|
||||
#include "LuaBridge/LuaBridge.h"
|
||||
|
||||
#include "ardour_dialog.h"
|
||||
#include "ardour_http.h"
|
||||
#include "ardour_ui.h"
|
||||
#include "public_editor.h"
|
||||
|
@ -463,85 +459,6 @@ lua_exec (std::string cmd)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Synchronous GUI-thread Progress dialog
|
||||
*
|
||||
* This shows a modal progress dialog with an optional
|
||||
* "Cancel" button. Since it runs in the UI thread
|
||||
* the script needs to regularly call progress(),
|
||||
* as well as close the dialog, as needed.
|
||||
*/
|
||||
class LuaProgressWindow : public ArdourDialog
|
||||
{
|
||||
public:
|
||||
/** Create a new progress window.
|
||||
* @param title Window title
|
||||
* @param allow_cancel include a "Cancel" option
|
||||
*/
|
||||
LuaProgressWindow (std::string const& title, bool allow_cancel)
|
||||
: ArdourDialog (title, true)
|
||||
, _canceled (false)
|
||||
{
|
||||
_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
|
||||
|
||||
set_border_width (12);
|
||||
get_vbox()->set_spacing (6);
|
||||
get_vbox()->pack_start (_bar, false, false);
|
||||
|
||||
if (allow_cancel) {
|
||||
using namespace Gtk;
|
||||
Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
||||
b->signal_clicked().connect (sigc::mem_fun (*this, &LuaProgressWindow::cancel_clicked));
|
||||
}
|
||||
|
||||
set_default_size (200, -1);
|
||||
show_all ();
|
||||
}
|
||||
|
||||
/** Report progress and update GUI.
|
||||
* @param prog progress in range 0..1 show a bar, values outside this range show a pulsing dialog.
|
||||
* @param text optional text to show on the progress-bar
|
||||
* @return true if cancel was clicked, false otherwise
|
||||
*/
|
||||
bool progress (float prog, std::string const& text = "")
|
||||
{
|
||||
if (!text.empty ()) {
|
||||
_bar.set_text (text);
|
||||
}
|
||||
if (prog < 0 || prog > 1) {
|
||||
std::cerr << "pulse\n";
|
||||
_bar.set_pulse_step(.1);
|
||||
_bar.pulse();
|
||||
} else {
|
||||
_bar.set_fraction (prog);
|
||||
}
|
||||
ARDOUR::GUIIdle ();
|
||||
return _canceled;
|
||||
}
|
||||
|
||||
bool canceled () const {
|
||||
return _canceled;
|
||||
}
|
||||
|
||||
/** Close and hide the dialog.
|
||||
*
|
||||
* This is required to be at the end, since the dialog
|
||||
* is modal and prevents other UI operations while visible.
|
||||
*/
|
||||
void done () {
|
||||
Gtk::Dialog::response(_canceled ? Gtk::RESPONSE_CANCEL : Gtk::RESPONSE_OK);
|
||||
}
|
||||
|
||||
private:
|
||||
void cancel_clicked () {
|
||||
_canceled = true;
|
||||
}
|
||||
|
||||
Gtk::ProgressBar _bar;
|
||||
bool _canceled;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int
|
||||
lua_actionlist (lua_State *L)
|
||||
{
|
||||
|
@ -841,11 +758,11 @@ LuaInstance::bind_dialog (lua_State* L)
|
|||
.addConst ("None", -1)
|
||||
.endNamespace ()
|
||||
|
||||
.beginClass <LuaProgressWindow> ("LuaProgressWindow")
|
||||
.beginClass <LuaDialog::ProgressWindow> ("ProgressWindow")
|
||||
.addConstructor <void (*) (std::string const&, bool)> ()
|
||||
.addFunction ("progress", &LuaProgressWindow::progress)
|
||||
.addFunction ("done", &LuaProgressWindow::done)
|
||||
.addFunction ("canceled", &LuaProgressWindow::canceled)
|
||||
.addFunction ("progress", &LuaDialog::ProgressWindow::progress)
|
||||
.addFunction ("done", &LuaDialog::ProgressWindow::done)
|
||||
.addFunction ("canceled", &LuaDialog::ProgressWindow::canceled)
|
||||
.endClass ()
|
||||
|
||||
.endNamespace ();
|
||||
|
|
Loading…
Reference in New Issue
Block a user