void FolderMenu::createCreateNewMenu() { QMenu* createMenu = new QMenu(this); createNewMenu_ = createMenu; QAction* action = new QAction(tr("Folder"), this); connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNewFolder())); createMenu->addAction(action); action = new QAction(tr("Blank File"), this); connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNewFile())); createMenu->addAction(action); // add more items to "Create New" menu from templates GList* templates = fm_template_list_all(fm_config->only_user_templates); if(templates) { createMenu->addSeparator(); for(GList* l = templates; l; l = l->next) { FmTemplate* templ = (FmTemplate*)l->data; /* we support directories differently */ if(fm_template_is_directory(templ)) continue; FmMimeType* mime_type = fm_template_get_mime_type(templ); const char* label = fm_template_get_label(templ); QString text = QString("%1 (%2)").arg(QString::fromUtf8(label)).arg(QString::fromUtf8(fm_mime_type_get_desc(mime_type))); FmIcon* icon = fm_template_get_icon(templ); if(!icon) icon = fm_mime_type_get_icon(mime_type); QAction* action = createMenu->addAction(IconTheme::icon(icon), text); action->setObjectName(QString::fromUtf8(fm_template_get_name(templ, NULL))); connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNew())); } } }
CreateNewMenu::CreateNewMenu(QWidget* dialogParent, FmPath* dirPath, QWidget* parent): QMenu(parent), dialogParent_(dialogParent), dirPath_(dirPath) { QAction* action = new QAction(QIcon::fromTheme("folder-new"), tr("Folder"), this); connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNewFolder); addAction(action); action = new QAction(QIcon::fromTheme("document-new"), tr("Blank File"), this); connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNewFile); addAction(action); // add more items to "Create New" menu from templates GList* templates = fm_template_list_all(fm_config->only_user_templates); if(templates) { addSeparator(); for(GList* l = templates; l; l = l->next) { FmTemplate* templ = (FmTemplate*)l->data; /* we support directories differently */ if(fm_template_is_directory(templ)) continue; FmMimeType* mime_type = fm_template_get_mime_type(templ); const char* label = fm_template_get_label(templ); QString text = QString("%1 (%2)").arg(QString::fromUtf8(label)).arg(QString::fromUtf8(fm_mime_type_get_desc(mime_type))); FmIcon* icon = fm_template_get_icon(templ); if(!icon) icon = fm_mime_type_get_icon(mime_type); QAction* action = addAction(IconTheme::icon(icon), text); action->setObjectName(QString::fromUtf8(fm_template_get_name(templ, NULL))); connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNew); } } }