awindowgui / mwindowedit / label rework
[goodguy/history.git] / cinelerra-5.1 / cinelerra / assetpopup.C
index 478b4568eb7d0c72ecb9ef6b3ffaad3af96484eb..14a538bbffd9a7543f57b4c159cd897d54fde92e 100644 (file)
  *
  */
 
+#include "asset.h"
 #include "assetedit.h"
 #include "assetpopup.h"
 #include "assetremove.h"
 #include "awindow.h"
 #include "awindowgui.h"
-#include "awindowmenu.h"
+#include "bcdisplayinfo.h"
 #include "bcsignals.h"
 #include "clipedit.h"
+#include "cstrdup.h"
 #include "cwindow.h"
 #include "cwindowgui.h"
 #include "edl.h"
+#include "edlsession.h"
+#include "filexml.h"
 #include "language.h"
 #include "localsession.h"
+#include "mainerror.h"
 #include "mainindexes.h"
 #include "mainsession.h"
 #include "mwindow.h"
 #include "vwindowgui.h"
 
 
-
 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
- : BC_PopupMenu(0,
-               0,
-               0,
-               "",
-               0)
+ : BC_PopupMenu(0, 0, 0, "", 0)
 {
        this->mwindow = mwindow;
        this->gui = gui;
@@ -59,18 +59,24 @@ AssetPopup::~AssetPopup()
 
 void AssetPopup::create_objects()
 {
+       BC_MenuItem *menu_item;
+       BC_SubMenu *submenu;
        add_item(info = new AssetPopupInfo(mwindow, this));
-       add_item(format = new AssetListFormat(mwindow));
+       add_item(format = new AWindowListFormat(mwindow));
        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));
        add_item(new AssetPopupPaste(mwindow, this));
-       add_item(new AssetMatchSize(mwindow, this));
-       add_item(new AssetMatchRate(mwindow, this));
-       add_item(new AssetMatchAll(mwindow, this));
-       add_item(new AssetPopupProjectRemove(mwindow, this));
-       add_item(new AssetPopupDiskRemove(mwindow, this));
+       add_item(menu_item = new BC_MenuItem(_("Match...")));
+       menu_item->add_submenu(submenu = new BC_SubMenu());
+       submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
+       submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
+       submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
+       add_item(menu_item = new BC_MenuItem(_("Remove...")));
+       menu_item->add_submenu(submenu = new BC_SubMenu());
+       submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
+       submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
 }
 
 void AssetPopup::paste_assets()
@@ -125,13 +131,6 @@ int AssetPopup::update()
 }
 
 
-
-
-
-
-
-
-
 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Info..."))
 {
@@ -160,10 +159,6 @@ int AssetPopupInfo::handle_event()
 }
 
 
-
-
-
-
 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Rebuild index"))
 {
@@ -183,11 +178,6 @@ int AssetPopupBuildIndex::handle_event()
 }
 
 
-
-
-
-
-
 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Sort items"))
 {
@@ -206,11 +196,6 @@ int AssetPopupSort::handle_event()
 }
 
 
-
-
-
-
-
 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("View"))
 {
@@ -240,11 +225,6 @@ int AssetPopupView::handle_event()
 }
 
 
-
-
-
-
-
 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("View in new window"))
 {
@@ -277,11 +257,6 @@ int AssetPopupViewWindow::handle_event()
 }
 
 
-
-
-
-
-
 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Paste"))
 {
@@ -300,12 +275,6 @@ int AssetPopupPaste::handle_event()
 }
 
 
-
-
-
-
-
-
 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Match project size"))
 {
@@ -319,13 +288,6 @@ int AssetMatchSize::handle_event()
        return 1;
 }
 
-
-
-
-
-
-
-
 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
  : BC_MenuItem(_("Match frame rate"))
 {
@@ -339,83 +301,303 @@ int AssetMatchRate::handle_event()
        return 1;
 }
 
+AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
+ : BC_MenuItem(_("Match all"))
+{
+       this->mwindow = mwindow;
+       this->popup = popup;
+}
 
+int AssetMatchAll::handle_event()
+{
+       popup->match_all();
+       return 1;
+}
 
 
+AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
+ : BC_MenuItem(_("Remove from project"))
+{
+       this->mwindow = mwindow;
+       this->popup = popup;
+}
 
+AssetPopupProjectRemove::~AssetPopupProjectRemove()
+{
+}
 
+int AssetPopupProjectRemove::handle_event()
+{
+       mwindow->remove_assets_from_project(1,
+               1,
+               mwindow->session->drag_assets,
+               mwindow->session->drag_clips);
+       return 1;
+}
 
 
-AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Match all"))
+AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
+ : BC_MenuItem(_("Remove from disk"))
 {
        this->mwindow = mwindow;
        this->popup = popup;
 }
 
-int AssetMatchAll::handle_event()
+
+AssetPopupDiskRemove::~AssetPopupDiskRemove()
 {
-       popup->match_all();
+}
+
+int AssetPopupDiskRemove::handle_event()
+{
+       mwindow->awindow->asset_remove->start();
        return 1;
 }
 
 
+AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
+ : BC_PopupMenu(0, 0, 0, "", 0)
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+}
 
+AssetListMenu::~AssetListMenu()
+{
+}
 
+void AssetListMenu::create_objects()
+{
+       add_item(format = new AWindowListFormat(mwindow));
+       add_item(new AWindowListSort(mwindow));
+       add_item(new AssetListCopy(mwindow));
+       add_item(new AssetListPaste(mwindow));
+       update_titles();
+}
 
+void AssetListMenu::update_titles()
+{
+       format->update();
+}
 
+AssetListCopy::AssetListCopy(MWindow *mwindow)
+ : BC_MenuItem(_("Copy file list"))
+{
+       this->mwindow = mwindow;
+       copy_dialog = 0;
+}
+AssetListCopy::~AssetListCopy()
+{
+       delete copy_dialog;
+}
 
+int AssetListCopy::handle_event()
+{
+       int len = 0;
+       MWindowGUI *gui = mwindow->gui;
+       gui->lock_window("AssetListCopy::handle_event");
+       mwindow->awindow->gui->collect_assets();
+       int n = mwindow->session->drag_assets->total;
+       for( int i=0; i<n; ++i ) {
+               Indexable *indexable = mwindow->session->drag_assets->values[i];
+               const char *path = indexable->path;
+               if( !*path ) continue;
+               len += strlen(path) + 1;
+       }
+       char *text = new char[len+1], *cp = text;
+       for( int i=0; i<n; ++i ) {
+               Indexable *indexable = mwindow->session->drag_assets->values[i];
+               const char *path = indexable->path;
+               if( !*path ) continue;
+               cp += sprintf(cp, "%s\n", path);
+       }
+       *cp = 0;
+       gui->unlock_window(); 
 
+       if( n ) {
+               if( !copy_dialog )
+                       copy_dialog = new AssetCopyDialog(this);
+               copy_dialog->start(text);
+       }
+       else {
+               eprintf(_("Nothing selected"));
+               delete [] text;
+       }
+       return 1;
+}
 
+AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
+ : BC_DialogThread()
+{
+        this->copy = copy;
+       copy_window = 0;
+}
 
+void AssetCopyDialog::start(char *text)
+{
+        close_window();
+        this->text = text;
+       BC_DialogThread::start();
+}
 
+AssetCopyDialog::~AssetCopyDialog()
+{
+        close_window();
+}
 
+BC_Window* AssetCopyDialog::new_gui()
+{
+        BC_DisplayInfo display_info;
+        int x = display_info.get_abs_cursor_x();
+        int y = display_info.get_abs_cursor_y();
 
+        copy_window = new AssetCopyWindow(this, x, y);
+        copy_window->create_objects();
+        return copy_window;
+}
 
-AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Remove from project"))
+void AssetCopyDialog::handle_done_event(int result)
 {
-       this->mwindow = mwindow;
-       this->popup = popup;
+       delete [] text;  text = 0;
 }
 
+void AssetCopyDialog::handle_close_event(int result)
+{
+        copy_window = 0;
+}
 
 
-AssetPopupProjectRemove::~AssetPopupProjectRemove()
+AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog, int x, int y)
+ : BC_Window(_(PROGRAM_NAME ": Copy File List"), x, y, 500, 200, 500, 200, 0, 0, 1)
 {
+        this->copy_dialog = copy_dialog;
 }
 
-int AssetPopupProjectRemove::handle_event()
+AssetCopyWindow::~AssetCopyWindow()
 {
-       mwindow->remove_assets_from_project(1,
-               1,
-               mwindow->session->drag_assets,
-               mwindow->session->drag_clips);
-       return 1;
 }
 
+void 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:")));
+       y += title->get_h() + pad;
+       int text_w = get_w() - x - 10;
+       int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
+       int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
+       char *text = copy_dialog->text;
+       int len = strlen(text) + BCTEXTLEN;
+       file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
+       file_list->create_objects();
 
+       add_subwindow(new BC_OKButton(this));
+        show_window();
+}
 
 
-AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Remove from disk"))
+AssetListPaste::AssetListPaste(MWindow *mwindow)
+ : BC_MenuItem(_("Paste file list"))
 {
        this->mwindow = mwindow;
-       this->popup = popup;
+       paste_dialog = 0;
+}
+AssetListPaste::~AssetListPaste()
+{
+       delete paste_dialog;
 }
 
+int AssetListPaste::handle_event()
+{
+       if( !paste_dialog )
+               paste_dialog = new AssetPasteDialog(this);
+       paste_dialog->start();
+       return 1;
+}
 
-AssetPopupDiskRemove::~AssetPopupDiskRemove()
+AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
+ : BC_DialogThread()
 {
+        this->paste = paste;
+       paste_window = 0;
 }
 
+AssetPasteDialog::~AssetPasteDialog()
+{
+        close_window();
+}
 
-int AssetPopupDiskRemove::handle_event()
+BC_Window* AssetPasteDialog::new_gui()
 {
-       mwindow->awindow->asset_remove->start();
-       return 1;
+        BC_DisplayInfo display_info;
+        int x = display_info.get_abs_cursor_x();
+        int y = display_info.get_abs_cursor_y();
+
+        paste_window = new AssetPasteWindow(this, x, y);
+        paste_window->create_objects();
+        return paste_window;
+}
+
+void AssetPasteDialog::handle_done_event(int result)
+{
+       if( result ) return;
+       const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
+       ArrayList<char*> path_list;
+       path_list.set_array_delete();
+
+       for( const char *cp=bp; cp<ep && *cp; ) {
+               const char *dp = strchr(cp, '\n');
+               if( !dp ) dp = ep;
+               char path[BCTEXTLEN], *pp = path;
+               int len = sizeof(path)-1;
+               while( --len>0 && cp<dp ) *pp++ = *cp++;
+               if( *cp ) ++cp;
+               *pp = 0;
+               if( !strlen(path) ) continue;
+               path_list.append(cstrdup(path));
+       }
+       if( !path_list.size() ) return;
+
+       MWindow *mwindow = paste->mwindow;
+       mwindow->interrupt_indexes();
+       mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
+       result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
+       mwindow->gui->unlock_window();
+       path_list.remove_all_objects();
+        mwindow->save_backup();
+        mwindow->restart_brender();
+       mwindow->session->changes_made = 1;
 }
 
+void AssetPasteDialog::handle_close_event(int result)
+{
+        paste_window = 0;
+}
+
+
+AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog, int x, int y)
+ : BC_Window(_(PROGRAM_NAME ": Paste File List"), x, y, 500, 200, 500, 200, 0, 0, 1)
+{
+        this->paste_dialog = paste_dialog;
+}
 
+AssetPasteWindow::~AssetPasteWindow()
+{
+}
 
+void 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:")));
+       y += title->get_h() + pad;
+       int text_w = get_w() - x - 10;
+       int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
+       int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
+       file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
+       file_list->create_objects();
+       add_subwindow(new BC_OKButton(this));
+       add_subwindow(new BC_CancelButton(this));
+        show_window();
+}