private bool ActivateScriptByPath(string scriptPath)
        {
            int index = Solution.Current.GetScriptIndexFromPath(scriptPath);

            if (-1 == index)
            {
                // The script is not currently opened, attempt to do that.
                if (textCore.LoadScriptFromFile(scriptPath) == false)
                {
                    return(false);
                }

                SetupTabInternal(scriptPath);
                return(true);
            }

            index = Solution.Current.GetScriptIndexFromPath(scriptPath);
            if (ScriptTabControl.CurrentTab == index)
            {
                return(true);
            }

            ScriptTabControl.ActivateTab(index);
            HandleScriptActivation();
            return(true);
        }
        public bool EnsureScriptsSaved()
        {
            int numberOfTabs = ScriptTabControl.TabCount;

            for (int i = 0; i < numberOfTabs; i++)
            {
                ScriptTabControl.ActivateTab(0);
                HandleScriptActivation();
                if (textEditorControl.ScriptTabClosingCallback())
                {
                    ScriptTabControl.CloseTab(0);
                    textCore.CloseScript(0);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #3
0
        private void OpenSolutionExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            Logger.LogDebug("Text-Editor-Control-OpenSolutionExecuted", "OpenSolutionExecuted");

            // Check to see if the solution needs saving. But then we cannot do
            // this because we ALWAYS have a start-up script, so user will be
            // prompt to save the solution even if she has not done anything after
            // launching DesignScript Studio.
            //
            // if (SaveSolutionInternal() == false)
            //    return;


            if (OpenSolutionInternal() == false)
            {
                return;
            }

            ScriptTabControl.CloseAllTabs();

            int count = Solution.Current.ScriptCount;

            for (int index = 0; index < count; ++index)
            {
                string path = Solution.Current.GetScriptPathFromIndex(index);
                string name = System.IO.Path.GetFileName(path);
                ScriptTabControl.InsertNewTab(name, scrollViewer);
            }

            int activeScript = Solution.Current.ActiveScriptIndex;

            ScriptTabControl.ActivateTab(activeScript);

            HandleScriptActivation();

            // Remove and add all expressions stored in the solution.
            InspectionViewControl.Instance.PopulateVariablesFromSolution();
            CommandManager.InvalidateRequerySuggested();
        }
Exemple #4
0
        private void OpenScriptExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;
            Logger.LogDebug("Text-Editor-Control-OnOpenScriptButton", "UserPressed");
            Stopwatch sw = new Stopwatch();

            sw.Start();

            if (null == TextEditorControl.HostApplication)
            {
                return; // Nothing to do.
            }
            string filePath = TextEditorControl.HostApplication.PromptScriptSelection();

            if (string.IsNullOrEmpty(filePath))
            {
                return; // Nothing to do, again.
            }
            if (parseTimer == null)
            {
                parseTimer          = new DispatcherTimer();
                parseTimer.Tick    += new EventHandler(OnParseTimerTick);
                parseTimer.Interval = new TimeSpan(0, 0, 1);
                parseTimer.Start();
            }

            if (textCore.LoadScriptFromFile(filePath))
            {
                SetupTabInternal(filePath);
            }
            else
            {
                // Even though "LoadScriptFromFile" returns false, it may be
                // due to the fact that the script has already been opened.
                // In such cases, we will be able to get the script index
                // given its name. If the index turns out to be valid here,
                // then we will simply activate the corresponding tab.
                //
                int index = Solution.Current.GetScriptIndexFromPath(filePath);
                if (index >= 0)
                {
                    ScriptTabControl.ActivateTab(index);
                }
                else
                {
                    MessageBox.Show(Configurations.UnsupportedFileType);
                }
            }

            HandleScriptActivation();

            grid.UpdateLayout();
            CommandManager.InvalidateRequerySuggested();
            textCanvas.Focus();

            IScriptObject script = Solution.Current.ActiveScript;

            Logger.LogPerf("TextEditorControl.OnOpenScriptButton", sw.ElapsedMilliseconds + " ms");
            if (null != script)
            {
                Logger.LogInfo("Text-Editor-Control-OnOpenScriptButton-Script", script.GetTextBuffer().GetContent());
            }
        }