heuristic to import into selected folder
This commit is contained in:
+51
-19
@@ -108,24 +108,7 @@ void Core::ImportFiles(const QStringList &urls, Folder* parent)
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectPanel* active_project_panel = olive::panel_focus_manager->MostRecentlyFocused<ProjectPanel>();
|
||||
Project* active_project;
|
||||
|
||||
if (active_project_panel == nullptr // Check that we found a Project panel
|
||||
|| (active_project = active_project_panel->project()) == nullptr) { // and that we could find an active Project
|
||||
|
||||
QMessageBox::critical(main_window_, error_capt, tr("Failed to find active Project panel"));
|
||||
|
||||
} else {
|
||||
|
||||
// If no parent was supplied, assume we're importing to the root
|
||||
if (parent == nullptr) {
|
||||
parent = active_project->root();
|
||||
}
|
||||
|
||||
olive::task_manager.AddTask(new ImportTask(parent, urls));
|
||||
|
||||
}
|
||||
olive::task_manager.AddTask(new ImportTask(parent, urls));
|
||||
}
|
||||
|
||||
void Core::SetTool(const olive::tool::Tool &tool)
|
||||
@@ -143,7 +126,56 @@ void Core::StartImportFootage()
|
||||
|
||||
// Check if the user actually selected files to import
|
||||
if (!files.isEmpty()) {
|
||||
ImportFiles(files);
|
||||
|
||||
// Locate the most recently focused Project panel (assume that's the panel the user wants to import into)
|
||||
ProjectPanel* active_project_panel = olive::panel_focus_manager->MostRecentlyFocused<ProjectPanel>();
|
||||
Project* active_project;
|
||||
|
||||
if (active_project_panel == nullptr // Check that we found a Project panel
|
||||
|| (active_project = active_project_panel->project()) == nullptr) { // and that we could find an active Project
|
||||
QMessageBox::critical(main_window_, tr("Import footage"), tr("Failed to find active Project panel"));
|
||||
return;
|
||||
}
|
||||
|
||||
Folder* folder = nullptr;
|
||||
|
||||
// Get the selected items from the panel
|
||||
QList<Item*> selected_items = active_project_panel->SelectedItems();
|
||||
|
||||
// Heuristic for finding the selected folder
|
||||
//
|
||||
// - If `folder` is nullptr, we set the first folder we find. Either the item itself if it's a folder, or the
|
||||
// item's parent.
|
||||
// - Otherwise, if all folders found are the same, we'll use that to import into.
|
||||
// - If more than one folder is found, we play it safe and import into the root folder
|
||||
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
Item* sel_item = selected_items.at(i);
|
||||
|
||||
// If this item is not a folder, presumably its parent is
|
||||
if (sel_item->type() != Item::kFolder) {
|
||||
sel_item = sel_item->parent();
|
||||
|
||||
Q_ASSERT(sel_item->type() == Item::kFolder);
|
||||
}
|
||||
|
||||
if (folder == nullptr) {
|
||||
// If the folder is nullptr, cache it as this folder
|
||||
folder = static_cast<Folder*>(sel_item);
|
||||
} else if (folder != sel_item) {
|
||||
// If not, we've already cached a folder so we check if it's the same
|
||||
// If it isn't, we "play it safe" and use the root folder
|
||||
folder = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't pick up a folder from the heuristic above for whatever reason, use root
|
||||
if (folder == nullptr) {
|
||||
folder = active_project->root();
|
||||
}
|
||||
|
||||
ImportFiles(files, folder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public:
|
||||
*
|
||||
* @param urls
|
||||
*/
|
||||
void ImportFiles(const QStringList& urls, Folder *parent = nullptr);
|
||||
void ImportFiles(const QStringList& urls, Folder *parent);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
|
||||
@@ -69,6 +69,11 @@ void ProjectPanel::set_project(Project *p)
|
||||
Retranslate();
|
||||
}
|
||||
|
||||
QList<Item *> ProjectPanel::SelectedItems()
|
||||
{
|
||||
return explorer_->SelectedItems();
|
||||
}
|
||||
|
||||
void ProjectPanel::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
|
||||
@@ -34,6 +34,8 @@ public:
|
||||
Project* project();
|
||||
void set_project(Project* p);
|
||||
|
||||
QList<Item*> SelectedItems();
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent* e) override;
|
||||
|
||||
|
||||
@@ -23,6 +23,24 @@
|
||||
Project::Project()
|
||||
{
|
||||
name_ = tr("(untitled)");
|
||||
|
||||
// FIXME: Test code
|
||||
Folder* f1 = new Folder();
|
||||
f1->set_name("F1");
|
||||
f1->set_parent(&root_);
|
||||
Folder* f2 = new Folder();
|
||||
f2->set_name("F2");
|
||||
f2->set_parent(f1);
|
||||
Folder* f3 = new Folder();
|
||||
f3->set_name("F3");
|
||||
f3->set_parent(&root_);
|
||||
Folder* f4 = new Folder();
|
||||
f4->set_name("F4");
|
||||
f4->set_parent(f1);
|
||||
Folder* f5 = new Folder();
|
||||
f5->set_name("F5");
|
||||
f5->set_parent(f3);
|
||||
// End Test code
|
||||
}
|
||||
|
||||
Folder *Project::root()
|
||||
|
||||
@@ -207,6 +207,24 @@ bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::canFetchMore(const QModelIndex &parent) const
|
||||
{
|
||||
// Check if this is a valid index
|
||||
if (parent.isValid()) {
|
||||
Item* item = GetItemObjectFromIndex(parent);
|
||||
|
||||
// Check if this item is a kFolder type
|
||||
// If it's a folder, we always return TRUE in order to always show the "expand triangle" icon,
|
||||
// even when there are no "physical" children
|
||||
if (item->type() == Item::kFolder) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, return default behavior
|
||||
return QAbstractItemModel::canFetchMore(parent);
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectViewModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
virtual bool canFetchMore(const QModelIndex &parent) const override;
|
||||
|
||||
/** Drag and drop support */
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
@@ -169,3 +169,34 @@ void ProjectExplorer::set_project(Project *p)
|
||||
{
|
||||
model_.set_project(p);
|
||||
}
|
||||
|
||||
QList<Item *> ProjectExplorer::SelectedItems()
|
||||
{
|
||||
QModelIndexList index_list;
|
||||
|
||||
// Determine which view is active and get its selected indexes
|
||||
switch (view_type_) {
|
||||
case olive::TreeView:
|
||||
index_list = tree_view_->selectionModel()->selectedRows();
|
||||
break;
|
||||
case olive::ListView:
|
||||
index_list = list_view_->selectionModel()->selectedRows();
|
||||
break;
|
||||
case olive::IconView:
|
||||
index_list = icon_view_->selectionModel()->selectedRows();
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert indexes to item objects
|
||||
QList<Item*> selected_items;
|
||||
|
||||
for (int i=0;i<index_list.size();i++) {
|
||||
const QModelIndex& index = index_list.at(i);
|
||||
|
||||
Item* item = static_cast<Item*>(index.internalPointer());
|
||||
|
||||
selected_items.append(item);
|
||||
}
|
||||
|
||||
return selected_items;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
Project* project();
|
||||
void set_project(Project* p);
|
||||
|
||||
QList<Item*> SelectedItems();
|
||||
|
||||
public slots:
|
||||
void set_view_type(olive::ProjectViewType type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user