From 568bf4145a8bc66472ea3625741dacbd3b56ccc0 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Wed, 19 Sep 2018 16:16:41 -0600 Subject: [PATCH] add save project feature, shortcuts update --- cinelerra-5.1/cinelerra/editpanel.C | 2 +- cinelerra-5.1/cinelerra/mainmenu.C | 3 + cinelerra-5.1/cinelerra/mwindow.C | 183 +++++++++++++++++++++++++++ cinelerra-5.1/cinelerra/mwindow.h | 3 + cinelerra-5.1/cinelerra/mwindow.inc | 1 + cinelerra-5.1/cinelerra/savefile.C | 146 +++++++++++++++++++-- cinelerra-5.1/cinelerra/savefile.h | 69 ++++++++++ cinelerra-5.1/cinelerra/savefile.inc | 15 ++- cinelerra-5.1/doc/shortcuts.html | 168 ++++++++++++++++++++++++ 9 files changed, 579 insertions(+), 11 deletions(-) diff --git a/cinelerra-5.1/cinelerra/editpanel.C b/cinelerra-5.1/cinelerra/editpanel.C index 32b2e848..1c357b54 100644 --- a/cinelerra-5.1/cinelerra/editpanel.C +++ b/cinelerra-5.1/cinelerra/editpanel.C @@ -1398,7 +1398,7 @@ LockLabelsButton::LockLabelsButton(MWindow *mwindow, int x, int y) "", 0, 0, 0) { this->mwindow = mwindow; - set_tooltip(_("Lock labels from moving")); + set_tooltip(_("Lock labels from moving with edits")); } int LockLabelsButton::handle_event() diff --git a/cinelerra-5.1/cinelerra/mainmenu.C b/cinelerra-5.1/cinelerra/mainmenu.C index 0bd56ec3..1deb52a1 100644 --- a/cinelerra-5.1/cinelerra/mainmenu.C +++ b/cinelerra-5.1/cinelerra/mainmenu.C @@ -112,6 +112,9 @@ void MainMenu::create_objects() filemenu->add_item(saveas = new SaveAs(mwindow)); save->create_objects(saveas); saveas->set_mainmenu(this); + SaveProject *save_project; + filemenu->add_item(save_project = new SaveProject(mwindow)); + filemenu->add_item(record_menu_item = new RecordMenuItem(mwindow)); #ifdef HAVE_DVB filemenu->add_item(new ChannelScan(mwindow)); diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index e57f6657..d680f508 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -28,6 +28,7 @@ #include "awindow.h" #include "batchrender.h" #include "bcdisplayinfo.h" +#include "bcprogressbox.h" #include "bcsignals.h" #include "bctimer.h" #include "bctrace.h" @@ -98,6 +99,7 @@ #include "removefile.h" #include "render.h" #include "resourcethread.h" +#include "savefile.inc" #include "samplescroll.h" #include "sha1.h" #include "sighandler.h" @@ -3649,6 +3651,187 @@ void MWindow::load_undo_data() fclose(fp); } + +int MWindow::copy_target(const char *path, const char *target) +{ + int ifd = ::open(path, O_RDONLY); + if( ifd < 0 ) { + eprintf("Cannot open asset: %s", path); + return 1; + } + int ret = 0; + int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777); + if( ofd >= 0 ) { + struct stat st; + int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0; + char progress_title[BCTEXTLEN]; + sprintf(progress_title, _("Copying: %s\n"), target); + BC_ProgressBox progress(-1, -1, progress_title, total_bytes); + + int64_t count = 0, len = -1; + int bfrsz = 0x100000; + uint8_t *bfr = new uint8_t[bfrsz]; + while( (len=::read(ifd, bfr, bfrsz)) > 0 ) { + if( len != ::write(ofd, bfr, len) ) { + eprintf("Error writing: %s", target); + break; + } + if( progress.is_cancelled() ) { + ret = 1; + break; + } + progress.update(count += len, 1); + } + delete [] bfr; + ::close(ofd); + + progress.stop_progress(); + if( len < 0 ) { + eprintf("Error reading: %s", path); + ret = 1; + } + } + else + eprintf("Cannot create asset target: %s", target); + ::close(ifd); + return ret; +} + +int MWindow::link_target(const char *real_path, const char *link_path, int relative) +{ + char target[BCTEXTLEN]; + if( relative ) { + const char *bp = real_path, *cp = bp; + const char *lp = link_path, *np = lp; + char *tp = target, *ep = tp+sizeof(target)-1, lch; + while( *lp && *bp && (lch=*lp++) == *bp++ ) { + if( lch == '/' ) { np = lp; cp = bp; } + } + while( tpcreate_objects(); + save_edl->copy_all(edl); + + char progress_title[BCTEXTLEN]; + sprintf(progress_title, _("Saving to %s:\n"), dir); + int total_assets = save_edl->assets->total(); + MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets); + int ret = 0; + Asset *current = save_edl->assets->first; + for( int i=0; !ret && current; ++i, current=NEXT ) { + char *path = current->path; + if( ::stat(path, &st) ) { + eprintf("Asset not found: %s", path); + continue; + } + char *real_path = realpath(path, 0); + const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1; + char link_path[BCTEXTLEN]; + snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp); + int skip = 0; + if( strcmp(real_path, link_path) ) { + if( !::lstat(link_path, &st) ) { + if( overwrite ) + ::remove(link_path); + else + skip = 1; + } + } + else { + eprintf("copy/link to self, skippped: %s", path); + skip = 1; + } + if( !skip ) { + if( save_mode == SAVE_PROJECT_COPY ) { + if( copy_target(real_path, link_path) ) + ret = 1; + } + else { + link_target(real_path, link_path, + save_mode == SAVE_PROJECT_RELLINK ? 1 : 0); + } + } + free(real_path); + strcpy(path, link_path); + + if( progress->is_cancelled() ) break; + progress->update(i); + } + + progress->stop_progress(); + delete progress; + + char *cp = strrchr(dir_path,'/'); + char *bp = cp ? cp+1 : dir_path; + char filename[BCTEXTLEN]; + snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp); + save_edl->set_path(filename); + FileXML file; + save_edl->save_xml(&file, filename); + file.terminate_string(); + + if( !file.write_to_file(filename) ) { + char string[BCTEXTLEN]; + sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string())); + gui->lock_window("SaveProject::run 2"); + gui->show_message(string); + gui->unlock_window(); + gui->mainmenu->add_load(filename); + } + else + eprintf(_("Couldn't open %s."), filename); + + save_edl->remove_user(); + + if( reload ) { + gui->lock_window("MWindow::save_project"); + ArrayList filenames; + filenames.append(filename); + load_filenames(&filenames, LOADMODE_REPLACE); + gui->unlock_window(); + } +} + + static inline int gcd(int m, int n) { int r; diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h index 9845ea6b..c6db8e7e 100644 --- a/cinelerra-5.1/cinelerra/mwindow.h +++ b/cinelerra-5.1/cinelerra/mwindow.h @@ -486,6 +486,9 @@ public: void redo_entry(BC_WindowBase *calling_window_gui); void save_undo_data(); void load_undo_data(); + int copy_target(const char *path, const char *target); + int link_target(const char *real_path, const char *link_path, int relative); + void save_project(const char *dir, int save_mode, int overwrite, int reload); int cut_automation(); int copy_automation(); diff --git a/cinelerra-5.1/cinelerra/mwindow.inc b/cinelerra-5.1/cinelerra/mwindow.inc index bf90324e..87650fec 100644 --- a/cinelerra-5.1/cinelerra/mwindow.inc +++ b/cinelerra-5.1/cinelerra/mwindow.inc @@ -129,6 +129,7 @@ N_("Cinelerra: Resources") N_("Cinelerra: Ruler") N_("Cinelerra: %s") N_("Cinelerra: Save") +N_("Cinelerra: Save Project"), N_("Cinelerra: Scale") N_("Cinelerra: Scan confirm") N_("Cinelerra: Scopes") diff --git a/cinelerra-5.1/cinelerra/savefile.C b/cinelerra-5.1/cinelerra/savefile.C index b38aec14..a8dcc9dc 100644 --- a/cinelerra-5.1/cinelerra/savefile.C +++ b/cinelerra-5.1/cinelerra/savefile.C @@ -21,13 +21,14 @@ #include "confirmsave.h" #include "bchash.h" +#include "bcrecentlist.h" #include "edl.h" -#include "errorbox.h" #include "file.h" #include "filexml.h" #include "fileformat.h" #include "indexfile.h" #include "language.h" +#include "mainerror.h" #include "mainmenu.h" #include "mwindow.h" #include "mwindowgui.h" @@ -228,21 +229,150 @@ void SaveAs::run() } +SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory) + : BC_FileBox(mwindow->gui->get_abs_cursor_x(1), + mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2, + init_directory, + _(PROGRAM_NAME ": Save"), + _("Enter a filename to save as")) +{ + this->mwindow = mwindow; +} +SaveFileWindow::~SaveFileWindow() {} + + + +int SaveProjectModeItem::handle_event() +{ + ((SaveProjectMode *)get_popup_menu())->update(id); + return 1; +} +SaveProjectMode::SaveProjectMode(SaveProjectWindow *gui, int x, int y) + : BC_PopupMenu(x, y, 100, "") +{ + this->gui = gui; + save_modes[SAVE_PROJECT_COPY] = _("Copy"); + save_modes[SAVE_PROJECT_SYMLINK] = _("SymLink"); + save_modes[SAVE_PROJECT_RELLINK] = _("RelLink"); +} +SaveProjectMode::~SaveProjectMode() +{ +} +void SaveProjectMode::create_objects() +{ + add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_COPY], SAVE_PROJECT_COPY)); + add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_SYMLINK], SAVE_PROJECT_SYMLINK)); + add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_RELLINK], SAVE_PROJECT_RELLINK)); + set_text(save_modes[gui->save_mode]); +} +void SaveProjectMode::update(int mode) +{ + if( gui->save_mode == mode ) return; + set_text(save_modes[gui->save_mode = mode]); +} -SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory) - : BC_FileBox(mwindow->gui->get_abs_cursor_x(1), - mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2, - init_directory, - _(PROGRAM_NAME ": Save"), - _("Enter a filename to save as")) +SaveProjectTextBox::SaveProjectTextBox(SaveProjectWindow *gui, int x, int y, int w) + : BC_TextBox(x, y, w, 1, gui->dir_path) +{ + this->gui = gui; +} +SaveProjectTextBox::~SaveProjectTextBox() +{ +} + +int SaveProjectTextBox::handle_event() +{ + return 1; +} + +SaveProjectWindow::SaveProjectWindow(MWindow *mwindow, const char *dir_path, + int save_mode, int overwrite, int reload) + : BC_Window(_(PROGRAM_NAME ": Save Project"), + mwindow->gui->get_abs_cursor_x(1), + mwindow->gui->get_abs_cursor_y(1) - + BC_WindowBase::get_resources()->filebox_h / 2, + 540, 220, 540, 220, 0) { this->mwindow = mwindow; + strcpy(this->dir_path, dir_path); + this->overwrite = overwrite; + this->save_mode = save_mode; + this->reload = reload; +} +SaveProjectWindow::~SaveProjectWindow() +{ } -SaveFileWindow::~SaveFileWindow() {} +void SaveProjectWindow::create_objects() +{ + int x = 20, y = 20, x1 = get_w()-80; + BC_Title *title; + add_subwindow(title = new BC_Title(x, y, _("Project Directory:"))); + y += title->get_h() + 10; + add_subwindow(textbox = new SaveProjectTextBox(this, x, y, x1-x)); + x1 += 10; + add_subwindow(recent_project = new BC_RecentList("RECENT_PROJECT", + mwindow->defaults, textbox, 10, x1, y, 300, 100)); + recent_project->load_items("RECENT_PROJECT"); + x1 += recent_project->get_w() + 10; + add_subwindow(browse_button = new BrowseButton(mwindow->theme, this, + textbox, x1, y-5, "", "", "", 1)); + y += textbox->get_h() + 20; + add_subwindow(mode_popup = new SaveProjectMode(this, x, y)); + mode_popup->create_objects(); + y += mode_popup->get_h() + 10; + x1 = x; + BC_CheckBox *overwrite_files, *reload_project; + add_subwindow(overwrite_files = new BC_CheckBox(x1, y, &overwrite, _("Overwrite files"))); + x1 += overwrite_files->get_w() + 20; + add_subwindow(reload_project = new BC_CheckBox(x1, y, &reload, _("Reload project"))); + add_subwindow(new BC_OKButton(this)); + add_subwindow(new BC_CancelButton(this)); + show_window(1); +} + +SaveProject::SaveProject(MWindow *mwindow) + : BC_MenuItem(_("Save Project..."), "Alt-S", 's'), Thread() +{ + set_alt(1); + this->mwindow = mwindow; +} + +int SaveProject::handle_event() +{ + start(); + return 1; +} + +void SaveProject::run() +{ + char dir_path[1024]; sprintf(dir_path, "~"); + mwindow->defaults->get("PROJECT_DIRECTORY", dir_path); + int reload = mwindow->defaults->get("PROJECT_RELOAD", 0); + int overwrite = mwindow->defaults->get("PROJECT_OVERWRITE", 0); + int save_mode = mwindow->defaults->get("PROJECT_SAVE_MODE", 0); + + SaveProjectWindow window(mwindow, dir_path, save_mode, overwrite, reload); + window.lock_window("SaveProject::run"); + window.create_objects(); + window.unlock_window(); + int result = window.run_window(); + if( result ) return; + + strcpy(dir_path, window.textbox->get_text()); + window.recent_project->add_item("RECENT_PROJECT", dir_path); + reload = window.get_reload(); + overwrite = window.get_overwrite(); + save_mode = window.get_save_mode(); + mwindow->defaults->update("PROJECT_DIRECTORY", dir_path); + mwindow->defaults->update("PROJECT_RELOAD", reload); + mwindow->defaults->update("PROJECT_OVERWRITE", overwrite); + mwindow->defaults->update("PROJECT_SAVE_MODE", save_mode); + mwindow->save_project(dir_path, save_mode, overwrite, reload); +} diff --git a/cinelerra-5.1/cinelerra/savefile.h b/cinelerra-5.1/cinelerra/savefile.h index a399b4e8..bfbcbddd 100644 --- a/cinelerra-5.1/cinelerra/savefile.h +++ b/cinelerra-5.1/cinelerra/savefile.h @@ -69,4 +69,73 @@ public: MWindow *mwindow; }; + +class SaveProjectModeItem : public BC_MenuItem +{ +public: + SaveProjectModeItem(const char *txt, int id) + : BC_MenuItem(txt) { this->id = id; } + + int handle_event(); + int id; +}; + +class SaveProjectMode : public BC_PopupMenu +{ + const char *save_modes[SAVE_PROJECT_MODES]; + int mode; +public: + SaveProjectMode(SaveProjectWindow *gui, int x, int y); + ~SaveProjectMode(); + + void create_objects(); + void update(int mode); + + SaveProjectWindow *gui; +}; + +class SaveProjectTextBox : public BC_TextBox +{ +public: + SaveProjectTextBox(SaveProjectWindow *gui, int x, int y, int w); + ~SaveProjectTextBox(); + int handle_event(); + + + SaveProjectWindow *gui; +}; + +class SaveProjectWindow : public BC_Window +{ +public: + SaveProjectWindow(MWindow *mwindow, const char *dir_path, + int save_mode, int overwrite, int reload); + ~SaveProjectWindow(); + void create_objects(); + + MWindow *mwindow; + SaveProjectTextBox *textbox; + BC_RecentList *recent_project; + BrowseButton *browse_button; + SaveProjectMode *mode_popup; + + char dir_path[BCTEXTLEN]; + int overwrite; + int save_mode; + int reload; + + int get_overwrite() { return overwrite; } + int get_save_mode() { return save_mode; } + int get_reload() { return reload; } +}; + +class SaveProject : public BC_MenuItem, public Thread +{ +public: + SaveProject(MWindow *mwindow); + int handle_event(); + void run(); + MWindow *mwindow; +}; + #endif diff --git a/cinelerra-5.1/cinelerra/savefile.inc b/cinelerra-5.1/cinelerra/savefile.inc index 870b479a..ac366310 100644 --- a/cinelerra-5.1/cinelerra/savefile.inc +++ b/cinelerra-5.1/cinelerra/savefile.inc @@ -22,8 +22,19 @@ #ifndef SAVEFILE_INC #define SAVEFILE_INC -class SaveAs; -class Save; class SaveBackup; +class Save; +class SaveAs; +class SaveFileWindow; +class SaveProjectWindow; +class SaveProjectModeItem; +class SaveProjectMode; +class SaveProjectWindow; +class SaveProject; + +#define SAVE_PROJECT_COPY 0 +#define SAVE_PROJECT_SYMLINK 1 +#define SAVE_PROJECT_RELLINK 2 +#define SAVE_PROJECT_MODES 3 #endif diff --git a/cinelerra-5.1/doc/shortcuts.html b/cinelerra-5.1/doc/shortcuts.html index fbb39542..dd775cc9 100644 --- a/cinelerra-5.1/doc/shortcuts.html +++ b/cinelerra-5.1/doc/shortcuts.html @@ -78,6 +78,12 @@ 'Shift-S' Save and name project + +
+ Save Project… + 'Alt-S' + Save a project for easy moving +
Record… @@ -1398,6 +1404,54 @@

+ + Timebar + Key + Qualifier + Description + + +
+ Left mouse bt + Ctrl + Changes to the next time format + + +
+ Middle mouse + Ctrl + Changes to the previous time format + + +
+ Left mouse bt +
+ Moves cursor position on the timeline + + +
+ Double click +
+ If between labels, selects that section + + +
+ Click label + Hold LMB + Drag label to elsewhere + + +
+ Click In/Out + Hold LMB + Drag In/Out pointer elsewhere + + +
+
+
+
+ Compositor
@@ -1608,6 +1662,66 @@
Reset projector + +
+
+
+
+ + + Timebar + Key + Qualifier + Description + + +
+ Left mouse bt + Ctrl + Changes to the next time format + + +
+ Middle mouse + Ctrl + Changes to the previous time format + + +
+ Left mouse bt +
+ Moves cursor position on the timeline + + +
+ Double click +
+ If between labels, selects that section + + +
+ Click label + Hold LMB + Drag label to elsewhere + + +
+ Click In/Out + Hold LMB + Drag In/Out pointer elsewhere + + +
+ Fat arrow end + Hold RMB + Preview region drag on blue-colored bar + + +
+
+
+
+ Transport & (plus 3 below) @@ -1884,6 +1998,60 @@
Brings up fullscreen/zoom/close menu + + Timebar + Key + Qualifier + Description + + +
+ Left mouse bt +
+ Moves cursor position on the timeline + + +
+ Double click +
+ If between labels, selects that section + + +
+ Click label + Hold LMB + Drag label to elsewhere + + +
+ Click In/Out + Hold LMB + Drag In/Out pointer elsewhere + + +
+ Fat arrow end + Hold RMB + Preview region drag on blue_colored bar + + +
+
+
+
+ + + Most Windows + ESC +
+ Cancels operation if no one grabs first + + +
+ ENTER +
+ Cancels operation if no one grabs first +

-- 2.26.2