plugin_arg_dialog.cpp

来自「ncbi源码」· C++ 代码 · 共 442 行

CPP
442
字号
/* * =========================================================================== * PRODUCTION $Log: plugin_arg_dialog.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 20:44:15  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.55 * PRODUCTION * =========================================================================== *//*  $Id: plugin_arg_dialog.cpp,v 1000.3 2004/06/01 20:44:15 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: *    CPluginArgDialog -- standard handler for plugin arguments */#include <ncbi_pch.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/obj_convert.hpp>#include <gui/core/plugin_arg_dialog.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/selection_buffer.hpp>#include <gui/dialogs/entry_form/table.hpp>#include <gui/plugin/PluginLibInfo.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/utils/app_popup.hpp>#include <gui/utils/message_box.hpp>#include <gui/widgets/fl/form.hpp>#include <gui/widgets/fl/frame.hpp>#include "plugin_arg_form.hpp"#include <FL/Fl_Multi_Browser.H>#include <FL/Fl_Check_Button.H>#include <FL/Fl_Menu_Button.H>#include <FL/Fl_Menu_Item.H>#include <FL/Enumerations.H>#include <objects/seq/Bioseq.hpp>#include <serial/serial.hpp>#include <serial/objostrasn.hpp>#include <serial/typeinfo.hpp>#include <algorithm>#include <map>#include <FL/fl_ask.H>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);#include "plugin_arg_dialog_.cpp"//// constants controlling layout//// default row height, in pixelsstatic const int sc_RowHeight = 25;// default fraction of the width devoted to labelsstatic const float sc_LabelFrac = 0.33f;CPluginArgDialog::CPluginArgDialog(CPluginHandle handle,                                   CPluginArgSet& args,                                    const TConstScopedObjects& selections)    : m_Handle(handle),      m_Args(NULL){    m_Window.reset(x_CreateWindow());    SetArgs(args, selections);    string str = handle.GetMenuItem();    if ( !str.empty() ) {        string::size_type pos = str.length() - 1;        while ( (pos = str.find_last_of("/", pos)) != string::npos) {            if (pos != 0  &&  str[pos-1] != '\\') {                str.erase(0, pos + 1);                break;            }        }    } else {        str = "Plugin Launcher Options";    }    SetTitle(str);    if (m_Handle.GetHelpFile().empty()) {        m_HelpButton->deactivate();    }}void CPluginArgDialog::Show(){    if (m_Window.get()) {        m_Window->size(m_Window->w(), m_Form->GetHeight() + 50);        // center the dialog over the currently active window        CenterOnActive();    }    CDialog::Show();}void CPluginArgDialog::SetTitle(const string& title){    m_Title = title;    if (m_Window.get()) {        m_Window->label(m_Title.c_str());    }}// Set the size of the windowvoid CPluginArgDialog::Size(int w, int h){    if (m_Window.get()) {        m_Window->size(w, h);    }}void CPluginArgDialog::SetArgs(CPluginArgSet& args,                               const TConstScopedObjects& selections){    if ( !m_Window.get() ) {        return;    }    m_Args = &args;    m_Selections = selections;    // clear the pack that holds our information    m_Form->SetArgs(args, selections);}void CPluginArgDialog::x_OnSaveOptions(){    //    // FIXME: reimplement so that object arguments are not processed    //    // first, process all of our formatters    m_Form->Process();    // now, verify that our set of arguments is valid    ITERATE (CPluginArgSet::Tdata, iter, m_Args->Get()) {        const CPluginArg& arg = **iter;        if ( !CPluginUtils::IsValid(arg)  &&             !(arg.IsSetOptional()  &&  arg.GetOptional()  && arg.IsEmpty())             ) {            string msg("Field '");            msg += arg.GetDesc();            msg += "' does not contain a valid value";            NcbiMessageBox(msg);            return;        }    }    const char* text = fl_input("Enter the menu item to use for these options");    if ( !text  ||  !*text ) {        return;    }    CRef<CPluginLibInfo> libinfo(new CPluginLibInfo());    libinfo->Assign(m_Handle.GetLibInfo());    libinfo->SetInfo().SetMenu_item(text);    CPluginRegistry::AddPlugin(*libinfo);}void CPluginArgDialog::x_OnOK(){    // first, process all of our formatters    m_Form->Process();    // now, verify that our set of arguments is valid    ITERATE (CPluginArgSet::Tdata, iter, m_Args->Get()) {        const CPluginArg& arg = **iter;        if ( !CPluginUtils::IsValid(arg)  &&             !(arg.IsSetOptional()  &&  arg.GetOptional()  && arg.IsEmpty())             ) {            string msg("Field '");            msg += arg.GetDesc();            msg += "' does not contain a valid value";            NcbiMessageBox(msg);            return;        }    }    // call the base class    CDialog::x_OnOK();}void CPluginArgDialog::x_OnHelp(){    string url = m_Handle.GetHelpFile();    if ( url.empty() ) {        NcbiMessageBox("No help is available for this plugin.");    } else {        CAppPopup::PopupURL(url);    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: plugin_arg_dialog.cpp,v $ * Revision 1000.3  2004/06/01 20:44:15  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.55 * * Revision 1.55  2004/06/01 18:03:18  dicuccio * Large rewrite: refactored argument form as a separate widget; lots of * code-clean-up * * Revision 1.54  2004/05/21 22:27:40  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.53  2004/04/07 12:46:01  dicuccio * Use TConstScopedObjects instead of CSelectionBuffer::TSelList * * Revision 1.52  2004/03/04 20:52:21  dicuccio * Initialize the un-initialized... * * Revision 1.51  2004/02/17 17:18:15  dicuccio * Be careful to use the most efficient possible path of object conversion in * CConvertCache * * Revision 1.50  2004/01/27 18:31:52  dicuccio * Added #includes.  Added unused classes for work-in-progress refactoring * * Revision 1.49  2004/01/21 12:38:18  dicuccio * redesigned CObjectCOnverter API to eliminate temporary object creation * * Revision 1.48  2004/01/07 15:47:30  dicuccio * Adjusted for API change in CPluginUtils::GetLabel() * * Revision 1.47  2004/01/05 19:10:16  dicuccio * Ignore blank lines in multiline input dialogs * * Revision 1.46  2003/12/31 20:27:40  dicuccio * Altered plugin arg dialog to correctly set the document in a document menu * * Revision 1.45  2003/12/23 20:23:21  jcherry * Make argument values persist across invocations of plugin * * Revision 1.44  2003/12/22 19:20:00  dicuccio * Code formatting * * Revision 1.43  2003/12/19 19:25:27  jcherry * Removed a bit of debugging code * * Revision 1.42  2003/12/16 21:51:11  jcherry * Processing of file parameters * * Revision 1.41  2003/12/16 20:39:47  jcherry * Added support for plugin arguments of type file * * Revision 1.40  2003/12/09 15:44:32  dicuccio * Use CDialog::CenterOnActive() instead of home-grown centering * * Revision 1.39  2003/12/04 18:09:49  dicuccio * Center the window in the screen * * Revision 1.38  2003/11/06 20:03:21  dicuccio * Added help button * * Revision 1.37  2003/10/27 17:37:11  dicuccio * Changed AddUserPlugin() to AddPlugin() * * Revision 1.36  2003/10/24 02:12:54  ucko * Implement CPluginArgDialog::Size (cribbed from CEntryFormTable) * * Revision 1.35  2003/10/23 16:15:48  dicuccio * Transitioned to use CFlForm instead of CEntryFormDialog.  Added initial API to * save user-defined plugins * * Revision 1.34  2003/10/10 16:05:51  friedman * Using CObjectConverter::Convert instead of CPluginUtils::Convert. * Use CConvertCache to cahce the object conversions. * * Revision 1.33  2003/10/07 13:36:09  dicuccio * Renamed CPluginURL* to CPluginValue*.  Moved validation code into CPluginUtils * * Revision 1.32  2003/09/29 17:15:30  dicuccio * Fixed callback for OK - should be (protected) x_OnOK() * * Revision 1.31  2003/09/29 15:28:16  dicuccio * OK callback is noew x_OnOK() * * Revision 1.30  2003/09/24 18:23:52  dicuccio * Code clean-ups.  Make sure that all sections are labelled if flag values are * present * * Revision 1.29  2003/09/04 14:01:51  dicuccio * Introduce IDocument and IView as abstract base classes for CDocument and CView * * Revision 1.28  2003/08/21 12:01:37  dicuccio * Correctly set the dialog title * * Revision 1.27  2003/08/20 16:28:30  ucko * More strstream-related fixes.  (Sigh.) * * Revision 1.26  2003/08/20 14:33:38  ucko * Fix use of CNcbiOstrstreamToString, which doesn't directly produce a string. * * Revision 1.25  2003/08/20 12:18:54  ucko * ostringstream is not 100% portable to older compilers; substitute * CNcbiOstrstream{,ToString}. * * Revision 1.24  2003/08/19 18:52:41  friedman * Large Menus (> 20) for Object coice menu and slector browser * is split into submenus according to Document and, within the * documents, into submenus of 20 entries. * * Revision 1.23  2003/08/06 14:21:58  friedman * Added plugin GUI for selecting multiple entries that is derived from the CObject * selected and the CObject specified, by the plugin, for the plugin arg. * * Revision 1.22  2003/07/31 16:55:20  dicuccio * Meaningless whitespace change * * Revision 1.21  2003/07/29 15:03:22  kuznets * Fixed crash with two-column checkbox layout. * * Revision 1.20  2003/07/23 17:54:14  dicuccio * Removed spurious comment about FLTK not saving the label of menu items * * Revision 1.19  2003/07/22 15:29:10  dicuccio * Changed to support new API in Convert().  Dropped support for * CSeqVector as a named type * * Revision 1.18  2003/07/21 19:28:05  dicuccio * CSelectionBuffer::TSelection is now an internal class with named members * * Revision 1.17  2003/07/21 14:55:27  friedman * Changed font of sebmenu label to FL_HELVETICA_BOLD_ITALIC * * Revision 1.16  2003/07/17 03:05:27  friedman * Added handling Flag/Boolean args as Check buttons. * Added passing in a TConstScopedObjects to CPluginArgDialog * Added handling CObjects - Bioseq as a menu drop down list. * * Revision 1.15  2003/07/16 15:22:36  dicuccio * Implemented tool tips for arguments * * Revision 1.14  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.13  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.12  2003/05/30 12:56:50  dicuccio * Converted code to use MessageBox() instead of fl_ask()/fl_message()/fl_alert() * * Revision 1.11  2003/05/19 13:35:59  dicuccio * Moved gui/core/plugin/ -> gui/plugin/.  Merged gui/core/algo, gui/core/doc/, * and gui/core/view/ into one library (gui/core/) * * Revision 1.10  2003/05/12 15:58:48  dicuccio * Added check - don't show hidden parameters * * Revision 1.9  2003/05/09 16:45:07  dicuccio * Correctly handle optional arguments - invalid but empty arguments are * permitted. * * Revision 1.8  2003/05/08 20:11:38  dicuccio * Added new menu for selecting seq-ids from documents.  Removed some dead * debugging code.  Fixed 0-based/1-based index for selecing current values in * Fl_Choice * * Revision 1.7  2003/04/29 14:40:31  dicuccio * Implemented multiline entry for entering sets of items (ints, doubles, strings) * * Revision 1.6  2003/04/24 16:28:30  dicuccio * Removed inappropriate creation of document selector for object argument type. * Fixed given API changes to IDocument * * Revision 1.5  2003/04/24 12:30:04  dicuccio * Added first representation of a document selector.  Changed internal API for * entry form tables - added ability to provide label rows, added ability to * inherit / extend base table * * Revision 1.4  2003/04/16 11:39:11  dicuccio * Large rewrite.  Fixed erroneous assumptions about data entering entry forms * - labels and drop-downs now work correctly * * Revision 1.3  2003/03/28 19:19:46  dicuccio * Split x_AddOptions() into multiple sub-functions.  Changed handling of * labels: use only the persistent label supplied by the argument itself. * * Revision 1.2  2003/03/25 13:10:29  dicuccio * Lots of changes.  Implemented argument formatter wrapper class - used to * pass values from FLTK widgets into individual represented arguments.  Added * OK click handler that validates and processes arguments. * * Revision 1.1  2003/03/21 13:43:20  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?