예제 #1
0
        /// <summary>
        /// Manages a form's size, location, and window state
        /// </summary>
        /// <param name="f">The form to manage</param>
        /// <param name="key">The key to the form's storage, and also it's feature name if implemented</param>
        /// <param name="restore">A flag indicating whether the engine should retore the form's previous state immediately</param>
        /// <returns></returns>
        public bool Manage(Form f, string key, bool restore)
        {
            try
            {
                foreach (DictionaryEntry entry in _listeners)
                {
                    Form form = (Form)entry.Key;
                    if (form == f)
                    {
                        return(true);
                    }
                }

                WindowPositionListener wpl = new WindowPositionListener();
                wpl.NeedsConfiguration += new XmlConfigurationEventHandler(OnListenerNeedsConfiguration);
                wpl.FinishedListening  += new EventHandler(OnListenerFinishedListening);

                lock (this.Listeners.SyncRoot)
                {
                    _listeners.Add(f, wpl);
                }

                return(wpl.Manage(f, key, restore));
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            return(false);
        }
예제 #2
0
 /// <summary>
 /// Stops the SnapIn
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void WindowPositioningEngineSnapIn_Stop(object sender, EventArgs e)
 {
     foreach (DictionaryEntry entry in _listeners)
     {
         try
         {
             WindowPositionListener wpl = (WindowPositionListener)entry.Value;
             wpl.WriteChangesAndRelease();
         }
         catch (System.Exception systemException)
         {
             System.Diagnostics.Trace.WriteLine(systemException);
         }
     }
 }
예제 #3
0
        private void WindowPositioningEngineSnapIn_BuildingFeatureList(object sender, FeatureCollectionEventArgs e)
        {
            WindowPositioningEngineSnapIn engine = WindowPositioningEngineSnapIn.Instance;

            foreach (DictionaryEntry entry in engine._listeners)
            {
                WindowPositionListener             wpl        = (WindowPositionListener)entry.Value;
                IWindowPositioningEngineFeaturable featurable = wpl.Target as IWindowPositioningEngineFeaturable;
                if (featurable != null)
                {
                    WindowPositionFeature wpf = new WindowPositionFeature(wpl.Key, "Controls the position and state of the window.", wpl.Target, FeatureActions.ResetToDefault);
                    wpf.Tag = wpl;
                    e.Features.Add(wpf);
                }
            }
        }
예제 #4
0
        private void WindowPositioningEngineSnapIn_AfterActionTakenForFeature(object sender, FeatureEventArgs e)
        {
            if (e.Feature != null)
            {
//				/// is the feature a configuration? if so try and delete the file
//				if (e.Feature.GetType() == typeof(ConfigurationFeature))
//				{
//					ConfigurationFeature cf = e.Feature as ConfigurationFeature;
//					if (cf != null)
//					{
//						switch(cf.ConfigurationName)
//						{
//						case SnapInHostingEngine.COMMON_CONFIGURATION:
//							if (e.Feature.Action == FeatureActions.ResetToDefault)
//							{
//								this.InstallMyCommonOptions();
//								this.ReadMyCommonOptions();
//							}
//							break;
//
//						case SnapInHostingEngine.LOCALUSER_CONFIGURATION:
//							if (e.Feature.Action == FeatureActions.ResetToDefault)
//							{
//								this.InstallMyLocalUserOptions();
//								this.ReadMyLocalUserOptions();
//							}
//							break;
//						};
//					}
//				}

                if (e.Feature.GetType() == typeof(WindowPositionFeature))
                {
                    WindowPositionFeature wpf = e.Feature as WindowPositionFeature;
                    if (wpf != null)
                    {
                        WindowPositionListener             wpl     = wpf.Tag as WindowPositionListener;
                        IWindowPositioningEngineFeaturable feature = wpl.Target as IWindowPositioningEngineFeaturable;
                        wpl.Target.Size        = feature.GetDefaultSize();
                        wpl.Target.Location    = feature.GetDefaultLocation();
                        wpl.Target.WindowState = feature.GetDefaultWindowState();
                    }
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Occurs when a window position listener is finished listening to a window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnListenerFinishedListening(object sender, EventArgs e)
 {
     try
     {
         WindowPositionListener wpl = sender as WindowPositionListener;
         if (wpl != null)
         {
             lock (this.Listeners.SyncRoot)
             {
                 // if we have a listener for this
                 if (_listeners.ContainsKey(wpl.Target))
                 {
                     // remove it now
                     _listeners.Remove(wpl.Target);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
 }
		/// <summary>
		/// Manages a form's size, location, and window state
		/// </summary>
		/// <param name="f">The form to manage</param>
		/// <param name="key">The key to the form's storage, and also it's feature name if implemented</param>
		/// <param name="restore">A flag indicating whether the engine should retore the form's previous state immediately</param>
		/// <returns></returns>
		public bool Manage(Form f, string key, bool restore)
		{
			try
			{
				foreach(DictionaryEntry entry in _listeners)
				{
					Form form = (Form)entry.Key;
					if (form == f)
						return true;
				}

				WindowPositionListener wpl = new WindowPositionListener();
				wpl.NeedsConfiguration += new XmlConfigurationEventHandler(OnListenerNeedsConfiguration);
				wpl.FinishedListening += new EventHandler(OnListenerFinishedListening);
				
				lock(this.Listeners.SyncRoot)
				{
					_listeners.Add(f, wpl);
				}
				
				return wpl.Manage(f, key, restore);
			}
			catch(Exception ex)
			{
				Trace.WriteLine(ex);
			}
			return false;
		}