Ejemplo n.º 1
0
void CommandProcessorBase::CloseOpenCommand()
{
    CLCommand::Ptr_t command = GetOpenCommand();
    wxCHECK_RET(command, "Trying to close to a non-existent or already-closed command");

    command->Close();
}
Ejemplo n.º 2
0
wxString GetBestLabel(CLCommand::Ptr_t command)
{
    wxString label, text;
    if (command) {
        if (!command->GetUserLabel().empty()) {
            label = command->GetUserLabel();
        } else {
            label = command->GetName();
            text =  command->GetText();
            size_t len = text.Len();
            if (len) {
                text.Replace("\r\n", "\\n"); // Otherwise newlines result in a multiline display!
                text.Replace("\n", "\\n");
                // Truncate long pastes
                if (len > 70) {
                    wxString shorter = text.Left(34);
                    shorter << " ... " << text.Right(34);
                    text = shorter;
                }
                label << " \"" << text << "\"";
            }
        }
    }
    return label;
}
Ejemplo n.º 3
0
void CommandProcessorBase::PopulateLabelledStatesMenu(wxMenu* menu)
{
    wxCHECK_RET(menu, "NULL menu");
    
    for (size_t n = menu->GetMenuItemCount(); n > 0; --n) { // We need to delete any items left over from a previous call
        wxMenuItem* item = menu->FindItemByPosition(n-1);
        if (item) {
            menu->Delete(item);
        }
    }
    

    if (!GetInitialCommand()->GetUserLabel().empty()) { // First any initial label
        menu->Append(FIRST_MENU_ID - 1, GetInitialCommand()->GetUserLabel()); // (Ab)use an out-of-range id to avoid confusion
    }

    int id = FIRST_MENU_ID;
    for (CLCommand::Vec_t::const_iterator iter = GetCommands().begin(); iter != GetCommands().end(); ++iter) {
        CLCommand::Ptr_t command = *iter;
        if (command && !command->GetUserLabel().empty()) {
            menu->Append(id, command->GetUserLabel());
        }
        ++id; // It's easier in the handler if the event id is the GetCommands() index, rather than a menu index
    }

    menu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CommandProcessorBase::OnLabelledStatesMenuItem), this);
}
Ejemplo n.º 4
0
void CommandProcessorBase::ProcessOpenCommand()
{
    CLCommand::Ptr_t command = GetOpenCommand();
    wxCHECK_RET(command, "Trying to process a non-existing or non-open command");

    command->SetName( GetBestLabel(command) );  // Update the item's label
    CloseOpenCommand();
}
Ejemplo n.º 5
0
void CommandProcessorBase::SetUserLabel(const wxString& label)
{
    if (GetOpenCommand()) {
        ProcessOpenCommand(); // We need to make it non-pending, otherwise it may change after the label is set; which probably won't be what the user expects
    }

    CLCommand::Ptr_t command = GetActiveCommand();
    if (command) {
        command->SetUserLabel(label);
    }
}
Ejemplo n.º 6
0
void CommandProcessorBase::DoPopulateUnRedoMenu(wxMenu& menu, bool undoing)
{
    wxString prefix(undoing ? _("Undo ") : _("Redo "));
    int id = FIRST_MENU_ID;
    int count = 0;

    if (undoing) {
        if (GetCommands().size() > 0) {
            for (CLCommand::Vec_t::const_reverse_iterator iter = GetCommands().rbegin() + GetNextUndoCommand(); iter != GetCommands().rend(); ++iter) {
                CLCommand::Ptr_t command = *iter;
                if (command) {
                    wxString label;
                    if (!command->GetUserLabel().empty()) {
                        if (command->GetName().Contains(":")) {
                            label = command->GetName().BeforeFirst(':') + ": ";
                        }
                        label << command->GetUserLabel();
                    } else {
                        if (command == GetOpenCommand()) {
                            label = GetBestLabel(command); // If the command's still open, there won't otherwise be a name string
                        } else {
                            label = command->GetName();
                        }
                    }
                    menu.Append(id++, wxString::Format("%i ", ++count) + prefix + label);
                }
            }
        }
    } else {
        for (CLCommand::Vec_t::const_iterator iter = GetCommands().begin() + GetCurrentCommand() + 1; iter != GetCommands().end(); ++iter) {
            CLCommand::Ptr_t command = *iter;
            if (command) {
                wxString label;
                if (!command->GetUserLabel().empty()) {
                    if (command->GetName().Contains(":")) {
                        label = command->GetName().BeforeFirst(':') + ": ";
                    }
                    label << command->GetUserLabel();
                } else {
                    label = command->GetName();
                }
                menu.Append(id++, wxString::Format("%i ", ++count) + prefix + label);
            }
        }
    }
}