Skip to content

Commit d678374

Browse files
Merge pull request #1271 from khalid-nasralla/PAINTROID-602
PAINTROID-602 Fix "Crash in DefaultCommandManager"
2 parents f3c6249 + 97fe713 commit d678374

1 file changed

Lines changed: 45 additions & 31 deletions

File tree

Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ class DefaultCommandManager(
141141
layerModel.addLayerAt(0, this)
142142
}
143143
}
144-
val commandToRestore = redoCommandList.pop()
145-
undoCommandList.addFirst(commandToRestore)
144+
145+
if (isRedoAvailable) {
146+
val commandToRestore = redoCommandList.pop()
147+
undoCommandList.addFirst(commandToRestore)
148+
}
146149

147150
return
148151
}
@@ -303,26 +306,29 @@ class DefaultCommandManager(
303306
}
304307

305308
override fun redoInConnectedLinesMode() {
306-
val command = redoCommandList.pop()
307-
if (command is ColorChangedCommand) {
308-
val colorCommandList = removeColorCommands()
309-
if (undoCommandList.isNotEmpty()) {
310-
val firstNonColorCommand = undoCommandList.first
311-
val color = command.color
309+
if (isRedoAvailable) {
310+
val command = redoCommandList.pop()
311+
312+
if (command is ColorChangedCommand) {
313+
val colorCommandList = removeColorCommands()
314+
if (undoCommandList.isNotEmpty()) {
315+
val firstNonColorCommand = undoCommandList.first
316+
val color = command.color
312317

313-
if (firstNonColorCommand is PathCommand) {
314-
firstNonColorCommand.paint.color = color
315-
} else if (firstNonColorCommand is PointCommand) {
316-
firstNonColorCommand.paint.color = color
318+
if (firstNonColorCommand is PathCommand) {
319+
firstNonColorCommand.paint.color = color
320+
} else if (firstNonColorCommand is PointCommand) {
321+
firstNonColorCommand.paint.color = color
322+
}
323+
executeAllCommands()
317324
}
318-
executeAllCommands()
325+
addAndExecuteCommands(colorCommandList)
319326
}
320-
addAndExecuteCommands(colorCommandList)
321-
}
322-
undoCommandList.addFirst(command)
327+
undoCommandList.addFirst(command)
323328

324-
executeCommand(command)
325-
notifyCommandExecuted()
329+
executeCommand(command)
330+
notifyCommandExecuted()
331+
}
326332
}
327333

328334
override fun getCommandManagerModelForCatrobatImage(): CommandManagerModel? {
@@ -339,29 +345,37 @@ class DefaultCommandManager(
339345
}
340346

341347
override fun adjustUndoListForClippingTool() {
342-
if (undoCommandList.first.toString().split(".", "@").size < FIVE) {
343-
return
344-
}
345-
val commandName = undoCommandList.first.toString().split(".", "@")[FIVE]
346-
if (commandName == ClippingCommand::class.java.simpleName) {
347-
val clippingCommand = undoCommandList.pop()
348-
undoCommandList.pop()
349-
undoCommandList.addFirst(clippingCommand)
348+
if (isUndoAvailable) {
349+
if (undoCommandList.first.toString().split(".", "@").size < FIVE) {
350+
return
351+
}
352+
val commandName = undoCommandList.first.toString().split(".", "@")[FIVE]
353+
if (commandName == ClippingCommand::class.java.simpleName) {
354+
val clippingCommand = undoCommandList.pop()
355+
undoCommandList.pop()
356+
undoCommandList.addFirst(clippingCommand)
357+
}
350358
}
351359
}
352360

353361
override fun undoInClippingTool() {
354-
val command = undoCommandList.pop()
355-
handleUndo(command)
356-
notifyCommandExecuted()
362+
if (isUndoAvailable) {
363+
val command = undoCommandList.pop()
364+
handleUndo(command)
365+
notifyCommandExecuted()
366+
}
357367
}
358368

359369
override fun popFirstCommandInUndo() {
360-
undoCommandList.pop()
370+
if (isUndoAvailable) {
371+
undoCommandList.pop()
372+
}
361373
}
362374

363375
override fun popFirstCommandInRedo() {
364-
redoCommandList.pop()
376+
if (isRedoAvailable) {
377+
redoCommandList.pop()
378+
}
365379
}
366380

367381
override fun setInitialStateCommand(command: Command) {

0 commit comments

Comments
 (0)