コード例 #1
0
 private void _packageList_RestartClick(object sender, EventArgs e)
 {
     if (Site.CreateTaskDialog().Confirm(this))
     {
         ErrorUtil.ThrowOnFailure(_env.RestartApplication());
     }
 }
コード例 #2
0
                protected INiHierarchy GetCurrentHierarchy(IServiceProvider serviceProvider)
                {
                    INiHierarchy hier;
                    var          currentFrame = GetCurrentWindowFrame(serviceProvider);

                    if (currentFrame != null)
                    {
                        hier = (INiHierarchy)currentFrame.GetPropertyEx(NiFrameProperty.Hierarchy);

                        if (hier != null)
                        {
                            return(hier);
                        }
                    }

                    ErrorUtil.ThrowOnFailure(((INiProjectExplorer)serviceProvider.GetService(typeof(INiProjectExplorer))).GetSelectedHierarchy(
                                                 out hier
                                                 ));

                    if (hier != null)
                    {
                        return(hier);
                    }

                    return(((INiProjectManager)serviceProvider.GetService(typeof(INiProjectManager))).ActiveProject);
                }
コード例 #3
0
ファイル: CorePackage.cs プロジェクト: vector-man/netide
        private void RegisterHelp()
        {
            var help = (INiHelp)GetService(typeof(INiHelp));

#if DEBUG
            string path = ((INiEnv)GetService(typeof(INiEnv))).FileSystemRoot;

            while (path != null)
            {
                string source = Path.Combine(path, "NetIde.TestPackage.Help");
                if (Directory.Exists(source))
                {
                    ErrorUtil.ThrowOnFailure(help.Register("test", source));
                    break;
                }

                path = Path.GetDirectoryName(path);
            }
#else
            var packageManager = ((INiPackageManager)GetService(typeof(INiPackageManager)));

            string installationPath;
            ErrorUtil.ThrowOnFailure(packageManager.GetInstallationPath(this, out installationPath));

            string helpFileName = Path.Combine(installationPath, "Help.zip");

            ErrorUtil.ThrowOnFailure(help.Register("test", helpFileName));
#endif
        }
コード例 #4
0
            public bool ProcessMessage(ref Message m)
            {
                var key = (Keys)(int)m.WParam | Control.ModifierKeys;

                Guid[] buttons;
                if (!_keyMap.TryGetValue(key, out buttons))
                {
                    return(false);
                }

                foreach (var id in buttons)
                {
                    NiCommandStatus status;
                    ErrorUtil.ThrowOnFailure(_commandManager.QueryStatus(id, out status));

                    bool enabled = (status & NiCommandStatus.Enabled) != 0;
                    bool visible = (status & NiCommandStatus.Invisible) == 0;

                    if (enabled && visible)
                    {
                        object result;
                        if (ErrorUtil.ThrowOnFailure(_commandManager.Exec(id, null, out result)))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
コード例 #5
0
ファイル: NiEnv.cs プロジェクト: vector-man/netide
        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));
            }
        }
コード例 #6
0
ファイル: CorePackage.cs プロジェクト: vector-man/netide
        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));
            }
        }
コード例 #7
0
ファイル: NiCommandManager.cs プロジェクト: vector-man/netide
        public HResult RegisterPriorityCommandTarget(INiCommandTarget commandTarget, out int cookie)
        {
            cookie = 0;

            try
            {
                if (commandTarget == null)
                {
                    throw new ArgumentNullException("commandTarget");
                }

                cookie = _nextPriorityCommandTargetCookie++;
                _priorityCommandTargets.Add(cookie, commandTarget);
                _priorityCommandTargetsOrdered.Add(commandTarget);

                // The available command targets have changed; force a requery.

                ErrorUtil.ThrowOnFailure(((INiShell)GetService(typeof(INiShell))).InvalidateRequerySuggested());

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
コード例 #8
0
        public HResult Navigate(string root, string path)
        {
            try
            {
                if (root == null)
                {
                    throw new ArgumentNullException("root");
                }
                if (path == null)
                {
                    throw new ArgumentNullException("path");
                }

                path = path.TrimStart('/');
                if (path.Length == 0)
                {
                    path = "/";
                }

                ErrorUtil.ThrowOnFailure(Show());

                _form.NavigateTo(String.Format(
                                     "http://localhost:{0}/{1}/{2}",
                                     GetServer().EndPoint.Port,
                                     root,
                                     path
                                     ));

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
コード例 #9
0
        public void SelectDetails(IStream stream, FileType fileType)
        {
            LastWriteTime = stream == null ? null : stream.LastWriteTime;

            if (stream == null)
            {
                FileSize = null;
            }
            else
            {
                long length;
                ErrorUtil.ThrowOnFailure(stream.GetLength(out length));

                FileSize = length;
            }

            var textFileType = fileType as TextFileType;

            HaveBom         = textFileType != null && textFileType.Encoding.GetPreamble().Length > 0;
            LineTermination = textFileType == null ? (LineTermination?)null : textFileType.LineTermination;
            Encoding        = textFileType == null ? null : textFileType.Encoding;

            if (textFileType == null)
            {
                ContentType = null;
            }
            else
            {
                var highlighter = HighlightingManager.Manager.FindHighlighterForFile(stream.Name);

                ContentType = highlighter == null ? null : highlighter.Name;
            }
        }
コード例 #10
0
        public static INiHierarchy FindByDocument(this INiHierarchy self, string document)
        {
            var projectItem = self as INiProjectItem;

            if (projectItem != null)
            {
                string fileName;
                ErrorUtil.ThrowOnFailure(projectItem.GetFileName(out fileName));

                if (fileName != null && String.Equals(document, fileName, StringComparison.OrdinalIgnoreCase))
                {
                    return(self);
                }
            }

            foreach (var child in self.GetChildren())
            {
                var result = FindByDocument(child, document);

                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
コード例 #11
0
                public void OnClose(NiFrameCloseMode closeMode, ref bool cancel)
                {
                    try
                    {
                        if (_owner._docData == null)
                        {
                            return;
                        }

                        NiSaveMode saveMode;

                        switch (closeMode)
                        {
                        case NiFrameCloseMode.PromptSave: saveMode = NiSaveMode.Save; break;

                        case NiFrameCloseMode.SaveIfDirty: saveMode = NiSaveMode.SilentSave; break;

                        default: return;
                        }

                        string document;
                        bool   saved;
                        ErrorUtil.ThrowOnFailure(_owner._docData.SaveDocData(saveMode, out document, out saved));

                        cancel = !saved;
                    }
                    catch (Exception ex)
                    {
                        Log.Warn("Failed to save document", ex);
                    }
                }
コード例 #12
0
        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));
            }
        }
コード例 #13
0
        public void RaisePerform()
        {
            Running = true;

            try
            {
                ErrorUtil.ThrowOnFailure(Handler.Perform(this));

                Success = true;
            }
            catch (Exception ex)
            {
                _syncContext.Send(
                    p => _jobManager.CreateTaskDialog()
                    .FromException(ex)
                    .Show(),
                    null
                    );

                Exception = ex;
            }
            finally
            {
                Running   = false;
                Completed = true;
            }
        }
コード例 #14
0
ファイル: NotificationItem.cs プロジェクト: vector-man/netide
        public void Update(INiNotificationItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string subject;

            ErrorUtil.ThrowOnFailure(item.GetSubject(out subject));
            Subject = subject;

            string message;

            ErrorUtil.ThrowOnFailure(item.GetMessage(out message));
            Message = message;

            NiNotificationItemPriority priority;

            ErrorUtil.ThrowOnFailure(item.GetPriority(out priority));
            Priority = priority;

            DateTime?created;

            ErrorUtil.ThrowOnFailure(item.GetCreated(out created));
            Created = created;
        }
コード例 #15
0
                protected string GetAllTextFromWindowFrame(INiWindowFrame windowFrame)
                {
                    var textLines = windowFrame.GetPropertyEx(NiFrameProperty.DocData) as INiTextLines;

                    if (textLines == null)
                    {
                        var docView = windowFrame.GetPropertyEx(NiFrameProperty.DocView) as INiWindowPane;
                        if (docView != null)
                        {
                            var textBufferProvider = docView as INiTextBufferProvider;
                            if (textBufferProvider != null)
                            {
                                INiTextBuffer textBuffer;
                                ErrorUtil.ThrowOnFailure(textBufferProvider.GetTextBuffer(out textBuffer));

                                textLines = textBuffer as INiTextLines;
                            }
                        }
                    }

                    if (textLines != null)
                    {
                        int line;
                        int index;
                        ErrorUtil.ThrowOnFailure(textLines.GetLastLineIndex(out line, out index));

                        string result;
                        ErrorUtil.ThrowOnFailure(textLines.GetLineText(0, 0, line, index, out result));

                        return(result);
                    }

                    return(null);
                }
コード例 #16
0
        protected BarControl(IServiceProvider serviceProvider, NiCommandBar bar, IBarControl control)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (bar == null)
            {
                throw new ArgumentNullException("bar");
            }

            _menuManager = (NiMenuManager)serviceProvider.GetService(typeof(INiMenuManager));
            _env         = (NiEnv)serviceProvider.GetService(typeof(INiEnv));

            Bar = bar;
            Bar.AppearanceChanged += Bar_AppearanceChanged;

            var objectWithSite = control as INiObjectWithSite;

            if (objectWithSite != null)
            {
                ErrorUtil.ThrowOnFailure(objectWithSite.SetSite(serviceProvider));
            }

            Control              = control;
            Control.Tag          = this;
            Control.QueryStatus += (s, e) => _menuManager.QueryStatus(Bar);

            UpdateItem();

            _groupManager = new GroupManager(Bar, serviceProvider, Control);
        }
コード例 #17
0
        private void Publish()
        {
            if (_suppressPublish)
            {
                return;
            }

            _suppressPublish = true;

            try
            {
                NiCommand.Value = Item.Text;

                if (NiCommand.Value != _lastPublished)
                {
                    _lastPublished = NiCommand.Value;

                    var commandManager = (INiCommandManager)_serviceProvider.GetService(typeof(INiCommandManager));

                    object unused;
                    ErrorUtil.ThrowOnFailure(commandManager.Exec(NiCommand.Id, Item.Text, out unused));
                }
            }
            finally
            {
                _suppressPublish = false;
            }
        }
コード例 #18
0
        private NiCommandStatus CanSaveFile()
        {
            if (_windowPaneSelection.ActiveDocument != null)
            {
                INiWindowFrame windowFrame;
                ErrorUtil.ThrowOnFailure(((INiShell)GetService(typeof(INiShell))).GetWindowFrameForWindowPane(
                                             _windowPaneSelection.ActiveDocument,
                                             out windowFrame
                                             ));

                Debug.Assert(windowFrame != null);

                if (windowFrame != null)
                {
                    var docData = (INiPersistDocData)windowFrame.GetPropertyEx(NiFrameProperty.DocData);

                    if (docData != null)
                    {
                        bool isDirty;
                        ErrorUtil.ThrowOnFailure(docData.IsDocDataDirty(out isDirty));

                        if (isDirty)
                        {
                            return(NiCommandStatus.Enabled);
                        }
                    }
                }
            }

            return(NiCommandStatus.Supported);
        }
コード例 #19
0
        private void QueryCommandStatus(INiCommandBarControl command)
        {
            NiCommandStatus status;

            ErrorUtil.ThrowOnFailure(_commandManager.QueryStatus(command.Id, out status));

            if ((status & NiCommandStatus.Supported) != 0)
            {
                command.IsEnabled = (status & NiCommandStatus.Enabled) != 0;
                command.IsVisible = (status & NiCommandStatus.Invisible) == 0;

                var button = command as INiCommandBarButton;

                if (button != null)
                {
                    button.IsLatched = (status & NiCommandStatus.Latched) != 0;
                }
            }

            var comboBox = command as NiCommandBarComboBox;

            if (comboBox != null && comboBox.IsVisible)
            {
                object result;
                if (ErrorUtil.ThrowOnFailure(_commandManager.Exec(command.Id, null, out result)))
                {
                    comboBox.SelectedValue = (string)result;
                }
                else
                {
                    comboBox.SelectedValue = null;
                }
            }
        }
コード例 #20
0
ファイル: MenuBuilder.cs プロジェクト: vector-man/netide
        private object OnButton(Button button)
        {
            var keys = ShortcutKeysUtil.Parse(button.Key);

            if (keys.Length > 0 && !ShortcutKeysUtil.IsValid(keys[0]))
            {
                throw new NetIdeException(String.Format(Labels.IllegalButtonShortcutKeys, button.Id, keys));
            }

            INiCommandBarButton command;

            ErrorUtil.ThrowOnFailure(_commandManager.CreateCommandBarButton(
                                         button.Guid != Guid.Empty ? button.Guid : Guid.NewGuid(),
                                         button.Priority,
                                         button.Id,
                                         out command
                                         ));

            command.Text         = _package.ResolveStringResource(button.Text);
            command.ToolTip      = _package.ResolveStringResource(button.ToolTip);
            command.DisplayStyle = Enum <NiCommandDisplayStyle> .Parse(button.Style.ToString());

            command.ShortcutKeys = keys.Length > 0 ? keys[0] : 0;
            ((NiCommandBarButton)command).Bitmap = ResolveBitmapResource(button.Image);

            return(command);
        }
コード例 #21
0
            private void OnActiveDocumentChanged()
            {
                var currentPane = _mainForm._windowPaneSelection.ActiveDocument;

                _currentUser = currentPane as INiStatusBarUser;

                Status status;

                if (_currentUser == null)
                {
                    status = _defaultStatus;
                }
                else
                {
                    if (!_statuses.TryGetValue(_currentUser, out status))
                    {
                        status = new Status();
                        _statuses.Add(_currentUser, status);

                        INiWindowFrame windowFrame;
                        ErrorUtil.ThrowOnFailure(((INiShell)GetService(typeof(INiShell))).GetWindowFrameForWindowPane(
                                                     currentPane,
                                                     out windowFrame
                                                     ));

                        Debug.Assert(windowFrame != null);

                        new WindowPaneListener(this, _currentUser, windowFrame);
                    }

                    ErrorUtil.ThrowOnFailure(_currentUser.SetInfo());
                }

                ApplyStatus(status);
            }
コード例 #22
0
 private void BuildCommandMapper()
 {
     _commandMapper.Add(
         TpResources.Help_Topic1,
         p => ErrorUtil.ThrowOnFailure(((INiHelp)GetService(typeof(INiHelp))).Navigate("test", "Topic1.html"))
         );
 }
コード例 #23
0
        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));
            }
        }
コード例 #24
0
        private void _shortcut_KeysChanged(object sender, EventArgs e)
        {
            INiCommandBarButton[] buttons;
            ErrorUtil.ThrowOnFailure(_mappings.GetButtons(_shortcut.Keys, out buttons));

            _shortcutsConflicts.BeginUpdate();
            _shortcutsConflicts.Items.Clear();

            foreach (var button in buttons)
            {
                _shortcutsConflicts.Items.Add(String.Format(
                                                  "{0} ({1})",
                                                  GetButtonCode(button),
                                                  ShortcutKeysUtil.ToDisplayString(_shortcut.Keys)
                                                  ));
            }

            if (_shortcutsConflicts.Items.Count > 0)
            {
                _shortcutsConflicts.SelectedIndex = 0;
            }

            _shortcutsConflicts.EndUpdate();

            UpdateEnabled();
        }
コード例 #25
0
        private void _commands_SelectedIndexChanged(object sender, EventArgs e)
        {
            var button = (Registration)_commands.SelectedItem;

            Debug.Assert(button != null);

            Keys[] keys;
            ErrorUtil.ThrowOnFailure(_mappings.GetKeys(button.Button, out keys));

            _assignedShortcuts.BeginUpdate();
            _assignedShortcuts.Items.Clear();

            foreach (var key in keys)
            {
                _assignedShortcuts.Items.Add(new Shortcut(key));
            }

            if (_assignedShortcuts.Items.Count > 0)
            {
                _assignedShortcuts.SelectedIndex = 0;
            }

            _assignedShortcuts.EndUpdate();

            UpdateEnabled();
        }
コード例 #26
0
        private void FlushAssignedShortcuts()
        {
            var button = (Registration)_commands.SelectedItem;
            var keys   = _assignedShortcuts.Items.Cast <Shortcut>().Select(p => p.Keys).ToArray();

            ErrorUtil.ThrowOnFailure(_mappings.SetKeys(button.Button, keys));
        }
コード例 #27
0
        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));
            }
        }
コード例 #28
0
ファイル: NiLogger.cs プロジェクト: vector-man/netide
        public NiLogger(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            var commandLine = ((INiCommandLine)GetService(typeof(INiCommandLine)));

            string logTarget;
            bool   present;

            ErrorUtil.ThrowOnFailure(commandLine.GetOption("/log", out present, out logTarget));

            bool enabled = present && !String.IsNullOrEmpty(logTarget);

            if (!enabled)
            {
                return;
            }

            try
            {
                _logStream = new StreamWriter(
                    File.Open(logTarget, FileMode.Append, FileAccess.Write, FileShare.Read)
                    );

                _logStream.AutoFlush = true;

                Enabled = true;
            }
            catch
            {
                // Ignore exceptions and just fail.
            }
        }
コード例 #29
0
ファイル: NiProject.cs プロジェクト: vector-man/netide
        public virtual HResult OpenItem(INiHierarchy hier, out INiWindowFrame windowFrame)
        {
            windowFrame = null;

            try
            {
                if ((NiHierarchyType?)hier.GetPropertyEx(NiHierarchyProperty.ItemType) == NiHierarchyType.File)
                {
                    string fileName;
                    ErrorUtil.ThrowOnFailure(((INiProjectItem)hier).GetFileName(out fileName));

                    return(((INiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).OpenStandardEditor(
                               null,
                               fileName,
                               hier,
                               this,
                               out windowFrame
                               ));
                }

                return(HResult.False);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
コード例 #30
0
ファイル: PageHost.cs プロジェクト: vector-man/netide
        protected override INiIsolationClient CreateWindow()
        {
            var window = new Proxy(this);

            ErrorUtil.ThrowOnFailure(window.Initialize());

            return(window);
        }