Some checks are pending
Build and Test / build (push) Has started running
- Create CommandOrigin.cpp with Origin_Commit, Origin_Pull, Origin_Push, Origin_Info, Origin_BOM commands - Commands delegate to current origin's extended operations - Commands auto-disable based on origin capabilities (supportsRevisions, supportsBOM, supportsPartNumbers) - Add 'Origin Tools' toolbar with PLM operations - Add origin commands to File menu - Register commands via CreateOriginCommands() in Application startup This implements Issue #14: Dynamic toolbar extension for Silo commands
278 lines
8.1 KiB
C++
278 lines
8.1 KiB
C++
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
/***************************************************************************
|
|
* Copyright (c) 2025 Kindred Systems *
|
|
* *
|
|
* This file is part of FreeCAD. *
|
|
* *
|
|
* FreeCAD is free software: you can redistribute it and/or modify it *
|
|
* under the terms of the GNU Lesser General Public License as *
|
|
* published by the Free Software Foundation, either version 2.1 of the *
|
|
* License, or (at your option) any later version. *
|
|
* *
|
|
* FreeCAD is distributed in the hope that it will be useful, but *
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
* Lesser General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
* License along with FreeCAD. If not, see *
|
|
* <https://www.gnu.org/licenses/>. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
/**
|
|
* @file CommandOrigin.cpp
|
|
* @brief Unified origin commands that work with the current origin
|
|
*
|
|
* These commands delegate to the current FileOrigin's extended operations.
|
|
* They are only active when the current origin supports the required capability.
|
|
*/
|
|
|
|
#include <App/Application.h>
|
|
#include <App/Document.h>
|
|
|
|
#include "Application.h"
|
|
#include "BitmapFactory.h"
|
|
#include "Command.h"
|
|
#include "Document.h"
|
|
#include "FileOrigin.h"
|
|
#include "MainWindow.h"
|
|
#include "OriginManager.h"
|
|
|
|
|
|
using namespace Gui;
|
|
|
|
//===========================================================================
|
|
// Origin_Commit
|
|
//===========================================================================
|
|
|
|
DEF_STD_CMD_A(OriginCmdCommit)
|
|
|
|
OriginCmdCommit::OriginCmdCommit()
|
|
: Command("Origin_Commit")
|
|
{
|
|
sGroup = "File";
|
|
sMenuText = QT_TR_NOOP("&Commit");
|
|
sToolTipText = QT_TR_NOOP("Commit changes as a new revision");
|
|
sWhatsThis = "Origin_Commit";
|
|
sStatusTip = sToolTipText;
|
|
sPixmap = "silo-commit";
|
|
sAccel = "Ctrl+Shift+C";
|
|
eType = AlterDoc;
|
|
}
|
|
|
|
void OriginCmdCommit::activated(int /*iMsg*/)
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
if (origin && origin->supportsRevisions()) {
|
|
origin->commitDocument(doc);
|
|
}
|
|
}
|
|
|
|
bool OriginCmdCommit::isActive()
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return false;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
return origin && origin->supportsRevisions();
|
|
}
|
|
|
|
//===========================================================================
|
|
// Origin_Pull
|
|
//===========================================================================
|
|
|
|
DEF_STD_CMD_A(OriginCmdPull)
|
|
|
|
OriginCmdPull::OriginCmdPull()
|
|
: Command("Origin_Pull")
|
|
{
|
|
sGroup = "File";
|
|
sMenuText = QT_TR_NOOP("&Pull");
|
|
sToolTipText = QT_TR_NOOP("Pull a specific revision from the origin");
|
|
sWhatsThis = "Origin_Pull";
|
|
sStatusTip = sToolTipText;
|
|
sPixmap = "silo-pull";
|
|
sAccel = "Ctrl+Shift+P";
|
|
eType = AlterDoc;
|
|
}
|
|
|
|
void OriginCmdPull::activated(int /*iMsg*/)
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
if (origin && origin->supportsRevisions()) {
|
|
origin->pullDocument(doc);
|
|
}
|
|
}
|
|
|
|
bool OriginCmdPull::isActive()
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return false;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
return origin && origin->supportsRevisions();
|
|
}
|
|
|
|
//===========================================================================
|
|
// Origin_Push
|
|
//===========================================================================
|
|
|
|
DEF_STD_CMD_A(OriginCmdPush)
|
|
|
|
OriginCmdPush::OriginCmdPush()
|
|
: Command("Origin_Push")
|
|
{
|
|
sGroup = "File";
|
|
sMenuText = QT_TR_NOOP("Pu&sh");
|
|
sToolTipText = QT_TR_NOOP("Push local changes to the origin");
|
|
sWhatsThis = "Origin_Push";
|
|
sStatusTip = sToolTipText;
|
|
sPixmap = "silo-push";
|
|
sAccel = "Ctrl+Shift+U";
|
|
eType = AlterDoc;
|
|
}
|
|
|
|
void OriginCmdPush::activated(int /*iMsg*/)
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
if (origin && origin->supportsRevisions()) {
|
|
origin->pushDocument(doc);
|
|
}
|
|
}
|
|
|
|
bool OriginCmdPush::isActive()
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return false;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
return origin && origin->supportsRevisions();
|
|
}
|
|
|
|
//===========================================================================
|
|
// Origin_Info
|
|
//===========================================================================
|
|
|
|
DEF_STD_CMD_A(OriginCmdInfo)
|
|
|
|
OriginCmdInfo::OriginCmdInfo()
|
|
: Command("Origin_Info")
|
|
{
|
|
sGroup = "File";
|
|
sMenuText = QT_TR_NOOP("&Info");
|
|
sToolTipText = QT_TR_NOOP("Show document information from origin");
|
|
sWhatsThis = "Origin_Info";
|
|
sStatusTip = sToolTipText;
|
|
sPixmap = "silo-info";
|
|
eType = 0;
|
|
}
|
|
|
|
void OriginCmdInfo::activated(int /*iMsg*/)
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
if (origin && origin->supportsPartNumbers()) {
|
|
origin->showInfo(doc);
|
|
}
|
|
}
|
|
|
|
bool OriginCmdInfo::isActive()
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return false;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
return origin && origin->supportsPartNumbers();
|
|
}
|
|
|
|
//===========================================================================
|
|
// Origin_BOM
|
|
//===========================================================================
|
|
|
|
DEF_STD_CMD_A(OriginCmdBOM)
|
|
|
|
OriginCmdBOM::OriginCmdBOM()
|
|
: Command("Origin_BOM")
|
|
{
|
|
sGroup = "File";
|
|
sMenuText = QT_TR_NOOP("&Bill of Materials");
|
|
sToolTipText = QT_TR_NOOP("Show Bill of Materials for this document");
|
|
sWhatsThis = "Origin_BOM";
|
|
sStatusTip = sToolTipText;
|
|
sPixmap = "silo-bom";
|
|
eType = 0;
|
|
}
|
|
|
|
void OriginCmdBOM::activated(int /*iMsg*/)
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
if (origin && origin->supportsBOM()) {
|
|
origin->showBOM(doc);
|
|
}
|
|
}
|
|
|
|
bool OriginCmdBOM::isActive()
|
|
{
|
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
|
if (!doc) {
|
|
return false;
|
|
}
|
|
|
|
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
|
|
return origin && origin->supportsBOM();
|
|
}
|
|
|
|
|
|
//===========================================================================
|
|
// Command Registration
|
|
//===========================================================================
|
|
|
|
namespace Gui {
|
|
|
|
void CreateOriginCommands()
|
|
{
|
|
CommandManager& rcCmdMgr = Application::Instance->commandManager();
|
|
|
|
rcCmdMgr.addCommand(new OriginCmdCommit());
|
|
rcCmdMgr.addCommand(new OriginCmdPull());
|
|
rcCmdMgr.addCommand(new OriginCmdPush());
|
|
rcCmdMgr.addCommand(new OriginCmdInfo());
|
|
rcCmdMgr.addCommand(new OriginCmdBOM());
|
|
}
|
|
|
|
} // namespace Gui
|