public Workspace(UI.GenericDataTemplateSelector layoutItemTemplateSelector) { Instance = this; this.KeyManager = new KeyManager(); this.KeyManager.RegisterKey(new ASKeyContainer(new KeyContainer(Properties.Localization.KeySearch, new Key[] { Key.LeftCtrl, Key.F }, this.DisplaySearchPopup))); this.BreakpointManager = new BreakpointManager(); foreach (var it in App.GetPlugins <IHotKeyPlugin>()) { foreach (var kc in it.GetGlobalHotKeys()) { this.KeyManager.RegisterKey(kc); } } this.LayoutItemTemplateSelector = layoutItemTemplateSelector; this.AvailablePanels = new ObservableCollection <PanelBase>(); this.AvalonDockDocuments = new ObservableCollection <DocumentBase>(); this.AvalonDockPanels = new ObservableCollection <PanelBase>(); this.DebugContext = new DebuggerContext(); foreach (var t in Assembly.GetExecutingAssembly().DefinedTypes) { if (typeof(PanelBase).IsAssignableFrom(t)) { var instance = Activator.CreateInstance(t, true) as PanelBase; this.AvailablePanels.Add(instance); } } const double DEF_WIN_HEIGHT = 512; const double DEF_WIN_WIDTH = 1024; //Load values this._WindowHeight = ConfigHost.App.WindowHeight; this._WindowWidth = ConfigHost.App.WindowWidth; this._WindowLeft = ConfigHost.App.WindowLeft; this._WindowTop = ConfigHost.App.WindowTop; this._WindowCurrentState = ConfigHost.App.WindowCurrentState; if (this._WindowHeight < 0) { this._WindowHeight = DEF_WIN_HEIGHT; } if (this._WindowWidth < 0) { this._WindowWidth = DEF_WIN_WIDTH; } if (this._WindowLeft < 0) { this._WindowLeft = (SystemParameters.PrimaryScreenWidth - DEF_WIN_WIDTH) / 2; } if (this._WindowTop < 0) { this._WindowTop = (SystemParameters.PrimaryScreenHeight - DEF_WIN_HEIGHT) / 2; } }
public Workspace(string path) { this.PaneDataTemplateSelector = new UI.GenericDataTemplateSelector(Assembly.GetExecutingAssembly(), (s) => s.StartsWith("ArmA.Studio.UI.DataTemplates.")); this.WorkingDir = path; this._PanelsAvailable = new ObservableCollection <PanelBase>(FindAllAnchorablePanelsInAssembly()); this.PanelsDisplayed = new ObservableCollection <PanelBase>(); this._DebugContext = new DebuggerContext(); this._DocumentsDisplayed = new ObservableCollection <DocumentBase>(); this._DocumentsAvailable = new ObservableCollection <DocumentBase>(FindAllDocumentsInAssembly()); this.CmdDisplayPanel = new RelayCommand((p) => { if (p is PanelBase) { var pb = p as PanelBase; if (this.PanelsDisplayed.Contains(p)) { pb.CurrentVisibility = pb.CurrentVisibility == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; } else { this.PanelsDisplayed.Add(pb); } } }); this.CmdDisplayLicensesDialog = new RelayCommand((p) => { var dlg = new Dialogs.LicenseViewer(); var dlgResult = dlg.ShowDialog(); }); this.CmdDockingManagerInitialized = new RelayCommand((p) => this.DockingMangerInitialized(p as DockingManager)); this.CmdMainWindowClosing = new RelayCommand((p) => { SaveLayout(this.MWDockingManager, Path.Combine(App.ConfigPath, CONST_DOCKING_MANAGER_LAYOUT_NAME)); App.Current.Shutdown((int)App.ExitCodes.OK); }); this.CmdSwitchWorkspace = new RelayCommand((p) => { if (App.SwitchWorkspace()) { App.Shutdown(App.ExitCodes.Restart); } }); this.CmdShowProperties = new RelayCommand((p) => { var dlgDc = new Dialogs.PropertiesDialogDataContext(); var dlg = new Dialogs.PropertiesDialog(dlgDc); dlg.ShowDialog(); if (dlgDc.RestartRequired) { var msgResult = MessageBox.Show(Properties.Localization.ChangesRequireRestart_Body, Properties.Localization.ChangesRequireRestart_Title, MessageBoxButton.YesNo, MessageBoxImage.Information); if (msgResult == MessageBoxResult.Yes) { App.Shutdown(App.ExitCodes.Restart); } } }); this.CmdQuit = new RelayCommand((p) => { App.Shutdown(App.ExitCodes.OK); }); this.CmdSave = new RelayCommand((p) => { foreach (var doc in this.DocumentsDisplayed) { if (doc.IsSelected) { if (!doc.HasChanges) { break; } doc.SaveDocument(doc.FilePath); break; } } }); this.CmdSaveAll = new RelayCommand((p) => { foreach (var doc in this.DocumentsDisplayed) { if (doc.HasChanges) { doc.SaveDocument(doc.FilePath); } } this.SaveSolution(); }); this.CmdActiveContentChanged = new RelayCommand((p) => { var dm = p as DockingManager; this.CurrentDocument = dm.ActiveContent as DocumentBase; }); const double DEF_WIN_HEIGHT = 512; const double DEF_WIN_WIDTH = 1024; this._WindowHeight = DEF_WIN_HEIGHT; this._WindowWidth = DEF_WIN_WIDTH; this._WindowLeft = (SystemParameters.PrimaryScreenWidth - DEF_WIN_WIDTH) / 2; if (this._WindowLeft < 0) { this._WindowLeft = 0; } this._WindowTop = (SystemParameters.PrimaryScreenHeight - DEF_WIN_HEIGHT) / 2; if (this._WindowTop < 0) { this._WindowTop = 0; } this._WindowCurrentState = WindowState.Normal; }
private static bool Splash_Workspace(Action <bool> SetIndeterminate, Action <string> SetDisplayText, Action <double> SetProgress, out Workspace w) { w = null; SetIndeterminate(true); string workspace; string solutionPath = string.Empty; #region set/get workspace path SetDisplayText(Properties.Localization.Splash_SettingWorkspace); Logger.Info("Trying to receive workspace..."); workspace = string.IsNullOrWhiteSpace(ConfigHost.App.WorkspacePath) ? Dialogs.WorkspaceSelectorDialog.GetWorkspacePath(string.Empty) : ConfigHost.App.WorkspacePath; if (string.IsNullOrWhiteSpace(workspace)) { Logger.Info("No workspace set, exiting"); Application.Current.Dispatcher.Invoke(() => MessageBox.Show(Properties.Localization.WorkspaceSelectorDialog_NoWorkspaceSelected, Properties.Localization.Whoops, MessageBoxButton.OK, MessageBoxImage.Error)); return(true); } else { Logger.Info($"Selected workspace: {workspace}"); ConfigHost.App.WorkspacePath = workspace; } if (!Directory.Exists(workspace)) { Logger.Info($"Creating Directory for workspace ..."); Directory.CreateDirectory(workspace); } #endregion var dataTemplateSelector = new UI.GenericDataTemplateSelector(); w = new Workspace(dataTemplateSelector); dataTemplateSelector.AddAllDataTemplatesInAssembly(Assembly.GetExecutingAssembly(), (s) => s.StartsWith("ArmA.Studio.UI.DataTemplates.")); foreach (var dt in App.GetPlugins <IDocumentProviderPlugin>().SelectMany((p) => p.DocumentDataTemplates)) { dataTemplateSelector.AddDataTemplate(dt); } foreach (var p in App.GetPlugins <IPaneProviderPlugin>()) { foreach (var dt in p.PaneDataTemplates) { dataTemplateSelector.AddDataTemplate(dt); } foreach (var paneType in p.PaneDataContextTypes) { var pane = Activator.CreateInstance(paneType) as Data.UI.PanelBase; w.AvailablePanels.Add(pane); } } w.PathUri = new Uri(workspace, UriKind.Absolute); #region Prepare Solution Logger.Info("Searching solution file in workspace"); SetDisplayText(Properties.Localization.Splash_SearchingSolutionFile); foreach (var file in Directory.EnumerateFiles(workspace, string.Concat('*', App.CONST_SOLUTIONEXTENSION))) { solutionPath = file; break; } SetDisplayText(Properties.Localization.Splash_PreparingSolution); try { if (string.IsNullOrWhiteSpace(solutionPath)) { solutionPath = Path.Combine(workspace, string.Concat("solution", App.CONST_SOLUTIONEXTENSION)); Logger.Info($"No solution file found, creating new at '{solutionPath}'"); w.Solution = new Data.Solution(); w.Solution.FileUri = new Uri(solutionPath, UriKind.Absolute); using (var stream = File.Open(solutionPath, FileMode.Create)) { Data.Solution.Serialize(w.Solution, stream); } } else { Logger.Info($"Solution file found: {solutionPath}"); using (var stream = File.OpenRead(solutionPath)) { w.Solution = Data.Solution.Deserialize(stream, new Uri(solutionPath, UriKind.Absolute)); } } } catch (UnauthorizedAccessException ex) { ConfigHost.App.WorkspacePath = string.Empty; Logger.Error(ex, "Exception while trying to get Solution"); App.ShowOperationFailedMessageBox(ex); App.Shutdown(App.ExitCodes.NoWorkspaceSelected); return(true); } catch (Exception ex) { Logger.Error(ex, "Exception while trying to get Solution"); App.ShowOperationFailedMessageBox(ex); App.Shutdown(App.ExitCodes.ConfigError); return(true); } SetDisplayText(Properties.Localization.Splash_LoadingBreakpointInformations); { //Load Breakpoints var filePath = Path.ChangeExtension(solutionPath, App.CONST_BREAKPOINTINFOEXTENSION); if (File.Exists(filePath)) { try { using (var stream = File.OpenRead(filePath)) { w.BreakpointManager.LoadBreakpoints(stream); } } catch (Exception ex) { App.ShowOperationFailedMessageBox(ex); } } else { using (var stream = File.Open(filePath, FileMode.Create)) { w.BreakpointManager.SaveBreakpoints(stream); } } } { //Load Watch Variables var filePath = Path.ChangeExtension(solutionPath, App.CONST_WATCHEXTENSION); if (File.Exists(filePath)) { try { using (var stream = File.OpenRead(filePath)) { var vvp = w.AvailablePanels.First((it) => it is DataContext.VariablesViewPane) as DataContext.VariablesViewPane; vvp.LoadVariables(stream); } } catch (Exception ex) { App.ShowOperationFailedMessageBox(ex, Properties.Localization.VariablesView_FailedToLoadExistingWatchEntries); } } else { using (var stream = File.Open(filePath, FileMode.Create)) { var vvp = w.AvailablePanels.First((it) => it is DataContext.VariablesViewPane) as DataContext.VariablesViewPane; vvp.SaveVariables(stream); } } } #endregion SetIndeterminate(false); return(false); }