git.s-ol.nu inkscape / 93f74e8
add basic livecode toolbar s-ol 3 years ago
7 changed file(s) with 238 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 [submodule "share/extensions"]
11 path = share/extensions
22 url = https://gitlab.com/inkscape/extensions.git
3 [submodule "src/livecode/janet-2geom"]
4 path = src/livecode/janet-2geom
5 url = https://git.s-ol.nu/janet-2geom/
(New empty file)
4343 toolbar/dropper-toolbar.cpp
4444 toolbar/eraser-toolbar.cpp
4545 toolbar/gradient-toolbar.cpp
46 toolbar/livecode-toolbar.cpp
4647 toolbar/lpe-toolbar.cpp
4748 toolbar/measure-toolbar.cpp
4849 toolbar/mesh-toolbar.cpp
7071 tools/flood-tool.cpp
7172 tools/freehand-base.cpp
7273 tools/gradient-tool.cpp
74 tools/livecode-tool.cpp
7375 tools/lpe-tool.cpp
7476 tools/measure-tool.cpp
7577 tools/mesh-tool.cpp
8587 tools/tool-base.cpp
8688 tools/tweak-tool.cpp
8789 tools/zoom-tool.cpp
88 tools/livecode-tool.cpp
8990
9091 dialog/aboutbox.cpp
9192 dialog/align-and-distribute.cpp
0 // SPDX-License-Identifier: GPL-2.0-or-later
1 /**
2 * @file
3 * Measure aux toolbar
4 */
5 /* Authors:
6 * Sol Bekic <s+inkscape@s-ol.nu>
7 * Copyright (C) 2019 Authors
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12 #include "livecode-toolbar.h"
13
14 #include <glibmm/i18n.h>
15 #include <giomm/file.h>
16 #include <gtkmm/liststore.h>
17 #include <gtkmm/filechooserdialog.h>
18
19 #include "desktop.h"
20 #include "inkscape.h"
21
22 #include "ui/icon-names.h"
23 #include "ui/tools/livecode-tool.h"
24 #include "ui/widget/combo-box-entry-tool-item.h"
25 #include "ui/widget/label-tool-item.h"
26
27 using Inkscape::UI::Widget::ComboBoxEntryToolItem;
28 using Inkscape::UI::Tools::LivecodeTool;
29
30 /** Temporary hack: Returns the node tool in the active desktop.
31 * Will go away during tool refactoring. */
32 static LivecodeTool *get_livecode_tool()
33 {
34 LivecodeTool *tool = nullptr;
35 if (SP_ACTIVE_DESKTOP) {
36 Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
37 if (SP_IS_LIVECODE_CONTEXT(ec)) {
38 tool = static_cast<LivecodeTool*>(ec);
39 }
40 }
41 return tool;
42 }
43
44
45 static void update_script_list(GtkListStore *model_files) {
46 gtk_list_store_clear(model_files);
47 auto prefs = Inkscape::Preferences::get();
48 Glib::ustring library_path= prefs->getString("/tools/livecode/library_dir");
49 Glib::RefPtr<Gio::File> library_dir = Gio::File::create_for_path(library_path);
50
51 auto enumerator = library_dir->enumerate_children();
52 if (!enumerator) {
53 g_error("couldn't find livecode library dir: %s", library_path.c_str());
54 return;
55 }
56
57 auto file_info = enumerator->next_file();
58 while (file_info)
59 {
60 if (file_info->get_file_type() == Gio::FILE_TYPE_REGULAR) {
61 GtkTreeIter iter;
62 gtk_list_store_append(model_files, &iter);
63 gtk_list_store_set(model_files, &iter, 0, file_info->get_name().c_str(), -1);
64 }
65 file_info = enumerator->next_file();
66 }
67 }
68
69 namespace Inkscape {
70 namespace UI {
71 namespace Toolbar {
72 LivecodeToolbar::LivecodeToolbar(SPDesktop *desktop)
73 : Toolbar(desktop)
74 {
75 auto prefs = Inkscape::Preferences::get();
76
77 /* active script */
78 {
79 GtkListStore* model_files = gtk_list_store_new( 1, G_TYPE_STRING );
80 update_script_list(model_files);
81
82 _active_script = Gtk::manage(new ComboBoxEntryToolItem("active_script",
83 _("active script"),
84 _("the currently running script"),
85 GTK_TREE_MODEL(model_files)));
86 _active_script->set_tooltip_text(_("Choose where scripts can be found"));
87 _active_script->signal_changed().connect(sigc::mem_fun(*this, &LivecodeToolbar::active_script_value_changed));
88 _active_script->focus_on_click(false);
89 add(*_active_script);
90 }
91
92 add_separator();
93
94 /* select library directory */
95 {
96 _select_library = Gtk::manage(new Gtk::ToolButton(_("Select Library Directory")));
97 _select_library->set_tooltip_text(_("Choose where scripts can be found"));
98 _select_library->set_icon_name(INKSCAPE_ICON("gears"));
99 _select_library->signal_clicked().connect(sigc::mem_fun(*this, &LivecodeToolbar::select_library_pressed));
100 add(*_select_library);
101 }
102
103 show_all();
104 }
105
106 GtkWidget *LivecodeToolbar::create(SPDesktop *desktop)
107 {
108 auto toolbar = new LivecodeToolbar(desktop);
109 return GTK_WIDGET(toolbar->gobj());
110 }
111
112 void LivecodeToolbar::active_script_value_changed()
113 {
114 // quit if run by the _changed callbacks
115 if (_freeze) {
116 return;
117 }
118 _freeze = true;
119
120 gchar *text = _active_script->get_active_text();
121
122 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
123 Glib::ustring path = prefs->getString("/tools/livecode/library_dir");
124
125
126 // _font_size_item->set_active_text( os.str().c_str() );
127
128 // @TODO: this can't be right, but I can't find a Gio:: path join helper right now
129 path += "/";
130 path += text;
131
132 LivecodeTool *tool = get_livecode_tool();
133 if (tool) {
134 // tool->loadScript(path);
135 }
136
137 _freeze = false;
138 g_free( text );
139 }
140
141 void LivecodeToolbar::select_library_pressed()
142 {
143 Gtk::FileChooserDialog dialog("Please choose the library directory folder",
144 Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
145 dialog.set_transient_for( *(INKSCAPE.active_desktop()->getToplevel()) );
146
147 dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL);
148 dialog.add_button("Select", Gtk::RESPONSE_OK);
149
150 int result = dialog.run();
151
152 switch(result) {
153 case Gtk::RESPONSE_OK: {
154 auto prefs = Inkscape::Preferences::get();
155 prefs->setString("/tools/livecode/library_dir", dialog.get_filename());
156 update_script_list(GTK_LIST_STORE(_active_script->get_model()));
157 break;
158 }
159 case Gtk::RESPONSE_CANCEL:
160 break;
161 default:
162 g_message("Unexpected response from FileChooserDialog");
163 break;
164 }
165 }
166
167
168 }
169 }
170 }
171
172
173 /*
174 Local Variables:
175 mode:c++
176 c-file-style:"stroustrup"
177 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
178 indent-tabs-mode:nil
179 fill-column:99
180 End:
181 */
182 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
0 // SPDX-License-Identifier: GPL-2.0-or-later
1 #ifndef SEEN_LIVECODE_TOOLBAR_H
2 #define SEEN_LIVECODE_TOOLBAR_H
3
4 /**
5 * @file
6 * Livecode aux toolbar
7 */
8 /* Authors:
9 * Sol Bekic <s+inkscape@s-ol.nu>
10 * Copyright (C) 2019 Authors
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15 #include "toolbar.h"
16
17 class SPDesktop;
18
19 namespace Inkscape {
20 namespace UI {
21 namespace Widget {
22 class ComboBoxEntryToolItem;
23 }
24
25 namespace Toolbar {
26 class LivecodeToolbar : public Toolbar {
27 private:
28 UI::Widget::ComboBoxEntryToolItem *_active_script;
29 Gtk::ToolButton *_select_library;
30
31 bool _freeze;
32 void active_script_value_changed();
33 void select_library_pressed();
34
35 protected:
36 LivecodeToolbar(SPDesktop *desktop);
37
38 public:
39 static GtkWidget *create(SPDesktop *desktop);
40 };
41
42 }
43 }
44 }
45
46 #endif /* !SEEN_LIVECODE_TOOLBAR_H */
4848 return LivecodeTool::prefsPath;
4949 }
5050
51 const std::string LivecodeTool::prefsPath = "/tools/ersaser";
51 const std::string LivecodeTool::prefsPath = "/tools/livecode";
5252
5353 LivecodeTool::LivecodeTool()
5454 : ToolBase(nullptr, false)
7373 #include "ui/toolbar/dropper-toolbar.h"
7474 #include "ui/toolbar/eraser-toolbar.h"
7575 #include "ui/toolbar/gradient-toolbar.h"
76 #include "ui/toolbar/livecode-toolbar.h"
7677 #include "ui/toolbar/lpe-toolbar.h"
7778 #include "ui/toolbar/mesh-toolbar.h"
7879 #include "ui/toolbar/measure-toolbar.h"
211212 SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")},
212213 { "/tools/lpetool", "lpetool_toolbox", Inkscape::UI::Toolbar::LPEToolbar::create, "LPEToolToolbar",
213214 SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")},
214 { "/tools/livecode", "livecode_toolbox", Inkscape::UI::Toolbar::EraserToolbar::create, "LivecodeToolbar", // @TODO:livecode
215 { "/tools/livecode", "livecode_toolbox", Inkscape::UI::Toolbar::LivecodeToolbar::create, "LivecodeToolbar",
215216 SP_VERB_INVALID, nullptr, nullptr},
216217 // If you change TextToolbar here, change it also in desktop-widget.cpp
217218 { "/tools/text", "text_toolbox", Inkscape::UI::Toolbar::TextToolbar::create, "TextToolbar",