//------------------------------------------------------------------
		private void GVClicked(object sender, System.EventArgs e)
		{
			MenuItem mi = (MenuItem) sender;
            checkSelectedItem(mi);
            string displayMode = LoadFromRegistry("displayMode", "category");

            GVstruct infoToGraph = new GVstruct();
            bool resizeGV = false;
            int[] dim = new int[4];
            if (mGraphicalView == null)
            {
                mGraphicalView = new GraphicalView(this);
                //resizeGV = true;                
               // mGraphicalView.Close();
               // mGraphicalView = null;
            }

            int catIndex = 0;
			if (mi != null)
			{
				string item = mi.ToString();
                catIndex = mLog.GetIndexForCategory(mi.Text);
                if (displayMode == "heap")
                    catIndex = 0;  // 0 means no category, or i.e. all categories
                mLogSnap = new MemManager.Log.SnapShot(mLog, mLog.FindHWIndexForCategory(catIndex), true);
                infoToGraph.PopulateGVStructFromSnapshot(mLog, mLogSnap, catIndex);
			}
            mGraphicalView.CopyGvInfo(infoToGraph, mLog, mLogSnap, mAllocators, catIndex);
            if (resizeGV)
                mGraphicalView.SetWindowSize(dim[0], dim[1]);
            
            mGraphicalView.Show();

            //the following goes after show to work correctly
            if (resizeGV)
                mGraphicalView.SetWindowLocation(new Point(dim[2], dim[3]));
        }
        //-------------------------------------------------------------------
        private void mMenuItemFilter_Click(object sender, System.EventArgs e)
        {
            FilterSelector fs = new FilterSelector();
            DialogResult res = fs.ShowDialog();
            if (res == DialogResult.OK)
            {
                mFilter = fs.GetFilter();
                int size = fs.GetSize();
                bool dir = fs.GetDirection();
                MemManager.Log.SnapShot FilterdLogSnap = null;
                if (mFilter != "")
                    FilterdLogSnap = new MemManager.Log.SnapShot(mLog, mLogSnap, mFilter, size, dir);

                PopulateFromSnapshot(mLog, mLogSnap, mFilter, size, dir);
                if (mMemoryGraph != null)
                {
               //     mMemoryGraph.HilightLogEntries(FilterdLogSnap);
                }
                if (mGraphicalView != null)
                {
                    mGraphicalView.UpdateHighlights(FilterdLogSnap);
                }
            }
        }
        //-------------------------------------------------------------------
//         private void menuItemCallstack_Click(object sender, System.EventArgs ev)
//         {
//             string appPath = Application.ExecutablePath;
//             int lastDir = appPath.LastIndexOf(@"\");
// 
//           //  string map = "D:\\projects\\buckeye\\buckeye\\main\\source\\DistPS3\\Launch_PS3d.elf";
//             string defaultLocationOfAddr2line = "D:\\usr\\local\\cell";
//             if (defaultLocationOfAddr2line != null)
//                 defaultLocationOfAddr2line += "\\host-win32\\ppu\\bin\\ppu-lv2-addr2line.exe";
// 
//             string pathToAddr2line = LoadFromRegistry("addr2linepath", defaultLocationOfAddr2line);
//             int item = -1;
//             for (int i = 0, e = mCollapsedView.Count; i < e; i++)
//             {
//                 if (mDataGrid.IsSelected(i))
//                 {
//                     item = i;
//                     break;
//                 }
//             }
// 
//             if (item == -1)
//             {
//                 item = mDataGrid.CurrentCell.RowNumber;
//             }
// 
//             if (item != -1)
//             {
//                 int colIndex = 0;
//                 int indexval = (int)mDataGrid[item, colIndex];
// /*
//                 CallStack opt = new CallStack();
//                 opt.SetMapPath(map);
//                 opt.SetAddr2linePath(pathToAddr2line);
//                 opt.SetLog(mLog);
//                 opt.SetEntryToLookUp(mLog.GetString(mLog[indexval].stackTraceString));
//                 opt.ShowDialog();
// 
//                 map = opt.GetMapPath();
//                 pathToAddr2line = opt.GetAddr2linePath();
//                 SaveToRegistry("addr2linepath", pathToAddr2line);
// */
//             }
//         }

        //-------------------------------------------------------------------
        private void mMenuItemEndOfLog_Click(object sender, System.EventArgs e)
        {
            mLogSnap = new MemManager.Log.SnapShot(mLog, mLog.Count, false);
            PopulateFromSnapshot(mLog, mLogSnap, "", 0, false);
            if (mMemoryGraph != null)
            {
                mMemoryGraph.HilightLogEntry(mLog.Count - 1);
            }
            if (mGraphicalView != null)
            {
                mGraphicalView.NewSnapShot(mLogSnap);
            }
        }
        //-------------------------------------------------------------------
        private void LabelClicked(object sender, System.EventArgs e)
        {
            MenuItem mi = (MenuItem)sender;
            ArrayList labels = mLog.GetLabels();
            if (mi != null)
            {
                string item = mi.ToString();
                MemManager.Log.LogEntry le = (MemManager.Log.LogEntry)labels[mi.Index];
                mLogSnap = new MemManager.Log.SnapShot(mLog, (int)le.index, false);

                // Repopulate
                PopulateFromSnapshot(mLog, mLogSnap, "", 0, false);

                if (mMemoryGraph != null)
                {
                    mMemoryGraph.HilightLogEntry((int)le.index);
                }
                if (mGraphicalView != null)
                {
                    mGraphicalView.NewSnapShot(mLogSnap);
                }
            }
        }
        //-------------------------------------------------------------------
        private void HWClicked(object sender, System.EventArgs e)
        {
            MenuItem mi = (MenuItem)sender;

            checkSelectedItem(mi);

            if (mi != null)
            {
                string item = mi.ToString();
                int category = mLog.GetIndexForCategory(mi.Text);
                int index = mLog.FindHWIndexForCategory(category);
                mLogSnap = new MemManager.Log.SnapShot(mLog, index, false);
  //              PopulateFromSnapshot(mLog, mLogSnap, "^" + mi.Text + "::");
                PopulateFromSnapshot(mLog, mLogSnap, "", 0, false);
                if (mMemoryGraph != null)
                {
                    mMemoryGraph.HilightLogEntry(index);
                }
                if (mGraphicalView != null)
                {
                    mGraphicalView.NewSnapShot(mLogSnap);
                }
            }
        }
		//-------------------------------------------------------------------
		void LoadLog(string fname)
		{
			if (!System.IO.File.Exists(fname))
				return;

			Cursor.Current = Cursors.WaitCursor;
			if (fname.ToLower().EndsWith(".bin"))
			{
				mLog = new MemManager.Log.Log();				
				if (mLog.Load(fname) == false)
				{
					Cursor.Current = Cursors.Default;
					System.Windows.Forms.MessageBox.Show("File was invalid, loading stopped", "Error");					
					return;
				}
                if (!mCategoryMode)
                    mLog.SwapToHeap();
				mLogSnap = new MemManager.Log.SnapShot(mLog, mLog.Count, false);
				mAllocators = mLog.GetAllocatorList();				
			}
			else
			{
				MemManager.Log.TCRLoader loader = new MemManager.Log.TCRLoader();
				mLog = loader.Load(fname);
				if (mLog == null)
				{
					Cursor.Current = Cursors.Default;
					System.Windows.Forms.MessageBox.Show("File was invalid, loading stopped", "Error");
					return;
				}
                if (!mCategoryMode)
                    mLog.SwapToHeap();
                mLogSnap = new MemManager.Log.SnapShot(mLog, mLog.Count, false);
                mAllocators = mLog.GetAllocatorList();
			}

            mFilename = fname;
			Cursor.Current = Cursors.Default;
            CreateInitialView();
        }
		public void SelectSnapShot(int index)
		{
            mLogSnap = new MemManager.Log.SnapShot(mLog, index, false);
			PopulateFromSnapshot(mLog, mLogSnap, "", 0, false);
			if (mMemoryGraph != null)
			{
				mMemoryGraph.HilightLogEntry(index);
			}
		}
 public void CompareSnapShot(int index)
 {
     if (index >= mLog.Count)
     {
         index = mLog.Count - 1;
     }
     MemManager.Log.SnapShot diffLogSnap = new MemManager.Log.SnapShot(mLog, index, mLogSnap, false);
     PopulateFromSnapshot(mLog, diffLogSnap, "", 0, false);
     if (mGraphicalView != null)
     {
         mGraphicalView.NewSnapShot(diffLogSnap);
     }
 }
		public void UpdateSnapShot(int index)
		{
			if (index >= mLog.Count)
			{
				index = mLog.Count - 1;
			}
            mLogSnap = new MemManager.Log.SnapShot(mLog, index, false);
            PopulateFromSnapshot(mLog, mLogSnap, mFilter, 0, false);

			if (mGraphicalView != null)
			{
				mGraphicalView.NewSnapShot(mLogSnap);
			}
		}
 private void mHeapView_Click(object sender, EventArgs e)
 {
     if (!mCategoryMode)
         return;
     checkSelectedItem((MenuItem)sender);
     SaveToRegistry("displayMode", "heap");
     mCategoryMode = false;
     mLog.SwapToHeap();
     mLogSnap = new MemManager.Log.SnapShot(mLog, mLog.Count, false);
     CreateInitialView();
 }