Beispiel #1
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;
}
Beispiel #2
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);
            }
        }
    }
}