Exemple #1
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                _uiShell.SetWaitCursor();

                Document document = _dte.ActiveDocument;

                if (IsFormatableDocument(document))
                {
                    Execute(document);
                }
            }
            catch (Exception ex)
            {
                string title   = $"Error in {GetType().Name}:";
                string message = string.Format(
                    CultureInfo.CurrentCulture,
                    "{0}\r\n\r\nIf this deems a malfunctioning of styler, please kindly submit an issue at https://github.com/Xavalon/XamlStyler.",
                    ex.Message);

                ShowMessageBox(title, message);
            }
        }
Exemple #2
0
 protected void SetWaitCursor()
 {
     if (this.site != null)
     {
         IVsHierarchy service = this.GetService(typeof(IVsHierarchy)) as IVsHierarchy;
         if (service != null)
         {
             Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP = null;
             if (service.GetSite(out ppSP) == 0)
             {
                 IntPtr ptr;
                 Guid   gUID = typeof(SVsUIShell).GUID;
                 Guid   riid = typeof(IVsUIShell).GUID;
                 if (ErrorHandler.Succeeded(ppSP.QueryService(ref gUID, ref riid, out ptr)))
                 {
                     IVsUIShell objectForIUnknown = Marshal.GetObjectForIUnknown(ptr) as IVsUIShell;
                     if (objectForIUnknown != null)
                     {
                         objectForIUnknown.SetWaitCursor();
                     }
                     Marshal.Release(ptr);
                 }
             }
         }
     }
 }
Exemple #3
0
        public new int Load(string pszFilename, uint grfMode, int fReadOnly)
        {
            if (pszFilename == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            loading = true;
            int hr = VSConstants.S_OK;

            try
            {
                // Show the wait cursor while loading the file
                IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                if (VsUiShell != null)
                {
                    // Note: we don't want to throw or exit if this call fails, so
                    // don't check the return code.
                    hr = VsUiShell.SetWaitCursor();
                }

                // Load the file
                StreamReader streamReader = new StreamReader(pszFilename);
                string       text         = streamReader.ReadToEnd();
                streamReader.Close();
                CommandWindow.Text = text;
                _isDirty           = 0;

                //Determine if the file is read only on the file system
                FileAttributes fileAttrs = File.GetAttributes(pszFilename);

                int isReadOnly = (int)fileAttrs & (int)FileAttributes.ReadOnly;

                //Set readonly if either the file is readonly for the user or on the file system
                if (0 == isReadOnly && 0 == fReadOnly)
                {
                    SetReadOnly(false);
                }
                else
                {
                    SetReadOnly(true);
                }

                // Hook up to file change notifications
                if (String.IsNullOrEmpty(_fileName) || 0 != String.Compare(_fileName, pszFilename, true, CultureInfo.CurrentCulture))
                {
                    _fileName = pszFilename;
                    SetFileChangeNotification(pszFilename, true);

                    // Notify the load or reload
                    NotifyDocChanged();
                }
            }
            finally
            {
                loading = false;
            }
            return(VSConstants.S_OK);
        }
Exemple #4
0
        /// <summary>
        /// Sets the wait cursor.
        /// </summary>
        public void SetWaitCursor()
        {
            IVsUIShell shell = GetService <IVsUIShell>(typeof(SVsUIShell));

            if (shell != null)
            {
                shell.SetWaitCursor();
            }
        }
Exemple #5
0
        /// <summary>
        /// Saves current document's buffer in the specified path
        /// </summary>
        /// <param name="path">File path</param>
        /// <param name="format">Index in the format list, specifying format of the saved file</param>
        public virtual void SaveFile(string path, uint format)
        {
            IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

            if (VsUiShell != null)
            {
                VsUiShell.SetWaitCursor();
            }
        }
Exemple #6
0
        /// <summary>
        /// Loads a file with specified path
        /// </summary>
        public virtual void LoadFile(string path)
        {
            IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

            if (VsUiShell != null)
            {
                VsUiShell.SetWaitCursor();
            }
        }
        public static void SetWaitCursor(IServiceProvider provider)
        {
            Guard.ArgumentNotNull(provider, "provider");

            IVsUIShell shell = provider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (shell != null)
            {
                ErrorHandler.ThrowOnFailure(shell.SetWaitCursor());
            }
        }
Exemple #8
0
        /// <summary>
        /// Loads the file content into the TextBox.
        /// </summary>
        /// <param name="pszFilename">Pointer to the full path name of the file to load.</param>
        /// <param name="grfMode">file format mode.</param>
        /// <param name="fReadOnly">determines if the file should be opened as read only.</param>
        /// <returns>S_OK if the method succeeds.</returns>
        int IPersistFileFormat.Load(string pszFilename, uint grfMode, int fReadOnly)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if ((pszFilename == null) &&
                ((fileName == null) || (fileName.Length == 0)))
            {
                throw new ArgumentNullException("pszFilename");
            }

            loading = true;
            int hr = VSConstants.S_OK;

            try
            {
                bool isReload = false;

                // If the new file name is null, then this operation is a reload
                if (pszFilename == null)
                {
                    isReload = true;
                }

                // Show the wait cursor while loading the file
                IVsUIShell vsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                if (vsUiShell != null)
                {
                    // Note: we don't want to throw or exit if this call fails, so
                    // don't check the return code.
                    vsUiShell.SetWaitCursor();
                }

                // Set the new file name
                if (!isReload)
                {
                    // Unsubscribe from the notification of the changes in the previous file.
                    fileName = pszFilename;
                }
                // Load the file
                //editorControl.LoadFile(fileName, RichTextBoxStreamType.PlainText);

                load(fileName);


                isDirty = false;

                // Notify the load or reload
                NotifyDocChanged();
            }
            finally
            {
                loading = false;
            }
            return(hr);
        }
        /// <summary>
        /// Changes the cursor to the hourglass cursor.
        /// </summary>
        /// <returns>A return code or S_OK.</returns>
        public int SetWaitCursor()
        {
            int hr = VSConstants.S_OK;

            IVsUIShell VsUiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (VsUiShell != null)
            {
                // There is no check for return code because
                // any failure of this call is ignored.
                hr = VsUiShell.SetWaitCursor();
            }

            return(hr);
        }
Exemple #10
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                _uiShell.SetWaitCursor();

                Document document = _dte.ActiveDocument;

                if (IsFormatableDocument(document))
                {
                    Execute(document);
                }
            }
            catch (Exception ex)
            {
                string title   = string.Format("Error in {0}:", GetType().Name);
                string message = string.Format(
                    CultureInfo.CurrentCulture,
                    "{0}\r\n\r\nIf this deems a malfunctioning of styler, please kindly submit an issue at http://xamlstyler.codeplex.com.",
                    ex.Message);

                ShowMessageBox(title, message);
            }
        }
Exemple #11
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

            try
            {
                uiShell.SetWaitCursor();
                switch ((int)((MenuCommand)sender).CommandID.ID)
                {
                case PkgCmdIDList.cmdidUpdateReports:
                    Views.UpdateReports dlg = new Views.UpdateReports(TeamExplorerIntegrator);
                    dlg.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidVCFolderSizes:
                    Views.FolderSizes dlg1 = new Views.FolderSizes(TeamExplorerIntegrator);
                    dlg1.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidAbout:
                    Views.about dlg2 = new Views.about();
                    dlg2.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidUpdateWorkItemTypes:
                    Views.UpdateWorkItemTypes dlg3 = new Views.UpdateWorkItemTypes(TeamExplorerIntegrator);
                    dlg3.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidSCSearchLargeFiles:
                    Views.FileSearch dlg4 = new Views.FileSearch(TeamExplorerIntegrator);
                    dlg4.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidFindInFiles:     //Deliberate fallthrough
                case PkgCmdIDList.cmdidFindInFilesSCEContext:
                    Views.FindInFiles dlg10 = new Views.FindInFiles(TeamExplorerIntegrator);
                    dlg10.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidBuildControllers:
                    Views.BuildControllers dlg5 = new Views.BuildControllers(TeamExplorerIntegrator);
                    dlg5.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidTestAttachments:
                    Views.TestAttachmentSize dlgTA = new Views.TestAttachmentSize(TeamExplorerIntegrator);
                    dlgTA.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidFailedLogins:
                    Views.FailedLogins dlg6 = new Views.FailedLogins(TeamExplorerIntegrator);
                    dlg6.ShowDialog();
                    break;

                case PkgCmdIDList.cmdidSubscriptions:
                    Views.Subscriptions dlg7 = new Views.Subscriptions(TeamExplorerIntegrator);
                    dlg7.ShowDialog();
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("***** MATTIAS **** " + ex.Message);

                Guid clsid = Guid.Empty;
                int  result;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                       0,
                                                                       ref clsid,
                                                                       "IterationManager",
                                                                       string.Format(CultureInfo.CurrentCulture, "Msg:  {0}.Stacktrace: {1}", ex.Message, ex.StackTrace),
                                                                       string.Empty,
                                                                       0,
                                                                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                       OLEMSGICON.OLEMSGICON_INFO,
                                                                       0, // false
                                                                       out result));
            }

            if (false)
            {
                Guid clsid = Guid.Empty;
                int  result;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                       0,
                                                                       ref clsid,
                                                                       "IterationManager",
                                                                       string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
                                                                       string.Empty,
                                                                       0,
                                                                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                       OLEMSGICON.OLEMSGICON_INFO,
                                                                       0, // false
                                                                       out result));
            }
        }
Exemple #12
0
        int IPersistFileFormat.Load(string pszFilename, uint grfMode, int fReadOnly)
        {
            if (pszFilename == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            //loading = true;
            int hr = VSConstants.S_OK;

            try
            {
                // Show the wait cursor while loading the file
                IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                if (VsUiShell != null)
                {
                    // Note: we don't want to throw or exit if this call fails, so
                    // don't check the return code.
                    hr = VsUiShell.SetWaitCursor();
                }

                editorControl.LoadFile(pszFilename);
                isDirty = false;

                //Determine if the file is read only on the file system
                FileAttributes fileAttrs = File.GetAttributes(pszFilename);

                int isReadOnly = (int)fileAttrs & (int)FileAttributes.ReadOnly;

                //Set readonly if either the file is readonly for the user or on the file system
                // TODO finish
                //if (0 == isReadOnly && 0 == fReadOnly)
                //    SetReadOnly(false);
                //else
                //    SetReadOnly(true);

                // Notify to the property window that some of the selected objects are changed
                // TODO finish
                //ITrackSelection track = TrackSelection;
                //if (null != track)
                //{
                //    hr = track.OnSelectChange((ISelectionContainer)selContainer);
                //    if (ErrorHandler.Failed(hr))
                //        return hr;
                //}

                // Hook up to file change notifications
                if (String.IsNullOrEmpty(fileName) || 0 != String.Compare(fileName, pszFilename, true, CultureInfo.CurrentCulture))
                {
                    fileName = pszFilename;
                    // TODO finish
                    //SetFileChangeNotification(pszFilename, true);

                    // Notify the load or reload
                    // TODO finish
                    //NotifyDocChanged();
                }
            }
            finally
            {
                //loading = false;
            }
            return(VSConstants.S_OK);
        }