13
0

Make convert_drop_to_paths() reusable

This commit is contained in:
Robin Gareus 2021-12-13 22:50:04 +01:00
parent a9e1a8a885
commit 4720a45868
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
6 changed files with 73 additions and 99 deletions

View File

@ -3499,91 +3499,6 @@ Editor::setup_tooltips ()
set_tooltip (nudge_clock, _("Nudge Clock\n(controls distance used to nudge regions and selections)"));
}
int
Editor::convert_drop_to_paths (
vector<string>& paths,
const RefPtr<Gdk::DragContext>& /*context*/,
gint /*x*/,
gint /*y*/,
const SelectionData& data,
guint /*info*/,
guint /*time*/)
{
if (_session == 0) {
return -1;
}
vector<string> uris = data.get_uris();
if (uris.empty()) {
/* This is seriously fucked up. Nautilus doesn't say that its URI lists
are actually URI lists. So do it by hand.
*/
if (data.get_target() != "text/plain") {
return -1;
}
/* Parse the "uri-list" format that Nautilus provides,
where each pathname is delimited by \r\n.
THERE MAY BE NO NULL TERMINATING CHAR!!!
*/
string txt = data.get_text();
char* p;
const char* q;
p = (char *) malloc (txt.length() + 1);
txt.copy (p, txt.length(), 0);
p[txt.length()] = '\0';
while (p)
{
if (*p != '#')
{
while (g_ascii_isspace (*p))
p++;
q = p;
while (*q && (*q != '\n') && (*q != '\r')) {
q++;
}
if (q > p)
{
q--;
while (q > p && g_ascii_isspace (*q))
q--;
if (q > p)
{
uris.push_back (string (p, q - p + 1));
}
}
}
p = strchr (p, '\n');
if (p)
p++;
}
free ((void*)p);
if (uris.empty()) {
return -1;
}
}
for (vector<string>::iterator i = uris.begin(); i != uris.end(); ++i) {
if ((*i).substr (0,7) == "file://") {
paths.push_back (Glib::filename_from_uri (*i));
}
}
return 0;
}
void
Editor::new_tempo_section ()
{

View File

@ -2076,16 +2076,6 @@ private:
bool show_gain_after_trim;
/* Drag-n-Drop */
int convert_drop_to_paths (
std::vector<std::string>& paths,
const Glib::RefPtr<Gdk::DragContext>& context,
gint x,
gint y,
const Gtk::SelectionData& data,
guint info,
guint time);
void track_canvas_drag_data_received (
const Glib::RefPtr<Gdk::DragContext>& context,
gint x,

View File

@ -464,10 +464,9 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
GdkEvent ev;
double cy;
if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
if (_session && convert_drop_to_paths (paths, data)) {
/* D-n-D coordinates are window-relative, so convert to canvas coordinates
*/
/* D-n-D coordinates are window-relative, so convert to canvas coordinates */
ev.type = GDK_BUTTON_RELEASE;
ev.button.x = x;

View File

@ -1029,7 +1029,7 @@ EditorRegions::drag_data_received (const RefPtr<Gdk::DragContext>& context,
return;
}
if (_editor->convert_drop_to_paths (paths, context, x, y, data, info, dtime) == 0) {
if (_session && convert_drop_to_paths (paths, data)) {
timepos_t pos;
bool copy = ((context->get_actions () & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);

View File

@ -869,3 +869,71 @@ ARDOUR_UI_UTILS::shared_popup_menu ()
{
return ARDOUR_UI::instance()->shared_popup_menu ();
}
bool
ARDOUR_UI_UTILS::convert_drop_to_paths (vector<string>& paths, const SelectionData& data)
{
vector<string> uris = data.get_uris();
if (uris.empty ()) {
/* This is seriously fucked up. Nautilus doesn't say that its URI lists
* are actually URI lists. So do it by hand.
*/
if (data.get_target() != "text/plain") {
return false;
}
/* Parse the "uri-list" format that Nautilus provides,
* where each pathname is delimited by \r\n.
*
* THERE MAY BE NO NULL TERMINATING CHAR!!!
*/
string txt = data.get_text();
char* p = (char *) malloc (txt.length() + 1);
txt.copy (p, txt.length(), 0);
p[txt.length()] = '\0';
while (p) {
if (*p != '#') {
while (g_ascii_isspace (*p)) {
p++;
}
const char* q = p;
while (*q && (*q != '\n') && (*q != '\r')) {
q++;
}
if (q > p) {
--q;
while (q > p && g_ascii_isspace (*q)) {
--q;
}
if (q > p) {
uris.push_back (string (p, q - p + 1));
}
}
}
p = strchr (p, '\n');
if (p) {
++p;
}
}
free ((void*)p);
if (uris.empty()) {
return false;
}
}
for (vector<string>::iterator i = uris.begin(); i != uris.end(); ++i) {
if ((*i).substr (0,7) == "file://") {
paths.push_back (Glib::filename_from_uri (*i));
}
}
return !paths.empty ();
}

View File

@ -110,5 +110,7 @@ bool running_from_source_tree ();
void inhibit_screensaver (bool);
bool convert_drop_to_paths (std::vector<std::string>&, const Gtk::SelectionData&);
} // namespace
#endif /* __ardour_gtk_utils_h__ */