edit_styles_dlg.cpp

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

CPP
312
字号
/* * =========================================================================== * PRODUCTION $Log: edit_styles_dlg.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 20:45:36  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * PRODUCTION * =========================================================================== *//*  $Id: edit_styles_dlg.cpp,v 1000.1 2004/06/01 20:45:36 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:  Robert G. Smith * * File Description: *    User-modifiable implementation file for extension of basic class,  *      CEditStylesDlg, a prototype dialog box used for editing preferences. *    A suitable mediator must be supplied to instantiate one. */#include <ncbi_pch.hpp>#include <gui/dialogs/config/edit_styles_dlg.hpp>#include <gui/dialogs/config/iconfig_mediator.hpp>#include <gui/dialogs/config/config_panel.hpp>#include <gui/utils/message_box.hpp>#include <FL/fl_ask.H>BEGIN_NCBI_SCOPE#include "edit_styles_dlg_.cpp"CEditStylesDlg::CEditStylesDlg(IConfigMediator& mediator){    m_ConfigMediator.Reset(& mediator);    m_Window.reset(x_CreateWindow());        SetTitle(m_ConfigMediator->GetWindowTitle());        // populate our browser    x_SetStates(m_ConfigMediator->GetStates());    // select the first thing in the state browser.    m_StyleBrowser->deselect();    m_StyleBrowser->value(1);    // OR find out what the current state is and select that.    // string first_state = m_ConfigMediator->GetCurrentState();    // x_SetSelectedState(first_state);    x_UpdateSetBtns();}void CEditStylesDlg::x_SetStates(list<string> const& states){    m_StyleBrowser->clear();    ITERATE(list<string>, state_it, states) {        m_StyleBrowser->add(state_it->c_str());    }}//// Browser selection -> State// Return in the state param the string displayed// on the selected line in the browser.// If nothing was selected returns false and 'state'// is unmodified.//bool CEditStylesDlg::x_GetSelectedState(string& state){    int sel_idx = m_StyleBrowser->value();    if (sel_idx == 0) {        return false;    }        const char *browser_text = m_StyleBrowser->text(sel_idx);    if (browser_text == NULL) {        return false;    }    string the_state(browser_text);    state.swap(the_state);    return true;}// State -> Browser selection// Select the line in the browser that has text the same// as the 'state' parameter. // Does nothing if that text was not found.void CEditStylesDlg::x_SetSelectedState(const string& state){    int n = m_StyleBrowser->size();    int i;    for (i = 1; i <= n; ++i) {        const char *a_text = m_StyleBrowser->text(i);        if (a_text != NULL  &&  state == a_text) {            m_StyleBrowser->deselect();            m_StyleBrowser->value(i);            x_UpdateSetBtns();            return;        }    }}void CEditStylesDlg::x_SelectFirstState(){    m_StyleBrowser->deselect();    m_StyleBrowser->value(1);    x_UpdateSetBtns();}void CEditStylesDlg::x_OnAdd(){    string  new_state;    if ( m_ConfigMediator->AddState(new_state) ) {        x_SetStates(m_ConfigMediator->GetStates());        x_SetSelectedState(new_state);        m_Window->redraw();    } else {        NcbiMessageBox("Failed to add new state.");    }}void CEditStylesDlg::x_OnCopy(){    string this_state;    if ( ! x_GetSelectedState(this_state) ) {        return;    }        string  new_state;    if ( m_ConfigMediator->DuplicateState(this_state, new_state) ) {        x_SetStates(m_ConfigMediator->GetStates());        x_SetSelectedState(new_state);        m_Window->redraw();    } else {        string msg("Can not copy ");        msg += this_state;        NcbiMessageBox(msg);    }}void CEditStylesDlg::x_OnRename(){    string this_state;    if ( ! x_GetSelectedState(this_state) ) {        return;    }        // can we do this?    if ( ! m_ConfigMediator->CanRenameState(this_state)) {        string msg("Can not rename ");        msg += this_state;        NcbiMessageBox(msg);        return;    }        // Get a new name from the user (requested name).    const char * req_state_cp =        fl_input("Rename %s as:", this_state.c_str(), this_state.c_str());    if (req_state_cp == 0) { // Canceled input        return;    }    string  req_state(req_state_cp);    if (req_state.empty()  ||  req_state  ==  this_state) {        // requested name blank or no change to the name.        return;    }        // rename it, get back the new name actually used.    string  new_state;    if ( m_ConfigMediator->RenameState(this_state, req_state, new_state) ) {        x_SetStates(m_ConfigMediator->GetStates());        x_SetSelectedState(new_state);        // did we rename the mediator's currently loaded state?        if (m_ConfigMediator->GetCurrentState() == this_state) {            m_ConfigMediator->Load(new_state);        }        m_Window->redraw();    } else {        // something else went wrong.        string msg("Can not rename ");        msg += this_state;        NcbiMessageBox(msg);    }}void CEditStylesDlg::x_OnDelete(){    string this_state;    if ( ! x_GetSelectedState(this_state) ) {        return;    }        if ( m_ConfigMediator->DeleteState(this_state) ) {        m_StyleBrowser->deselect();        x_SetStates(m_ConfigMediator->GetStates());                // did we delete the currently loaded state?        if (m_ConfigMediator->GetCurrentState() == this_state) {            // select and load the first state in the list.            x_SelectFirstState();            string first_state;            x_GetSelectedState(first_state);            m_ConfigMediator->Load(first_state);        }        m_Window->redraw();    } else {        string msg("Can not delete ");        msg += this_state;        NcbiMessageBox(msg);    }}void CEditStylesDlg::x_UpdateSetBtns(){    bool    delRenameOn = true;        string this_state;    if ( x_GetSelectedState(this_state) ) {        if ( ! m_ConfigMediator->CanRenameState(this_state)) {            delRenameOn = false;        }    }        if (delRenameOn) {        m_RenameBtn->activate();        m_DeleteBtn->activate();    } else {        m_RenameBtn->deactivate();        m_DeleteBtn->deactivate();    }     }END_NCBI_SCOPE/* * =========================================================================== * $Log: edit_styles_dlg.cpp,v $ * Revision 1000.1  2004/06/01 20:45:36  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * * Revision 1.3  2004/05/21 22:27:41  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.2  2004/01/08 13:24:03  rsmith * fix button updating. * * Revision 1.1  2004/01/02 21:04:21  rsmith * initial checkin * * Revision 1.1  2003/12/30 14:09:38  dicuccio * Initial check-in - moved from gui/config * * Revision 1.5  2003/12/29 14:38:14  rsmith * take out SetTitle since it is supplied by the parent class. * * Revision 1.4  2003/11/21 12:52:25  rsmith * Fix bug with renaming loaded set of values. * * Revision 1.3  2003/11/18 20:23:46  rsmith * Various bug fixes and enhancements. * * Revision 1.2  2003/10/14 12:48:54  dicuccio * Inherit from CDialog.  Fix resizing issues.  Standardized widget sizes. * * Revision 1.1  2003/10/10 17:43:42  rsmith * moved from gui/core to gui/config * * Revision 1.1  2003/09/26 18:15:31  rsmith * plugin configration data and dialog * * =========================================================================== */

⌨️ 快捷键说明

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