1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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 :
|