add clip folders, icon margins, fix safe regions, update neophyte, fix folder edl...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / assetpopup.C
index 238a73c694addb15f8685ecf71a89ef4971ba8ce..59e13131507e0b2cbcb685078069de58cd25744c 100644 (file)
 #include "edl.h"
 #include "edlsession.h"
 #include "file.h"
+#include "filesystem.h"
 #include "filexml.h"
 #include "language.h"
+#include "loadfile.h"
 #include "localsession.h"
 #include "mainerror.h"
 #include "mainindexes.h"
+#include "mainmenu.h"
 #include "mainsession.h"
 #include "mwindow.h"
 #include "mwindowgui.h"
@@ -73,10 +76,7 @@ void AssetPopup::create_objects()
        BC_SubMenu *submenu;
        add_item(info = new AssetPopupInfo(mwindow, this));
        add_item(format = new AWindowListFormat(mwindow, gui));
-       add_item(menu_item = new BC_MenuItem(_("Sort...")));
-       menu_item->add_submenu(submenu = new BC_SubMenu());
-       submenu->add_submenuitem(new AssetPopupSortNames(mwindow, this));
-       submenu->add_submenuitem(new AssetPopupSortTimes(mwindow, this));
+       add_item(new AssetPopupSort(mwindow, this));
        add_item(index = new AssetPopupBuildIndex(mwindow, this));
        add_item(view = new AssetPopupView(mwindow, this));
        add_item(view_window = new AssetPopupViewWindow(mwindow, this));
@@ -102,8 +102,7 @@ void AssetPopup::paste_assets()
 
        gui->collect_assets();
        mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
-               mwindow->edl->tracks->first,
-               0);   // do not overwrite
+               mwindow->edl->tracks->first, 0);   // do not overwrite
 
        gui->unlock_window();
        mwindow->gui->unlock_window();
@@ -160,10 +159,13 @@ int AssetPopupInfo::handle_event()
 {
        int cur_x, cur_y;
        popup->gui->get_abs_cursor(cur_x, cur_y);
-       if( mwindow->session->drag_assets->size() ) {
-               AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
-               asset_edit->edit_asset(
-                       mwindow->session->drag_assets->values[0], cur_x, cur_y);
+       int n = mwindow->session->drag_assets->size();
+       if( n > 0 ) {
+               for( int i=0; i<n; ++i ) {
+                       AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
+                       asset_edit->edit_asset(
+                               mwindow->session->drag_assets->values[i], cur_x-30*i, cur_y-30*i);
+               }
        }
        else if( mwindow->session->drag_clips->size() ) {
                popup->gui->awindow->clip_edit->edit_clip(
@@ -192,37 +194,20 @@ int AssetPopupBuildIndex::handle_event()
 }
 
 
-AssetPopupSortNames::AssetPopupSortNames(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Sort names"))
-{
-       this->mwindow = mwindow;
-       this->popup = popup;
-}
-
-AssetPopupSortNames::~AssetPopupSortNames()
-{
-}
-
-int AssetPopupSortNames::handle_event()
-{
-       mwindow->awindow->gui->sort_assets(0);
-       return 1;
-}
-
-AssetPopupSortTimes::AssetPopupSortTimes(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Sort times"))
+AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
+ : BC_MenuItem(_("Sort"))
 {
        this->mwindow = mwindow;
        this->popup = popup;
 }
 
-AssetPopupSortTimes::~AssetPopupSortTimes()
+AssetPopupSort::~AssetPopupSort()
 {
 }
 
-int AssetPopupSortTimes::handle_event()
+int AssetPopupSort::handle_event()
 {
-       mwindow->awindow->gui->sort_assets(1);
+       mwindow->awindow->gui->sort_assets();
        return 1;
 }
 
@@ -267,18 +252,18 @@ AssetPopupViewWindow::~AssetPopupViewWindow()
 
 int AssetPopupViewWindow::handle_event()
 {
-// Find window with nothing
-       VWindow *vwindow = mwindow->get_viewer(1);
-
-// TODO: create new vwindow or change current vwindow
-       if( mwindow->session->drag_assets->total )
-               vwindow->change_source(
-                       mwindow->session->drag_assets->values[0]);
-       else
-       if( mwindow->session->drag_clips->total )
-               vwindow->change_source(
-                       mwindow->session->drag_clips->values[0]);
-
+       for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
+               VWindow *vwindow = mwindow->get_viewer(1);
+               vwindow->gui->lock_window("AssetPopupView::handle_event 1");
+               vwindow->change_source(mwindow->session->drag_assets->get(i));
+               vwindow->gui->unlock_window();
+       }
+       for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
+               VWindow *vwindow = mwindow->get_viewer(1);
+               vwindow->gui->lock_window("AssetPopupView::handle_event 2");
+               vwindow->change_source(mwindow->session->drag_clips->get(i));
+               vwindow->gui->unlock_window();
+       }
        return 1;
 }
 
@@ -415,6 +400,7 @@ AssetListMenu::~AssetListMenu()
 
 void AssetListMenu::create_objects()
 {
+       add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
        add_item(format = new AWindowListFormat(mwindow, gui));
        add_item(new AWindowListSort(mwindow, gui));
        add_item(new AssetListCopy(mwindow, gui));
@@ -436,6 +422,23 @@ void AssetListMenu::create_objects()
        update_titles(shots_displayed = 1);
 }
 
+AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
+ : BC_MenuItem(_("Load files..."), "o", 'o')
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+}
+
+AssetPopupLoadFile::~AssetPopupLoadFile()
+{
+}
+
+int AssetPopupLoadFile::handle_event()
+{
+       mwindow->gui->mainmenu->load_file->thread->start();
+       return 1;
+}
+
 void AssetListMenu::update_titles(int shots)
 {
        format->update();
@@ -554,6 +557,7 @@ AssetCopyWindow::~AssetCopyWindow()
 
 void AssetCopyWindow::create_objects()
 {
+       lock_window("AssetCopyWindow::create_objects");
        BC_Title *title;
        int x = 10, y = 10, pad = 5;
        add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
@@ -568,6 +572,7 @@ void AssetCopyWindow::create_objects()
 
        add_subwindow(new BC_OKButton(this));
        show_window();
+       unlock_window();
 }
 
 int AssetCopyWindow::resize_event(int w, int h)
@@ -679,6 +684,7 @@ AssetPasteWindow::~AssetPasteWindow()
 
 void AssetPasteWindow::create_objects()
 {
+       lock_window("AssetPasteWindow::create_objects()");
        BC_Title *title;
        int x = 10, y = 10, pad = 5;
        add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
@@ -691,6 +697,7 @@ void AssetPasteWindow::create_objects()
        add_subwindow(new BC_OKButton(this));
        add_subwindow(new BC_CancelButton(this));
        show_window();
+       unlock_window();
 }
 
 int AssetPasteWindow::resize_event(int w, int h)
@@ -751,10 +758,13 @@ int SnapshotMenuItem::handle_event()
                preferences->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);
+       Asset *asset = new Asset(asset_path);
+       delete [] asset_path;
+
        int fw = edl->get_w(), fh = edl->get_h();
        int fcolor_model = edl->session->color_model;
 
-       Asset *asset = new Asset(filename);
        switch( mode ) {
        case SNAPSHOT_PNG:
                asset->format = FILE_PNG;
@@ -973,8 +983,9 @@ int GrabshotPopup::grab_event(XEvent *event)
                preferences->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]);
-
-       Asset *asset = new Asset(filename);
+       char *asset_path = FileSystem::basepath(filename);
+       Asset *asset = new Asset(asset_path);
+       delete [] asset_path;
        switch( mode ) {
        case GRABSHOT_PNG:
                asset->format = FILE_PNG;