Changeset View
Changeset View
Standalone View
Standalone View
commands/kpCommandHistoryBase.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 78 | { | |||
---|---|---|---|---|---|
101 | m_undoMinLimit = 10; | 101 | m_undoMinLimit = 10; | ||
102 | m_undoMaxLimit = 500; | 102 | m_undoMaxLimit = 500; | ||
103 | m_undoMaxLimitSizeLimit = 16 * 1048576; | 103 | m_undoMaxLimitSizeLimit = 16 * 1048576; | ||
104 | 104 | | |||
105 | 105 | | |||
106 | m_documentRestoredPosition = 0; | 106 | m_documentRestoredPosition = 0; | ||
107 | 107 | | |||
108 | 108 | | |||
109 | if (doReadConfig) | 109 | if (doReadConfig) { | ||
110 | readConfig (); | 110 | readConfig (); | ||
111 | } | 111 | } | ||
112 | } | ||||
112 | 113 | | |||
113 | kpCommandHistoryBase::~kpCommandHistoryBase () | 114 | kpCommandHistoryBase::~kpCommandHistoryBase () | ||
114 | { | 115 | { | ||
115 | ::ClearPointerList (&m_undoCommandList); | 116 | ::ClearPointerList (&m_undoCommandList); | ||
116 | ::ClearPointerList (&m_redoCommandList); | 117 | ::ClearPointerList (&m_redoCommandList); | ||
117 | 118 | | |||
118 | delete d; | 119 | delete d; | ||
119 | } | 120 | } | ||
Show All 17 Lines | |||||
137 | { | 138 | { | ||
138 | return m_undoMinLimit; | 139 | return m_undoMinLimit; | ||
139 | } | 140 | } | ||
140 | 141 | | |||
141 | // public | 142 | // public | ||
142 | void kpCommandHistoryBase::setUndoMinLimit (int limit) | 143 | void kpCommandHistoryBase::setUndoMinLimit (int limit) | ||
143 | { | 144 | { | ||
144 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" | 145 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" | ||
145 | << limit << ")" | 146 | << limit << ")"; | ||
146 | << endl; | | |||
147 | 147 | | |||
148 | if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) | 148 | if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) | ||
149 | { | 149 | { | ||
150 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" | 150 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" | ||
151 | << limit << ")" | 151 | << limit << ")"; | ||
152 | << endl; | | |||
153 | return; | 152 | return; | ||
154 | } | 153 | } | ||
155 | 154 | | |||
156 | if (limit == m_undoMinLimit) | 155 | if (limit == m_undoMinLimit) { | ||
157 | return; | 156 | return; | ||
157 | } | ||||
158 | 158 | | |||
159 | m_undoMinLimit = limit; | 159 | m_undoMinLimit = limit; | ||
160 | trimCommandListsUpdateActions (); | 160 | trimCommandListsUpdateActions (); | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | 163 | | |||
164 | // public | 164 | // public | ||
165 | int kpCommandHistoryBase::undoMaxLimit () const | 165 | int kpCommandHistoryBase::undoMaxLimit () const | ||
166 | { | 166 | { | ||
167 | return m_undoMaxLimit; | 167 | return m_undoMaxLimit; | ||
168 | } | 168 | } | ||
169 | 169 | | |||
170 | // public | 170 | // public | ||
171 | void kpCommandHistoryBase::setUndoMaxLimit (int limit) | 171 | void kpCommandHistoryBase::setUndoMaxLimit (int limit) | ||
172 | { | 172 | { | ||
173 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" | 173 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" | ||
174 | << limit << ")" | 174 | << limit << ")"; | ||
175 | << endl; | | |||
176 | 175 | | |||
177 | if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) | 176 | if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) | ||
178 | { | 177 | { | ||
179 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" | 178 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" | ||
180 | << limit << ")" | 179 | << limit << ")"; | ||
181 | << endl; | | |||
182 | return; | 180 | return; | ||
183 | } | 181 | } | ||
184 | 182 | | |||
185 | if (limit == m_undoMaxLimit) | 183 | if (limit == m_undoMaxLimit) { | ||
186 | return; | 184 | return; | ||
185 | } | ||||
187 | 186 | | |||
188 | m_undoMaxLimit = limit; | 187 | m_undoMaxLimit = limit; | ||
189 | trimCommandListsUpdateActions (); | 188 | trimCommandListsUpdateActions (); | ||
190 | } | 189 | } | ||
191 | 190 | | |||
192 | 191 | | |||
193 | // public | 192 | // public | ||
194 | kpCommandSize::SizeType kpCommandHistoryBase::undoMaxLimitSizeLimit () const | 193 | kpCommandSize::SizeType kpCommandHistoryBase::undoMaxLimitSizeLimit () const | ||
195 | { | 194 | { | ||
196 | return m_undoMaxLimitSizeLimit; | 195 | return m_undoMaxLimitSizeLimit; | ||
197 | } | 196 | } | ||
198 | 197 | | |||
199 | // public | 198 | // public | ||
200 | void kpCommandHistoryBase::setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit) | 199 | void kpCommandHistoryBase::setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit) | ||
201 | { | 200 | { | ||
202 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" | 201 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" | ||
203 | << sizeLimit << ")" | 202 | << sizeLimit << ")"; | ||
204 | << endl; | | |||
205 | 203 | | |||
206 | if (sizeLimit < 0 || | 204 | if (sizeLimit < 0 || | ||
207 | sizeLimit > (500 * 1048576)/*"ought to be enough for anybody"*/) | 205 | sizeLimit > (500 * 1048576)/*"ought to be enough for anybody"*/) | ||
208 | { | 206 | { | ||
209 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" | 207 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" | ||
210 | << sizeLimit << ")" | 208 | << sizeLimit << ")"; | ||
211 | << endl; | | |||
212 | return; | 209 | return; | ||
213 | } | 210 | } | ||
214 | 211 | | |||
215 | if (sizeLimit == m_undoMaxLimitSizeLimit) | 212 | if (sizeLimit == m_undoMaxLimitSizeLimit) { | ||
216 | return; | 213 | return; | ||
214 | } | ||||
217 | 215 | | |||
218 | m_undoMaxLimitSizeLimit = sizeLimit; | 216 | m_undoMaxLimitSizeLimit = sizeLimit; | ||
219 | trimCommandListsUpdateActions (); | 217 | trimCommandListsUpdateActions (); | ||
220 | } | 218 | } | ||
221 | 219 | | |||
222 | 220 | | |||
223 | // public | 221 | // public | ||
224 | void kpCommandHistoryBase::readConfig () | 222 | void kpCommandHistoryBase::readConfig () | ||
Show All 25 Lines | |||||
250 | } | 248 | } | ||
251 | 249 | | |||
252 | 250 | | |||
253 | // public | 251 | // public | ||
254 | void kpCommandHistoryBase::addCommand (kpCommand *command, bool execute) | 252 | void kpCommandHistoryBase::addCommand (kpCommand *command, bool execute) | ||
255 | { | 253 | { | ||
256 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::addCommand(" | 254 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::addCommand(" | ||
257 | << command | 255 | << command | ||
258 | << ",execute=" << execute << ")" | 256 | << ",execute=" << execute << ")"; | ||
259 | << endl; | | |||
260 | 257 | | |||
261 | if (execute) | 258 | if (execute) { | ||
262 | command->execute (); | 259 | command->execute (); | ||
260 | } | ||||
263 | 261 | | |||
264 | m_undoCommandList.push_front (command); | 262 | m_undoCommandList.push_front (command); | ||
265 | ::ClearPointerList (&m_redoCommandList); | 263 | ::ClearPointerList (&m_redoCommandList); | ||
266 | 264 | | |||
267 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition | 265 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
268 | << endl; | | |||
269 | if (m_documentRestoredPosition != INT_MAX) | 266 | if (m_documentRestoredPosition != INT_MAX) | ||
270 | { | 267 | { | ||
271 | if (m_documentRestoredPosition > 0) | 268 | if (m_documentRestoredPosition > 0) { | ||
272 | m_documentRestoredPosition = INT_MAX; | 269 | m_documentRestoredPosition = INT_MAX; | ||
273 | else | 270 | } | ||
271 | else { | ||||
274 | m_documentRestoredPosition--; | 272 | m_documentRestoredPosition--; | ||
275 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition | 273 | } | ||
276 | << endl; | 274 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
277 | } | 275 | } | ||
278 | 276 | | |||
279 | trimCommandListsUpdateActions (); | 277 | trimCommandListsUpdateActions (); | ||
280 | } | 278 | } | ||
281 | 279 | | |||
282 | // public | 280 | // public | ||
283 | void kpCommandHistoryBase::clear () | 281 | void kpCommandHistoryBase::clear () | ||
284 | { | 282 | { | ||
Show All 10 Lines | |||||
295 | //--------------------------------------------------------------------- | 293 | //--------------------------------------------------------------------- | ||
296 | 294 | | |||
297 | // protected slot | 295 | // protected slot | ||
298 | void kpCommandHistoryBase::undoInternal () | 296 | void kpCommandHistoryBase::undoInternal () | ||
299 | { | 297 | { | ||
300 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::undoInternal()"; | 298 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::undoInternal()"; | ||
301 | 299 | | |||
302 | kpCommand *undoCommand = nextUndoCommand (); | 300 | kpCommand *undoCommand = nextUndoCommand (); | ||
303 | if (!undoCommand) | 301 | if (!undoCommand) { | ||
304 | return; | 302 | return; | ||
303 | } | ||||
305 | 304 | | |||
306 | undoCommand->unexecute (); | 305 | undoCommand->unexecute (); | ||
307 | 306 | | |||
308 | 307 | | |||
309 | m_undoCommandList.erase (m_undoCommandList.begin ()); | 308 | m_undoCommandList.erase (m_undoCommandList.begin ()); | ||
310 | m_redoCommandList.push_front (undoCommand); | 309 | m_redoCommandList.push_front (undoCommand); | ||
311 | 310 | | |||
312 | 311 | | |||
313 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition | 312 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
314 | << endl; | | |||
315 | if (m_documentRestoredPosition != INT_MAX) | 313 | if (m_documentRestoredPosition != INT_MAX) | ||
316 | { | 314 | { | ||
317 | m_documentRestoredPosition++; | 315 | m_documentRestoredPosition++; | ||
318 | if (m_documentRestoredPosition == 0) | 316 | if (m_documentRestoredPosition == 0) | ||
319 | emit documentRestored (); | 317 | emit documentRestored (); | ||
320 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition | 318 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
321 | << endl; | | |||
322 | } | 319 | } | ||
323 | } | 320 | } | ||
324 | 321 | | |||
325 | //--------------------------------------------------------------------- | 322 | //--------------------------------------------------------------------- | ||
326 | 323 | | |||
327 | // protected slot | 324 | // protected slot | ||
328 | void kpCommandHistoryBase::redoInternal () | 325 | void kpCommandHistoryBase::redoInternal () | ||
329 | { | 326 | { | ||
330 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::redoInternal()"; | 327 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::redoInternal()"; | ||
331 | 328 | | |||
332 | kpCommand *redoCommand = nextRedoCommand (); | 329 | kpCommand *redoCommand = nextRedoCommand (); | ||
333 | if (!redoCommand) | 330 | if (!redoCommand) { | ||
334 | return; | 331 | return; | ||
332 | } | ||||
335 | 333 | | |||
336 | redoCommand->execute (); | 334 | redoCommand->execute (); | ||
337 | 335 | | |||
338 | 336 | | |||
339 | m_redoCommandList.erase (m_redoCommandList.begin ()); | 337 | m_redoCommandList.erase (m_redoCommandList.begin ()); | ||
340 | m_undoCommandList.push_front (redoCommand); | 338 | m_undoCommandList.push_front (redoCommand); | ||
341 | 339 | | |||
342 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition | 340 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
343 | << endl; | | |||
344 | if (m_documentRestoredPosition != INT_MAX) | 341 | if (m_documentRestoredPosition != INT_MAX) | ||
345 | { | 342 | { | ||
346 | m_documentRestoredPosition--; | 343 | m_documentRestoredPosition--; | ||
347 | if (m_documentRestoredPosition == 0) | 344 | if (m_documentRestoredPosition == 0) { | ||
348 | emit documentRestored (); | 345 | emit documentRestored (); | ||
349 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition | 346 | } | ||
350 | << endl; | 347 | qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
351 | } | 348 | } | ||
352 | } | 349 | } | ||
353 | 350 | | |||
354 | //--------------------------------------------------------------------- | 351 | //--------------------------------------------------------------------- | ||
355 | 352 | | |||
356 | // public slot virtual | 353 | // public slot virtual | ||
357 | void kpCommandHistoryBase::undo () | 354 | void kpCommandHistoryBase::undo () | ||
358 | { | 355 | { | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
406 | } | 403 | } | ||
407 | 404 | | |||
408 | 405 | | |||
409 | // protected | 406 | // protected | ||
410 | QString kpCommandHistoryBase::undoActionText () const | 407 | QString kpCommandHistoryBase::undoActionText () const | ||
411 | { | 408 | { | ||
412 | kpCommand *undoCommand = nextUndoCommand (); | 409 | kpCommand *undoCommand = nextUndoCommand (); | ||
413 | 410 | | |||
414 | if (undoCommand) | 411 | return (undoCommand) ? i18n ("&Undo: %1", undoCommand->name ()) : i18n ("&Undo"); | ||
415 | return i18n ("&Undo: %1", undoCommand->name ()); | | |||
416 | else | | |||
417 | return i18n ("&Undo"); | | |||
418 | } | 412 | } | ||
419 | 413 | | |||
420 | // protected | 414 | // protected | ||
421 | QString kpCommandHistoryBase::redoActionText () const | 415 | QString kpCommandHistoryBase::redoActionText () const | ||
422 | { | 416 | { | ||
423 | kpCommand *redoCommand = nextRedoCommand (); | 417 | kpCommand *redoCommand = nextRedoCommand (); | ||
424 | 418 | | |||
425 | if (redoCommand) | 419 | return (redoCommand) ? i18n ("&Redo: %1", redoCommand->name ()) : i18n ("&Redo"); | ||
426 | return i18n ("&Redo: %1", redoCommand->name ()); | | |||
427 | else | | |||
428 | return i18n ("&Redo"); | | |||
429 | } | 420 | } | ||
430 | 421 | | |||
431 | 422 | | |||
432 | // protected | 423 | // protected | ||
433 | QString kpCommandHistoryBase::undoActionToolTip () const | 424 | QString kpCommandHistoryBase::undoActionToolTip () const | ||
434 | { | 425 | { | ||
435 | kpCommand *undoCommand = nextUndoCommand (); | 426 | kpCommand *undoCommand = nextUndoCommand (); | ||
436 | 427 | | |||
437 | if (undoCommand) | 428 | return (undoCommand) ? i18n ("Undo: %1", undoCommand->name ()) : i18n ("Undo"); | ||
438 | return i18n ("Undo: %1", undoCommand->name ()); | | |||
439 | else | | |||
440 | return i18n ("Undo"); | | |||
441 | } | 429 | } | ||
442 | 430 | | |||
443 | // protected | 431 | // protected | ||
444 | QString kpCommandHistoryBase::redoActionToolTip () const | 432 | QString kpCommandHistoryBase::redoActionToolTip () const | ||
445 | { | 433 | { | ||
446 | kpCommand *redoCommand = nextRedoCommand (); | 434 | kpCommand *redoCommand = nextRedoCommand (); | ||
447 | 435 | | |||
448 | if (redoCommand) | 436 | return (redoCommand) ? i18n ("Redo: %1", redoCommand->name ()) : i18n ("Redo"); | ||
449 | return i18n ("Redo: %1", redoCommand->name ()); | | |||
450 | else | | |||
451 | return i18n ("Redo"); | | |||
452 | } | 437 | } | ||
453 | 438 | | |||
454 | 439 | | |||
455 | // protected | 440 | // protected | ||
456 | void kpCommandHistoryBase::trimCommandListsUpdateActions () | 441 | void kpCommandHistoryBase::trimCommandListsUpdateActions () | ||
457 | { | 442 | { | ||
458 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandListsUpdateActions()"; | 443 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandListsUpdateActions()"; | ||
459 | 444 | | |||
460 | trimCommandLists (); | 445 | trimCommandLists (); | ||
461 | updateActions (); | 446 | updateActions (); | ||
462 | } | 447 | } | ||
463 | 448 | | |||
464 | // protected | 449 | // protected | ||
465 | void kpCommandHistoryBase::trimCommandList (QLinkedList <kpCommand *> *commandList) | 450 | void kpCommandHistoryBase::trimCommandList (QLinkedList <kpCommand *> *commandList) | ||
466 | { | 451 | { | ||
467 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandList()"; | 452 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandList()"; | ||
468 | QTime timer; timer.start (); | 453 | QTime timer; timer.start (); | ||
469 | 454 | | |||
470 | if (!commandList) | 455 | if (!commandList) | ||
471 | { | 456 | { | ||
472 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::trimCommandList() passed 0 commandList" | 457 | qCCritical(kpLogCommands) << "kpCommandHistoryBase::trimCommandList() passed 0 commandList"; | ||
473 | << endl; | | |||
474 | return; | 458 | return; | ||
475 | } | 459 | } | ||
476 | 460 | | |||
477 | 461 | | |||
478 | qCDebug(kpLogCommands) << "\tsize=" << commandList->size () | 462 | qCDebug(kpLogCommands) << "\tsize=" << commandList->size () | ||
479 | << " undoMinLimit=" << m_undoMinLimit | 463 | << " undoMinLimit=" << m_undoMinLimit | ||
480 | << " undoMaxLimit=" << m_undoMaxLimit | 464 | << " undoMaxLimit=" << m_undoMaxLimit | ||
481 | << " undoMaxLimitSizeLimit=" << m_undoMaxLimitSizeLimit | 465 | << " undoMaxLimitSizeLimit=" << m_undoMaxLimitSizeLimit; | ||
482 | << endl; | | |||
483 | if (static_cast<int> (commandList->size ()) <= m_undoMinLimit) | 466 | if (static_cast<int> (commandList->size ()) <= m_undoMinLimit) | ||
484 | { | 467 | { | ||
485 | qCDebug(kpLogCommands) << "\t\tsize under undoMinLimit - done"; | 468 | qCDebug(kpLogCommands) << "\t\tsize under undoMinLimit - done"; | ||
486 | return; | 469 | return; | ||
487 | } | 470 | } | ||
488 | 471 | | |||
489 | qCDebug(kpLogCommands) << "\tsize over undoMinLimit - iterating thru cmds:"; | 472 | qCDebug(kpLogCommands) << "\tsize over undoMinLimit - iterating thru cmds:"; | ||
490 | 473 | | |||
Show All 9 Lines | 480 | { | |||
500 | if (sizeSoFar <= m_undoMaxLimitSizeLimit) | 483 | if (sizeSoFar <= m_undoMaxLimitSizeLimit) | ||
501 | { | 484 | { | ||
502 | sizeSoFar += (*it)->size (); | 485 | sizeSoFar += (*it)->size (); | ||
503 | } | 486 | } | ||
504 | 487 | | |||
505 | qCDebug(kpLogCommands) << "\t\t" << upto << ":" | 488 | qCDebug(kpLogCommands) << "\t\t" << upto << ":" | ||
506 | << " name='" << (*it)->name () | 489 | << " name='" << (*it)->name () | ||
507 | << "' size=" << (*it)->size () | 490 | << "' size=" << (*it)->size () | ||
508 | << " sizeSoFar=" << sizeSoFar | 491 | << " sizeSoFar=" << sizeSoFar; | ||
509 | << endl; | | |||
510 | 492 | | |||
511 | if (upto >= m_undoMinLimit) | 493 | if (upto >= m_undoMinLimit) | ||
512 | { | 494 | { | ||
513 | if (upto >= m_undoMaxLimit || | 495 | if (upto >= m_undoMaxLimit || | ||
514 | sizeSoFar > m_undoMaxLimitSizeLimit) | 496 | sizeSoFar > m_undoMaxLimitSizeLimit) | ||
515 | { | 497 | { | ||
516 | #if DEBUG_KP_COMMAND_HISTORY && 0 | 498 | #if DEBUG_KP_COMMAND_HISTORY && 0 | ||
517 | qCDebug(kpLogCommands) << "\t\t\tkill"; | 499 | qCDebug(kpLogCommands) << "\t\t\tkill"; | ||
518 | #endif | 500 | #endif | ||
519 | delete (*it); | 501 | delete (*it); | ||
520 | it = m_undoCommandList.erase (it); | 502 | it = m_undoCommandList.erase (it); | ||
521 | advanceIt = false; | 503 | advanceIt = false; | ||
522 | } | 504 | } | ||
523 | } | 505 | } | ||
524 | 506 | | |||
525 | if (advanceIt) | 507 | if (advanceIt) { | ||
526 | it++; | 508 | it++; | ||
509 | } | ||||
527 | upto++; | 510 | upto++; | ||
528 | } | 511 | } | ||
529 | 512 | | |||
530 | qCDebug(kpLogCommands) << "\ttook " << timer.elapsed () << "ms"; | 513 | qCDebug(kpLogCommands) << "\ttook " << timer.elapsed () << "ms"; | ||
531 | } | 514 | } | ||
532 | 515 | | |||
533 | // protected | 516 | // protected | ||
534 | void kpCommandHistoryBase::trimCommandLists () | 517 | void kpCommandHistoryBase::trimCommandLists () | ||
535 | { | 518 | { | ||
536 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandLists()"; | 519 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::trimCommandLists()"; | ||
537 | 520 | | |||
538 | trimCommandList (&m_undoCommandList); | 521 | trimCommandList (&m_undoCommandList); | ||
539 | trimCommandList (&m_redoCommandList); | 522 | trimCommandList (&m_redoCommandList); | ||
540 | 523 | | |||
541 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition | 524 | qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; | ||
542 | << endl; | | |||
543 | if (m_documentRestoredPosition != INT_MAX) | 525 | if (m_documentRestoredPosition != INT_MAX) | ||
544 | { | 526 | { | ||
545 | qCDebug(kpLogCommands) << "\t\tundoCmdList.size=" << m_undoCommandList.size () | 527 | qCDebug(kpLogCommands) << "\t\tundoCmdList.size=" << m_undoCommandList.size () | ||
546 | << " redoCmdList.size=" << m_redoCommandList.size () | 528 | << " redoCmdList.size=" << m_redoCommandList.size (); | ||
547 | << endl; | | |||
548 | if (m_documentRestoredPosition > static_cast<int> (m_redoCommandList.size ()) || | 529 | if (m_documentRestoredPosition > static_cast<int> (m_redoCommandList.size ()) || | ||
549 | -m_documentRestoredPosition > static_cast<int> (m_undoCommandList.size ())) | 530 | -m_documentRestoredPosition > static_cast<int> (m_undoCommandList.size ())) | ||
550 | { | 531 | { | ||
551 | qCDebug(kpLogCommands) << "\t\t\tinvalidate documentRestoredPosition"; | 532 | qCDebug(kpLogCommands) << "\t\t\tinvalidate documentRestoredPosition"; | ||
552 | m_documentRestoredPosition = INT_MAX; | 533 | m_documentRestoredPosition = INT_MAX; | ||
553 | } | 534 | } | ||
554 | } | 535 | } | ||
555 | } | 536 | } | ||
556 | 537 | | |||
557 | 538 | | |||
558 | static void populatePopupMenu (QMenu *popupMenu, | 539 | static void populatePopupMenu (QMenu *popupMenu, | ||
559 | const QString &undoOrRedo, | 540 | const QString &undoOrRedo, | ||
560 | const QLinkedList <kpCommand *> &commandList) | 541 | const QLinkedList <kpCommand *> &commandList) | ||
561 | { | 542 | { | ||
562 | if (!popupMenu) | 543 | if (!popupMenu) { | ||
563 | return; | 544 | return; | ||
545 | } | ||||
564 | 546 | | |||
565 | popupMenu->clear (); | 547 | popupMenu->clear (); | ||
566 | 548 | | |||
567 | QLinkedList <kpCommand *>::const_iterator it = commandList.begin (); | 549 | QLinkedList <kpCommand *>::const_iterator it = commandList.begin (); | ||
568 | int i = 0; | 550 | int i = 0; | ||
569 | while (i < 10 && it != commandList.end ()) | 551 | while (i < 10 && it != commandList.end ()) | ||
570 | { | 552 | { | ||
571 | QAction *action = new QAction(i18n ("%1: %2", undoOrRedo, (*it)->name ()), popupMenu); | 553 | QAction *action = new QAction(i18n ("%1: %2", undoOrRedo, (*it)->name ()), popupMenu); | ||
Show All 28 Lines | 572 | { | |||
600 | 582 | | |||
601 | // But in icon mode, a tooltip with context is useful. | 583 | // But in icon mode, a tooltip with context is useful. | ||
602 | m_actionUndo->setToolTip (undoActionToolTip ()); | 584 | m_actionUndo->setToolTip (undoActionToolTip ()); | ||
603 | QTime timer; timer.start (); | 585 | QTime timer; timer.start (); | ||
604 | populatePopupMenu (m_actionUndo->menu (), | 586 | populatePopupMenu (m_actionUndo->menu (), | ||
605 | i18n ("Undo"), | 587 | i18n ("Undo"), | ||
606 | m_undoCommandList); | 588 | m_undoCommandList); | ||
607 | qCDebug(kpLogCommands) << "\tpopuplatePopupMenu undo=" << timer.elapsed () | 589 | qCDebug(kpLogCommands) << "\tpopuplatePopupMenu undo=" << timer.elapsed () | ||
608 | << "ms" << endl;; | 590 | << "ms"; | ||
609 | 591 | | |||
610 | m_actionRedo->setEnabled (static_cast<bool> (nextRedoCommand ())); | 592 | m_actionRedo->setEnabled (static_cast<bool> (nextRedoCommand ())); | ||
611 | // Don't want to keep changing toolbar text. | 593 | // Don't want to keep changing toolbar text. | ||
612 | // TODO: As a bad side-effect, the menu doesn't have "Undo: <action>" | 594 | // TODO: As a bad side-effect, the menu doesn't have "Undo: <action>" | ||
613 | // anymore. In any case, the KDE4 KToolBarPopupAction | 595 | // anymore. In any case, the KDE4 KToolBarPopupAction | ||
614 | // sucks in menus as it forces the clicking of a submenu. IMO, | 596 | // sucks in menus as it forces the clicking of a submenu. IMO, | ||
615 | // there should be no submenu in the menu. | 597 | // there should be no submenu in the menu. | ||
616 | //m_actionRedo->setText (redoActionText ()); | 598 | //m_actionRedo->setText (redoActionText ()); | ||
617 | 599 | | |||
618 | // But in icon mode, a tooltip with context is useful. | 600 | // But in icon mode, a tooltip with context is useful. | ||
619 | m_actionRedo->setToolTip (redoActionToolTip ()); | 601 | m_actionRedo->setToolTip (redoActionToolTip ()); | ||
620 | timer.restart (); | 602 | timer.restart (); | ||
621 | populatePopupMenu (m_actionRedo->menu (), | 603 | populatePopupMenu (m_actionRedo->menu (), | ||
622 | i18n ("Redo"), | 604 | i18n ("Redo"), | ||
623 | m_redoCommandList); | 605 | m_redoCommandList); | ||
624 | qCDebug(kpLogCommands) << "\tpopuplatePopupMenu redo=" << timer.elapsed () | 606 | qCDebug(kpLogCommands) << "\tpopuplatePopupMenu redo=" << timer.elapsed () | ||
625 | << "ms" << endl; | 607 | << "ms"; | ||
626 | } | 608 | } | ||
627 | 609 | | |||
628 | 610 | | |||
629 | // public | 611 | // public | ||
630 | kpCommand *kpCommandHistoryBase::nextUndoCommand () const | 612 | kpCommand *kpCommandHistoryBase::nextUndoCommand () const | ||
631 | { | 613 | { | ||
632 | if (m_undoCommandList.isEmpty ()) | 614 | if (m_undoCommandList.isEmpty ()) { | ||
633 | return nullptr; | 615 | return nullptr; | ||
616 | } | ||||
634 | 617 | | |||
635 | return m_undoCommandList.first (); | 618 | return m_undoCommandList.first (); | ||
636 | } | 619 | } | ||
637 | 620 | | |||
638 | // public | 621 | // public | ||
639 | kpCommand *kpCommandHistoryBase::nextRedoCommand () const | 622 | kpCommand *kpCommandHistoryBase::nextRedoCommand () const | ||
640 | { | 623 | { | ||
641 | if (m_redoCommandList.isEmpty ()) | 624 | if (m_redoCommandList.isEmpty ()) { | ||
642 | return nullptr; | 625 | return nullptr; | ||
626 | } | ||||
643 | 627 | | |||
644 | return m_redoCommandList.first (); | 628 | return m_redoCommandList.first (); | ||
645 | } | 629 | } | ||
646 | 630 | | |||
647 | 631 | | |||
648 | // public | 632 | // public | ||
649 | void kpCommandHistoryBase::setNextUndoCommand (kpCommand *command) | 633 | void kpCommandHistoryBase::setNextUndoCommand (kpCommand *command) | ||
650 | { | 634 | { | ||
651 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setNextUndoCommand(" | 635 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::setNextUndoCommand("<< command << ")"; | ||
652 | << command | | |||
653 | << ")" | | |||
654 | << endl; | | |||
655 | 636 | | |||
656 | if (m_undoCommandList.isEmpty ()) | 637 | if (m_undoCommandList.isEmpty ()) { | ||
657 | return; | 638 | return; | ||
658 | 639 | } | |||
659 | 640 | | |||
660 | delete *m_undoCommandList.begin (); | 641 | delete *m_undoCommandList.begin (); | ||
661 | *m_undoCommandList.begin () = command; | 642 | *m_undoCommandList.begin () = command; | ||
662 | 643 | | |||
663 | | ||||
664 | trimCommandListsUpdateActions (); | 644 | trimCommandListsUpdateActions (); | ||
665 | } | 645 | } | ||
666 | 646 | | |||
667 | 647 | | |||
668 | // public slot virtual | 648 | // public slot virtual | ||
669 | void kpCommandHistoryBase::documentSaved () | 649 | void kpCommandHistoryBase::documentSaved () | ||
670 | { | 650 | { | ||
671 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::documentSaved()"; | 651 | qCDebug(kpLogCommands) << "kpCommandHistoryBase::documentSaved()"; | ||
672 | 652 | | |||
673 | m_documentRestoredPosition = 0; | 653 | m_documentRestoredPosition = 0; | ||
674 | } | 654 | } |