create new folder added

This commit is contained in:
itsmattkc
2019-07-05 11:04:23 -05:00
parent dae4310a7e
commit bc631c495d
10 changed files with 170 additions and 39 deletions
+3 -1
View File
@@ -20,6 +20,8 @@
#include "menushared.h"
#include "core.h"
MenuShared olive::menu_shared;
MenuShared::MenuShared()
@@ -31,7 +33,7 @@ void MenuShared::Initialize()
// "New" menu shared items
new_project_item_ = Menu::CreateItem(this, "newproj", nullptr, nullptr, "Ctrl+N");
new_sequence_item_ = Menu::CreateItem(this, "newseq", nullptr, nullptr, "Ctrl+Shift+N");
new_folder_item_ = Menu::CreateItem(this, "newfolder", nullptr, nullptr);
new_folder_item_ = Menu::CreateItem(this, "newfolder", &olive::core, SLOT(CreateNewFolder()));
// "Edit" menu shared items
edit_cut_item_ = Menu::CreateItem(this, "cut", nullptr, nullptr, "Ctrl+X");
@@ -200,3 +200,55 @@ QList<Item *> ProjectExplorer::SelectedItems()
return selected_items;
}
Folder *ProjectExplorer::GetSelectedFolder()
{
if (project() == nullptr) {
return nullptr;
}
Folder* folder = nullptr;
// Get the selected items from the panel
QList<Item*> selected_items = 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 it's 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 = project()->root();
}
return folder;
}
ProjectViewModel *ProjectExplorer::model()
{
return &model_;
}
@@ -55,6 +55,25 @@ public:
QList<Item*> SelectedItems();
/**
* @brief Use a heuristic to determine which (if any) folder is selected
*
* Generally for some import/adding processes, we assume that if a folder is selected, the user probably wants to
* create the new object in it rather than in the root. If, however, more than one folder is selected, we can't
* truly determine any folder from this and just return the root instead.
*
* @return
*
* A folder that's heuristically been determined as "selected", or the root directory if none, or nullptr if no
* project is open.
*/
Folder* GetSelectedFolder();
/**
* @brief Access the ViewModel model of the project
*/
ProjectViewModel* model();
public slots:
void set_view_type(olive::ProjectViewType type);