bootstrap cinfinity picons, rework picon access, chaninfo tweak
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "assetedit.h"
24 #include "assetpopup.h"
25 #include "assets.h"
26 #include "awindowgui.h"
27 #include "awindow.h"
28 #include "bcsignals.h"
29 #include "bchash.h"
30 #include "cache.h"
31 #include "bccmodels.h"
32 #include "clippopup.h"
33 #include "cursors.h"
34 #include "cwindowgui.h"
35 #include "cwindow.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "effectlist.h"
39 #include "file.h"
40 #include "filesystem.h"
41 #include "folderlistmenu.h"
42 #include "indexable.h"
43 #include "keys.h"
44 #include "language.h"
45 #include "labels.h"
46 #include "labelpopup.h"
47 #include "localsession.h"
48 #include "mainmenu.h"
49 #include "mainsession.h"
50 #include "mwindowgui.h"
51 #include "mwindow.h"
52 #include "nestededls.h"
53 #include "newfolder.h"
54 #include "preferences.h"
55 #include "theme.h"
56 #include "vframe.h"
57 #include "vicon.h"
58 #include "vwindowgui.h"
59 #include "vwindow.h"
60
61 #include "data/lad_picon_png.h"
62 #include "data/ff_audio_png.h"
63 #include "data/ff_video_png.h"
64
65 #include<stdio.h>
66 #include<unistd.h>
67 #include<fcntl.h>
68
69
70 const char *AWindowGUI::folder_names[] =
71 {
72         N_("Audio Effects"),
73         N_("Video Effects"),
74         N_("Audio Transitions"),
75         N_("Video Transitions"),
76         N_("Labels"),
77         N_("Clips"),
78         N_("Media"),
79         N_("Proxy"),
80 };
81
82
83 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
84  : VIcon(w, h, framerate)
85 {
86         this->picon = picon;
87         this->length = length;
88         temp = 0;
89 }
90
91 AssetVIcon::~AssetVIcon()
92 {
93         delete temp;
94 }
95
96 VFrame *AssetVIcon::frame()
97 {
98         if( seq_no >= images.size() ) {
99                 MWindow *mwindow = picon->mwindow;
100                 Asset *asset = (Asset *)picon->indexable;
101                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
102                 if( !file ) return 0;
103                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
104                         delete temp;  temp = 0;
105                 }
106                 if( !temp )
107                         temp = new VFrame(asset->width, asset->height, BC_RGB888);
108                 int ww = picon->gui->vicon_thread->view_w;
109                 int hh = picon->gui->vicon_thread->view_h;
110                 while( seq_no >= images.size() ) {
111                         file->set_layer(0);
112                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
113                         file->set_video_position(pos,0);
114                         file->read_frame(temp);
115                         add_image(temp, ww, hh, BC_RGB8);
116                 }
117                 mwindow->video_cache->check_in(asset);
118         }
119         return *images[seq_no];
120 }
121
122 int64_t AssetVIcon::set_seq_no(int64_t no)
123 {
124         if( no >= length ) no = 0;
125         return seq_no = no;
126 }
127
128 int AssetVIcon::get_vx()
129 {
130         BC_ListBox *lbox = picon->gui->asset_list;
131         return lbox->get_item_x(picon);
132 }
133 int AssetVIcon::get_vy()
134 {
135         BC_ListBox *lbox = picon->gui->asset_list;
136         return lbox->get_item_y(picon) + lbox->get_title_h();
137 }
138
139
140 AssetPicon::AssetPicon(MWindow *mwindow,
141         AWindowGUI *gui, Indexable *indexable)
142  : BC_ListBoxItem()
143 {
144         reset();
145         this->mwindow = mwindow;
146         this->gui = gui;
147         this->indexable = indexable;
148         indexable->add_user();
149         this->id = indexable->id;
150 }
151
152 AssetPicon::AssetPicon(MWindow *mwindow,
153         AWindowGUI *gui, EDL *edl)
154  : BC_ListBoxItem()
155 {
156         reset();
157         this->mwindow = mwindow;
158         this->gui = gui;
159         this->edl = edl;
160         edl->add_user();
161         this->id = edl->id;
162 }
163
164 AssetPicon::AssetPicon(MWindow *mwindow,
165         AWindowGUI *gui, int folder, int persist)
166  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]),
167         folder>=0 && folder<AWINDOW_FOLDERS ?
168                 gui->folder_icons[folder]: gui->folder_icon)
169 {
170         reset();
171         foldernum = folder;
172         this->mwindow = mwindow;
173         this->gui = gui;
174         persistent = persist;
175 }
176
177 AssetPicon::AssetPicon(MWindow *mwindow,
178         AWindowGUI *gui, PluginServer *plugin)
179  : BC_ListBoxItem()
180 {
181         reset();
182         this->mwindow = mwindow;
183         this->gui = gui;
184         this->plugin = plugin;
185 }
186
187 AssetPicon::AssetPicon(MWindow *mwindow,
188         AWindowGUI *gui, Label *label)
189  : BC_ListBoxItem()
190 {
191         reset();
192         this->mwindow = mwindow;
193         this->gui = gui;
194         this->label = label;
195         indexable = 0;
196         icon = 0;
197         id = 0;
198 }
199
200 AssetPicon::~AssetPicon()
201 {
202         if( vicon )
203                 gui->vicon_thread->del_vicon(vicon);
204         if( indexable ) indexable->remove_user();
205         if( edl ) edl->remove_user();
206         if( icon && !gui->protected_pixmap(icon) ) {
207                 delete icon;
208                 if( !plugin ) delete icon_vframe;
209         }
210 }
211
212 void AssetPicon::reset()
213 {
214         plugin = 0;
215         label = 0;
216         indexable = 0;
217         edl = 0;
218         foldernum = AW_NO_FOLDER;
219         icon = 0;
220         icon_vframe = 0;
221         vicon = 0;
222         in_use = 1;
223         id = 0;
224         persistent = 0;
225 }
226
227 void AssetPicon::create_objects()
228 {
229         FileSystem fs;
230         char name[BCTEXTLEN];
231         int pixmap_w, pixmap_h;
232
233         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
234
235         if( indexable ) {
236                 fs.extract_name(name, indexable->path);
237                 set_text(name);
238         }
239
240         if( indexable && indexable->is_asset ) {
241                 Asset *asset = (Asset*)indexable;
242                 if( asset->video_data ) {
243                         if( mwindow->preferences->use_thumbnails ) {
244                                 gui->unlock_window();
245                                 File *file = mwindow->video_cache->check_out(asset,
246                                         mwindow->edl,
247                                         1);
248
249                                 if( file ) {
250                                         int height = asset->height > 0 ? asset->height : 1;
251                                         pixmap_w = pixmap_h * asset->width / height;
252
253                                         file->set_layer(0);
254                                         file->set_video_position(0, 0);
255
256                                         if( gui->temp_picon &&
257                                                 (gui->temp_picon->get_w() != asset->width ||
258                                                 gui->temp_picon->get_h() != asset->height) ) {
259                                                 delete gui->temp_picon;
260                                                 gui->temp_picon = 0;
261                                         }
262
263                                         if( !gui->temp_picon ) {
264                                                 gui->temp_picon = new VFrame(0, -1,
265                                                         asset->width, asset->height,
266                                                         BC_RGB888, -1);
267                                         }
268                                         { char string[BCTEXTLEN];
269                                         sprintf(string, _("Reading %s"), name);
270                                         mwindow->gui->lock_window("AssetPicon::create_objects");
271                                         mwindow->gui->show_message(string);
272                                         mwindow->gui->unlock_window(); }
273                                         file->read_frame(gui->temp_picon);
274                                         mwindow->video_cache->check_in(asset);
275
276                                         gui->lock_window("AssetPicon::create_objects 1");
277                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
278                                         icon->draw_vframe(gui->temp_picon,
279                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
280                                         icon_vframe = new VFrame(0,
281                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
282                                         icon_vframe->transfer_from(gui->temp_picon);
283                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
284 // vicon images
285                                                 double framerate = asset->get_frame_rate();
286                                                 if( !framerate ) framerate = VICON_RATE;
287                                                 int64_t frames = asset->get_video_frames();
288                                                 double secs = frames / framerate;
289                                                 if( secs > 5 ) secs = 5;
290                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
291                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
292                                                 gui->vicon_thread->add_vicon(vicon);
293                                         }
294
295                                 }
296                                 else {
297                                         gui->lock_window("AssetPicon::create_objects 2");
298                                         icon = gui->video_icon;
299                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
300                                 }
301                         }
302                         else {
303                                 icon = gui->video_icon;
304                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
305                         }
306                 }
307                 else
308                 if( asset->audio_data ) {
309                         icon = gui->audio_icon;
310                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
311                 }
312
313         }
314         else
315         if( indexable && !indexable->is_asset ) {
316                 icon = gui->video_icon;
317                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
318         }
319         else
320         if( edl ) {
321                 set_text(strcpy(name, edl->local_session->clip_title));
322                 icon = gui->clip_icon;
323                 icon_vframe = mwindow->theme->get_image("clip_icon");
324         }
325         else
326         if( plugin ) {
327                 strcpy(name,  plugin->title);
328                 set_text(name);
329                 icon_vframe = plugin->get_picon();
330                 if( icon_vframe )
331                         icon = gui->create_pixmap(icon_vframe);
332                 else if( plugin->audio ) {
333                         if( plugin->transition ) {
334                                 icon = gui->atransition_icon;
335                                 icon_vframe = gui->atransition_vframe;
336                         }
337                         else if( plugin->is_ffmpeg() ) {
338                                 icon = gui->ff_aud_icon;
339                                 icon_vframe = gui->ff_aud_vframe;
340                         }
341                         else if( plugin->is_ladspa() ) {
342                                 icon = gui->ladspa_icon;
343                                 icon_vframe = gui->ladspa_vframe;
344                         }
345                         else {
346                                 icon = gui->aeffect_icon;
347                                 icon_vframe = gui->aeffect_vframe;
348                         }
349                 }
350                 else if( plugin->video ) {
351                         if( plugin->transition ) {
352                                 icon = gui->vtransition_icon;
353                                 icon_vframe = gui->vtransition_vframe;
354                         }
355                         else if( plugin->is_ffmpeg() ) {
356                                 icon = gui->ff_vid_icon;
357                                 icon_vframe = gui->ff_vid_vframe;
358                         }
359                         else {
360                                 icon = gui->veffect_icon;
361                                 icon_vframe = gui->veffect_vframe;
362                         }
363                 }
364         }
365         else
366         if( label ) {
367                 Units::totext(name,
368                               label->position,
369                               mwindow->edl->session->time_format,
370                               mwindow->edl->session->sample_rate,
371                               mwindow->edl->session->frame_rate,
372                               mwindow->edl->session->frames_per_foot);
373                 set_text(name);
374                 icon = gui->label_icon;
375                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL];
376                 set_icon(icon);
377                 set_icon_vframe(icon_vframe);
378         }
379         if( !icon ) {
380                 icon = gui->file_icon;
381                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
382         }
383         set_icon(icon);
384         set_icon_vframe(icon_vframe);
385 }
386
387 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
388  : BC_Window(_(PROGRAM_NAME ": Resources"),
389         mwindow->session->awindow_x, mwindow->session->awindow_y,
390         mwindow->session->awindow_w, mwindow->session->awindow_h,
391         100, 100, 1, 1, 1)
392 {
393         this->mwindow = mwindow;
394         this->awindow = awindow;
395
396         file_vframe = 0;                file_icon = 0;
397         folder_vframe = 0;              folder_icon = 0;
398         audio_vframe = 0;               audio_icon = 0;
399         video_vframe = 0;               video_icon = 0;
400         label_vframe = 0;               label_icon = 0;
401
402         atransition_vframe = 0;         atransition_icon = 0;
403         vtransition_vframe = 0;         vtransition_icon = 0;
404         aeffect_vframe = 0;             aeffect_icon = 0;
405         ladspa_vframe = 0;              ladspa_icon = 0;
406         veffect_vframe = 0;             veffect_icon = 0;
407         ff_aud_vframe = 0;              ff_aud_icon = 0;
408         ff_vid_vframe = 0;              ff_vid_icon = 0;
409
410         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
411         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
412         clip_folder_vframe = 0;         clip_folder_icon = 0;
413         label_folder_vframe = 0;        label_folder_icon = 0;
414         media_folder_vframe = 0;        media_folder_icon = 0;
415         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
416         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
417         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
418
419         ladspa_vframe = 0;              ladspa_icon = 0;
420         ff_aud_vframe = 0;              ff_aud_icon = 0;
421         ff_vid_vframe = 0;              ff_vid_icon = 0;
422
423         clip_vframe = 0;                clip_icon = 0;
424         atransition_vframe = 0;         atransition_icon = 0;
425         vtransition_vframe = 0;         vtransition_icon = 0;
426         aeffect_vframe = 0;             aeffect_icon = 0;
427         veffect_vframe = 0;             veffect_icon = 0;
428
429         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
430         newfolder_thread = 0;
431         asset_menu = 0;
432         effectlist_menu = 0;
433         assetlist_menu = 0;
434         cliplist_menu = 0;
435         labellist_menu = 0;
436         folderlist_menu = 0;
437         temp_picon = 0;
438         allow_iconlisting = 1;
439         remove_plugin = 0;
440         vicon_thread = 0;
441         vicon_drawing = 1;
442         displayed_folder = AW_NO_FOLDER;
443 }
444
445 AWindowGUI::~AWindowGUI()
446 {
447         assets.remove_all_objects();
448         folders.remove_all_objects();
449         aeffects.remove_all_objects();
450         veffects.remove_all_objects();
451         atransitions.remove_all_objects();
452         vtransitions.remove_all_objects();
453         labellist.remove_all_objects();
454         displayed_assets[1].remove_all_objects();
455
456         delete vicon_thread;
457         delete newfolder_thread;
458
459         delete asset_menu;
460         delete clip_menu;
461         delete label_menu;
462         delete effectlist_menu;
463         delete assetlist_menu;
464         delete cliplist_menu;
465         delete labellist_menu;
466         delete folderlist_menu;
467         delete temp_picon;
468         delete remove_plugin;
469
470         delete file_vframe;             delete file_icon;
471         delete folder_vframe;           delete folder_icon;
472         delete audio_vframe;            delete audio_icon;
473         delete video_vframe;            delete video_icon;
474         delete label_vframe;            delete label_icon;
475         delete clip_vframe;             delete clip_icon;
476         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
477         delete atransition_folder_vframe; delete atransition_folder_icon;
478         delete veffect_folder_vframe;   delete veffect_folder_icon;
479         delete vtransition_folder_vframe; delete vtransition_folder_icon;
480         delete clip_folder_vframe;      delete clip_folder_icon;
481         delete label_folder_vframe;     delete label_folder_icon;
482         delete media_folder_vframe;     delete media_folder_icon;
483         delete proxy_folder_vframe;     delete proxy_folder_icon;
484         delete ladspa_vframe;           delete ladspa_icon;
485         delete ff_aud_vframe;           delete ff_aud_icon;
486         delete ff_vid_vframe;           delete ff_vid_icon;
487         delete atransition_vframe;      delete atransition_icon;
488         delete vtransition_vframe;      delete vtransition_icon;
489         delete aeffect_vframe;          delete aeffect_icon;
490         delete veffect_vframe;          delete veffect_icon;
491 }
492
493 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
494 {
495         return  icon == file_icon ||
496                 icon == folder_icon ||
497                 icon == audio_icon ||
498                 icon == video_icon ||
499                 icon == clip_icon ||
500                 icon == label_icon ||
501                 icon == vtransition_icon ||
502                 icon == atransition_icon ||
503                 icon == veffect_icon ||
504                 icon == aeffect_icon ||
505                 icon == ladspa_icon ||
506                 icon == ff_aud_icon ||
507                 icon == ff_vid_icon ||
508                 icon == aeffect_folder_icon ||
509                 icon == veffect_folder_icon ||
510                 icon == atransition_folder_icon ||
511                 icon == vtransition_folder_icon ||
512                 icon == label_folder_icon ||
513                 icon == clip_folder_icon ||
514                 icon == media_folder_icon ||
515                 icon == proxy_folder_icon;
516 }
517
518 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
519 {
520         char png_path[BCTEXTLEN];
521         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
522         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
523                 File::get_plugin_path(), plugin_icons, name);
524         if( access(png_path, R_OK) ) return 0;
525         return VFramePng::vframe_png(png_path,0,0);
526 }
527
528 VFrame *AWindowGUI::get_picon(const char *name)
529 {
530         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
531         if( !vframe ) {
532                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
533                 snprintf(pp, ep-pp, "%s.png", name);
534                 unsigned char *data = mwindow->theme->get_image_data(png_name);
535                 if( data ) vframe = new VFramePng(data, 0.);
536         }
537         return vframe;
538 }
539
540 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
541 {
542         vfrm = get_picon(fn);
543         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
544         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
545 }
546 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
547 {
548         vfrm = get_picon(fn);
549         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
550         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
551 }
552 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
553 {
554         vfrm = get_picon(fn);
555         if( !vfrm ) vfrm = new VFramePng(png);
556         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
557 }
558
559 void AWindowGUI::create_objects()
560 {
561         lock_window("AWindowGUI::create_objects");
562         asset_titles[0] = C_("Title");
563         asset_titles[1] = _("Comments");
564
565         set_icon(mwindow->theme->get_image("awindow_icon"));
566
567         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
568         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
569         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
570         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
571         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
572
573         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
574         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
575         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
576         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
577         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
578         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
579         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
580         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
581
582         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
583         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
584         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
585         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
586         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
587         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
588         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
589         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
590
591         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
592         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
593         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
594         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
595         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
596
597         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
598         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
599         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
600
601 // Mandatory folders
602         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
603         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
604         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
605         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
606         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
607         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
608         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
609         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
610
611         create_label_folder();
612
613         mwindow->theme->get_awindow_sizes(this);
614         load_defaults(mwindow->defaults);
615
616         add_subwindow(asset_list = new AWindowAssets(mwindow, this,
617                 mwindow->theme->alist_x, mwindow->theme->alist_y,
618                 mwindow->theme->alist_w, mwindow->theme->alist_h));
619
620         vicon_thread = new VIconThread(asset_list);
621         vicon_thread->start();
622
623         add_subwindow(divider = new AWindowDivider(mwindow, this,
624                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
625                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
626
627         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
628
629         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
630         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
631         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
632         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
633         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
634         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
635         add_tools->create_objects();
636         fy += add_tools->get_h();  fh -= add_tools->get_h();
637         add_subwindow(folder_list = new AWindowFolders(mwindow,
638                 this, fx, fy, fw, fh));
639         update_effects();
640
641         //int x = mwindow->theme->abuttons_x;
642         //int y = mwindow->theme->abuttons_y;
643
644
645         newfolder_thread = new NewFolderThread(mwindow, this);
646
647         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
648         asset_menu->create_objects();
649         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
650         clip_menu->create_objects();
651         add_subwindow(label_menu = new LabelPopup(mwindow, this));
652         label_menu->create_objects();
653
654         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
655         effectlist_menu->create_objects();
656         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
657         assetlist_menu->create_objects();
658         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
659         cliplist_menu->create_objects();
660         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
661         labellist_menu->create_objects();
662
663         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
664         folderlist_menu->create_objects();
665
666         create_custom_xatoms();
667         unlock_window();
668 }
669
670 int AWindowGUI::resize_event(int w, int h)
671 {
672         mwindow->session->awindow_x = get_x();
673         mwindow->session->awindow_y = get_y();
674         mwindow->session->awindow_w = w;
675         mwindow->session->awindow_h = h;
676
677         mwindow->theme->get_awindow_sizes(this);
678         mwindow->theme->draw_awindow_bg(this);
679         reposition_objects();
680
681 //      int x = mwindow->theme->abuttons_x;
682 //      int y = mwindow->theme->abuttons_y;
683 //      new_bin->reposition_window(x, y);
684 //      x += new_bin->get_w();
685 //      delete_bin->reposition_window(x, y);
686 //      x += delete_bin->get_w();
687 //      rename_bin->reposition_window(x, y);
688 //      x += rename_bin->get_w();
689 //      delete_disk->reposition_window(x, y);
690 //      x += delete_disk->get_w();
691 //      delete_project->reposition_window(x, y);
692 //      x += delete_project->get_w();
693 //      info->reposition_window(x, y);
694 //      x += info->get_w();
695 //      redraw_index->reposition_window(x, y);
696 //      x += redraw_index->get_w();
697 //      paste->reposition_window(x, y);
698 //      x += paste->get_w();
699 //      append->reposition_window(x, y);
700 //      x += append->get_w();
701 //      view->reposition_window(x, y);
702
703         BC_WindowBase::resize_event(w, h);
704         return 1;
705 }
706
707 int AWindowGUI::translation_event()
708 {
709         mwindow->session->awindow_x = get_x();
710         mwindow->session->awindow_y = get_y();
711         return 0;
712 }
713
714 void AWindowGUI::reposition_objects()
715 {
716         asset_list->reposition_window(
717                 mwindow->theme->alist_x, mwindow->theme->alist_y,
718                 mwindow->theme->alist_w, mwindow->theme->alist_h);
719         divider->reposition_window(
720                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
721                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
722         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
723         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
724         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
725         avicon_drawing->reposition_window(fw-avicon_w, fy);
726         fy += add_tools->get_h();  fh -= add_tools->get_h();
727         folder_list->reposition_window(fx, fy, fw, fh);
728 }
729
730 int AWindowGUI::save_defaults(BC_Hash *defaults)
731 {
732         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
733         defaults->update("VICON_DRAWING", vicon_drawing);
734         return 0;
735 }
736
737 int AWindowGUI::load_defaults(BC_Hash *defaults)
738 {
739         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
740         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
741         return 0;
742 }
743
744 int AWindowGUI::close_event()
745 {
746         hide_window();
747         mwindow->session->show_awindow = 0;
748         unlock_window();
749
750         mwindow->gui->lock_window("AWindowGUI::close_event");
751         mwindow->gui->mainmenu->show_awindow->set_checked(0);
752         mwindow->gui->unlock_window();
753
754         lock_window("AWindowGUI::close_event");
755         save_defaults(mwindow->defaults);
756         mwindow->save_defaults();
757         return 1;
758 }
759
760 void AWindowGUI::start_vicon_drawing()
761 {
762         if( !vicon_drawing ) return;
763         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
764         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
765         vicon_thread->start_drawing();
766 }
767
768 void AWindowGUI::stop_vicon_drawing()
769 {
770         vicon_thread->stop_drawing();
771 }
772
773 AWindowRemovePluginGUI::
774 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
775         int x, int y, PluginServer *plugin)
776  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
777 {
778         this->awindow = awindow;
779         this->thread = thread;
780         this->plugin = plugin;
781         VFrame *vframe = plugin->get_picon();
782         icon = vframe ? create_pixmap(vframe) : 0;
783         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
784 }
785
786 AWindowRemovePluginGUI::
787 ~AWindowRemovePluginGUI()
788 {
789         if( !awindow->gui->protected_pixmap(icon) )
790                 delete icon;
791         plugin_list.remove_all();
792 }
793
794 void AWindowRemovePluginGUI::create_objects()
795 {
796         BC_Button *ok_button = new BC_OKButton(this);
797         add_subwindow(ok_button);
798         BC_Button *cancel_button = new BC_CancelButton(this);
799         add_subwindow(cancel_button);
800         int x = 10, y = 10;
801         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
802         add_subwindow(title);
803         y += title->get_h() + 5;
804         list = new BC_ListBox(x, y,
805                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
806                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
807         add_subwindow(list);
808         show_window();
809 }
810
811 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
812 {
813         int ret = 0;
814         for( int i=0; i<folder.size(); ) {
815                 AssetPicon *picon = (AssetPicon *)folder[i];
816                 if( picon->plugin == plugin ) {
817                         folder.remove_object_number(i);
818                         ++ret;
819                         continue;
820                 }
821                 ++i;
822         }
823         return ret;
824 }
825
826 void AWindowRemovePlugin::handle_close_event(int result)
827 {
828         if( !result ) {
829                 printf(_("remove %s\n"), plugin->path);
830                 ArrayList<BC_ListBoxItem*> *folder =
831                         plugin->audio ? plugin->transition ?
832                                 &awindow->gui->atransitions :
833                                 &awindow->gui->aeffects :
834                         plugin->video ?  plugin->transition ?
835                                 &awindow->gui->vtransitions :
836                                 &awindow->gui->veffects :
837                         0;
838                 if( folder ) remove_plugin(plugin, *folder);
839                 char plugin_path[BCTEXTLEN];
840                 strcpy(plugin_path, plugin->path);
841                 MWindow *mwindow = awindow->mwindow;
842                 mwindow->plugindb->remove(plugin);
843                 remove(plugin_path);
844                 char index_path[BCTEXTLEN];
845                 snprintf(index_path, sizeof(index_path), "%s/%s",
846                         mwindow->preferences->plugin_dir, PLUGIN_FILE);
847                 remove(index_path);
848                 char picon_path[BCTEXTLEN];
849                 FileSystem fs;
850                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
851                         File::get_plugin_path());
852                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
853                 plugin->get_plugin_png_name(png_name);
854                 fs.update(picon_path);
855                 for( int i=0; i<fs.dir_list.total; ++i ) {
856                         char *fs_path = fs.dir_list[i]->path;
857                         if( !fs.is_dir(fs_path) ) continue;
858                         snprintf(png_path, sizeof(picon_path), "%s/%s",
859                                 fs_path, png_name);
860                         remove(png_path);
861                 }
862                 delete plugin;  plugin = 0;
863                 awindow->gui->async_update_assets();
864         }
865 }
866
867 AWindowRemovePlugin::
868 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
869  : BC_DialogThread()
870 {
871         this->awindow = awindow;
872         this->plugin = plugin;
873 }
874
875 AWindowRemovePlugin::
876 ~AWindowRemovePlugin()
877 {
878         close_window();
879 }
880
881 BC_Window* AWindowRemovePlugin::new_gui()
882 {
883         int x = awindow->gui->get_abs_cursor_x(0);
884         int y = awindow->gui->get_abs_cursor_y(0);
885         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
886         gui->create_objects();
887         return gui;
888 }
889
890 int AWindowGUI::keypress_event()
891 {
892         switch( get_keypress() ) {
893         case 'w': case 'W':
894                 if( ctrl_down() ) {
895                         close_event();
896                         return 1;
897                 }
898                 break;
899         case DELETE:
900                 if( shift_down() ) {
901                         PluginServer* plugin = selected_plugin();
902                         if( !plugin ) break;
903                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
904                         unlock_window();
905                         remove_plugin->start();
906                         lock_window();
907                 }
908         }
909         return 0;
910 }
911
912
913
914 int AWindowGUI::create_custom_xatoms()
915 {
916         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
917         return 0;
918 }
919 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
920 {
921         if( event->message_type == UpdateAssetsXAtom ) {
922                 update_assets();
923                 return 1;
924         }
925         return 0;
926 }
927
928 void AWindowGUI::async_update_assets()
929 {
930         xatom_event event;
931         event.message_type = UpdateAssetsXAtom;
932         send_custom_xatom(&event);
933 }
934
935
936 void AWindowGUI::update_folder_list()
937 {
938         stop_vicon_drawing();
939         for( int i = 0; i < folders.total; i++ ) {
940                 AssetPicon *picon = (AssetPicon*)folders.values[i];
941                 picon->in_use = 0;
942         }
943
944 // Search assets for folders
945         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
946                 const char *folder = mwindow->edl->folders.values[i];
947                 int exists = 0;
948
949                 for( int j = 0; j < folders.total; j++ ) {
950                         AssetPicon *picon = (AssetPicon*)folders.values[j];
951                         if( !strcasecmp(picon->get_text(), folder) ) {
952                                 exists = 1;
953                                 picon->in_use = 1;
954                                 break;
955                         }
956                 }
957
958                 if( !exists ) {
959                         int aw_folder = folder_number(folder);
960                         if( aw_folder >= 0 ) {
961                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
962                                 picon->create_objects();
963                                 folders.append(picon);
964                         }
965                 }
966         }
967
968 // Delete unused non-persistent folders
969         for( int i=folders.total; --i>=0; ) {
970                 AssetPicon *picon = (AssetPicon*)folders.values[i];
971                 if( !picon->in_use && !picon->persistent ) {
972                         delete picon;
973                         folders.remove_number(i);
974                 }
975         }
976
977         start_vicon_drawing();
978 }
979
980 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
981         int do_audio, int do_video, int is_realtime, int is_transition)
982 {
983         ArrayList<PluginServer*> plugin_list;
984 // Get pointers to plugindb entries
985         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
986                         0, plugin_list);
987
988         for( int i = 0; i < plugin_list.total; i++ ) {
989                 PluginServer *server = plugin_list.values[i];
990                 int visible = plugin_visibility & (1<<server->dir_idx);
991                 if( !visible ) continue;
992 // Create new listitem
993                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
994                 picon->create_objects();
995                 output->append(picon);
996         }
997 }
998
999 void AWindowGUI::create_label_folder()
1000 {
1001         Label *current;
1002         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1003                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1004                 picon->create_objects();
1005                 labellist.append(picon);
1006         }
1007 }
1008
1009
1010 void AWindowGUI::update_asset_list()
1011 {
1012         for( int i = 0; i < assets.total; i++ ) {
1013                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1014                 picon->in_use = 0;
1015         }
1016
1017 // Synchronize EDL clips
1018         for( int i = 0; i < mwindow->edl->clips.total; i++ ) {
1019                 int exists = 0;
1020
1021 // Look for clip in existing listitems
1022                 for( int j = 0; j < assets.total && !exists; j++ ) {
1023                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1024
1025                         if( picon->id == mwindow->edl->clips.values[i]->id ) {
1026                                 picon->edl = mwindow->edl->clips.values[i];
1027                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
1028                                 exists = 1;
1029                                 picon->in_use = 1;
1030                         }
1031                 }
1032
1033 // Create new listitem
1034                 if( !exists ) {
1035                         AssetPicon *picon = new AssetPicon(mwindow,
1036                                 this, mwindow->edl->clips.values[i]);
1037                         picon->create_objects();
1038                         assets.append(picon);
1039                 }
1040         }
1041
1042 // Synchronize EDL assets
1043         for( Asset *current = mwindow->edl->assets->first;
1044                 current;
1045                 current = NEXT ) {
1046                 int exists = 0;
1047
1048 // Look for asset in existing listitems
1049                 for( int j = 0; j < assets.total && !exists; j++ ) {
1050                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1051
1052                         if( picon->id == current->id ) {
1053                                 picon->indexable = current;
1054                                 exists = 1;
1055                                 picon->in_use = 1;
1056                                 break;
1057                         }
1058                 }
1059
1060 // Create new listitem
1061                 if( !exists ) {
1062                         AssetPicon *picon = new AssetPicon(mwindow,
1063                                 this, current);
1064                         picon->create_objects();
1065                         assets.append(picon);
1066                 }
1067         }
1068
1069         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1070         mwindow->gui->default_message();
1071         mwindow->gui->unlock_window();
1072
1073 // Synchronize nested EDLs
1074         for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) {
1075                 int exists = 0;
1076                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
1077
1078 // Look for asset in existing listitems
1079                 for( int j = 0; j < assets.total && !exists; j++ ) {
1080                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1081
1082                         if( picon->id == indexable->id ) {
1083                                 picon->indexable = indexable;
1084                                 exists = 1;
1085                                 picon->in_use = 1;
1086                                 break;
1087                         }
1088                 }
1089
1090 // Create new listitem
1091                 if( !exists ) {
1092                         AssetPicon *picon = new AssetPicon(mwindow,
1093                                 this, indexable);
1094                         picon->create_objects();
1095                         assets.append(picon);
1096                 }
1097         }
1098
1099         for( int i = assets.size() - 1; i >= 0; i-- ) {
1100                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1101                 if( !picon->in_use ) {
1102                         delete picon;
1103                         assets.remove_number(i);
1104                 }
1105         }
1106 }
1107
1108 void AWindowGUI::update_picon(Indexable *indexable)
1109 {
1110         VIcon *vicon = 0;
1111         for( int i = 0; i < assets.total; i++ ) {
1112                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1113                 if( picon->indexable == indexable ||
1114                     picon->edl == (EDL *)indexable ) {
1115                         char name[BCTEXTLEN];
1116                         FileSystem fs;
1117                         fs.extract_name(name, indexable->path);
1118                         picon->set_text(name);
1119                         vicon = picon->vicon;
1120                         break;
1121                 }
1122         }
1123         if( vicon ) {
1124                 stop_vicon_drawing();
1125                 vicon->clear_images();
1126                 vicon->reset(indexable->get_frame_rate());
1127                 start_vicon_drawing();
1128         }
1129 }
1130
1131 void AWindowGUI::sort_assets()
1132 {
1133         switch( mwindow->edl->session->awindow_folder ) {
1134         case AW_AEFFECT_FOLDER:
1135                 sort_picons(&aeffects);
1136                 break;
1137         case AW_VEFFECT_FOLDER:
1138                 sort_picons(&veffects);
1139                 break;
1140         case AW_ATRANSITION_FOLDER:
1141                 sort_picons(&atransitions);
1142                 break;
1143         case AW_VTRANSITION_FOLDER:
1144                 sort_picons(&vtransitions);
1145                 break;
1146         case AW_LABEL_FOLDER:
1147                 sort_picons(&labellist);
1148                 break;
1149         default:
1150                 sort_picons(&assets);
1151         }
1152 // reset xyposition
1153         asset_list->update_format(asset_list->get_format(), 0);
1154         update_assets();
1155 }
1156
1157 void AWindowGUI::sort_folders()
1158 {
1159         sort_picons(&folders);
1160         folder_list->update_format(folder_list->get_format(), 0);
1161         update_assets();
1162 }
1163
1164 void AWindowGUI::collect_assets()
1165 {
1166         int i = 0;
1167         mwindow->session->drag_assets->remove_all();
1168         mwindow->session->drag_clips->remove_all();
1169         while(1)
1170         {
1171                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
1172                 if( !result ) break;
1173
1174                 if( result->indexable ) mwindow->session->drag_assets->append(result->indexable);
1175                 if( result->edl ) mwindow->session->drag_clips->append(result->edl);
1176         }
1177 }
1178
1179 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1180         ArrayList<BC_ListBoxItem*> *src, int folder)
1181 {
1182 // Remove current pointers
1183         dst[0].remove_all();
1184         dst[1].remove_all_objects();
1185
1186 // Create new pointers
1187         for( int i = 0; i < src->total; i++ ) {
1188                 AssetPicon *picon = (AssetPicon*)src->values[i];
1189                 if( folder < 0 ||
1190                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1191                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1192                         BC_ListBoxItem *item2, *item1;
1193                         dst[0].append(item1 = picon);
1194                         if( picon->edl )
1195                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1196                         else
1197                         if( picon->label && picon->label->textstr )
1198                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1199                         else
1200                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1201                         item1->set_autoplace_text(1);
1202                         item2->set_autoplace_text(1);
1203                 }
1204         }
1205 }
1206
1207 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1208 {
1209         int done = 0;
1210         while(!done)
1211         {
1212                 done = 1;
1213                 for( int i = 0; i < src->total - 1; i++ ) {
1214                         BC_ListBoxItem *item1 = src->values[i];
1215                         BC_ListBoxItem *item2 = src->values[i + 1];
1216                         item1->set_autoplace_icon(1);
1217                         item2->set_autoplace_icon(1);
1218                         item1->set_autoplace_text(1);
1219                         item2->set_autoplace_text(1);
1220                         if( strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1221                                 src->values[i + 1] = item1;
1222                                 src->values[i] = item2;
1223                                 done = 0;
1224                         }
1225                 }
1226         }
1227 }
1228
1229
1230 void AWindowGUI::filter_displayed_assets()
1231 {
1232         //allow_iconlisting = 1;
1233         asset_titles[0] = C_("Title");
1234         asset_titles[1] = _("Comments");
1235
1236         switch( mwindow->edl->session->awindow_folder ) {
1237         case AW_AEFFECT_FOLDER:
1238                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1239                 break;
1240         case AW_VEFFECT_FOLDER:
1241                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1242                 break;
1243         case AW_ATRANSITION_FOLDER:
1244                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1245                 break;
1246         case AW_VTRANSITION_FOLDER:
1247                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1248                 break;
1249         case AW_LABEL_FOLDER:
1250                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1251                 asset_titles[0] = _("Time Stamps");
1252                 asset_titles[1] = C_("Title");
1253                 //allow_iconlisting = 0;
1254                 break;
1255         default:
1256                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1257                 break;
1258         }
1259
1260         // Ensure the current folder icon is highlighted
1261         int selected_folder = mwindow->edl->session->awindow_folder;
1262         for( int i = 0; i < folders.total; i++ ) {
1263                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1264                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1265                 folder_item->set_selected(selected);
1266         }
1267 }
1268
1269
1270 void AWindowGUI::update_assets()
1271 {
1272         update_folder_list();
1273         update_asset_list();
1274         labellist.remove_all_objects();
1275         create_label_folder();
1276         filter_displayed_assets();
1277
1278         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1279                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1280         }
1281         int folder_xposition = folder_list->get_xposition();
1282         int folder_yposition = folder_list->get_yposition();
1283         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1284
1285         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1286                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1287         }
1288         int asset_xposition = asset_list->get_xposition();
1289         int asset_yposition = asset_list->get_yposition();
1290         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1291                 displayed_folder = mwindow->edl->session->awindow_folder;
1292                 asset_xposition = asset_yposition = 0;
1293         }
1294         asset_list->update(displayed_assets, asset_titles,
1295                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1296                 asset_xposition, asset_yposition, -1, 0);
1297         asset_list->center_selection();
1298
1299         flush();
1300         return;
1301 }
1302
1303 void AWindowGUI::update_effects()
1304 {
1305         aeffects.remove_all_objects();
1306         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1307         veffects.remove_all_objects();
1308         create_persistent_folder(&veffects, 0, 1, 1, 0);
1309         atransitions.remove_all_objects();
1310         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1311         vtransitions.remove_all_objects();
1312         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1313 }
1314
1315 int AWindowGUI::folder_number(const char *name)
1316 {
1317         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1318                 if( !strcasecmp(name, folder_names[i]) ) return i;
1319         }
1320         return AW_NO_FOLDER;
1321 }
1322
1323 int AWindowGUI::drag_motion()
1324 {
1325         if( get_hidden() ) return 0;
1326
1327         int result = 0;
1328         return result;
1329 }
1330
1331 int AWindowGUI::drag_stop()
1332 {
1333         if( get_hidden() ) return 0;
1334
1335         return 0;
1336 }
1337
1338 Indexable* AWindowGUI::selected_asset()
1339 {
1340         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1341         return picon ? picon->indexable : 0;
1342 }
1343
1344 PluginServer* AWindowGUI::selected_plugin()
1345 {
1346         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1347         return picon ? picon->plugin : 0;
1348 }
1349
1350 AssetPicon* AWindowGUI::selected_folder()
1351 {
1352         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1353         return picon;
1354 }
1355
1356
1357
1358
1359
1360
1361
1362
1363 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1364  : BC_SubWindow(x, y, w, h)
1365 {
1366         this->mwindow = mwindow;
1367         this->gui = gui;
1368 }
1369 AWindowDivider::~AWindowDivider()
1370 {
1371 }
1372
1373 int AWindowDivider::button_press_event()
1374 {
1375         if( is_event_win() && cursor_inside() ) {
1376                 mwindow->session->current_operation = DRAG_PARTITION;
1377                 return 1;
1378         }
1379         return 0;
1380 }
1381
1382 int AWindowDivider::cursor_motion_event()
1383 {
1384         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1385                 int wmin = 25;
1386                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1387                 int fw = gui->get_relative_cursor_x();
1388                 if( fw > wmax ) fw = wmax;
1389                 if( fw < wmin ) fw = wmin;
1390                 mwindow->session->afolders_w = fw;
1391                 mwindow->theme->get_awindow_sizes(gui);
1392                 gui->reposition_objects();
1393                 gui->flush();
1394         }
1395         return 0;
1396 }
1397
1398 int AWindowDivider::button_release_event()
1399 {
1400         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1401                 mwindow->session->current_operation = NO_OPERATION;
1402                 return 1;
1403         }
1404         return 0;
1405 }
1406
1407
1408
1409
1410
1411
1412 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1413  : BC_ListBox(x, y, w, h,
1414                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1415                         LISTBOX_ICONS : LISTBOX_TEXT,
1416                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1417                 0,                // Titles for columns.  Set to 0 for no titles
1418                 0,                // width of each column
1419                 1,                // Total columns.
1420                 0,                // Pixel of top of window.
1421                 0,                // If this listbox is a popup window
1422                 LISTBOX_SINGLE,   // Select one item or multiple items
1423                 ICON_TOP,         // Position of icon relative to text of each item
1424                 1)                // Allow drags
1425 {
1426         this->mwindow = mwindow;
1427         this->gui = gui;
1428         set_drag_scroll(0);
1429 }
1430
1431 AWindowFolders::~AWindowFolders()
1432 {
1433 }
1434
1435 int AWindowFolders::selection_changed()
1436 {
1437         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1438         if( picon ) {
1439                 gui->stop_vicon_drawing();
1440
1441                 if( get_button_down() && get_buttonpress() == 3 ) {
1442                         gui->folderlist_menu->update_titles();
1443                         gui->folderlist_menu->activate_menu();
1444                 }
1445
1446                 mwindow->edl->session->awindow_folder = picon->foldernum;
1447                 gui->asset_list->draw_background();
1448                 gui->async_update_assets();
1449
1450                 gui->start_vicon_drawing();
1451         }
1452         return 1;
1453 }
1454
1455 int AWindowFolders::button_press_event()
1456 {
1457         int result = 0;
1458
1459         result = BC_ListBox::button_press_event();
1460
1461         if( !result ) {
1462                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1463                         gui->folderlist_menu->update_titles();
1464                         gui->folderlist_menu->activate_menu();
1465                         result = 1;
1466                 }
1467         }
1468
1469
1470         return result;
1471 }
1472
1473
1474
1475
1476
1477
1478
1479 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1480  : BC_ListBox(x, y, w, h,
1481                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1482                         LISTBOX_ICONS : LISTBOX_TEXT,
1483                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1484                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1485                 mwindow->edl->session->asset_columns, // width of each column
1486                 1,                // Total columns.
1487                 0,                // Pixel of top of window.
1488                 0,                // If this listbox is a popup window
1489                 LISTBOX_MULTIPLE, // Select one item or multiple items
1490                 ICON_TOP,         // Position of icon relative to text of each item
1491                 -1)               // Allow drags, require shift for scrolling
1492 {
1493         this->mwindow = mwindow;
1494         this->gui = gui;
1495         set_drag_scroll(0);
1496         set_scroll_stretch(1, 1);
1497 }
1498
1499 AWindowAssets::~AWindowAssets()
1500 {
1501 }
1502
1503 int AWindowAssets::button_press_event()
1504 {
1505         int result = 0;
1506
1507         result = BC_ListBox::button_press_event();
1508
1509         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1510                 BC_ListBox::deactivate_selection();
1511                 int folder = mwindow->edl->session->awindow_folder;
1512                 switch( folder ) {
1513                 case AW_AEFFECT_FOLDER:
1514                 case AW_VEFFECT_FOLDER:
1515                 case AW_ATRANSITION_FOLDER:
1516                 case AW_VTRANSITION_FOLDER:
1517                         gui->effectlist_menu->update();
1518                         gui->effectlist_menu->activate_menu();
1519                         break;
1520                 case AW_LABEL_FOLDER:
1521                         gui->labellist_menu->update();
1522                         gui->labellist_menu->activate_menu();
1523                         break;
1524                 case AW_CLIP_FOLDER:
1525                         gui->cliplist_menu->update();
1526                         gui->cliplist_menu->activate_menu();
1527                         break;
1528                 case AW_MEDIA_FOLDER:
1529                 case AW_PROXY_FOLDER:
1530                         gui->assetlist_menu->update_titles();
1531                         gui->assetlist_menu->activate_menu();
1532                         break;
1533                 }
1534                 result = 1;
1535         }
1536
1537         return result;
1538 }
1539
1540
1541 int AWindowAssets::handle_event()
1542 {
1543         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
1544         if( !asset_picon ) return 0;
1545         switch( mwindow->edl->session->awindow_folder ) {
1546         case AW_AEFFECT_FOLDER:
1547         case AW_VEFFECT_FOLDER:
1548         case AW_ATRANSITION_FOLDER:
1549         case AW_VTRANSITION_FOLDER: return 1;
1550         }
1551         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1552                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1553         if( !vwindow || !vwindow->is_running() ) return 1;
1554
1555         vwindow->gui->lock_window("AWindowAssets::handle_event");
1556         if( asset_picon->indexable )
1557                 vwindow->change_source(asset_picon->indexable);
1558         else if( asset_picon->edl )
1559                 vwindow->change_source(asset_picon->edl);
1560         vwindow->gui->unlock_window();
1561         return 1;
1562 }
1563
1564 int AWindowAssets::selection_changed()
1565 {
1566 // Show popup window
1567         AssetPicon *item;
1568         if( get_button_down() && get_buttonpress() == 3 &&
1569             (item = (AssetPicon*)get_selection(0, 0)) ) {
1570                 int folder = mwindow->edl->session->awindow_folder;
1571                 switch( folder ) {
1572                 case AW_AEFFECT_FOLDER:
1573                 case AW_VEFFECT_FOLDER:
1574                 case AW_ATRANSITION_FOLDER:
1575                 case AW_VTRANSITION_FOLDER:
1576                         gui->effectlist_menu->update();
1577                         gui->effectlist_menu->activate_menu();
1578                         break;
1579                 case AW_LABEL_FOLDER:
1580                         if( !item->label ) break;
1581                         gui->label_menu->activate_menu();
1582                         break;
1583                 case AW_CLIP_FOLDER:
1584                         if( !item->indexable && !item->edl ) break;
1585                         gui->clip_menu->update();
1586                         gui->clip_menu->activate_menu();
1587                         break;
1588                 default:
1589                         if( !item->indexable && !item->edl ) break;
1590                         gui->asset_menu->update();
1591                         gui->asset_menu->activate_menu();
1592                         break;
1593                 }
1594
1595                 BC_ListBox::deactivate_selection();
1596                 return 1;
1597         }
1598         else if( get_button_down() && get_buttonpress() == 1 &&
1599                  (item = (AssetPicon*)get_selection(0, 0)) ) {
1600                 VIcon *vicon = 0;
1601                 if( !gui->vicon_thread->viewing ) {
1602                         vicon = item->vicon;
1603                 }
1604                 gui->vicon_thread->set_view_popup(vicon);
1605
1606         }
1607         return 0;
1608 }
1609
1610 void AWindowAssets::draw_background()
1611 {
1612         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1613         set_color(BC_WindowBase::get_resources()->audiovideo_color);
1614         set_font(LARGEFONT);
1615         int aw_folder = mwindow->edl->session->awindow_folder;
1616         if( aw_folder < 0 ) return;
1617         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
1618         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
1619                 aw_name, -1, get_bg_surface());
1620 }
1621
1622 int AWindowAssets::drag_start_event()
1623 {
1624         int collect_pluginservers = 0;
1625         int collect_assets = 0;
1626
1627         if( BC_ListBox::drag_start_event() ) {
1628                 switch( mwindow->edl->session->awindow_folder ) {
1629                 case AW_AEFFECT_FOLDER:
1630                         mwindow->session->current_operation = DRAG_AEFFECT;
1631                         collect_pluginservers = 1;
1632                         break;
1633                 case AW_VEFFECT_FOLDER:
1634                         mwindow->session->current_operation = DRAG_VEFFECT;
1635                         collect_pluginservers = 1;
1636                         break;
1637                 case AW_ATRANSITION_FOLDER:
1638                         mwindow->session->current_operation = DRAG_ATRANSITION;
1639                         collect_pluginservers = 1;
1640                         break;
1641                 case AW_VTRANSITION_FOLDER:
1642                         mwindow->session->current_operation = DRAG_VTRANSITION;
1643                         collect_pluginservers = 1;
1644                         break;
1645                 case AW_LABEL_FOLDER:
1646                         // do nothing!
1647                         break;
1648                 default:
1649                         mwindow->session->current_operation = DRAG_ASSET;
1650                         collect_assets = 1;
1651                         break;
1652                 }
1653
1654                 if( collect_pluginservers ) {
1655                         int i = 0;
1656                         mwindow->session->drag_pluginservers->remove_all();
1657                         while(1)
1658                         {
1659                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1660                                 if( !result ) break;
1661
1662                                 mwindow->session->drag_pluginservers->append(result->plugin);
1663                         }
1664                 }
1665
1666                 if( collect_assets ) {
1667                         gui->collect_assets();
1668                 }
1669
1670                 return 1;
1671         }
1672         return 0;
1673 }
1674
1675 int AWindowAssets::drag_motion_event()
1676 {
1677         BC_ListBox::drag_motion_event();
1678         unlock_window();
1679
1680         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1681         mwindow->gui->drag_motion();
1682         mwindow->gui->unlock_window();
1683
1684         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
1685                 VWindow *vwindow = mwindow->vwindows.get(i);
1686                 if( !vwindow->is_running() ) continue;
1687                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1688                 vwindow->gui->drag_motion();
1689                 vwindow->gui->unlock_window();
1690         }
1691
1692         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1693         mwindow->cwindow->gui->drag_motion();
1694         mwindow->cwindow->gui->unlock_window();
1695
1696         lock_window("AWindowAssets::drag_motion_event");
1697         return 0;
1698 }
1699
1700 int AWindowAssets::drag_stop_event()
1701 {
1702         int result = 0;
1703
1704         result = gui->drag_stop();
1705
1706         unlock_window();
1707
1708         if( !result ) {
1709                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1710                 result = mwindow->gui->drag_stop();
1711                 mwindow->gui->unlock_window();
1712         }
1713
1714         if( !result ) {
1715                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
1716                         VWindow *vwindow = mwindow->vwindows.get(i);
1717                         if( !vwindow ) continue;
1718                         if( !vwindow->is_running() ) continue;
1719                         if( vwindow->gui->is_hidden() ) continue;
1720                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1721                         if( vwindow->gui->cursor_above() &&
1722                             vwindow->gui->get_cursor_over_window() ) {
1723                                 result = vwindow->gui->drag_stop();
1724                         }
1725                         vwindow->gui->unlock_window();
1726                 }
1727         }
1728
1729         if( !result ) {
1730                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1731                 result = mwindow->cwindow->gui->drag_stop();
1732                 mwindow->cwindow->gui->unlock_window();
1733         }
1734
1735         lock_window("AWindowAssets::drag_stop_event");
1736
1737         if( result ) get_drag_popup()->set_animation(0);
1738
1739         BC_ListBox::drag_stop_event();
1740         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1741         return 0;
1742 }
1743
1744 int AWindowAssets::column_resize_event()
1745 {
1746         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1747         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1748         return 1;
1749 }
1750
1751 int AWindowAssets::focus_in_event()
1752 {
1753         gui->start_vicon_drawing();
1754         return 0;
1755 }
1756
1757 int AWindowAssets::focus_out_event()
1758 {
1759         gui->stop_vicon_drawing();
1760         return BC_ListBox::focus_out_event();
1761 }
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1775  : BC_Button(x, y, mwindow->theme->newbin_data)
1776 {
1777         this->mwindow = mwindow;
1778         this->gui = gui;
1779         set_tooltip(_("New bin"));
1780 }
1781
1782 int AWindowNewFolder::handle_event()
1783 {
1784         gui->newfolder_thread->start_new_folder();
1785         return 1;
1786 }
1787
1788 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1789  : BC_Button(x, y, mwindow->theme->deletebin_data)
1790 {
1791         this->mwindow = mwindow;
1792         this->gui = gui;
1793         set_tooltip(_("Delete bin"));
1794 }
1795
1796 int AWindowDeleteFolder::handle_event()
1797 {
1798         if( gui->folder_list->get_selection(0, 0) ) {
1799                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1800                 mwindow->delete_folder(folder->get_text());
1801         }
1802         return 1;
1803 }
1804
1805 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1806  : BC_Button(x, y, mwindow->theme->renamebin_data)
1807 {
1808         this->mwindow = mwindow;
1809         this->gui = gui;
1810         set_tooltip(_("Rename bin"));
1811 }
1812
1813 int AWindowRenameFolder::handle_event()
1814 {
1815         return 1;
1816 }
1817
1818 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1819  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1820 {
1821         this->mwindow = mwindow;
1822         this->gui = gui;
1823         set_tooltip(_("Delete asset from disk"));
1824 }
1825
1826 int AWindowDeleteDisk::handle_event()
1827 {
1828         return 1;
1829 }
1830
1831 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1832  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1833 {
1834         this->mwindow = mwindow;
1835         this->gui = gui;
1836         set_tooltip(_("Delete asset from project"));
1837 }
1838
1839 int AWindowDeleteProject::handle_event()
1840 {
1841         return 1;
1842 }
1843
1844 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1845 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
1846 // {
1847 //      this->mwindow = mwindow;
1848 //      this->gui = gui;
1849 //      set_tooltip(_("Edit information on asset"));
1850 // }
1851 // 
1852 // int AWindowInfo::handle_event()
1853 // {
1854 //      int cur_x, cur_y;
1855 //      gui->get_abs_cursor(cur_x, cur_y, 0);
1856 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
1857 //      return 1;
1858 // }
1859
1860 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1861  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1862 {
1863         this->mwindow = mwindow;
1864         this->gui = gui;
1865         set_tooltip(_("Redraw index"));
1866 }
1867
1868 int AWindowRedrawIndex::handle_event()
1869 {
1870         return 1;
1871 }
1872
1873 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1874  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1875 {
1876         this->mwindow = mwindow;
1877         this->gui = gui;
1878         set_tooltip(_("Paste asset on recordable tracks"));
1879 }
1880
1881 int AWindowPaste::handle_event()
1882 {
1883         return 1;
1884 }
1885
1886 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1887  : BC_Button(x, y, mwindow->theme->appendasset_data)
1888 {
1889         this->mwindow = mwindow;
1890         this->gui = gui;
1891         set_tooltip(_("Append asset in new tracks"));
1892 }
1893
1894 int AWindowAppend::handle_event()
1895 {
1896         return 1;
1897 }
1898
1899 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1900  : BC_Button(x, y, mwindow->theme->viewasset_data)
1901 {
1902         this->mwindow = mwindow;
1903         this->gui = gui;
1904         set_tooltip(_("View asset"));
1905 }
1906
1907 int AWindowView::handle_event()
1908 {
1909         return 1;
1910 }
1911
1912 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
1913  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
1914 {
1915         this->mwindow = mwindow;
1916         this->gui = gui;
1917 }
1918
1919 void AddTools::create_objects()
1920 {
1921         uint64_t vis = 0;
1922         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
1923         vis |= 1 << PLUGIN_LADSPA_ID;
1924         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
1925         vis |= 1 << PLUGIN_FFMPEG_ID;
1926         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1927                 PluginServer *plugin = MWindow::plugindb->get(i);
1928                 if( !plugin->audio && !plugin->video ) continue;
1929                 int idx = plugin->dir_idx;
1930                 uint32_t msk = 1 << idx;
1931                 if( (msk & vis) != 0 ) continue;
1932                 vis |= msk;
1933                 char parent[BCTEXTLEN];
1934                 strcpy(parent, plugin->path);
1935                 char *bp = strrchr(parent, '/');
1936                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
1937                 if( !bp ) bp = parent; else ++bp;
1938                 add_item(new AddPluginItem(this, bp, idx));
1939         }
1940 }
1941
1942 #if 0
1943 // plugin_dirs list from toplevel makefile include plugin_defs
1944 N_("ladspa")
1945 N_("ffmpeg")
1946 N_("audio_tools")
1947 N_("audio_transitions")
1948 N_("blending")
1949 N_("colors")
1950 N_("exotic")
1951 N_("transforms")
1952 N_("tv_effects")
1953 N_("video_tools")
1954 N_("video_transitions")
1955 #endif
1956
1957 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
1958  : BC_MenuItem(_(text))
1959 {
1960         this->menu = menu;
1961         this->idx = idx;
1962         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
1963         int chk = (msk & vis) ? 1 : 0;
1964         set_checked(chk);
1965 }
1966
1967 int AddPluginItem::handle_event()
1968 {
1969         int chk = get_checked() ^ 1;
1970         set_checked(chk);
1971         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
1972         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
1973         menu->gui->update_effects();
1974         menu->gui->save_defaults(menu->mwindow->defaults);
1975         menu->gui->async_update_assets();
1976         return 1;
1977 }
1978
1979 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
1980  : BC_Toggle(x, y, images, agui->vicon_drawing)
1981 {
1982         this->agui = agui;
1983         set_tooltip(_("draw vicons"));
1984 }
1985
1986 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
1987 {
1988         int text_line = -1, toggle_x = -1, toggle_y = -1;
1989         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
1990         BC_Toggle::calculate_extents(agui, images, 1,
1991                 &text_line, ww, hh, &toggle_x, &toggle_y,
1992                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
1993 }
1994
1995 AVIconDrawing::~AVIconDrawing()
1996 {
1997 }
1998
1999 int AVIconDrawing::handle_event()
2000 {
2001         agui->vicon_drawing = get_value();
2002         if( agui->vicon_drawing )
2003                 agui->start_vicon_drawing();
2004         else
2005                 agui->stop_vicon_drawing();
2006         return 1;
2007 }
2008
2009
2010 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2011  : BC_MenuItem("")
2012 {
2013         this->mwindow = mwindow;
2014         this->gui = gui;
2015 }
2016
2017 int AWindowListFormat::handle_event()
2018 {
2019         gui->stop_vicon_drawing();
2020
2021         EDLSession *session = mwindow->edl->session;
2022         switch( session->assetlist_format ) {
2023         case ASSETS_TEXT:
2024                 session->assetlist_format = ASSETS_ICONS;
2025                 break;
2026         case ASSETS_ICONS:
2027                 session->assetlist_format = ASSETS_TEXT;
2028                 break;
2029         }
2030
2031         gui->asset_list->update_format(session->assetlist_format, 1);
2032         if( !mwindow->awindow->gui->allow_iconlisting ) {
2033                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2034         }
2035
2036         gui->start_vicon_drawing();
2037         return 1;
2038 }
2039
2040 void AWindowListFormat::update()
2041 {
2042         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2043                 (char*)_("Display icons") : (char*)_("Display text"));
2044 }
2045
2046 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2047  : BC_MenuItem(_("Sort items"))
2048 {
2049         this->mwindow = mwindow;
2050         this->gui = gui;
2051 }
2052
2053 int AWindowListSort::handle_event()
2054 {
2055         gui->sort_assets();
2056         return 1;
2057 }
2058