using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Core.Common.Base.Data;
using Core.Common.Base.Plugin;
using Core.Common.Controls.Swf.TreeViewControls;
using Core.Common.Controls.Views;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Forms.MainWindow;
using Core.Common.Gui.Forms.MessageWindow;
using Core.Common.Gui.Forms.PropertyGridView;
using Core.Common.Gui.Forms.SplashScreen;
using Core.Common.Gui.Forms.ViewManager;
using Core.Common.Gui.Properties;
using Core.Common.Utils;
using Core.Common.Utils.Events;
using Core.Common.Utils.Extensions;
using Core.Common.Utils.Reflection;
using Core.GIS.SharpMap.UI.Helpers;
using log4net;
using log4net.Appender;
using log4net.Repository.Hierarchy;
namespace Core.Common.Gui
{
///
/// Gui class provides graphical user functionality for a given IApplication.
///
public class RingtoetsGui : IGui, IContextMenuBuilderProvider
{
public event EventHandler SelectionChanged; // TODO: make it weak
public event Action ProjectOpened;
public event Action ProjectClosing;
private static readonly ILog log = LogManager.GetLogger(typeof(RingtoetsGui));
private static RingtoetsGui instance;
private static string instanceCreationStackTrace;
private readonly IList commands = new List();
private readonly ApplicationCore applicationCore;
private MainWindow mainWindow;
private object selection;
private ViewList documentViews;
private ViewList toolWindowViews;
private AvalonDockDockingManager toolWindowViewsDockingManager;
private SplashScreen splashScreen;
private bool settingSelection;
private bool runFinished;
private bool isExiting;
private Project project;
private bool userSettingsDirty;
private ApplicationSettingsBase userSettings;
public RingtoetsGui(ApplicationCore applicationCore = null, GuiCoreSettings fixedSettings = null)
{
// error detection code, make sure we use only a single instance of RingtoetsGui at a time
if (instance != null)
{
instance = null; // reset to that the consequent creations won't fail.
throw new InvalidOperationException(Resources.RingtoetsGui_Only_a_single_instance_of_Ringtoets_is_allowed_at_the_same_time_per_process_Make_sure_that_the_previous_instance_was_disposed_correctly_stack_trace + instanceCreationStackTrace);
}
ApplicationCore = applicationCore ?? new ApplicationCore();
FixedSettings = fixedSettings ?? new GuiCoreSettings();
instance = this;
instanceCreationStackTrace = new StackTrace().ToString();
ViewPropertyEditor.Gui = this;
Plugins = new List();
UserSettings = Settings.Default;
CommandHandler = new GuiCommandHandler(this);
Application.EnableVisualStyles();
ProjectOpened += ApplicationProjectOpened;
}
public bool SkipDialogsOnExit { get; set; }
public Action OnMainWindowLoaded { get; set; }
public string ProjectFilePath { get; set; }
public ApplicationCore ApplicationCore { get; private set; }
public Project Project
{
get
{
return project;
}
set
{
if (project != null)
{
if (ProjectClosing != null)
{
ProjectClosing(project);
}
}
project = value;
if (project != null)
{
if (ProjectOpened != null)
{
ProjectOpened(project);
}
}
}
}
public object Selection
{
get
{
return selection;
}
set
{
if (selection == value || settingSelection)
{
return;
}
if (null != DocumentViews)
{
DocumentViews.IgnoreActivation = true;
}
selection = value;
settingSelection = true;
try
{
if (SelectionChanged != null)
{
SelectionChanged(selection, new SelectedItemChangedEventArgs(value));
}
}
finally
{
settingSelection = false;
}
if (!isExiting && mainWindow != null && !mainWindow.IsWindowDisposed)
{
mainWindow.ValidateItems();
}
if (null != DocumentViews)
{
DocumentViews.IgnoreActivation = false;
}
}
}
public IList Commands
{
get
{
return commands;
}
}
public IGuiCommandHandler CommandHandler { get; set; }
public IViewList DocumentViews
{
get
{
return documentViews;
}
}
public IViewResolver DocumentViewsResolver { get; private set; }
public IPropertyResolver PropertyResolver { get; private set; }
public IViewList ToolWindowViews
{
get
{
return toolWindowViews;
}
}
public IMainWindow MainWindow
{
get
{
return mainWindow;
}
set
{
mainWindow = (MainWindow)value;
mainWindow.Gui = this;
}
}
public IList Plugins { get; private set; }
public GuiCoreSettings FixedSettings { get; private set; }
public ApplicationSettingsBase UserSettings
{
get
{
return userSettings;
}
private set
{
if (userSettings != null)
{
userSettings.PropertyChanged -= UserSettingsPropertyChanged;
}
userSettings = value;
if (userSettings != null)
{
userSettings.PropertyChanged += UserSettingsPropertyChanged;
}
userSettingsDirty = false;
}
}
public bool IsViewRemoveOnItemDeleteSuspended { get; set; }
public IContextMenuBuilderProvider ContextMenuProvider
{
get
{
return this;
}
}
public IContextMenuBuilder Get(ITreeNode treeNode)
{
return new ContextMenuBuilder(CommandHandler, treeNode);
}
public IEnumerable GetAllDataWithViewDefinitionsRecursively(object rootDataObject)
{
var resultSet = new HashSet