Beispiel #1
0
        private void beforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            command.Enabled = false;
            command.Visible = false;

            var prj = HelperFunctions.GetSelectedProject(QtVsToolsPackage.Instance.Dte);

            if (!HelperFunctions.IsQtProject(prj) || QtVsToolsPackage.Instance.Dte.SelectedItems.Count <= 0)
            {
                return;
            }

            foreach (SelectedItem si in QtVsToolsPackage.Instance.Dte.SelectedItems)
            {
                if (!HelperFunctions.IsTranslationFile(si.Name))
                {
                    return; // Don't display commands if one of the selected files is not a .ts file.
                }
            }

            command.Enabled = Translation.ToolsAvailable(prj);
            command.Visible = true;
        }
Beispiel #2
0
        private void beforeQueryStatus(object sender, EventArgs e)
        {
            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            var project            = HelperFunctions.GetSelectedProject(QtVsToolsPackage.Instance.Dte);
            var isQtProject        = HelperFunctions.IsQtProject(project);
            var isQMakeProject     = HelperFunctions.IsQMakeProject(project);
            var isQtMsBuildEnabled = QtProject.IsQtMsBuildEnabled(project);

            if (!isQtProject && !isQMakeProject)
            {
                command.Enabled = command.Visible = false;
                return;
            }

            switch ((CommandId)command.CommandID.ID)
            {
            // TODO: Fix these functionality and re-enable the menu items
            case CommandId.ConvertToQtProjectId:
            case CommandId.ConvertToQmakeProjectId: {
                command.Visible = false;
            }
            break;

            case CommandId.ImportPriFileProjectId:
            case CommandId.ExportPriFileProjectId:
            case CommandId.ExportProFileProjectId:
                command.Visible = true;
                command.Enabled = HelperFunctions.IsQtProject(HelperFunctions
                                                              .GetSelectedProject(QtVsToolsPackage.Instance.Dte));
                break;

            case CommandId.lUpdateOnProjectId:
            case CommandId.lReleaseOnProjectId:
                command.Visible = true;
                command.Enabled = Translation.ToolsAvailable(project);
                break;

            //case CommandId.ConvertToQmakeProjectId:
            case CommandId.QtProjectSettingsProjectId: {
                var status = vsCommandStatus.vsCommandStatusSupported;
                if (project != null)
                {
                    if (isQtProject)
                    {
                        status |= vsCommandStatus.vsCommandStatusEnabled;
                    }
                    else if (isQMakeProject)
                    {
                        status |= vsCommandStatus.vsCommandStatusInvisible;
                    }
                }
                command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0);
                command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0);
            }
            break;

            //case CommandId.ConvertToQtProjectId:
            case CommandId.ChangeProjectQtVersionProjectId: {
                var status = vsCommandStatus.vsCommandStatusSupported;
                if ((project == null) || isQtProject)
                {
                    status |= vsCommandStatus.vsCommandStatusInvisible;
                }
                else if (isQMakeProject)
                {
                    status |= vsCommandStatus.vsCommandStatusEnabled;
                }
                else
                {
                    status |= vsCommandStatus.vsCommandStatusInvisible;
                }
                command.Enabled = ((status & vsCommandStatus.vsCommandStatusEnabled) != 0);
                command.Visible = ((status & vsCommandStatus.vsCommandStatusInvisible) == 0);
            }
            break;

            case CommandId.ProjectConvertToQtMsBuild: {
                if (project == null || (!isQtProject && !isQMakeProject))
                {
                    command.Visible = false;
                    command.Enabled = false;
                }
                else if (isQtMsBuildEnabled)
                {
                    command.Visible = true;
                    command.Enabled = false;
                }
                else
                {
                    command.Visible = true;
                    command.Enabled = true;
                }
            }
            break;

            case CommandId.ProjectRefreshIntelliSense: {
                command.Visible = command.Enabled = isQtMsBuildEnabled;
            }
            break;
            }

            if (project != null && isQtProject)
            {
                int projectVersion = QtProject.GetFormatVersion(project);
                switch ((CommandId)command.CommandID.ID)
                {
                case CommandId.ChangeProjectQtVersionProjectId:
                    if (projectVersion >= Resources.qtMinFormatVersion_Settings)
                    {
                        command.Visible = command.Enabled = false;
                    }
                    break;

                case CommandId.ProjectConvertToQtMsBuild:
                    if (projectVersion >= Resources.qtProjectFormatVersion)
                    {
                        command.Visible = command.Enabled = false;
                    }
                    else
                    {
                        command.Visible = command.Enabled = true;
                        if (isQtMsBuildEnabled)
                        {
                            command.Text = "Upgrade to latest Qt project format version";
                        }
                    }
                    break;
                }
            }
        }