Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 18444)
+++ wp-includes/theme.php	(working copy)
@@ -345,42 +345,9 @@
 		$stylesheet_files = array();
 		$template_files = array();
 
-		$stylesheet_dir = @ dir("$theme_root/$stylesheet");
-		if ( $stylesheet_dir ) {
-			while ( ($file = $stylesheet_dir->read()) !== false ) {
-				if ( !preg_match('|^\.+$|', $file) ) {
-					if ( preg_match('|\.css$|', $file) )
-						$stylesheet_files[] = "$theme_root/$stylesheet/$file";
-					elseif ( preg_match('|\.php$|', $file) )
-						$template_files[] = "$theme_root/$stylesheet/$file";
-				}
-			}
-			@ $stylesheet_dir->close();
-		}
+		search_for_theme_files_r("$theme_root/$stylesheet", 'both', $stylesheet_files, $template_files);
+		search_for_theme_files_r("$template_directory", 'script', $stylesheet_files, $template_files);
 
-		$template_dir = @ dir("$template_directory");
-		if ( $template_dir ) {
-			while ( ($file = $template_dir->read()) !== false ) {
-				if ( preg_match('|^\.+$|', $file) )
-					continue;
-				if ( preg_match('|\.php$|', $file) ) {
-					$template_files[] = "$template_directory/$file";
-				} elseif ( is_dir("$template_directory/$file") ) {
-					$template_subdir = @ dir("$template_directory/$file");
-					if ( !$template_subdir )
-						continue;
-					while ( ($subfile = $template_subdir->read()) !== false ) {
-						if ( preg_match('|^\.+$|', $subfile) )
-							continue;
-						if ( preg_match('|\.php$|', $subfile) )
-							$template_files[] = "$template_directory/$file/$subfile";
-					}
-					@ $template_subdir->close();
-				}
-			}
-			@ $template_dir->close();
-		}
-
 		//Make unique and remove duplicates when stylesheet and template are the same i.e. most themes
 		$template_files = array_unique($template_files);
 		$stylesheet_files = array_unique($stylesheet_files);
@@ -465,6 +432,47 @@
 }
 
 /**
+ * Search recursively for theme files
+ *
+ * @global array $__search_for_theme_files_parsed_directories To avoid recursion
+ *
+ * @param string Path to the current directory to search
+ * @param string File types to add ('css', 'script' or 'both')
+ * @param array Array to store stylesheet (.css) files
+ * @param array Array to store template (.php|.js) files
+ */
+$__search_for_theme_files_parsed_directories = array();
+ 
+function search_for_theme_files_r( $path, $file_types, array &$stylesheet_files, array &$template_files ) {
+	global $__search_for_theme_files_parsed_directories;
+
+	// Avoiding recursion
+	$rp = realpath($path);
+	if (in_array($rp, $__search_for_theme_files_parsed_directories))
+		return;
+	$__search_for_theme_files_parsed_directories[] = $rp;
+	
+	// Looking for files
+	$dir = @dir($path);
+	if ($dir) {
+		while ( ($file = $dir->read()) !== false ) {
+			if ( !preg_match('|^\.+$|', $file) ) {
+				$fn = "{$path}/{$file}";
+				if ( !is_readable( $fn ) )
+					continue;
+				if ( is_dir( $fn ) )
+					search_for_theme_files_r( $fn, $file_types, $stylesheet_files, $template_files );
+				else if ( preg_match('|\.css$|', $file) && ( 'css' == $file_types || 'both' == $file_types ) )
+					$stylesheet_files[] = $fn;
+				elseif ( preg_match('#\.(php|js)$#', $file) && ( 'script' == $file_types || 'both' == $file_types ) )
+					$template_files[] = $fn;
+			}
+		}
+		@$dir->close();
+	}
+}
+
+/**
  * Retrieve theme roots.
  *
  * @since 2.9.0
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 18444)
+++ wp-includes/functions.php	(working copy)
@@ -6,6 +6,30 @@
  */
 
 /**
+ * Sort files by path
+ *
+ * Please refer to http://www.php.net/manual/en/function.usort.php for further information on the parameters
+ *
+ * @param mixed First item to compare
+ * @param midex Second item to compare
+ * @return int an integer based on the comparison result
+ */
+function sort_files_by_path($a, $b) {
+	$dirA = dirname( $a );
+	if ( '.' != $dirA )
+		$dirA .= '/';
+	$dirB = dirname( $b );
+	if ( '.' != $dirB )
+		$dirB .= '/';
+	$countA = substr_count( $dirA, DIRECTORY_SEPARATOR );
+	$countB = substr_count( $dirB, DIRECTORY_SEPARATOR );
+	if ( $countA == $countB )
+		return strcmp($a, $b);
+	else
+		return $countA - $countB;
+}
+
+/**
  * Converts MySQL DATETIME field to user specified date format.
  *
  * If $dateformatstring has 'G' value, then gmmktime() function will be used to
Index: wp-admin/includes/plugin.php
===================================================================
--- wp-admin/includes/plugin.php	(revision 18444)
+++ wp-admin/includes/plugin.php	(working copy)
@@ -159,35 +159,30 @@
  *
  * @since 2.8.0
  *
+ * @global $plugins
+ *
  * @param string $plugin Plugin ID
  * @return array List of files relative to the plugin root.
  */
 function get_plugin_files($plugin) {
 	$plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
-	$dir = dirname($plugin_file);
-	$plugin_files = array($plugin);
-	if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {
-		$plugins_dir = @ opendir( $dir );
-		if ( $plugins_dir ) {
-			while (($file = readdir( $plugins_dir ) ) !== false ) {
-				if ( substr($file, 0, 1) == '.' )
-					continue;
-				if ( is_dir( $dir . '/' . $file ) ) {
-					$plugins_subdir = @ opendir( $dir . '/' . $file );
-					if ( $plugins_subdir ) {
-						while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
-							if ( substr($subfile, 0, 1) == '.' )
-								continue;
-							$plugin_files[] = plugin_basename("$dir/$file/$subfile");
-						}
-						@closedir( $plugins_subdir );
-					}
-				} else {
-					if ( plugin_basename("$dir/$file") != $plugin )
-						$plugin_files[] = plugin_basename("$dir/$file");
-				}
+	$plugin_keys = array_keys( $GLOBALS['plugins'] );
+
+	if ( in_array($plugin, $plugin_keys) ) {
+		$dir = dirname( $plugin_file );
+		$plugin_files = array($plugin);
+		if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {
+			search_for_plugin_files_r($dir, $plugin_files);
+			$plugin_files = array_unique($plugin_files);
+		}
+	}
+	else {
+		foreach ($plugin_keys as $p) {
+			$pdir = dirname( WP_PLUGIN_DIR . '/' . $plugin );
+			if ( substr( $plugin_file, 0, strlen( $pdir ) ) == $pdir) {
+				var_dump($p);
+				return get_plugin_files( $p );
 			}
-			@closedir( $plugins_dir );
 		}
 	}
 
@@ -277,6 +272,43 @@
 }
 
 /**
+ * Search recursively for plugin files
+ *
+ * @global array $__search_for_plugin_files_parsed_directories To avoid recursion
+ *
+ * @param string Path to the current directory to search
+ * @param array Array to store files
+ */
+$__search_for_plugin_files_parsed_directories = array();
+ 
+function search_for_plugin_files_r( $path, array &$files ) {
+	global $__search_for_plugin_files_parsed_directories;
+
+	// Avoiding recursion
+	$rp = realpath($path);
+	if (in_array($rp, $__search_for_plugin_files_parsed_directories))
+		return;
+	$__search_for_plugin_files_parsed_directories[] = $rp;
+	
+	// Looking for files
+	$dir = @dir($path);
+	if ($dir) {
+		while ( ($file = $dir->read()) !== false ) {
+			if ( !preg_match('|^\.+$|', $file) ) {
+				$fn = "{$path}/{$file}";
+				if ( !is_readable( $fn ) )
+					continue;
+				if ( is_dir( $fn ) )
+					search_for_plugin_files_r( $fn, $files );
+				elseif ( preg_match('#\.(php|js)$#', $file) )
+					$files[] = plugin_basename( $fn );
+			}
+		}
+		@$dir->close();
+	}
+}
+
+/**
  * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data.
  *
  * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins).
Index: wp-admin/theme-editor.php
===================================================================
--- wp-admin/theme-editor.php	(revision 18444)
+++ wp-admin/theme-editor.php	(working copy)
@@ -183,13 +183,16 @@
 		if ( $is_child_theme && strpos( $template_file, trailingslashit( $template_dir ) ) === 0 )
 			continue;
 
-		$description = trim( get_file_description($template_file) );
-		$template_show = basename($template_file);
+		if ( dirname( $template_file ) == $template_dir )
+			$description = trim( get_file_description($template_file) );
+		else
+			$description = trim( str_replace( "{$template_dir}/", '', $template_file ) );
+		$template_show = str_replace("{$template_dir}/", '', $template_file);
 		$filedesc = ( $description != $template_file ) ? "$description<br /><span class='nonessential'>($template_show)</span>" : "$description";
 		$filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($template_show)</span></span>" : $filedesc;
 		$template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc );
 	}
-	ksort( $template_mapping );
+	uksort( $template_mapping, 'sort_files_by_path' );
 	while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) :
 	?>
 		<li><a href="theme-editor.php?file=<?php echo urlencode( $template_file ) ?>&amp;theme=<?php echo urlencode( $theme ) ?>&amp;dir=theme"><?php echo $filedesc ?></a></li>
@@ -205,13 +208,16 @@
 		if ( $is_child_theme && strpos( $style_file, trailingslashit( $template_dir ) ) === 0 )
 			continue;
 
-		$description = trim( get_file_description($style_file) );
-		$style_show = basename($style_file);
+		if ( dirname( $style_file ) == $template_dir )
+			$description = trim( get_file_description($style_file) );
+		else
+			$description = trim( str_replace( "{$stylesheet_dir}/", '', $style_file ) );
+		$style_show = str_replace("{$stylesheet_dir}/", '', $style_file);
 		$filedesc = ( $description != $style_file ) ? "$description<br /><span class='nonessential'>($style_show)</span>" : "$description";
 		$filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($style_show)</span></span>" : $filedesc;
 		$template_mapping[ $description ] = array( _get_template_edit_filename($style_file, $stylesheet_dir), $filedesc );
 	}
-	ksort( $template_mapping );
+	uksort( $template_mapping, 'sort_files_by_path' );
 	while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) :
 		?>
 		<li><a href="theme-editor.php?file=<?php echo urlencode( $style_file ) ?>&amp;theme=<?php echo urlencode($theme) ?>&amp;dir=style"><?php echo $filedesc ?></a></li>
Index: wp-admin/plugin-editor.php
===================================================================
--- wp-admin/plugin-editor.php	(revision 18444)
+++ wp-admin/plugin-editor.php	(working copy)
@@ -203,6 +203,7 @@
 
 	<ul>
 <?php
+usort($plugin_files, 'sort_files_by_path');
 foreach ( $plugin_files as $plugin_file ) :
 	// Get the extension of the file
 	if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {
