Index: /CKEditor/trunk/CHANGES.html
===================================================================
--- /CKEditor/trunk/CHANGES.html	(revision 5245)
+++ /CKEditor/trunk/CHANGES.html	(revision 5246)
@@ -72,4 +72,5 @@
 		<li><a href="http://dev.fckeditor.net/ticket/4717">#4717</a> : 'Unlink' and 'Outdent' command buttons should be disabled on editor startup.</li>
 		<li><a href="http://dev.fckeditor.net/ticket/5119">#5119</a> : Disabled command buttons are not being properly marked when focused.</li>
+		<li><a href="http://dev.fckeditor.net/ticket/5307">#5307</a> : Hide dialog page cause problem when there's only two remains.</li>
 	</ul>
 	<h3>
Index: /CKEditor/trunk/_source/plugins/dialog/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/dialog/plugin.js	(revision 5245)
+++ /CKEditor/trunk/_source/plugins/dialog/plugin.js	(revision 5246)
@@ -336,5 +336,5 @@
 				processed = 1;
 			}
-			else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode )
+			else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
 			{
 				// Alt-F10 puts focus into the current tab item in the tab bar.
@@ -894,15 +894,10 @@
 			page.setAttribute( 'aria-labelledby', tabId );
 
-			// If only a single page exist, a different style is used in the central pane.
-			if ( this._.pageCount === 0 )
-				this.parts.dialog.addClass( 'cke_single_page' );
-			else
-				this.parts.dialog.removeClass( 'cke_single_page' );
-
 			// Take records for the tabs and elements created.
 			this._.tabs[ contents.id ] = [ tab, page ];
 			this._.tabIdList.push( contents.id );
-			this._.pageCount++;
+			!contents.hidden && this._.pageCount++;
 			this._.lastTab = tab;
+			this.updateStyle();
 
 			var contentMap = this._.contents[ contents.id ] = {},
@@ -962,4 +957,11 @@
 		},
 
+		// Dialog state-specific style updates.
+		updateStyle : function()
+		{
+			// If only a single page shown, a different style is used in the central pane.
+			this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
+		},
+
 		/**
 		 * Hides a page's tab away from the dialog.
@@ -971,7 +973,13 @@
 		{
 			var tab = this._.tabs[id] && this._.tabs[id][0];
-			if ( !tab )
+			if ( !tab || this._.pageCount == 1 )
 				return;
+			// Switch to other tab first when we're hiding the active tab.
+			else if ( id == this._.currentTabId )
+				this.selectPage( getPreviousVisibleTab.call( this ) );
+
 			tab.hide();
+			this._.pageCount--;
+			this.updateStyle();
 		},
 
@@ -988,4 +996,6 @@
 				return;
 			tab.show();
+			this._.pageCount++;
+			this.updateStyle();
 		},
 
