Only enable Commands when appropriate
Remove dupl code
This commit is contained in:
@@ -65,6 +65,7 @@
|
||||
#include <Mod/TechDraw/App/DrawViewDraft.h>
|
||||
#include <Mod/TechDraw/Gui/QGVPage.h>
|
||||
|
||||
#include "DrawGuiUtil.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "TaskProjGroup.h"
|
||||
#include "TaskSectionView.h"
|
||||
@@ -74,60 +75,6 @@ using namespace TechDrawGui;
|
||||
using namespace std;
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// utility routines
|
||||
//===========================================================================
|
||||
|
||||
//! find a DrawPage in Selection or Document
|
||||
//TODO: code is duplicated in CommandCreateDims and CommandDecorate
|
||||
TechDraw::DrawPage* _findPage(Gui::Command* cmd)
|
||||
{
|
||||
//check if a DrawPage is currently displayed
|
||||
auto mdiView( Gui::getMainWindow()->activeWindow() );
|
||||
auto mvp( dynamic_cast<MDIViewPage *>(mdiView) );
|
||||
if (mvp) {
|
||||
return mvp->getQGVPage()->getDrawPage();
|
||||
} else {
|
||||
TechDraw::DrawPage* page(nullptr);
|
||||
|
||||
//DrawPage not displayed, check Selection and/or Document for a DrawPage
|
||||
auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
|
||||
auto selPages( cmd->getSelection().getObjectsOfType(drawPageType) );
|
||||
if (selPages.empty()) { //no page in selection
|
||||
selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
|
||||
if (selPages.empty()) { //no page in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
|
||||
QObject::tr("Create a page first."));
|
||||
return page;
|
||||
} else if (selPages.size() > 1) { //multiple pages in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Can not determine correct page."));
|
||||
return page;
|
||||
} else { //use only page in document
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
} else if (selPages.size() > 1) { //multiple pages in selection
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Select exactly 1 page."));
|
||||
return page;
|
||||
} else { //use only page in selection
|
||||
page = static_cast<TechDraw::DrawPage *>(selPages.front());
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDrawingPageActive(Gui::Document *doc)
|
||||
{
|
||||
if (doc)
|
||||
// checks if a DrawPage Viewprovider is in Edit and is in no special mode
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(TechDrawGui::ViewProviderPage::getClassTypeId()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_NewPageDef (default template)
|
||||
//===========================================================================
|
||||
@@ -299,7 +246,7 @@ CmdTechDrawNewView::CmdTechDrawNewView()
|
||||
void CmdTechDrawNewView::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -350,8 +297,7 @@ void CmdTechDrawNewView::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawNewView::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -375,8 +321,7 @@ CmdTechDrawNewViewSection::CmdTechDrawNewViewSection()
|
||||
void CmdTechDrawNewViewSection::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
//TODO: should just use BaseView's page
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -420,8 +365,13 @@ void CmdTechDrawNewViewSection::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawNewViewSection::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
bool taskInProgress = false;
|
||||
if (havePage) {
|
||||
taskInProgress = Gui::Control().activeDialog();
|
||||
}
|
||||
return (havePage && haveView && !taskInProgress);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -445,7 +395,7 @@ CmdTechDrawProjGroup::CmdTechDrawProjGroup()
|
||||
void CmdTechDrawProjGroup::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -480,18 +430,18 @@ void CmdTechDrawProjGroup::activated(int iMsg)
|
||||
// create the rest of the desired views
|
||||
Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true));
|
||||
|
||||
// // add the multiView to the page
|
||||
// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),multiViewName.c_str());
|
||||
|
||||
updateActive();
|
||||
commitCommand();
|
||||
}
|
||||
|
||||
bool CmdTechDrawProjGroup::isActive(void)
|
||||
{
|
||||
if ( !hasActiveDocument() || Gui::Control().activeDialog())
|
||||
return false;
|
||||
return true;
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool taskInProgress = false;
|
||||
if (havePage) {
|
||||
taskInProgress = Gui::Control().activeDialog();
|
||||
}
|
||||
return (havePage && !taskInProgress);
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +466,7 @@ CmdTechDrawAnnotation::CmdTechDrawAnnotation()
|
||||
void CmdTechDrawAnnotation::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -532,7 +482,7 @@ void CmdTechDrawAnnotation::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawAnnotation::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -557,7 +507,7 @@ CmdTechDrawClip::CmdTechDrawClip()
|
||||
void CmdTechDrawClip::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -577,7 +527,7 @@ void CmdTechDrawClip::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawClip::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -589,7 +539,6 @@ DEF_STD_CMD_A(CmdTechDrawClipPlus);
|
||||
CmdTechDrawClipPlus::CmdTechDrawClipPlus()
|
||||
: Command("TechDraw_ClipPlus")
|
||||
{
|
||||
// seting the
|
||||
sGroup = QT_TR_NOOP("TechDraw");
|
||||
sMenuText = QT_TR_NOOP("&ClipPlus");
|
||||
sToolTipText = QT_TR_NOOP("Add a View to a clip group in the active drawing");
|
||||
@@ -601,12 +550,12 @@ CmdTechDrawClipPlus::CmdTechDrawClipPlus()
|
||||
void CmdTechDrawClipPlus::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
if (selection.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select 1 DrawViewClip and 1 DrawView."));
|
||||
return;
|
||||
}
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
if (selection.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select 1 DrawViewClip and 1 DrawView."));
|
||||
return;
|
||||
}
|
||||
|
||||
TechDraw::DrawViewClip* clip = 0;
|
||||
TechDraw::DrawView* view = 0;
|
||||
@@ -657,7 +606,16 @@ void CmdTechDrawClipPlus::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawClipPlus::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveClip = false;
|
||||
if (havePage) {
|
||||
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
|
||||
auto selClips = getDocument()->getObjectsOfType(drawClipType);
|
||||
if (!selClips.empty()) {
|
||||
haveClip = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveClip);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -721,7 +679,16 @@ void CmdTechDrawClipMinus::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawClipMinus::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveClip = false;
|
||||
if (havePage) {
|
||||
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
|
||||
auto selClips = getDocument()->getObjectsOfType(drawClipType);
|
||||
if (!selClips.empty()) {
|
||||
haveClip = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveClip);
|
||||
}
|
||||
|
||||
|
||||
@@ -746,7 +713,7 @@ CmdTechDrawSymbol::CmdTechDrawSymbol()
|
||||
void CmdTechDrawSymbol::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -772,7 +739,7 @@ void CmdTechDrawSymbol::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawSymbol::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -796,7 +763,7 @@ CmdTechDrawDraftView::CmdTechDrawDraftView()
|
||||
void CmdTechDrawDraftView::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -823,7 +790,7 @@ void CmdTechDrawDraftView::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawDraftView::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -855,7 +822,7 @@ void CmdTechDrawSpreadsheet::activated(int iMsg)
|
||||
}
|
||||
std::string SpreadName = spreads.front()->getNameInDocument();
|
||||
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -872,7 +839,17 @@ void CmdTechDrawSpreadsheet::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawSpreadsheet::isActive(void)
|
||||
{
|
||||
return (getActiveGuiDocument() ? true : false);
|
||||
//need a Page and a SpreadSheet::Sheet
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveSheet = false;
|
||||
if (havePage) {
|
||||
auto spreadSheetType( Spreadsheet::Sheet::getClassTypeId() );
|
||||
auto selSheets = getDocument()->getObjectsOfType(spreadSheetType);
|
||||
if (!selSheets.empty()) {
|
||||
haveSheet = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveSheet);
|
||||
}
|
||||
|
||||
|
||||
@@ -896,7 +873,7 @@ CmdTechDrawExportPage::CmdTechDrawExportPage()
|
||||
void CmdTechDrawExportPage::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
@@ -917,7 +894,7 @@ void CmdTechDrawExportPage::activated(int iMsg)
|
||||
|
||||
bool CmdTechDrawExportPage::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user