summaryrefslogtreecommitdiffstats
path: root/src/ui/toolbar/livecode-toolbar.cpp
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-12-01 20:41:31 +0000
committers-ol <s-ol@users.noreply.github.com>2019-12-01 20:41:31 +0000
commit93f74e8d761c1ac04d0800765f5185243cf907a0 (patch)
treea5d8d1be6408a810c0b054d35bfccdbebdfccfb6 /src/ui/toolbar/livecode-toolbar.cpp
parentadd api and input modules for the livecoding tool (diff)
downloadinkscape-93f74e8d761c1ac04d0800765f5185243cf907a0.tar.gz
inkscape-93f74e8d761c1ac04d0800765f5185243cf907a0.zip
add basic livecode toolbar
Diffstat (limited to 'src/ui/toolbar/livecode-toolbar.cpp')
-rw-r--r--src/ui/toolbar/livecode-toolbar.cpp183
1 files changed, 183 insertions, 0 deletions
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 :