///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.Omea.SamplePlugins.Siam
{
public class SyncAction : IAction
{
///
/// Creates an either Sync action.
///
/// Plugin.
/// Type of the synchronization to be invoked by this action.
/// True if the action should start Sync, False if should abort Sync.
internal SyncAction(Plugin pluginSiam, Plugin.SyncType synctype, bool bStart)
{
_pluginSiam = pluginSiam;
_synctype = synctype;
_bStart = bStart;
}
///
/// Plugin.
///
protected Plugin _pluginSiam;
///
/// Synchronization type to be initiated by this action.
///
protected Plugin.SyncType _synctype;
///
/// True if the action should start Sync, False if should abort Sync.
///
protected bool _bStart;
#region IAction Members
public void Execute( IActionContext context )
{
if(_bStart)
{
if(_pluginSiam.Running)
_pluginSiam.AbortSync();
_pluginSiam.StartSync( _synctype, true );
}
else
_pluginSiam.AbortSync();
}
public void Update( IActionContext context, ref ActionPresentation presentation )
{
if(_pluginSiam.Running) // Some sync is running
{
if(!_bStart) // Stop action?
presentation.Enabled = !_pluginSiam.MustStop;
else if((_pluginSiam.RunningSyncType == Plugin.SyncType.DeferredSyncIn) && (_synctype != Plugin.SyncType.SyncIn)) // Start action, and a deferred sync is currently running — allow to start sync-out or restart the deferred sync
presentation.Enabled = true;
else
presentation.Enabled = false;
}
else // No sync is running
presentation.Enabled = _bStart; // Enable all the start actions
}
#endregion
}
}