summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
m---------src/livecode/janet-2geom0
-rw-r--r--src/ui/CMakeLists.txt3
-rw-r--r--src/ui/toolbar/livecode-toolbar.cpp183
-rw-r--r--src/ui/toolbar/livecode-toolbar.h47
-rw-r--r--src/ui/tools/livecode-tool.cpp2
-rw-r--r--src/widgets/toolbox.cpp3
6 files changed, 235 insertions, 3 deletions
diff --git a/src/livecode/janet-2geom b/src/livecode/janet-2geom
new file mode 160000
+Subproject a3495ede6711d3221780ebbc9adb9a230120655
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 8c911fd59..99def5902 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -44,6 +44,7 @@ set(ui_SRC
toolbar/dropper-toolbar.cpp
toolbar/eraser-toolbar.cpp
toolbar/gradient-toolbar.cpp
+ toolbar/livecode-toolbar.cpp
toolbar/lpe-toolbar.cpp
toolbar/measure-toolbar.cpp
toolbar/mesh-toolbar.cpp
@@ -71,6 +72,7 @@ set(ui_SRC
tools/flood-tool.cpp
tools/freehand-base.cpp
tools/gradient-tool.cpp
+ tools/livecode-tool.cpp
tools/lpe-tool.cpp
tools/measure-tool.cpp
tools/mesh-tool.cpp
@@ -86,7 +88,6 @@ set(ui_SRC
tools/tool-base.cpp
tools/tweak-tool.cpp
tools/zoom-tool.cpp
- tools/livecode-tool.cpp
dialog/aboutbox.cpp
dialog/align-and-distribute.cpp
diff --git a/src/ui/toolbar/livecode-toolbar.cpp b/src/ui/toolbar/livecode-toolbar.cpp
new file mode 100644
index 000000000..81533fec7
--- /dev/null
+++ b/src/ui/toolbar/livecode-toolbar.cpp
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/**
+ * @file
+ * Measure aux toolbar
+ */
+/* Authors:
+ * Sol Bekic <s+inkscape@s-ol.nu>
+ * Copyright (C) 2019 Authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include "livecode-toolbar.h"
+
+#include <glibmm/i18n.h>
+#include <giomm/file.h>
+#include <gtkmm/liststore.h>
+#include <gtkmm/filechooserdialog.h>
+
+#include "desktop.h"
+#include "inkscape.h"
+
+#include "ui/icon-names.h"
+#include "ui/tools/livecode-tool.h"
+#include "ui/widget/combo-box-entry-tool-item.h"
+#include "ui/widget/label-tool-item.h"
+
+using Inkscape::UI::Widget::ComboBoxEntryToolItem;
+using Inkscape::UI::Tools::LivecodeTool;
+
+/** Temporary hack: Returns the node tool in the active desktop.
+ * Will go away during tool refactoring. */
+static LivecodeTool *get_livecode_tool()
+{
+ LivecodeTool *tool = nullptr;
+ if (SP_ACTIVE_DESKTOP) {
+ Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
+ if (SP_IS_LIVECODE_CONTEXT(ec)) {
+ tool = static_cast<LivecodeTool*>(ec);
+ }
+ }
+ return tool;
+}
+
+
+static void update_script_list(GtkListStore *model_files) {
+ gtk_list_store_clear(model_files);
+ auto prefs = Inkscape::Preferences::get();
+ Glib::ustring library_path= prefs->getString("/tools/livecode/library_dir");
+ Glib::RefPtr<Gio::File> library_dir = Gio::File::create_for_path(library_path);
+
+ auto enumerator = library_dir->enumerate_children();
+ if (!enumerator) {
+ g_error("couldn't find livecode library dir: %s", library_path.c_str());
+ return;
+ }
+
+ auto file_info = enumerator->next_file();
+ while (file_info)
+ {
+ if (file_info->get_file_type() == Gio::FILE_TYPE_REGULAR) {
+ GtkTreeIter iter;
+ gtk_list_store_append(model_files, &iter);
+ gtk_list_store_set(model_files, &iter, 0, file_info->get_name().c_str(), -1);
+ }
+ file_info = enumerator->next_file();
+ }
+}
+
+namespace Inkscape {
+namespace UI {
+namespace Toolbar {
+LivecodeToolbar::LivecodeToolbar(SPDesktop *desktop)
+ : Toolbar(desktop)
+{
+ auto prefs = Inkscape::Preferences::get();
+
+ /* active script */
+ {
+ GtkListStore* model_files = gtk_list_store_new( 1, G_TYPE_STRING );
+ update_script_list(model_files);
+
+ _active_script = Gtk::manage(new ComboBoxEntryToolItem("active_script",
+ _("active script"),
+ _("the currently running script"),
+ GTK_TREE_MODEL(model_files)));
+ _active_script->set_tooltip_text(_("Choose where scripts can be found"));
+ _active_script->signal_changed().connect(sigc::mem_fun(*this, &LivecodeToolbar::active_script_value_changed));
+ _active_script->focus_on_click(false);
+ add(*_active_script);
+ }
+
+ add_separator();
+
+ /* select library directory */
+ {
+ _select_library = Gtk::manage(new Gtk::ToolButton(_("Select Library Directory")));
+ _select_library->set_tooltip_text(_("Choose where scripts can be found"));
+ _select_library->set_icon_name(INKSCAPE_ICON("gears"));
+ _select_library->signal_clicked().connect(sigc::mem_fun(*this, &LivecodeToolbar::select_library_pressed));
+ add(*_select_library);
+ }
+
+ show_all();
+}
+
+GtkWidget *LivecodeToolbar::create(SPDesktop *desktop)
+{
+ auto toolbar = new LivecodeToolbar(desktop);
+ return GTK_WIDGET(toolbar->gobj());
+}
+
+void LivecodeToolbar::active_script_value_changed()
+{
+ // quit if run by the _changed callbacks
+ if (_freeze) {
+ return;
+ }
+ _freeze = true;
+
+ gchar *text = _active_script->get_active_text();
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring path = prefs->getString("/tools/livecode/library_dir");
+
+
+ // _font_size_item->set_active_text( os.str().c_str() );
+
+ // @TODO: this can't be right, but I can't find a Gio:: path join helper right now
+ path += "/";
+ path += text;
+
+ LivecodeTool *tool = get_livecode_tool();
+ if (tool) {
+ // tool->loadScript(path);
+ }
+
+ _freeze = false;
+ g_free( text );
+}
+
+void LivecodeToolbar::select_library_pressed()
+{
+ Gtk::FileChooserDialog dialog("Please choose the library directory folder",
+ Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ dialog.set_transient_for( *(INKSCAPE.active_desktop()->getToplevel()) );
+
+ dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
+ dialog.add_button("Select", Gtk::RESPONSE_OK);
+
+ int result = dialog.run();
+
+ switch(result) {
+ case Gtk::RESPONSE_OK: {
+ auto prefs = Inkscape::Preferences::get();
+ prefs->setString("/tools/livecode/library_dir", dialog.get_filename());
+ update_script_list(GTK_LIST_STORE(_active_script->get_model()));
+ break;
+ }
+ case Gtk::RESPONSE_CANCEL:
+ break;
+ default:
+ g_message("Unexpected response from FileChooserDialog");
+ break;
+ }
+}
+
+
+}
+}
+}
+
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/toolbar/livecode-toolbar.h b/src/ui/toolbar/livecode-toolbar.h
new file mode 100644
index 000000000..abfd4f46f
--- /dev/null
+++ b/src/ui/toolbar/livecode-toolbar.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef SEEN_LIVECODE_TOOLBAR_H
+#define SEEN_LIVECODE_TOOLBAR_H
+
+/**
+ * @file
+ * Livecode aux toolbar
+ */
+/* Authors:
+ * Sol Bekic <s+inkscape@s-ol.nu>
+ * Copyright (C) 2019 Authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include "toolbar.h"
+
+class SPDesktop;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+class ComboBoxEntryToolItem;
+}
+
+namespace Toolbar {
+class LivecodeToolbar : public Toolbar {
+private:
+ UI::Widget::ComboBoxEntryToolItem *_active_script;
+ Gtk::ToolButton *_select_library;
+
+ bool _freeze;
+ void active_script_value_changed();
+ void select_library_pressed();
+
+protected:
+ LivecodeToolbar(SPDesktop *desktop);
+
+public:
+ static GtkWidget *create(SPDesktop *desktop);
+};
+
+}
+}
+}
+
+#endif /* !SEEN_LIVECODE_TOOLBAR_H */
diff --git a/src/ui/tools/livecode-tool.cpp b/src/ui/tools/livecode-tool.cpp
index 0c125ac05..0071f47b3 100644
--- a/src/ui/tools/livecode-tool.cpp
+++ b/src/ui/tools/livecode-tool.cpp
@@ -49,7 +49,7 @@ const std::string& LivecodeTool::getPrefsPath()
return LivecodeTool::prefsPath;
}
-const std::string LivecodeTool::prefsPath = "/tools/ersaser";
+const std::string LivecodeTool::prefsPath = "/tools/livecode";
LivecodeTool::LivecodeTool()
: ToolBase(nullptr, false)
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 8b02211d0..40e04bef6 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -74,6 +74,7 @@
#include "ui/toolbar/dropper-toolbar.h"
#include "ui/toolbar/eraser-toolbar.h"
#include "ui/toolbar/gradient-toolbar.h"
+#include "ui/toolbar/livecode-toolbar.h"
#include "ui/toolbar/lpe-toolbar.h"
#include "ui/toolbar/mesh-toolbar.h"
#include "ui/toolbar/measure-toolbar.h"
@@ -212,7 +213,7 @@ static struct {
SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")},
{ "/tools/lpetool", "lpetool_toolbox", Inkscape::UI::Toolbar::LPEToolbar::create, "LPEToolToolbar",
SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")},
- { "/tools/livecode", "livecode_toolbox", Inkscape::UI::Toolbar::EraserToolbar::create, "LivecodeToolbar", // @TODO:livecode
+ { "/tools/livecode", "livecode_toolbox", Inkscape::UI::Toolbar::LivecodeToolbar::create, "LivecodeToolbar",
SP_VERB_INVALID, nullptr, nullptr},
// If you change TextToolbar here, change it also in desktop-widget.cpp
{ "/tools/text", "text_toolbox", Inkscape::UI::Toolbar::TextToolbar::create, "TextToolbar",