예제 #1
0
void
MainWindow::add_toolbar_button(DebuggerCommand* cmd,
                               const string& tip,
                               const char* stock,
                               SArray& pixmap,
                               Properties& prop)
{
    ToolBar* toolbar = get_toolbar(prop);

    if (pixmap.empty())
    {
        pixmap.push_back("");
    }
    SArray noArg;

    Widget* btn =
        CHKPTR(toolbar)->add_button(
            pixmap.cstrings(),
            tip.c_str(),
            Gtk_BIND(Gtk_SLOT(this, &MainWindow::run_macro), cmd, noArg),
            uisAttachedThreadStop, // FIXME: let the caller specify it
            cmd->name(),
            stock);

    btn->show_all();
    commandMap_[cmd] = btn;
}
예제 #2
0
void
MainWindow::toolbar_entry_dialog(DebuggerCommand* command,
                                 Properties* cmdProperties)
{
    const string msg = cmdProperties->get_string("message", "");
    EntryDialog dialog(msg, debugger().properties(), command->name());

    SArray args;

    string userString = dialog.run();
    if (!userString.empty())
    {
        args.push_back(userString);
        run_macro(command, args);
    }
}
예제 #3
0
void MainWindow::add_command(DebuggerCommand* cmd)
{
    if (!is_ui_thread())
    {
        run_on_ui_thread(command(&MainWindow::add_command, this, cmd));
    }
    else
    {
        dbgout(0) << __func__ << ": " << cmd->name() << endl;
        //
        // The command object may implement a Properties interface,
        // (a dictionary, essentially) which allows the various
        // CommandCenter implementations to extract the parameters
        // that apply.
        //
        // In this particular case, we look for params that tell:
        // 1) whether the command to be added is a toolbar button
        // (other types are not supported yet, but things such as
        // menu items may are on the drawing board and may be added soon),
        // and:
        // 2) if a toolbar button, what are its attributes (tooltip
        // text, what pixmap or stock image to show, etc).
        //
        if (Properties* prop = interface_cast<Properties*>(cmd))
        {
            SArray pixmap;

            string tip = prop->get_string("tooltip", "");
            const char* stock = prop->get_string("stock");

            if (const char* xpm = prop->get_string("pixmap"))
            {
                typedef boost::char_separator<char> Delim;
                typedef boost::tokenizer<Delim> Tokenizer;

                string tmp(xpm);
                Tokenizer tok(tmp, Delim("\n"));

                Tokenizer::iterator i = tok.begin();
                for (; i != tok.end(); ++i)
                {
                    pixmap.push_back(*i);
                }
            }

            if (const char* type = prop->get_string("type"))
            {
                if (strcmp(type, "tool") == 0)
                {
                    add_toolbar_button(cmd, tip, stock, pixmap, *prop);
                }
                else if (strcmp(type, "tool-dialog") == 0)
                {
                    add_toolbar_dialog(cmd, tip, stock, pixmap, *prop);
                }
                else
                {
                    throw runtime_error("pluggable command type \""
                                        + string(type)
                                        + "\" not supported");
                }
            }
        }
    }
}