Exemplo n.º 1
0
            public static bool TryGetSingleSelectedFile(out string file)
            {
                file = null;
                try
                {
                    var selectedItems = Package.IDE.SelectedItems;
                    if (selectedItems.Count != 1)
                    {
                        return(false);
                    }

                    var files = GetFiles(selectedItems);
                    if (files.Count == 1)
                    {
                        file = files[0];
                        return(!string.IsNullOrEmpty(file));
                    }
                }
                catch (Exception ex)
                {
                    OutputWindow.Error("Failed to get a single selected file.", ex);
                }

                return(false);
            }
Exemplo n.º 2
0
            public static bool TryGetSelectedFiles(out string file1, out string file2)
            {
                file1 = file2 = null;
                try
                {
                    var selectedItems = Package.IDE.SelectedItems;
                    if (selectedItems.Count != 2)
                    {
                        return(false);
                    }

                    var files = GetFiles(selectedItems);
                    if (files.Count == 2)
                    {
                        file1 = files[0];
                        file2 = files[1];
                        return(!string.IsNullOrEmpty(file1) && !string.IsNullOrEmpty(file2));
                    }
                }
                catch (Exception ex)
                {
                    OutputWindow.Error("Failed to get selected files.", ex);
                }

                return(false);
            }
 private bool TryGetDocumentActiveDocumentFile(out string file)
 {
     file = null;
     try
     {
         file = Package.IDE.ActiveDocument.FullName;
         return(true);
     }
     catch (Exception ex)
     {
         OutputWindow.Error("Failed to get active document file.", ex);
         return(false);
     }
 }
Exemplo n.º 4
0
        private static void OnBaseBeforeQueryStatus(object sender, EventArgs e)
        {
            var command     = sender as BaseCommand;
            var commandName = command.GetType().Name;

            OutputWindow.Debug($"Command {commandName} OnBeforeQueryStatus.");

            try
            {
                command.OnBeforeQueryStatus();
            }
            catch (Exception ex)
            {
                OutputWindow.Error($"Failed to enable command {commandName}.", ex);
            }
        }
Exemplo n.º 5
0
        private static void OnBaseCommandEventHandler(object sender, EventArgs e)
        {
            var command     = sender as BaseCommand;
            var commandName = command.GetType().Name;

            OutputWindow.Info($"Execute command {commandName}.");

            try
            {
                command.OnExecute();
            }
            catch (Exception ex)
            {
                MessageBox.Error(VSPackage.ErrorMessageTitle, ex.Message);
                OutputWindow.Error($"Failed to execute command {commandName}.", ex);
            }
        }