public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } // If we were provided an INiTextLines, perform its initialization // now. We clear the field to force correct initialization. if (_textLines != null) { var textLines = _textLines; _textLines = null; return(SetBuffer(textLines)); } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } ErrorUtil.ThrowOnFailure(Frame.SetIcon(Resources.Folders)); ErrorUtil.ThrowOnFailure(Frame.SetCaption(Labels.ProjectExplorer)); _control = new ProjectExplorerControl { Site = new SiteProxy(this), Dock = DockStyle.Fill }; Controls.Add(_control); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } Env = (INiEnv)GetService(typeof(INiEnv)); RegisterProjectFactory(new ProjectFactory()); Env.MainWindow.Caption = Labels.PackageDescription; Env.MainWindow.Icon = Resources.MainIcon; BuildCommandMapper(); ErrorUtil.ThrowOnFailure( ((INiProjectExplorer)GetService(typeof(INiProjectExplorer))).Show() ); RegisterHelp(); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } var commandManager = (INiCommandManager)GetService(typeof(INiCommandManager)); var menuManager = (NiMenuManager)GetService(typeof(INiMenuManager)); INiCommandBar toolbar; ErrorUtil.ThrowOnFailure(commandManager.FindCommandBar(_id, out toolbar)); if (toolbar != null) { _control = menuManager.CreateHost((NiCommandBar)toolbar); var toolStrip = (ToolStrip)_control.Control; toolStrip.GripStyle = ToolStripGripStyle.Hidden; Controls.Add(toolStrip); } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } ErrorUtil.ThrowOnFailure(Frame.SetCaption(Labels.Notifications)); _control = new NotificationsControl { Site = new SiteProxy(this), Dock = DockStyle.Fill }; Controls.Add(_control); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult RestartApplication() { try { var hr = Quit(); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } var args = Environment.GetCommandLineArgs(); Process.Start(new ProcessStartInfo { WorkingDirectory = _initialWorkingDirectory, UseShellExecute = false, FileName = args[0], Arguments = String.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(Escaping.ShellArgument)) }); Environment.Exit(0); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult CloseAllDocuments(NiSaveAllMode mode) { try { var hr = SaveAllDocuments(mode, true); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } foreach (var windowFrame in ((INiShell)GetService(typeof(INiShell))).GetDocumentWindows()) { // We specifically request the frame not to save, because // the SaveAllDocuments should already have taken care of this // and we may have dirty windows because the user said the // documents shouldn't be saved. ErrorUtil.ThrowOnFailure(windowFrame.Close(NiFrameCloseMode.NoSave)); } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult CreateEditor(string document, out string editorCaption, out INiWindowPane editor) { editor = null; editorCaption = null; try { INiTextLines textLines = null; // If we were opened from a real document or hier, set a text buffer. // NiOpenDocumentManager will initialize this. if (document != null) { var registry = (INiLocalRegistry)GetService(typeof(INiLocalRegistry)); object instance; var hr = registry.CreateInstance(new Guid(NiConstants.TextLines), this, out instance); if (ErrorUtil.Failure(hr)) { return(hr); } textLines = (INiTextLines)instance; Guid languageServiceId; hr = ((INiLanguageServiceRegistry)GetService(typeof(INiLanguageServiceRegistry))).FindForFileName( document, out languageServiceId ); if (ErrorUtil.Failure(hr)) { return(hr); } hr = textLines.SetLanguageServiceID(languageServiceId); if (ErrorUtil.Failure(hr)) { return(hr); } } editor = new TextEditorWindow(textLines); editor.SetSite(this); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult OpenStandardEditor(Guid?editorGuid, string document, INiHierarchy hier, IServiceProvider serviceProvider, out INiWindowFrame windowFrame) { windowFrame = null; try { if (document == null) { throw new ArgumentNullException("document"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } INiEditorFactory editorFactory; Guid resolvedEditorGuid; var hr = ((NiEnv)GetService(typeof(INiEnv))).GetStandardEditorFactory(null, document, out editorFactory, out resolvedEditorGuid); if (ErrorUtil.Failure(hr)) { return(hr); } if (editorFactory == null) { return(HResult.False); } return(OpenSpecificEditor( document, resolvedEditorGuid, editorFactory, hier, serviceProvider, out windowFrame )); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult OpenSpecificEditor(string document, Guid editorType, INiHierarchy hier, IServiceProvider serviceProvider, out INiWindowFrame windowFrame) { windowFrame = null; try { INiEditorFactory editorFactory; var hr = ((INiEnv)GetService(typeof(INiEnv))).GetStandardEditorFactory(editorType, null, out editorFactory); if (ErrorUtil.Failure(hr)) { return(hr); } return(OpenSpecificEditor(document, editorType, editorFactory, hier, serviceProvider, out windowFrame)); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } var control = CreateClient(); control.Dock = DockStyle.Fill; Controls.Add(control); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult CloseProject() { try { if (ActiveProject == null) { return(HResult.OK); } var hr = ((INiEnv)GetService(typeof(INiEnv))).CloseAllDocuments(NiSaveAllMode.All); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } if (((NiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).HaveOpenDocuments) { throw new InvalidOperationException(Labels.OpenDocumentsPresent); } var activeProject = ActiveProject; ActiveProject = null; ErrorUtil.ThrowOnFailure(activeProject.Close()); if (((NiRunningDocumentTable)GetService(typeof(INiRunningDocumentTable))).HaveOpenDocuments) { Log.Warn("There are still documents in the running document table after closing the project"); } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult CreateProjectViaDialog(string startDirectory) { try { using (var dialog = new SaveFileDialog()) { dialog.Title = Labels.CreateProject; string fileName = CreateOpenProjectViaDialog(dialog, startDirectory); if (fileName != null) { var hr = ((INiProjectManager)GetService(typeof(INiProjectManager))).CloseProject(); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } hr = CreateProject(dialog.FileName); if (ErrorUtil.Success(hr)) { return(HResult.OK); } this.CreateTaskDialog() .MainInstruction(Labels.CannotCreateProject) .Alert(); } return(HResult.False); } } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } Env = (INiEnv)GetService(typeof(INiEnv)); Env.MainWindow.Caption = Labels.PackageDescription; Env.MainWindow.Icon = Resources.MainIcon; return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult Quit() { try { bool canClose = ((NiPackageManager)GetService(typeof(INiPackageManager))).QueryClose(); if (!canClose) { return(HResult.False); } var hr = CloseAllDocuments(NiSaveAllMode.All); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } hr = ((INiProjectManager)GetService(typeof(INiProjectManager))).CloseProject(); if (ErrorUtil.Failure(hr) || hr == HResult.False) { return(hr); } _connectionPoint.ForAll(p => p.OnBeginShutdown()); MainForm.AllowQuit = true; ErrorUtil.ThrowOnFailure(MainWindow.Close()); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public override HResult Initialize() { try { var hr = base.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } ErrorUtil.ThrowOnFailure(Frame.SetCaption(Labels.FindResults)); _editor = new NiEditor { Site = new SiteProxy(this), Dock = DockStyle.Fill }; ErrorUtil.ThrowOnFailure(_editor.TextBuffer.SetStateFlags( NiTextBufferState.ReadOnly )); ErrorUtil.ThrowOnFailure(_editor.TextBuffer.SetLanguageServiceID( new Guid(NiConstants.LanguageServiceDefault) )); _listener = new Listener(this); Controls.Add(_editor); return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
private HResult OpenProject(string fileName, NiProjectCreateMode mode) { try { if (fileName == null) { throw new ArgumentNullException("fileName"); } // Find the associated factory. INiProjectFactory factory = null; string extension = Path.GetExtension(fileName); if (extension != null) { Debug.Assert(extension[0] == '.' && extension.Length > 1); factory = FindProjectFactory(extension.Substring(1)); } if (factory == null) { throw new ArgumentException(NeutralResources.CannotFindProjectFactory, "fileName"); } // Close the existing project. if (ActiveProject != null) { var activeProject = ActiveProject; ActiveProject = null; activeProject.Close(); } // Create and load the new project. INiProject project; var result = factory.CreateProject( fileName, mode, out project ); if (ErrorUtil.Failure(result)) { return(result); } project.SetPropertyEx(NiHierarchyProperty.OwnerType, factory.GetType().GUID); ActiveProject = project; return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
private HResult OpenSpecificEditor(string document, Guid editorType, INiEditorFactory editorFactory, INiHierarchy hier, IServiceProvider serviceProvider, out INiWindowFrame windowFrame) { windowFrame = null; try { if (document == null) { throw new ArgumentNullException("document"); } if (editorFactory == null) { throw new ArgumentNullException("editorFactory"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } OpenDocument openDocument; if (_openDocuments.TryGetValue(document, out openDocument)) { ErrorUtil.ThrowOnFailure(openDocument.WindowFrame.Show()); return(HResult.OK); } string editorCaption; INiWindowPane windowPane; var hr = editorFactory.CreateEditor(document, out editorCaption, out windowPane); if (ErrorUtil.Failure(hr)) { return(hr); } if (windowPane == null) { return(HResult.False); } hr = windowPane.SetSite(serviceProvider); if (ErrorUtil.Failure(hr)) { return(hr); } hr = ((INiShell)GetService(typeof(INiShell))).CreateToolWindow( windowPane, NiDockStyle.Document, NiToolWindowOrientation.Top, out windowFrame ); if (ErrorUtil.Failure(hr)) { return(hr); } ErrorUtil.ThrowOnFailure(windowFrame.SetCaption( editorCaption ?? Path.GetFileName(document) )); hr = windowPane.Initialize(); if (ErrorUtil.Failure(hr)) { return(hr); } var docData = windowPane as INiPersistDocData; if (docData == null) { var textBufferProvider = windowPane as INiTextBufferProvider; if (textBufferProvider != null) { INiTextBuffer textBuffer; hr = textBufferProvider.GetTextBuffer(out textBuffer); if (ErrorUtil.Failure(hr)) { return(hr); } docData = textBuffer; } } int rdtCooke = -1; if (docData != null) { hr = docData.LoadDocData(document); if (ErrorUtil.Failure(hr)) { return(hr); } hr = ((INiRunningDocumentTable)GetService(typeof(INiRunningDocumentTable))).Register( document, hier, docData, out rdtCooke ); if (ErrorUtil.Failure(hr)) { return(hr); } } windowFrame.SetPropertyEx(NiFrameProperty.DocCookie, rdtCooke); windowFrame.SetPropertyEx(NiFrameProperty.DocView, windowPane); windowFrame.SetPropertyEx(NiFrameProperty.DocData, docData); windowFrame.SetPropertyEx(NiFrameProperty.Document, document); windowFrame.SetPropertyEx(NiFrameProperty.EditorType, editorType); windowFrame.SetPropertyEx(NiFrameProperty.Hierarchy, hier); windowFrame.SetPropertyEx(NiFrameProperty.Type, NiFrameType.Document); _openDocuments.Add(document, new OpenDocument( this, document, hier, windowFrame, rdtCooke, docData )); return(windowFrame.Show()); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }