00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include "Workbench.h"
00027 #include "WorkbenchPy.h"
00028 #include "PythonWorkbenchPy.h"
00029 #include "MenuManager.h"
00030 #include "ToolBarManager.h"
00031 #include "DockWindowManager.h"
00032 #include "Application.h"
00033 #include "Action.h"
00034 #include "Command.h"
00035 #include "Control.h"
00036 #include "ToolBoxManager.h"
00037 #include "Window.h"
00038 #include "Selection.h"
00039 #include "MainWindow.h"
00040 #include <Gui/CombiView.h>
00041 #include <Gui/TaskView/TaskView.h>
00042 #include <Gui/TaskView/TaskWatcher.h>
00043
00044 #include <App/Application.h>
00045 #include <App/DocumentObject.h>
00046 #include <Base/Parameter.h>
00047 #include <Base/Interpreter.h>
00048
00049 using namespace Gui;
00050
00200
00201 TYPESYSTEM_SOURCE_ABSTRACT(Gui::Workbench, Base::BaseClass)
00202
00203 Workbench::Workbench()
00204 : _name("")
00205 {
00206 }
00207
00208 Workbench::~Workbench()
00209 {
00210 }
00211
00212 std::string Workbench::name() const
00213 {
00214 return _name;
00215 }
00216
00217 void Workbench::setName(const std::string& name)
00218 {
00219 _name = name;
00220 }
00221
00222 void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const
00223 {
00224 std::string name = this->name();
00225 ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
00226 ->GetGroup("Workbench")->GetGroup(name.c_str())->GetGroup(toolbar);
00227
00228 std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups();
00229 CommandManager& rMgr = Application::Instance->commandManager();
00230 for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) {
00231 bool active = (*it)->GetBool("Active", true);
00232 if (!active)
00233 continue;
00234 ToolBarItem* bar = new ToolBarItem(root);
00235 bar->setCommand("Custom");
00236
00237
00238 std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap();
00239 for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) {
00240 if (it2->first == "Separator") {
00241 *bar << "Separator";
00242 } else if (it2->first == "Name") {
00243 bar->setCommand(it2->second);
00244 } else {
00245 Command* pCmd = rMgr.getCommandByName(it2->first.c_str());
00246 if (!pCmd) {
00247
00248 std::string pyMod = it2->second + "Gui";
00249 try {
00250 Base::Interpreter().loadModule(pyMod.c_str());
00251 }
00252 catch(const Base::Exception&) {
00253 }
00254
00255
00256 pCmd = rMgr.getCommandByName(it2->first.c_str());
00257 }
00258
00259 if (pCmd) {
00260 *bar << it2->first;
00261 }
00262 }
00263 }
00264 }
00265 }
00266
00267 void Workbench::setupCustomShortcuts() const
00268 {
00269
00270 ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter();
00271 if ( hGrp->HasGroup("Shortcut") ) {
00272 hGrp = hGrp->GetGroup("Shortcut");
00273
00274 const CommandManager& cCmdMgr = Application::Instance->commandManager();
00275 std::vector<std::pair<std::string,std::string> > items = hGrp->GetASCIIMap();
00276 for ( std::vector<std::pair<std::string,std::string> >::iterator it = items.begin(); it != items.end(); ++it )
00277 {
00278 Command* cmd = cCmdMgr.getCommandByName(it->first.c_str());
00279 if (cmd && cmd->getAction())
00280 {
00281
00282 QString str = QString::fromUtf8(it->second.c_str());
00283 QKeySequence shortcut = str;
00284 cmd->getAction()->setShortcut(shortcut);
00285 }
00286 }
00287 }
00288 }
00289
00290 void Workbench::setupContextMenu(const char* recipient,MenuItem* item) const
00291 {
00292 }
00293
00294 void Workbench::createMainWindowPopupMenu(MenuItem*) const
00295 {
00296 }
00297
00298 void Workbench::activated()
00299 {
00300 }
00301
00302 void Workbench::deactivated()
00303 {
00304 }
00305
00306 bool Workbench::activate()
00307 {
00308 ToolBarItem* tb = setupToolBars();
00309 setupCustomToolbars(tb, "Toolbar");
00310 ToolBarManager::getInstance()->setup( tb );
00311 delete tb;
00312
00313 ToolBarItem* cb = setupCommandBars();
00314 setupCustomToolbars(cb, "Toolboxbar");
00315
00316 delete cb;
00317
00318 DockWindowItems* dw = setupDockWindows();
00319 DockWindowManager::instance()->setup( dw );
00320 delete dw;
00321
00322 MenuItem* mb = setupMenuBar();
00323 MenuManager::getInstance()->setup( mb );
00324 delete mb;
00325
00326 setupCustomShortcuts();
00327
00328 return true;
00329 }
00330
00331 void Workbench::retranslate() const
00332 {
00333 ToolBarManager::getInstance()->retranslate();
00334
00335 DockWindowManager::instance()->retranslate();
00336 MenuManager::getInstance()->retranslate();
00337 }
00338
00339 PyObject* Workbench::getPyObject()
00340 {
00341 return new WorkbenchPy(this);
00342 }
00343
00344 void Workbench::addTaskWatcher(std::vector<Gui::TaskView::TaskWatcher*> &Watcher)
00345 {
00346 Gui::TaskView::TaskView* taskView = Control().taskPanel();
00347 if (taskView)
00348 taskView->addTaskWatcher(Watcher);
00349 }
00350
00351 void Workbench::removeTaskWatcher(void)
00352 {
00353 Gui::TaskView::TaskView* taskView = Control().taskPanel();
00354 if (taskView)
00355 taskView->clearTaskWatcher();
00356 }
00357
00358
00359
00360 #if 0 // needed for Qt's lupdate utility
00361 qApp->translate("Workbench", "&File");
00362 qApp->translate("Workbench", "&Edit");
00363 qApp->translate("Workbench", "Standard views");
00364 qApp->translate("Workbench", "&Stereo");
00365 qApp->translate("Workbench", "&Zoom");
00366 qApp->translate("Workbench", "Visibility");
00367 qApp->translate("Workbench", "&View");
00368 qApp->translate("Workbench", "&Tools");
00369 qApp->translate("Workbench", "&Macro");
00370 qApp->translate("Workbench", "&Windows");
00371 qApp->translate("Workbench", "&On-line help");
00372 qApp->translate("Workbench", "&Help");
00373 qApp->translate("Workbench", "File");
00374 qApp->translate("Workbench", "Macro");
00375 qApp->translate("Workbench", "View");
00376 qApp->translate("Workbench", "Special Ops");
00377 #endif
00378
00379 TYPESYSTEM_SOURCE(Gui::StdWorkbench, Gui::Workbench)
00380
00381 StdWorkbench::StdWorkbench()
00382 : Workbench()
00383 {
00384 }
00385
00386 StdWorkbench::~StdWorkbench()
00387 {
00388 }
00389
00390 void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
00391 {
00392 if (strcmp(recipient,"View") == 0)
00393 {
00394 MenuItem* StdViews = new MenuItem;
00395 StdViews->setCommand( "Standard views" );
00396
00397 *StdViews << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewTop" << "Std_ViewRight"
00398 << "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft";
00399
00400 *item << "Std_ViewFitAll" << "Std_ViewFitSelection" << StdViews
00401 << "Separator" << "Std_ViewDockUndockFullscreen";
00402
00403 if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
00404 *item << "Separator" << "Std_SetAppearance" << "Std_ToggleVisibility" << "Std_TreeSelection"
00405 << "Std_RandomColor" << "Separator" << "Std_Delete";
00406 }
00407 else if (strcmp(recipient,"Tree") == 0)
00408 {
00409 if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
00410 *item << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
00411 << "Separator" << "Std_SetAppearance" << "Std_RandomColor"
00412 << "Separator" << "Std_Delete";
00413 }
00414 }
00415
00416 void StdWorkbench::createMainWindowPopupMenu(MenuItem* item) const
00417 {
00418 *item << "Std_DlgCustomize";
00419 }
00420
00421 MenuItem* StdWorkbench::setupMenuBar() const
00422 {
00423
00424 MenuItem* menuBar = new MenuItem;
00425
00426
00427 MenuItem* file = new MenuItem( menuBar );
00428 file->setCommand("&File");
00429 *file << "Std_New" << "Std_Open" << "Separator" << "Std_CloseActiveWindow"
00430 << "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs"
00431 << "Separator" << "Std_Import" << "Std_Export"
00432 << "Std_MergeProjects" << "Std_ProjectInfo"
00433 << "Separator" << "Std_Print" << "Std_PrintPreview" << "Std_PrintPdf"
00434 << "Separator" << "Std_RecentFiles" << "Separator" << "Std_Quit";
00435
00436
00437 MenuItem* edit = new MenuItem( menuBar );
00438 edit->setCommand("&Edit");
00439 *edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
00440 << "Std_Paste" << "Std_DuplicateSelection" << "Separator"
00441 << "Std_Refresh" << "Std_SelectAll" << "Std_Delete" << "Std_Placement"
00442 << "Separator" << "Std_DlgPreferences";
00443
00444
00445 MenuItem* stdviews = new MenuItem;
00446 stdviews->setCommand("Standard views");
00447 *stdviews << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo"
00448 << "Separator" << "Std_ViewFront" << "Std_ViewRight"
00449 << "Std_ViewTop" << "Separator" << "Std_ViewRear"
00450 << "Std_ViewLeft" << "Std_ViewBottom";
00451
00452
00453 MenuItem* view3d = new MenuItem;
00454 view3d->setCommand("&Stereo");
00455 *view3d << "Std_ViewIvStereoRedGreen" << "Std_ViewIvStereoQuadBuff"
00456 << "Std_ViewIvStereoInterleavedRows" << "Std_ViewIvStereoInterleavedColumns"
00457 << "Std_ViewIvStereoOff" << "Separator" << "Std_ViewIvIssueCamPos";
00458
00459
00460 MenuItem* zoom = new MenuItem;
00461 zoom->setCommand("&Zoom");
00462 *zoom << "Std_ViewZoomIn" << "Std_ViewZoomOut" << "Separator" << "Std_ViewBoxZoom";
00463
00464
00465 MenuItem* visu = new MenuItem;
00466 visu->setCommand("Visibility");
00467 *visu << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
00468 << "Separator" << "Std_ToggleObjects" << "Std_ShowObjects" << "Std_HideObjects"
00469 << "Separator" << "Std_ToggleSelectability";
00470
00471
00472 MenuItem* view = new MenuItem( menuBar );
00473 view->setCommand("&View");
00474 *view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" << "Separator"
00475 << stdviews << "Std_FreezeViews" << "Separator" << view3d << zoom
00476 << "Std_ViewDockUndockFullscreen" << "Std_AxisCross" << "Std_ToggleClipPlane"
00477 << "Std_TextureMapping" << "Separator" << visu
00478 << "Std_ToggleVisibility" << "Std_ToggleNavigation"
00479 << "Std_SetAppearance" << "Std_RandomColor" << "Separator"
00480 << "Std_MeasureDistance" << "Separator"
00481 << "Std_Workbench" << "Std_ToolBarMenu" << "Std_DockViewMenu" << "Separator"
00482 << "Std_ViewStatusBar";
00483
00484
00485 MenuItem* tool = new MenuItem( menuBar );
00486 tool->setCommand("&Tools");
00487 *tool << "Std_DlgParameter" << "Separator"
00488 << "Std_ViewScreenShot" << "Std_SceneInspector" << "Std_DemoMode"
00489 << "Separator" << "Std_DlgCustomize";
00490
00491
00492 MenuItem* macro = new MenuItem( menuBar );
00493 macro->setCommand("&Macro");
00494 *macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
00495 << "Separator" << "Std_DlgMacroExecuteDirect" << "Std_MacroStartDebug"
00496 << "Std_MacroStopDebug" << "Std_MacroStepOver" << "Std_ToggleBreakpoint";
00497
00498
00499 MenuItem* wnd = new MenuItem( menuBar );
00500 wnd->setCommand("&Windows");
00501 *wnd << "Std_ActivateNextWindow" << "Std_ActivatePrevWindow" << "Separator"
00502 << "Std_TileWindows" << "Std_CascadeWindows"
00503 << "Std_ArrangeIcons" << "Separator" << "Std_WindowsMenu" << "Std_Windows";
00504
00505
00506 MenuItem* sep = new MenuItem( menuBar );
00507 sep->setCommand( "Separator" );
00508
00509
00510 MenuItem* helpWebsites = new MenuItem;
00511 helpWebsites->setCommand("&On-line help");
00512 *helpWebsites << "Std_OnlineHelpWebsite" << "Std_FreeCADWebsite" << "Std_PythonWebsite";
00513
00514 MenuItem* help = new MenuItem( menuBar );
00515 help->setCommand("&Help");
00516 *help << "Std_OnlineHelp" << "Std_OnlineHelpPython" << "Std_PythonHelp"
00517 << helpWebsites << "Separator" << "Std_About"
00518 << "Std_AboutQt" << "Separator" << "Std_WhatsThis";
00519
00520 return menuBar;
00521 }
00522
00523 ToolBarItem* StdWorkbench::setupToolBars() const
00524 {
00525 ToolBarItem* root = new ToolBarItem;
00526
00527
00528 ToolBarItem* file = new ToolBarItem( root );
00529 file->setCommand("File");
00530 *file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut"
00531 << "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator"
00532 << "Std_Refresh" << "Separator" << "Std_Workbench" << "Std_WhatsThis";
00533
00534
00535 ToolBarItem* macro = new ToolBarItem( root );
00536 macro->setCommand("Macro");
00537 *macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
00538 << "Std_DlgMacroExecuteDirect";
00539
00540
00541 ToolBarItem* view = new ToolBarItem( root );
00542 view->setCommand("View");
00543 *view << "Std_ViewFitAll" << "Separator" << "Std_ViewAxo" << "Separator" << "Std_ViewFront"
00544 << "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft"
00545 << "Std_ViewBottom" << "Separator" << "Std_MeasureDistance" ;
00546
00547 return root;
00548 }
00549
00550 ToolBarItem* StdWorkbench::setupCommandBars() const
00551 {
00552 ToolBarItem* root = new ToolBarItem;
00553
00554
00555 ToolBarItem* view = new ToolBarItem( root );
00556 view->setCommand("Standard views");
00557 *view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo" << "Separator"
00558 << "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" << "Separator"
00559 << "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom";
00560
00561 ToolBarItem* macro = new ToolBarItem( root );
00562 macro->setCommand("Special Ops");
00563 *macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord" << "Std_MacroStopRecord"
00564 << "Std_DlgMacroExecute" << "Std_DlgCustomize";
00565
00566 return root;
00567 }
00568
00569 DockWindowItems* StdWorkbench::setupDockWindows() const
00570 {
00571 DockWindowItems* root = new DockWindowItems();
00572 root->addDockWidget("Std_ToolBox", Qt::RightDockWidgetArea, false, false);
00573
00574 root->addDockWidget("Std_TreeView", Qt::LeftDockWidgetArea, true, false);
00575 root->addDockWidget("Std_PropertyView", Qt::LeftDockWidgetArea, true, false);
00576 root->addDockWidget("Std_SelectionView", Qt::LeftDockWidgetArea, false, false);
00577 root->addDockWidget("Std_CombiView", Qt::LeftDockWidgetArea, false, false);
00578 root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, true, true);
00579
00580 root->addDockWidget("Std_PythonView", Qt::BottomDockWidgetArea, true, true);
00581 return root;
00582 }
00583
00584
00585
00586 TYPESYSTEM_SOURCE(Gui::BlankWorkbench, Gui::Workbench)
00587
00588 BlankWorkbench::BlankWorkbench()
00589 : Workbench()
00590 {
00591 }
00592
00593 BlankWorkbench::~BlankWorkbench()
00594 {
00595 }
00596
00597 void BlankWorkbench::activated()
00598 {
00599 QList<QDockWidget*> dw = getMainWindow()->findChildren<QDockWidget*>();
00600 for (QList<QDockWidget*>::iterator it = dw.begin(); it != dw.end(); ++it)
00601 (*it)->toggleViewAction()->setVisible(false);
00602 getMainWindow()->statusBar()->hide();
00603 }
00604
00605 void BlankWorkbench::deactivated()
00606 {
00607 getMainWindow()->statusBar()->show();
00608 }
00609
00610 void BlankWorkbench::setupContextMenu(const char* recipient,MenuItem* item) const
00611 {
00612 }
00613
00614 MenuItem* BlankWorkbench::setupMenuBar() const
00615 {
00616 return new MenuItem();
00617 }
00618
00619 ToolBarItem* BlankWorkbench::setupToolBars() const
00620 {
00621 return new ToolBarItem();
00622 }
00623
00624 ToolBarItem* BlankWorkbench::setupCommandBars() const
00625 {
00626 return new ToolBarItem();
00627 }
00628
00629 DockWindowItems* BlankWorkbench::setupDockWindows() const
00630 {
00631 return new DockWindowItems();
00632 }
00633
00634
00635
00636 TYPESYSTEM_SOURCE(Gui::NoneWorkbench, Gui::StdWorkbench)
00637
00638 NoneWorkbench::NoneWorkbench()
00639 : StdWorkbench()
00640 {
00641 }
00642
00643 NoneWorkbench::~NoneWorkbench()
00644 {
00645 }
00646
00647 void NoneWorkbench::setupContextMenu(const char* recipient,MenuItem* item) const
00648 {
00649 }
00650
00651 MenuItem* NoneWorkbench::setupMenuBar() const
00652 {
00653
00654 MenuItem* menuBar = new MenuItem;
00655
00656
00657 MenuItem* file = new MenuItem( menuBar );
00658 file->setCommand("&File");
00659 *file << "Std_Quit";
00660
00661
00662 MenuItem* edit = new MenuItem( menuBar );
00663 edit->setCommand("&Edit");
00664 *edit << "Std_DlgPreferences";
00665
00666
00667 MenuItem* view = new MenuItem( menuBar );
00668 view->setCommand("&View");
00669 *view << "Std_Workbench";
00670
00671
00672 MenuItem* sep = new MenuItem( menuBar );
00673 sep->setCommand("Separator");
00674
00675
00676 MenuItem* help = new MenuItem( menuBar );
00677 help->setCommand("&Help");
00678 *help << "Std_OnlineHelp" << "Std_About" << "Std_AboutQt";
00679
00680 return menuBar;
00681 }
00682
00683 ToolBarItem* NoneWorkbench::setupToolBars() const
00684 {
00685 ToolBarItem* root = new ToolBarItem;
00686 return root;
00687 }
00688
00689 ToolBarItem* NoneWorkbench::setupCommandBars() const
00690 {
00691 ToolBarItem* root = new ToolBarItem;
00692 return root;
00693 }
00694
00695 DockWindowItems* NoneWorkbench::setupDockWindows() const
00696 {
00697 DockWindowItems* root = new DockWindowItems();
00698 root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, true, false);
00699 return root;
00700 }
00701
00702
00703
00704 TYPESYSTEM_SOURCE(Gui::TestWorkbench, Gui::Workbench)
00705
00706 TestWorkbench::TestWorkbench()
00707 : StdWorkbench()
00708 {
00709 }
00710
00711 TestWorkbench::~TestWorkbench()
00712 {
00713 }
00714
00715 MenuItem* TestWorkbench::setupMenuBar() const
00716 {
00717
00718 MenuItem* menuBar = StdWorkbench::setupMenuBar();
00719
00720 MenuItem* item = menuBar->findItem("&Help");
00721 item->removeItem(item->findItem("Std_WhatsThis"));
00722
00723
00724 MenuItem* test = new MenuItem;
00725 menuBar->insertItem( item, test );
00726 test->setCommand( "Test &Commands" );
00727 *test << "Std_Test1" << "Std_Test2" << "Std_Test3" << "Std_Test4" << "Std_Test5"
00728 << "Std_Test6" << "Std_Test7" << "Std_Test8";
00729
00730
00731 MenuItem* opiv = new MenuItem;
00732 menuBar->insertItem( item, opiv );
00733 opiv->setCommand("&Inventor View");
00734 *opiv << "Std_ViewExample1" << "Std_ViewExample2" << "Std_ViewExample3";
00735
00736 return menuBar;
00737 }
00738
00739 ToolBarItem* TestWorkbench::setupToolBars() const
00740 {
00741 return 0;
00742 }
00743
00744 ToolBarItem* TestWorkbench::setupCommandBars() const
00745 {
00746 return 0;
00747 }
00748
00749
00750
00751 TYPESYSTEM_SOURCE(Gui::PythonWorkbench, Gui::Workbench)
00752
00753 PythonWorkbench::PythonWorkbench() : _workbenchPy(0)
00754 {
00755 _menuBar = StdWorkbench::setupMenuBar();
00756 _contextMenu = new MenuItem;
00757 _toolBar = StdWorkbench::setupToolBars();
00758 _commandBar = new ToolBarItem;
00759 }
00760
00761 PythonWorkbench::~PythonWorkbench()
00762 {
00763 delete _menuBar;
00764 delete _contextMenu;
00765 delete _toolBar;
00766 delete _commandBar;
00767 if (_workbenchPy)
00768 {
00769 _workbenchPy->setInvalid();
00770 _workbenchPy->DecRef();
00771 }
00772 }
00773
00774 PyObject* PythonWorkbench::getPyObject()
00775 {
00776 if (!_workbenchPy)
00777 {
00778 _workbenchPy = new PythonWorkbenchPy(this);
00779 }
00780
00781
00782 _workbenchPy->IncRef();
00783
00784 return _workbenchPy;
00785 }
00786
00787 MenuItem* PythonWorkbench::setupMenuBar() const
00788 {
00789 return _menuBar->copy();
00790 }
00791
00792 ToolBarItem* PythonWorkbench::setupToolBars() const
00793 {
00794 return _toolBar->copy();
00795 }
00796
00797 ToolBarItem* PythonWorkbench::setupCommandBars() const
00798 {
00799 return _commandBar->copy();
00800 }
00801
00802 void PythonWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
00803 {
00804 StdWorkbench::setupContextMenu(recipient, item);
00805 QList<MenuItem*> items = _contextMenu->getItems();
00806 for (QList<MenuItem*>::Iterator it = items.begin(); it != items.end(); ++it) {
00807 item->appendItem((*it)->copy());
00808 }
00809 }
00810
00811 void PythonWorkbench::appendMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const
00812 {
00813 if ( menu.empty() || items.empty() )
00814 return;
00815
00816 std::list<std::string>::const_iterator jt=menu.begin();
00817 MenuItem* item = _menuBar->findItem( *jt );
00818 if (!item)
00819 {
00820 Gui::MenuItem* wnd = _menuBar->findItem( "&Windows" );
00821 item = new MenuItem;
00822 item->setCommand( *jt );
00823 _menuBar->insertItem( wnd, item );
00824 }
00825
00826
00827 for ( jt++; jt != menu.end(); jt++ )
00828 {
00829 MenuItem* subitem = item->findItem( *jt );
00830 if ( !subitem )
00831 {
00832 subitem = new MenuItem(item);
00833 subitem->setCommand( *jt );
00834 }
00835 item = subitem;
00836 }
00837
00838 for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it)
00839 *item << *it;
00840 }
00841
00842 void PythonWorkbench::removeMenu(const std::string& menu) const
00843 {
00844 MenuItem* item = _menuBar->findItem(menu);
00845 if ( item ) {
00846 _menuBar->removeItem(item);
00847 delete item;
00848 }
00849 }
00850
00851 std::list<std::string> PythonWorkbench::listMenus() const
00852 {
00853 std::list<std::string> menus;
00854 QList<MenuItem*> items = _menuBar->getItems();
00855 for ( QList<MenuItem*>::ConstIterator it = items.begin(); it != items.end(); ++it )
00856 menus.push_back((*it)->command());
00857 return menus;
00858 }
00859
00860 void PythonWorkbench::appendContextMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const
00861 {
00862 MenuItem* item = _contextMenu;
00863 for (std::list<std::string>::const_iterator jt=menu.begin();jt!=menu.end();++jt) {
00864 MenuItem* subitem = item->findItem(*jt);
00865 if (!subitem) {
00866 subitem = new MenuItem(item);
00867 subitem->setCommand(*jt);
00868 }
00869 item = subitem;
00870 }
00871
00872 for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it)
00873 *item << *it;
00874 }
00875
00876 void PythonWorkbench::removeContextMenu(const std::string& menu) const
00877 {
00878 MenuItem* item = _contextMenu->findItem(menu);
00879 if (item) {
00880 _contextMenu->removeItem(item);
00881 delete item;
00882 }
00883 }
00884
00885 void PythonWorkbench::clearContextMenu()
00886 {
00887 _contextMenu->clear();
00888 }
00889
00890 void PythonWorkbench::appendToolbar(const std::string& bar, const std::list<std::string>& items) const
00891 {
00892 ToolBarItem* item = _toolBar->findItem(bar);
00893 if (!item)
00894 {
00895 item = new ToolBarItem(_toolBar);
00896 item->setCommand(bar);
00897 }
00898
00899 for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it)
00900 *item << *it;
00901 }
00902
00903 void PythonWorkbench::removeToolbar(const std::string& bar) const
00904 {
00905 ToolBarItem* item = _toolBar->findItem(bar);
00906 if (item) {
00907 _toolBar->removeItem(item);
00908 delete item;
00909 }
00910 }
00911
00912 std::list<std::string> PythonWorkbench::listToolbars() const
00913 {
00914 std::list<std::string> bars;
00915 QList<ToolBarItem*> items = _toolBar->getItems();
00916 for (QList<ToolBarItem*>::ConstIterator item = items.begin(); item != items.end(); ++item)
00917 bars.push_back((*item)->command());
00918 return bars;
00919 }
00920
00921 void PythonWorkbench::appendCommandbar(const std::string& bar, const std::list<std::string>& items) const
00922 {
00923 ToolBarItem* item = _commandBar->findItem( bar );
00924 if ( !item )
00925 {
00926 item = new ToolBarItem(_commandBar);
00927 item->setCommand(bar);
00928 }
00929
00930 for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it)
00931 *item << *it;
00932 }
00933
00934 void PythonWorkbench::removeCommandbar(const std::string& bar) const
00935 {
00936 ToolBarItem* item = _commandBar->findItem(bar);
00937 if ( item ) {
00938 _commandBar->removeItem(item);
00939 delete item;
00940 }
00941 }
00942
00943 std::list<std::string> PythonWorkbench::listCommandbars() const
00944 {
00945 std::list<std::string> bars;
00946 QList<ToolBarItem*> items = _commandBar->getItems();
00947 for (QList<ToolBarItem*>::ConstIterator item = items.begin(); item != items.end(); ++item)
00948 bars.push_back((*item)->command());
00949 return bars;
00950 }
00951