Nautilus select file patch



This was my rag-tag attempt at getting the nautilus metadata to select
the file we want. It actually kinda works, except that nautilus does
not query the metadata continually, and since it remains running in
the background, theres no real way to force a cosmetic reload of basic
config.

But anyways, here it is, untested, but my first realy forray into C#,
and it was quite fun ;)

--Kevin Kubasik
? beagle.c
? Util/NautilusTest.cs
? po/.intltool-merge-cache
? wrappers/python/.deps
? wrappers/python/.libs
? wrappers/python/beagle.la
? wrappers/python/beagle.lo
? wrappers/python/beaglemodule.lo
Index: Util/NautilusTools.cs
===================================================================
RCS file: /cvs/gnome/beagle/Util/NautilusTools.cs,v
retrieving revision 1.5
diff -u -p -r1.5 NautilusTools.cs
--- Util/NautilusTools.cs	10 Mar 2005 02:02:33 -0000	1.5
+++ Util/NautilusTools.cs	16 Dec 2005 05:12:19 -0000
@@ -109,7 +109,7 @@ namespace Beagle.Util {
 			XmlNode subnode = node.SelectSingleNode ("keyword");
 			if (subnode == null)
 				return null;
-
+			
 			XmlNode attr = subnode.Attributes.GetNamedItem ("name");
 			return attr != null ? attr.Value : null;
 		}
@@ -122,5 +122,109 @@ namespace Beagle.Util {
 			XmlNode attr = node.Attributes.GetNamedItem ("annotation");
 			return attr != null ? attr.Value : null;
 		}
+		
+		static public void SetFile(string path){
+			int index = path.LastIndexOf("/");
+			char[] c = path.ToCharArray();
+			String tempPath;
+			string fileName, metaFile;
+			bool cont = true;
+			int i;
+			i = c.Length-1;
+			while(i>0 && c[i] != '/'){
+				c[i] = ' ';
+				i--;
+			}
+			i = c.Length-1;
+			while(i>0 && c[i] != '/'){
+				c[i] = ' ';
+				i--;
+			}
+			//Console.WriteLine("Writing the contents of my array");
+			//Console.WriteLine(c);
+			tempPath = new String(c);
+			//Console.WriteLine(tempPath);
+			//Console.WriteLine(index + " " + (path.Length-index));
+			tempPath=tempPath.Trim();
+			Console.WriteLine(tempPath);
+			
+			fileName= path.Substring(index,(path.Length)-index);
+			//Console.WriteLine(GetMetaFileName (path));
+			metaFile = GetMetaFileName (path);
+			path = path.Replace(" ","%20");
+			//Console.WriteLine(path);
+			fileName = fileName.Substring(1);
+			//Console.WriteLine(fileName);
+			
+			//<?xml version=\"1.0\"?>\n<directory>
+			
+			String str;
+			str = "<file name=\""
+			+fileName+"\" window_scroll_position=\"file://"
+			+path+"\" window_show_hidden_files=\"0\"/>";
+			if(!(File.Exists(metaFile))){
+				str = "<?xml version=\"1.0\"?>\n<directory><file name=\""
+			+fileName+"\" window_scroll_position=\"file://"
+			+path+"\" window_show_hidden_files=\"0\"/></directory>";
+			}
+			
+			Console.WriteLine(str);
+			Console.WriteLine("MetaFile:" + metaFile);
+			if(metaFile != null && (File.Exists(metaFile))){
+				StreamReader sr =  new StreamReader(metaFile);
+				ArrayList metaCont = new ArrayList();
+				StringBuilder sb = new StringBuilder();
+				while(sr.Peek() >= 0){
+					Console.Write((char)sr.Peek()+" ");
+					if((char) (sr.Peek()) == '>'){
+						sb.Append((char)sr.Read());
+						metaCont.Add(sb.ToString());
+						sb.Remove(0,sb.Length);
+					}
+					else{
+						sb.Append((char)sr.Read());
+					}
+				}
+				sr.Close();
+				Console.WriteLine("\nNow Print the Array");
+				Array ob;
+				
+				ob = metaCont.ToArray(System.Type.GetType("System.String"));
+				ob.Initialize();
+				
+				
+				ArrayList array = new ArrayList(ob);
+				Console.WriteLine(array.Count);
+				for(i=0;i<array.Count;i++){
+					Console.WriteLine(array.get_Item(i));
+					if(str.Equals(array.get_Item(i))){
+						array.RemoveAt(i);
+						array.Insert(i,str);
+						Console.WriteLine("Removing some elements");
+					}
+					else{
+						array.Insert(array.Count-2,str);
+						break;
+					}
+				}
+				
+				/*
+				if(File.Exists(metaFile))
+					File.Delete(metaFile);
+				*/
+				StreamWriter sw = File.CreateText(metaFile);
+				
+				for(int count =0; count<array.Count;count++){
+					Console.WriteLine(array.get_Item(count) + " at index:" +count);
+					sw.WriteLine(array.get_Item(count));
+				}
+				sw.Flush();
+				sw.Close();
+				
+			}
+			
+			
+		}
+
 	}
 }


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