dload_menu.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:21k
- /*
- * ===========================================================================
- * PRODUCTION $Log: dload_menu.cpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 20:43:46 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.30
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: dload_menu.cpp,v 1000.3 2004/06/01 20:43:46 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- *
- * CDLoadMenuData_Impl -- Abstract class to hold callback information
- * necessary to spawn a document / data loader plugin
- * from an FLTK callback
- *
- * COpenMenuData -- Class to hold / launch plugin to open a new
- * document
- * CImportMenuData -- Class to hold / launch plugin to import data into
- * an existing record
- * CSaveAsMenuData -- Class to hold / launch plugin to save the current
- * record
- * CUnloadMenuData -- Class to unload a document from memory
- *
- * CDocLoaderMenuMgr -- Manager for dynamic FLTK document laoder plugin
- * menu + callback data
- */
- #include <ncbi_pch.hpp>
- #include <gui/plugin/PluginMessage.hpp>
- #include <gui/plugin/PluginMRUList.hpp>
- #include <gui/plugin/PluginMRUEntry.hpp>
- #include <gui/core/dload_factory.hpp>
- #include <gui/core/dload_menu.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_registry.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/plugin_handle.hpp>
- #include <gui/core/plugin_dlg.hpp>
- #include <gui/utils/message_box.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- //
- // internal base class used by suclasses. This class exists to keep
- // CPluginHandle private within the context of this header.
- //
- class CDLoadMenuData_Impl : public IDLoadMenuData
- {
- public:
- //CDLoadMenuData_Impl(CPluginHandle plugin);
- CDLoadMenuData_Impl(const string& plugin_name);
- virtual ~CDLoadMenuData_Impl() {}
- protected:
- string m_Plugin;
- };
- //
- // concrete data class for loading new documents
- //
- class COpenMenuData : public CDLoadMenuData_Impl
- {
- public:
- COpenMenuData(const string& plugin)
- : CDLoadMenuData_Impl(plugin)
- {
- }
- COpenMenuData(CPluginHandle plugin)
- : CDLoadMenuData_Impl(plugin.GetClassName())
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( m_Plugin.empty() ) {
- return;
- }
- // we create a dummy selection buffer to hold our single document
- CPluginUtils::CallPlugin(m_Plugin, eDataCommand_load);
- }
- };
- class COpenMenuDataEx : public IDLoadMenuData
- {
- public:
- COpenMenuDataEx()
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( !m_Dlg.get() ) {
- m_Dlg.reset(new CPluginDlg(eDataCommand_load));
- }
- m_Dlg->Show();
- }
- private:
- auto_ptr<CPluginDlg> m_Dlg;
- };
- //
- // concrete data class for loading new documents
- //
- class CSearchMenuData : public CDLoadMenuData_Impl
- {
- public:
- CSearchMenuData(const string& plugin)
- : CDLoadMenuData_Impl(plugin)
- {
- }
- CSearchMenuData(CPluginHandle plugin)
- : CDLoadMenuData_Impl(plugin.GetClassName())
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( m_Plugin.empty() ) {
- return;
- }
- CPluginUtils::CallPlugin(m_Plugin, eDataCommand_search);
- }
- };
- //
- // concrete data class for loading new documents
- //
- class CManageMenuData : public CDLoadMenuData_Impl
- {
- public:
- CManageMenuData(const string& plugin)
- : CDLoadMenuData_Impl(plugin)
- {
- }
- CManageMenuData(CPluginHandle plugin)
- : CDLoadMenuData_Impl(plugin.GetClassName())
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( m_Plugin.empty() ) {
- return;
- }
- CPluginUtils::CallPlugin(m_Plugin, eDataCommand_manage);
- }
- };
- //
- // concrete data class for importing into current documents
- //
- class CImportMenuData : public CDLoadMenuData_Impl
- {
- public:
- CImportMenuData(CPluginHandle plugin, IDocument* doc)
- : CDLoadMenuData_Impl(plugin.GetClassName()),
- m_Doc(doc)
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( m_Plugin.empty() || !m_Doc ) {
- return;
- }
- CPluginUtils::CallPlugin(m_Plugin, eDataCommand_import, m_Doc);
- }
- private:
- IDocument* m_Doc;
- };
- //
- // concrete data class for saving current documents
- //
- class CSaveMenuData : public CDLoadMenuData_Impl
- {
- public:
- CSaveMenuData(const string& plugin_name, IDocument* doc)
- : CDLoadMenuData_Impl(plugin_name),
- m_Doc(doc)
- {
- }
-
- CSaveMenuData(CPluginHandle plugin, IDocument* doc)
- : CDLoadMenuData_Impl(plugin.GetClassName()),
- m_Doc(doc)
- {
- }
-
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( m_Plugin.empty() || !m_Doc ) {
- return;
- }
- CPluginUtils::CallPlugin(m_Plugin, eDataCommand_save, m_Doc);
- }
- private:
- IDocument* m_Doc;
- };
- //
- // concrete data class for unloading documents
- //
- class CUnloadMenuData : public CDLoadMenuData_Impl
- {
- public:
- CUnloadMenuData(IDocument* doc)
- : CDLoadMenuData_Impl(kEmptyStr),
- m_Doc(doc)
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( !m_Doc ) {
- return;
- }
- if (CDocManager::ReleaseDocument(m_Doc)) {
- m_Doc = NULL;
- }
- }
- private:
- IDocument* m_Doc;
- };
- //
- // concrete data class for most recently used documents
- //
- class CRecentMenuData : public CDLoadMenuData_Impl
- {
- public:
- CRecentMenuData(CPluginMessage& msg)
- : CDLoadMenuData_Impl(kEmptyStr),
- m_Msg(&msg)
- {
- }
- //
- // DoCallback()
- // here we handle the meat of creating a new view
- //
- void DoCallback()
- {
- if ( !m_Msg ) {
- return;
- }
- CPluginUtils::CallPlugin(*m_Msg);
- }
- private:
- CPluginMessage* m_Msg;
- };
- //
- // default ctor for our base menu data class
- //
- CDLoadMenuData_Impl::CDLoadMenuData_Impl(const string& plugin_name)
- : m_Plugin(plugin_name)
- {
- }
- //
- // default ctor for the view menu manager class
- //
- CDocLoaderMenuMgr::CDocLoaderMenuMgr(Fl_Menu_* menu, const string& base)
- : CFltkMenuMgrBase<IDLoadMenuData>(menu)
- {
- SetMenuBase(base);
- }
- //
- // Clear()
- // this clears the contents of our two submenus
- //
- void CDocLoaderMenuMgr::Clear()
- {
- // Do our base class clear
- x_ClearData();
- if ( !m_Menu ) {
- return;
- }
- string base = m_Base;
- if ( !base.empty() ) {
- base += "/";
- }
- x_RemoveSubitems(base + "Open");
- x_RemoveSubitems(base + "Import");
- x_RemoveSubitems(base + "Save as");
- x_RemoveSubitems(base + "Unload");
- x_RemoveSubitems(base + "Recent Documents");
- }
- //
- // AddOpenMenu()
- // This fills out a new menu to hold the
- //
- void CDocLoaderMenuMgr::AddOpenMenu()
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Open";
- #if 0
- x_AddItem(menu_base, new COpenMenuDataEx());
- #else
- int items_added = 0;
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(CPluginCommandSet::e_Data);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'load' command
- CPluginHandle plugin = *iter;
- if ( !plugin.HasCommandSubtype(eDataCommand_load) ) {
- continue;
- }
- string s = plugin.GetMenuItem();
- if ( !menu_base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new COpenMenuData(plugin.GetClassName()));
- ++items_added;
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no plugins loaded)");
- }
- #endif
- }
- //
- // AddRecentMenu()
- // This fills out a new menu to hold the
- //
- void CDocLoaderMenuMgr::AddRecentMenu()
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Recent Documents/";
- int items_added = 0;
- ITERATE (CPluginMRUList::Tdata, iter, CDocManager::GetMRUCache().Get()) {
- ++items_added;
- CRef<CPluginMRUEntry> entry = *iter;
- string s = menu_base + "&" +
- NStr::IntToString(items_added) + " " + entry->GetLabel();
- x_AddItem(s, new CRecentMenuData(entry->SetMessage()));
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no plugins loaded)");
- }
- }
- //
- // AddImportMenu()
- // This fills out a dynamic menu for importing into a given document. If the
- // parameter 'doc' is NULL, then a menu is produced for importing into every
- // loaded document.
- //
- void CDocLoaderMenuMgr::AddImportMenu(IDocument* doc)
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Import/";
- int items_added = 0;
- if (doc) {
- // we add an import menu for this document only
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(eDataCommand_import, doc);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'load' command
- CPluginHandle plugin = *iter;
- string s = plugin.GetMenuItem();
- if ( !menu_base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new CImportMenuData(plugin, doc));
- ++items_added;
- }
- } else if (CDocManager::GetDocuments().size() != 0) {
- // we add an import menu for all documents
- NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,
- CDocManager::GetDocuments()) {
- doc = *doc_iter;
- if ( !doc ) {
- continue;
- }
- string base = menu_base + doc->GetShortTitle();
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(eDataCommand_import, doc);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'load' command
- CPluginHandle plugin = *iter;
- string s = plugin.GetMenuItem();
- if ( !base.empty() ) {
- s = base + "/" + s;
- }
- x_AddItem(s, new CImportMenuData(plugin, doc));
- ++items_added;
- }
- }
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no records loaded)");
- }
- }
- //
- // AddSearchMenu()
- // This fills out a new menu to hold the
- //
- void CDocLoaderMenuMgr::AddSearchMenu()
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Search/";
- int items_added = 0;
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(CPluginCommandSet::e_Data);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'load' command
- CPluginHandle plugin = *iter;
- if ( !plugin.HasCommandSubtype(eDataCommand_search) ) {
- continue;
- }
- string s = plugin.GetMenuItem();
- if ( !menu_base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new CSearchMenuData(plugin.GetClassName()));
- ++items_added;
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no plugins loaded)");
- }
- }
- //
- // AddManageMenu()
- // This fills out a new menu to hold the
- //
- void CDocLoaderMenuMgr::AddManageMenu()
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Manage Data Sources/";
- int items_added = 0;
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(CPluginCommandSet::e_Data);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'load' command
- CPluginHandle plugin = *iter;
- if ( !plugin.HasCommandSubtype(eDataCommand_manage) ) {
- continue;
- }
- string s = plugin.GetMenuItem();
- if ( !menu_base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new CManageMenuData(plugin.GetClassName()));
- ++items_added;
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no plugins loaded)");
- }
- }
- //
- // AddSaveAsMenu()
- // This fills out a dynamic menu for saving a given document. If the
- // parameter 'doc' is NULL, then a menu is produced for saving every
- // loaded document.
- //
- void CDocLoaderMenuMgr::AddSaveAsMenu(IDocument* doc)
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Save as/";
- int items_added = 0;
- if (doc) {
- // we add an import menu for this document only
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(eDataCommand_save, doc);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'save' command
- CPluginHandle plugin = *iter;
- string s = plugin.GetMenuItem();
- if ( !menu_base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new CSaveMenuData(plugin, doc));
- ++items_added;
- }
- } else if (CDocManager::GetDocuments().size() != 0) {
- // we add an import menu for all documents
- NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,
- CDocManager::GetDocuments()) {
- doc = *doc_iter;
- if ( !doc ) {
- continue;
- }
- string base = menu_base + doc->GetShortTitle();
- CPluginRegistry::TPlugins plugins =
- CPluginRegistry::GetPlugins(eDataCommand_save, doc);
- NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, plugins) {
- // verify that we support the 'save' command
- CPluginHandle plugin = *iter;
- string s = plugin.GetMenuItem();
- if ( !base.empty() ) {
- s = menu_base + s;
- }
- x_AddItem(s, new CSaveMenuData(plugin, doc));
- ++items_added;
- }
- }
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no records loaded)");
- }
- }
- //
- // AddUnloadMenu()
- // This produces a menu for explicitly unloading a given document
- //
- void CDocLoaderMenuMgr::AddUnloadMenu(IDocument* doc)
- {
- string menu_base = m_Base;
- if ( !menu_base.empty() ) {
- menu_base += "/";
- }
- menu_base += "Unload/";
- int items_added = 0;
- if (doc) {
- // we add an import menu for this document only
- x_AddItem(menu_base, new CUnloadMenuData(doc));
- ++items_added;
- } else if (CDocManager::GetDocuments().size() != 0) {
- // we add an import menu for all documents
- NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,
- CDocManager::GetDocuments()) {
- doc = *doc_iter;
- if ( !doc ) {
- continue;
- }
- string s = menu_base + doc->GetShortTitle();
- x_AddItem(s, new CUnloadMenuData(*doc_iter));
- ++items_added;
- }
- }
- if (items_added == 0) {
- x_AddNullItem(menu_base + "(no records loaded)");
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: dload_menu.cpp,v $
- * Revision 1000.3 2004/06/01 20:43:46 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.30
- *
- * Revision 1.30 2004/06/01 18:38:35 dicuccio
- * Fixed multiple definition compiler error
- *
- * Revision 1.29 2004/06/01 18:01:58 dicuccio
- * Updated to match new API in CDocManager. Added commented-out implementation of
- * new plugin options dialog
- *
- * Revision 1.28 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.27 2004/05/18 15:06:15 friedman
- * Removed included tha does not exist
- *
- * Revision 1.26 2004/05/18 11:13:24 friedman
- * Handle adding recently loaded documents into the MRU list.
- *
- * Revision 1.25 2004/04/16 14:37:10 dicuccio
- * Drop unneeded selection buffer parameter
- *
- * Revision 1.24 2003/11/06 20:06:29 dicuccio
- * Moved USING_SCOPE(objects) to implementation files
- *
- * Revision 1.23 2003/10/27 17:36:38 dicuccio
- * Removed #include for pld request status enum
- *
- * Revision 1.22 2003/09/16 13:59:00 dicuccio
- * Code clean-up. Renamed interface class for doc loader menu data
- *
- * Revision 1.21 2003/09/04 14:01:51 dicuccio
- * Introduce IDocument and IView as abstract base classes for CDocument and CView
- *
- * Revision 1.20 2003/08/04 17:29:42 dicuccio
- * Changed menu signature for manage to 'Manage Data Sources'
- *
- * Revision 1.19 2003/07/31 16:53:21 dicuccio
- * Added implementations for search / manage plugin commands
- *
- * Revision 1.18 2003/07/21 19:26:48 dicuccio
- * Changed data class interface from Run() to DoCallback() -- more descriptive.
- * Modified all menu structures to accept a selection buffer; use selection
- * buffers internally for all operations. Fixed screening of plugins based on
- * selection contents
- *
- * Revision 1.17 2003/07/14 11:00:22 shomrat
- * Plugin messageing system related changes
- *
- * Revision 1.16 2003/06/25 17:02:54 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.15 2003/05/30 14:15:41 dicuccio
- * Renamed MessageBox to NcbiMessageBox because brain-dead MSVC thinks this is
- * ::MessageBox and rewrites the symbol as MessageBoxA, which results in an
- * unresolved external and conflict with the Win32 API :(.
- *
- * Revision 1.14 2003/05/30 12:56:50 dicuccio
- * Converted code to use MessageBox() instead of fl_ask()/fl_message()/fl_alert()
- *
- * Revision 1.13 2003/04/29 14:36:49 dicuccio
- * Fully implemented screening of plugins based on selection content - updated
- * API to match
- *
- * Revision 1.12 2003/04/24 16:26:32 dicuccio
- * Plugins are now responsible for marshalling documents (not the framework's
- * function). Also, fixed given API changes to IDocument
- *
- * Revision 1.11 2003/04/16 18:19:20 dicuccio
- * Modified menu handlers to use generic plugin launch mechanism (CallPlugin())
- *
- * Revision 1.10 2003/03/10 22:58:51 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.9 2003/02/26 17:53:31 dicuccio
- * Cleaned up the dynamic menus to make the dynamic menus resistant to menu
- * refreshes while the menu callback is running
- *
- * Revision 1.8 2003/02/24 13:03:15 dicuccio
- * Renamed classes in plugin spec:
- * CArgSeg --> CPluginArgSet
- * CArgument --> CPluginArg
- * CPluginArgs --> CPluginCommand
- * CPluginCommands --> CPluginCommandSet
- *
- * Revision 1.7 2003/02/20 19:49:54 dicuccio
- * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk
- * over to use new plugin architecture.
- *
- * Revision 1.6 2003/02/05 19:48:29 dicuccio
- * Implemented save for data loader dynamic menus
- *
- * Revision 1.5 2003/01/15 21:06:51 dicuccio
- * Removed useless _TRACE()
- *
- * Revision 1.4 2003/01/13 13:10:06 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace
- * ncbi. Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2003/01/10 17:36:41 dicuccio
- * Changed TPluginList --> TPlugins
- *
- * Revision 1.2 2002/12/30 17:52:18 dicuccio
- * Added private menu callback handler - delays call to
- * CDocManager::UpdateAllViews(), which invalidates current menu data objects.
- *
- * Revision 1.1 2002/12/20 19:15:54 dicuccio
- * Initial revision.
- *
- * ===========================================================================
- */