158 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			158 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Drawing;
 | 
						|
using System.Data;
 | 
						|
using System.Text;
 | 
						|
using System.Windows.Forms;
 | 
						|
using VEPROMS.CSLA.Library;
 | 
						|
using JR.Utils.GUI.Forms;
 | 
						|
 | 
						|
namespace Volian.Controls.Library
 | 
						|
{
 | 
						|
  public partial class DisplayBookMarks : UserControl
 | 
						|
	{
 | 
						|
  #region delegates and Events
 | 
						|
    // C2015-022 added event so that we can update child PROMS windows
 | 
						|
    public delegate void ResetBookMarksInPROMSWindowsEvent(object sender, EventArgs args);
 | 
						|
    public event ResetBookMarksInPROMSWindowsEvent ResetBookMarksInPROMSWindows;
 | 
						|
    private void OnResetBookMarksInPROMSWindows()
 | 
						|
    {
 | 
						|
      if (ResetBookMarksInPROMSWindows != null)
 | 
						|
        ResetBookMarksInPROMSWindows(this, new EventArgs());
 | 
						|
    }
 | 
						|
  #endregion //delegates and Events
 | 
						|
    #region Properties
 | 
						|
    private MostRecentItemList _MyBookMarks;
 | 
						|
    public MostRecentItemList MyBookMarks
 | 
						|
    {
 | 
						|
      get { return _MyBookMarks; }
 | 
						|
      set { _MyBookMarks = value; }
 | 
						|
    }
 | 
						|
		private ItemInfo _CurItemInfo = null;
 | 
						|
		private bool _Initalizing = false;
 | 
						|
		private DisplayTabControl _MyDisplayTabControl;
 | 
						|
		public DisplayTabControl MyDisplayTabControl
 | 
						|
		{
 | 
						|
			get { return _MyDisplayTabControl; }
 | 
						|
			set
 | 
						|
			{
 | 
						|
				if (value == null) return;
 | 
						|
				_MyDisplayTabControl = value;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private EditItem _MyEditItem;
 | 
						|
		public EditItem MyEditItem
 | 
						|
		{
 | 
						|
			get { return _MyEditItem; }
 | 
						|
			set 
 | 
						|
			{
 | 
						|
				if (value == null) return;
 | 
						|
				if (_CurItemInfo != null && _CurItemInfo.ItemID == value.MyItemInfo.ItemID) return;
 | 
						|
				_MyEditItem = value;
 | 
						|
				_CurItemInfo = MyEditItem.MyItemInfo;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		//private StepRTB _MyRTB;
 | 
						|
		//public StepRTB MyRTB
 | 
						|
		//{
 | 
						|
		//    get { return _MyRTB; }
 | 
						|
		//    set
 | 
						|
		//    {
 | 
						|
		//        if (value == null) return;
 | 
						|
		//        if (_CurItemInfo != null && _CurItemInfo.ItemID == value.MyItemInfo.ItemID) return;
 | 
						|
		//        _MyRTB = value;
 | 
						|
		//        _CurItemInfo = MyRTB.MyItemInfo;
 | 
						|
		//    }
 | 
						|
		//}
 | 
						|
		#endregion
 | 
						|
		#region Constructors
 | 
						|
		public DisplayBookMarks()
 | 
						|
		{
 | 
						|
			InitializeComponent();
 | 
						|
			//SetupBookMarks();
 | 
						|
		}
 | 
						|
		public void SetupBookMarks()
 | 
						|
		{
 | 
						|
			if (_MyBookMarks == null)
 | 
						|
			{
 | 
						|
				_MyBookMarks = MostRecentItemList.GetMRILst((System.Collections.Specialized.StringCollection)(Properties.Settings.Default["BookMarks"]),0);
 | 
						|
				_MyBookMarks.AfterRemove += new ItemInfoEvent(_MyBookMarks_AfterRemove);
 | 
						|
			}
 | 
						|
			lbxBookMarks.SelectedValueChanged += new EventHandler(lbxBookMarks_SelectedValueChanged);
 | 
						|
			RefreshBookMarkData();
 | 
						|
			//btnPrevPos.Enabled = false;
 | 
						|
			//lbxBookMarks.Enabled = false;
 | 
						|
			//_PrevBookMark = null;
 | 
						|
		}
 | 
						|
 | 
						|
		void _MyBookMarks_AfterRemove(object sender)
 | 
						|
		{
 | 
						|
			RefreshBookMarkData();
 | 
						|
		}
 | 
						|
		private void RefreshBookMarkData()
 | 
						|
		{
 | 
						|
      ResetBookMarkList();
 | 
						|
      OnResetBookMarksInPROMSWindows(); // C2015-022 trigger event to update child PROMS windows with current bookmark list
 | 
						|
			SaveBookMarks();
 | 
						|
		}
 | 
						|
 | 
						|
    // Part of Separate Windows upgrade C2015-022
 | 
						|
    // Call from FrmVEPROMS which spins through all of the child windows and updates the bookmark list in each
 | 
						|
    // - broke is code out of RefreshBookMarkData()
 | 
						|
    public void ResetBookMarkList() 
 | 
						|
    {
 | 
						|
			lbxBookMarks.DataSource = null;
 | 
						|
			lbxBookMarks.DisplayMember = "MenuTitle";
 | 
						|
			lbxBookMarks.DataSource = _MyBookMarks;
 | 
						|
			btnClrBookMrks.Enabled = (lbxBookMarks.Items.Count > 0);
 | 
						|
			btnRmvCurBookMrk.Enabled = lbxBookMarks.SelectedIndex > -1;
 | 
						|
    }
 | 
						|
    private void SaveBookMarks()
 | 
						|
		{
 | 
						|
			Properties.Settings.Default.BookMarks = _MyBookMarks.ToSettings();
 | 
						|
			Properties.Settings.Default.Save();
 | 
						|
		}
 | 
						|
		void lbxBookMarks_SelectedValueChanged(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			btnRmvCurBookMrk.Enabled = (lbxBookMarks.SelectedIndex >= 0);
 | 
						|
		}
 | 
						|
		public void AddBookMark(ItemInfo itm)
 | 
						|
		{
 | 
						|
			_MyBookMarks.Add(itm);
 | 
						|
			RefreshBookMarkData();
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region Events
 | 
						|
		private void btnSetBookMrk_Click(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			if (_CurItemInfo == null)
 | 
						|
			{
 | 
						|
				FlexibleMessageBox.Show("Cannot set a bookmark on this item.");
 | 
						|
				return;
 | 
						|
			}
 | 
						|
			_MyBookMarks.Add(_CurItemInfo);
 | 
						|
			RefreshBookMarkData();
 | 
						|
		}
 | 
						|
 | 
						|
		private void btnRmvCurBookMrk_Click(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			_MyBookMarks.RemoveAt(lbxBookMarks.SelectedIndex);
 | 
						|
			RefreshBookMarkData();
 | 
						|
		}
 | 
						|
 | 
						|
		private void btnClrBookMrks_Click(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			_MyBookMarks.Clear();
 | 
						|
			RefreshBookMarkData();
 | 
						|
		}
 | 
						|
		private void lbxBookMarks_Click(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			MostRecentItem itm = lbxBookMarks.SelectedValue as MostRecentItem;
 | 
						|
			if(itm != null)
 | 
						|
				MyDisplayTabControl.OpenItem(itm.MyItemInfo);
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
	}
 | 
						|
}
 |