~blue-shell/kde-baseapps/netrunner_4.10

« back to all changes in this revision

Viewing changes to dolphin/src/views/renamedialog.cpp

  • Committer: Frank Reininghaus
  • Date: 2013-06-20 17:37:53 UTC
  • Revision ID: git-v1:6f2e1403480bf5617b0cba92d6cbbbb4f62aec2c
Allow renaming multiple files without number if extensions are different

Normally, we only allow renaming multiple files if the new file name
contains a contiguous sequence of '#' placeholders, which are then
replaced by numbers.

However, if all extensions are different, we can also rename the files
without such a placeholder because the original extension is preserved
when renaming.

This had been possible some time ago already. That this "accidental
feature" was lost was a side effect of the fix for bug 318942.

BUG: 321234
FIXED-IN: 4.10.5
REVIEW: 111079

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    m_newName(),
46
46
    m_lineEdit(0),
47
47
    m_items(items),
 
48
    m_allExtensionsDifferent(true),
48
49
    m_spinBox(0)
49
50
{
50
51
    const QSize minSize = minimumSize();
107
108
    topLayout->addWidget(m_lineEdit);
108
109
 
109
110
    if (!m_renameOneItem) {
 
111
        QSet<QString> extensions;
 
112
        foreach (const KFileItem& item, m_items) {
 
113
            const QString extension = KMimeType::extractKnownExtension(item.url().prettyUrl().toLower());
 
114
 
 
115
            if (extensions.contains(extension)) {
 
116
                m_allExtensionsDifferent = false;
 
117
                break;
 
118
            }
 
119
 
 
120
            extensions.insert(extension);
 
121
        }
 
122
 
110
123
        QLabel* infoLabel = new QLabel(i18nc("@info", "# will be replaced by ascending numbers starting with:"), page);
111
124
        m_spinBox = new KIntSpinBox(0, 10000, 1, 1, page, 10);
112
125
 
146
159
{
147
160
    bool enable = !newName.isEmpty() && (newName != QLatin1String("..")) && (newName != QLatin1String("."));
148
161
    if (enable && !m_renameOneItem) {
149
 
        // Assure that the new name contains exactly one # (or a connected sequence of #'s)
150
162
        const int count = newName.count(QLatin1Char('#'));
151
 
        const int first = newName.indexOf(QLatin1Char('#'));
152
 
        const int last = newName.lastIndexOf(QLatin1Char('#'));
153
 
        enable = (last - first + 1 == count);
 
163
        if (count == 0) {
 
164
            // Renaming multiple files without '#' will only work if all extensions are different.
 
165
            enable = m_allExtensionsDifferent;
 
166
        } else {
 
167
            // Assure that the new name contains exactly one # (or a connected sequence of #'s)
 
168
            const int first = newName.indexOf(QLatin1Char('#'));
 
169
            const int last = newName.lastIndexOf(QLatin1Char('#'));
 
170
            enable = (last - first + 1 == count);
 
171
        }
154
172
    }
155
173
    enableButtonOk(enable);
156
174
}