locked
Reopen editor programmatically RRS feed

  • Question

  • Probably I am asking a very noob question, but I have not found any way to do in anywhere.

    I need just Reopen the editor, not the file or project.
    Why? The have an editor factory that load diferent editor pane in acording of content file. Each editor can be diferent by interfaces, implementations or simple by version. But from one editor it can change the type of file or upgrade the version, so I need force to reopen editor.

     

    Wednesday, June 2, 2010 11:53 AM

Answers

  • Hi Tales,

    Based on my understanding, if you add a new version Custom Editor to Visual Studio, it's better to restart Visual Studio. But if you want to update the custom version manually, use dte.ItemOperations.OpenFile() function should works. But as your concern, it will change the order of tabs. As a workaround, I would suggest you try to use close the solution in IDE and reopen it. For details, please see following code:

        Dim str As String
        str = DTE.Solution.FullName
        DTE.ExecuteCommand("File.CloseSolution")
        DTE.Solution.Open(str)

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Nancy Shao Wednesday, June 16, 2010 5:50 AM
    Wednesday, June 9, 2010 6:11 AM

All replies

  • Hi Tales,

    Thanks for using MSDN forum.

    Do you mean you want to open a file with different editor after changed the type? If so, you can use DTE.Openfile() method or ItemOperations.OpenFile Method to open a file with a specify editor or the default editor. For the types of editor to open files in IDE, please see Constants Fields  .If you don't specify the editor in these methods, IDE will determine the correct editor to open this file.

    And you don't need to reopen editor, when a file is opened in IDE, the corresponding editor will be atuomatically invoked.

    If I misunderstood you, or you have any comments, please feel free to let me know.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, June 3, 2010 3:08 AM
  • Hi Nancy,

    Thank you for your attention,

    When the user open my custom file (.mycustomfile) at first time my IVsEditorFactory read its content and create a editor by type and version (We can have multiple editors version installed). Think the the user can update the version inside the editor, so this already opened editor must be closed and reopened with the correct version.

    Recently I 'solved' with the code below:

          EnvDTE.DTE dte = (EnvDTE.DTE)vsServiceProvider.GetService(typeof(EnvDTE.DTE));
          dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesNo);
          dte.ItemOperations.OpenFile(FileName);
    

    But seems not be a good pratice, and has some side effects. 1 - The new editor does't remains in the same location in the list of tabs. 2 - I need discard or save chages before reopen. 3 - The Close command with vsSaveChangesPrompt does not return the user option, (Save, don't save or cancel). And maybe we don't need to save because we can have another editor using the same DocData (an XML editor for example).

    Thanks again,
    Tales Aguiar

    Thursday, June 3, 2010 7:37 PM
  • Hi Tales,

    Based on my understanding, if you add a new version Custom Editor to Visual Studio, it's better to restart Visual Studio. But if you want to update the custom version manually, use dte.ItemOperations.OpenFile() function should works. But as your concern, it will change the order of tabs. As a workaround, I would suggest you try to use close the solution in IDE and reopen it. For details, please see following code:

        Dim str As String
        str = DTE.Solution.FullName
        DTE.ExecuteCommand("File.CloseSolution")
        DTE.Solution.Open(str)

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Nancy Shao Wednesday, June 16, 2010 5:50 AM
    Wednesday, June 9, 2010 6:11 AM
  • Hi Tales,

    I am writing to follow up this issue. Please let me know what I can help. Thanks.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, June 14, 2010 6:11 AM