[gnome-subtitles] Fix crash in bug #638238, with the help of Michał Sawicz. If there's no selection, insert new subti



commit 4f629cfbbcc0168b7bac307ce545777a811caa7e
Author: Pedro Castro <mail pedrocastro org>
Date:   Wed Dec 29 02:48:31 2010 +0000

    Fix crash in bug #638238, with the help of MichaÅ? Sawicz. If there's no selection, insert new subtitles at the end.

 .../Core/Command/InsertSubtitleCommand.cs          |   17 ++++++++++++++++-
 src/GnomeSubtitles/Core/EventHandlers.cs           |    4 +++-
 2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/src/GnomeSubtitles/Core/Command/InsertSubtitleCommand.cs b/src/GnomeSubtitles/Core/Command/InsertSubtitleCommand.cs
index 3360c16..b1d96c8 100644
--- a/src/GnomeSubtitles/Core/Command/InsertSubtitleCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/InsertSubtitleCommand.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2008 Pedro Castro
+ * Copyright (C) 2006-2010 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -107,4 +107,19 @@ public class InsertFirstSubtitleCommand : InsertSubtitleCommand {
 
 }
 
+public class InsertLastSubtitleCommand : InsertSubtitleCommand {
+	
+	public InsertLastSubtitleCommand () : base(Util.IntToPath(Base.Document.Subtitles.Count - 1)) {
+	}
+	
+	protected override TreePath GetNewPath () {
+		return Util.IntToPath(Base.Document.Subtitles.Count);
+	}
+	
+	protected override void InsertNew () {
+		Base.Ui.View.InsertNewAfter(Path);
+	}
+
+}
+
 }
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 770c85d..cb75941 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -139,8 +139,10 @@ public class EventHandlers {
 	public void OnEditInsertSubtitleAfter (object o, EventArgs args) {
 		if (Base.Document.Subtitles.Count == 0)
 			Base.CommandManager.Execute(new InsertFirstSubtitleCommand());
-		else
+		else if (Base.Ui.View.Selection.Count > 0)
 			Base.CommandManager.Execute(new InsertSubtitleAfterCommand());
+		else
+			Base.CommandManager.Execute(new InsertLastSubtitleCommand());
 	}
 	
 	public void OnEditDeleteSubtitles (object o, EventArgs args) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]