tweak loadmode icons/tooltips, change snap/grabshot default path, fix broken vicon...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / assetpopup.C
index d8142f02606b69a93f8c47de21974fdae712b72a..ba828166fa48e285de9f62f922c55a863a94007b 100644 (file)
@@ -77,6 +77,7 @@ void AssetPopup::create_objects()
        add_item(info = new AssetPopupInfo(mwindow, this));
        add_item(format = new AWindowListFormat(mwindow, gui));
        add_item(open_edl = new AssetPopupOpenEDL(mwindow, this));
+       add_item(close_edl = new AssetPopupCloseEDL(mwindow, gui));
        add_item(to_clip = new AssetPopupToClip(mwindow, this));
        add_item(sort = new AssetPopupSort(mwindow, this));
        add_item(index = new AssetPopupBuildIndex(mwindow, this));
@@ -145,6 +146,28 @@ int AssetPopup::update()
        format->update();
        int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
        gui->collect_assets(proxy);
+       int enable_open = 0;
+       int assets_total = mwindow->session->drag_assets->size();
+       Indexable *idxbl = !assets_total ? 0 :
+               mwindow->session->drag_assets->get(0);
+       if( idxbl ) {
+               if( idxbl->is_asset ) {
+                       Asset *asset = (Asset *)idxbl;
+                       if( asset->format == FILE_REF )
+                               enable_open = 1;
+               }
+               else
+                       enable_open = 1;
+       }
+       open_edl->set_enabled(enable_open);
+       int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
+       close_edl->set_enabled(enable_close);
+       int enable_clip = 0;
+       for( int i=0; !enable_clip && i<assets_total; ++i ) {
+               Indexable *idxbl = mwindow->session->drag_assets->get(i);
+               if( !idxbl->is_asset ) enable_clip = 1;
+       }
+       to_clip->set_enabled(enable_clip);
        return 0;
 }
 
@@ -194,16 +217,56 @@ AssetPopupOpenEDL::~AssetPopupOpenEDL()
 int AssetPopupOpenEDL::handle_event()
 {
        int assets_total = mwindow->session->drag_assets->size();
-       if( assets_total ) {
-               popup->unlock_window();
-               Indexable *idxbl = mwindow->session->drag_assets->get(0);
-               EDL *edl = idxbl && !idxbl->is_asset ? (EDL *)idxbl : 0;
-               if( edl )
-                       mwindow->stack_push(edl);
-               else
-                       eprintf(_("media is not EDL:\n%s"), idxbl->path);
-               popup->lock_window("AssetPopupOpenEDL::handle_event");
+       if( !assets_total ) return 1;
+       popup->unlock_window();
+       EDL *edl = 0;
+       Indexable *idxbl = mwindow->session->drag_assets->get(0);
+       if( idxbl->is_asset ) {
+               Asset *asset = (Asset *)idxbl;
+               if( asset->format == FILE_REF ) {
+                       FileXML xml_file;
+                       const char *filename = asset->path;
+                       if( xml_file.read_from_file(filename, 1) ) {
+                               eprintf(_("Error: unable to open:\n  %s"), filename);
+                               return 1;
+                       }
+                       edl = new EDL;
+                       edl->create_objects();
+                       if( edl->load_xml(&xml_file, LOAD_ALL) ) {
+                               eprintf(_("Error: unable to load:\n  %s"), filename);
+                               edl->remove_user();
+                               return 1;
+                       }
+               }
+       }
+       else {
+               edl = (EDL *)idxbl;
        }
+       if( edl )
+               mwindow->stack_push(edl, idxbl);
+       else
+               eprintf(_("media is not EDL:\n%s"), idxbl->path);
+       popup->lock_window("AssetPopupOpenEDL::handle_event");
+       return 1;
+}
+
+AssetPopupCloseEDL::AssetPopupCloseEDL(MWindow *mwindow, AWindowGUI *gui)
+ : BC_MenuItem(_("Close EDL"))
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+}
+AssetPopupCloseEDL::~AssetPopupCloseEDL()
+{
+}
+
+int AssetPopupCloseEDL::handle_event()
+{
+       gui->unlock_window();
+       mwindow->gui->lock_window("AssetPopupCloseEDL::handle_event");
+       mwindow->stack_pop();
+       mwindow->gui->unlock_window();
+       gui->lock_window("AssetPopupCloseEDL::handle_event");
        return 1;
 }
 
@@ -463,16 +526,13 @@ AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
 
 AssetListMenu::~AssetListMenu()
 {
-       if( !shots_displayed ) {
-               delete asset_snapshot;
-               delete asset_grabshot;
-       }
 }
 
 void AssetListMenu::create_objects()
 {
        add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
        add_item(format = new AWindowListFormat(mwindow, gui));
+       add_item(close_edl = new AssetPopupCloseEDL(mwindow, gui));
        add_item(select_used = new AssetSelectUsed(mwindow, gui));
        BC_SubMenu *submenu;
        select_used->add_submenu(submenu = new BC_SubMenu());
@@ -497,7 +557,7 @@ void AssetListMenu::create_objects()
        grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
        grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
        grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"),  GRABSHOT_PPM));
-       update_titles(shots_displayed = 1);
+       update_titles(1);
 }
 
 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
@@ -520,16 +580,10 @@ int AssetPopupLoadFile::handle_event()
 void AssetListMenu::update_titles(int shots)
 {
        format->update();
-       if( shots && !shots_displayed ) {
-               shots_displayed = 1;
-               add_item(asset_snapshot);
-               add_item(asset_grabshot);
-       }
-       else if( !shots && shots_displayed ) {
-               shots_displayed = 0;
-               remove_item(asset_snapshot);
-               remove_item(asset_grabshot);
-       }
+       int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
+       close_edl->set_enabled(enable_close);
+       asset_snapshot->set_enabled(shots);
+       asset_grabshot->set_enabled(shots);
 }
 
 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
@@ -733,7 +787,8 @@ void AssetPasteDialog::handle_done_event(int result)
        MWindow *mwindow = paste->mwindow;
        mwindow->interrupt_indexes();
        mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
-       result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
+       result = mwindow->load_filenames(&path_list,
+               LOADMODE_RESOURCESONLY, LOADMODE_EDL_CLIP, 0);
        mwindow->gui->unlock_window();
        path_list.remove_all_objects();
        mwindow->save_backup();
@@ -837,12 +892,13 @@ int SnapshotMenuItem::handle_event()
        if( !edl->have_video() ) return 1;
 
        Preferences *preferences = mwindow->preferences;
-       char filename[BCTEXTLEN];
+       char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
+       File::getenv_path(snapshot_path, preferences->snapshot_path);
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
-               preferences->snapshot_path, _("snap"),
+               snapshot_path, _("snap"),
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);
@@ -1062,12 +1118,13 @@ int GrabshotPopup::grab_event(XEvent *event)
 
        MWindow *mwindow = grab_thread->mwindow;
        Preferences *preferences = mwindow->preferences;
-       char filename[BCTEXTLEN];
+       char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
+       File::getenv_path(snapshot_path, preferences->snapshot_path);
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
-               preferences->snapshot_path, _("grab"),
+               snapshot_path, _("grab"),
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);