Ejemplo n.º 1
0
        /// <inheritdoc/>
        public IViewContent OpenFile(FileName fileName, bool switchToOpenedView)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            LoggingService.Info("Open file " + fileName);

            IViewContent viewContent = GetOpenFile(fileName);

            if (viewContent != null)
            {
                if (switchToOpenedView)
                {
                    viewContent.WorkbenchWindow.SelectWindow();
                }
                return(viewContent);
            }

            IDisplayBinding binding = SD.DisplayBindingService.GetBindingPerFileName(fileName);

            if (binding == null)
            {
                binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName));
            }
            if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK)
            {
                RecentOpen.AddRecentFile(fileName);
            }
            return(GetOpenFile(fileName));
        }
Ejemplo n.º 2
0
        public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
        {
            RecentOpen recentOpen = FileService.RecentOpen;

            if (recentOpen.RecentProject.Count > 0)
            {
                MenuCommand[] items = new MenuCommand[recentOpen.RecentProject.Count];
                for (int i = 0; i < recentOpen.RecentProject.Count; ++i)
                {
                    string accelaratorKeyPrefix = i < 10 ? "&" + ((i + 1) % 10) + " " : "";
                    items[i]             = new MenuCommand(accelaratorKeyPrefix + recentOpen.RecentProject[i], new EventHandler(LoadRecentProject));
                    items[i].Tag         = recentOpen.RecentProject[i].ToString();
                    items[i].Description = StringParser.Parse(ResourceService.GetString("Dialog.Componnents.RichMenuItem.LoadProjectDescription"),
                                                              new string[, ] {
                        { "PROJECT", recentOpen.RecentProject[i].ToString() }
                    });
                }
                return(items);
            }

            MenuCommand defaultMenu = new MenuCommand("${res:Dialog.Componnents.RichMenuItem.NoRecentProjectsString}");

            defaultMenu.Enabled = false;

            return(new MenuCommand[] { defaultMenu });
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public IFileViewContent OpenFile(FileName fileName, bool switchToOpenedView)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            Current.Log.Info("Open file " + fileName);

            IFileViewContent viewContent = GetOpenFile(fileName);

            if (viewContent != null)
            {
                if (switchToOpenedView)
                {
                    viewContent.IsSelected = true;
                }
                return(viewContent);
            }

            IDisplayBinding binding = Altaxo.Current.GetRequiredService <IDisplayBindingService>().GetBindingPerFileName(fileName);

            if (binding == null)
            {
                binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName));
            }
            if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK)
            {
                RecentOpen.AddRecentFile(fileName);
            }
            return(GetOpenFile(fileName));
        }
Ejemplo n.º 4
0
        public ICollection BuildItems(Codon codon, object owner)
        {
            RecentOpen recentOpen = FileService.RecentOpen;

            if (recentOpen.RecentProject.Count > 0)
            {
                var items = new System.Windows.Controls.MenuItem[recentOpen.RecentProject.Count];

                for (int i = 0; i < recentOpen.RecentProject.Count; ++i)
                {
                    // variable inside loop, so that anonymous method refers to correct recent file
                    string recentProject        = recentOpen.RecentProject[i];
                    string accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10) + " " : "";
                    items[i] = new System.Windows.Controls.MenuItem()
                    {
                        Header = accelaratorKeyPrefix + recentProject
                    };
                    items[i].Click += delegate {
                        ProjectService.LoadSolution(recentProject);
                    };
                }
                return(items);
            }
            else
            {
                return(new [] { new System.Windows.Controls.MenuItem {
                                    Header = StringParser.Parse("${res:Dialog.Componnents.RichMenuItem.NoRecentProjectsString}"),
                                    IsEnabled = false
                                } });
            }
        }
Ejemplo n.º 5
0
 /// <inheritdoc/>
 public IViewContent OpenFileWith(FileName fileName, IDisplayBinding displayBinding, bool switchToOpenedView)
 {
     if (displayBinding == null)
     {
         throw new ArgumentNullException("displayBinding");
     }
     if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(displayBinding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK)
     {
         RecentOpen.AddRecentFile(fileName);
     }
     return(GetOpenFile(fileName));
 }
Ejemplo n.º 6
0
        protected override void Update(CommandArrayInfo info)
        {
            RecentOpen recentOpen = IdeApp.Workbench.RecentOpen;

            if (recentOpen.RecentProjectsCount <= 0)
            {
                return;
            }

            int i = 0;

            foreach (RecentItem ri in recentOpen.RecentProjects)
            {
                //getting the icon requires probing the file, so handle IO errors
                IconId icon;
                try {
                    if (!File.Exists(ri.LocalPath))
                    {
                        continue;
                    }

                    icon = IdeApp.Services.ProjectService.FileFormats.GetFileFormats
                               (ri.LocalPath, typeof(Solution)).Length > 0
                                                        ? "md-solution"
                                                        : "md-workspace";
                }
                catch (UnauthorizedAccessException exAccess) {
                    LoggingService.LogWarning("Error building recent solutions list (Permissions)", exAccess);
                    continue;
                }
                catch (IOException ex) {
                    LoggingService.LogWarning("Error building recent solutions list", ex);
                    continue;
                }

                string accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10).ToString() + " " : "";
                string label = ((ri.Private == null || ri.Private.Length < 1)
                                                ? Path.GetFileNameWithoutExtension(ri.ToString())
                                                : ri.Private);
                CommandInfo cmd = new CommandInfo(accelaratorKeyPrefix + label.Replace("_", "__"));
                cmd.Icon = icon;

                string str = GettextCatalog.GetString("Load solution {0}", ri.ToString());
                if (IdeApp.Workspace.IsOpen)
                {
                    str += " - " + GettextCatalog.GetString("Hold Control to open in current workspace.");
                }
                cmd.Description = str;
                info.Add(cmd, ri);
                i++;
            }
        }
Ejemplo n.º 7
0
        protected override void Update(CommandArrayInfo info)
        {
            RecentOpen recentOpen = IdeApp.Workbench.RecentOpen;

            if (recentOpen.RecentFilesCount > 0)
            {
                int i = 0;
                foreach (RecentItem ri in recentOpen.RecentFiles)
                {
                    string      accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10).ToString() + " " : "";
                    string      label = ((ri.Private == null || ri.Private.Length < 1) ? Path.GetFileName(ri.ToString()) : ri.Private);
                    CommandInfo cmd   = new CommandInfo(accelaratorKeyPrefix + label.Replace("_", "__"));
                    cmd.Description = GettextCatalog.GetString("Open {0}", ri.ToString());
                    Gdk.Pixbuf icon = DesktopService.GetPixbufForFile(ri.ToString(), IconSize.Menu);
                    if (icon != null)
                    {
                        cmd.Icon = ImageService.GetStockId(icon, IconSize.Menu);
                    }
                    info.Add(cmd, ri);
                    i++;
                }
            }
        }
Ejemplo n.º 8
0
        public static void Initialize(IProgressMonitor monitor)
        {
            Counters.Initialization.Trace("Creating Workbench");
            workbench = new Workbench();
            Counters.Initialization.Trace("Creating Root Workspace");
            workspace = new RootWorkspace();
            Counters.Initialization.Trace("Creating Services");
            projectOperations = new ProjectOperations();
            helpOperations    = new HelpOperations();
            commandService    = new CommandManager();
            ideServices       = new IdeServices();
            CustomToolService.Init();
            AutoTestService.Start(commandService, Preferences.EnableAutomatedTesting);

            commandService.CommandTargetScanStarted  += CommandServiceCommandTargetScanStarted;
            commandService.CommandTargetScanFinished += CommandServiceCommandTargetScanFinished;

            KeyBindingService.LoadBindingsFromExtensionPath("/MonoDevelop/Ide/KeyBindingSchemes");
            KeyBindingService.LoadCurrentBindings("MD2");

            commandService.CommandError += delegate(object sender, CommandErrorArgs args) {
                MessageService.ShowException(args.Exception, args.ErrorMessage);
            };

            FileService.ErrorHandler = FileServiceErrorHandler;

            monitor.BeginTask(GettextCatalog.GetString("Loading Workbench"), 5);
            Counters.Initialization.Trace("Loading Commands");

            commandService.LoadCommands("/MonoDevelop/Ide/Commands");
            monitor.Step(1);

            Counters.Initialization.Trace("Initializing Workbench");
            workbench.Initialize(monitor);
            monitor.Step(1);

            InternalLog.EnableErrorNotification();

            monitor.Step(1);

            Counters.Initialization.Trace("Restoring Workbench State");
            workbench.Show("SharpDevelop.Workbench.WorkbenchMemento");
            monitor.Step(1);

            Counters.Initialization.Trace("Flushing GUI events");
            DispatchService.RunPendingEvents();
            Counters.Initialization.Trace("Flushed GUI events");

            MessageService.RootWindow = workbench.RootWindow;

            commandService.EnableIdleUpdate = true;

            // Default file format
            MonoDevelop.Projects.Services.ProjectServiceLoaded += delegate(object sender, EventArgs e) {
                ((ProjectService)sender).DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat;
            };

            IdeApp.Preferences.DefaultProjectFileFormatChanged += delegate {
                IdeApp.Services.ProjectService.DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat;
            };

            // Perser service initialization
            MonoDevelop.Projects.Dom.Parser.ProjectDomService.TrackFileChanges            = true;
            MonoDevelop.Projects.Dom.Parser.ProjectDomService.ParseProgressMonitorFactory = new ParseProgressMonitorFactory();


            // Startup commands
            Counters.Initialization.Trace("Running Startup Commands");
            AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged);
            monitor.EndTask();

            // Set initial run flags
            Counters.Initialization.Trace("Upgrading Settings");

            if (PropertyService.Get("MonoDevelop.Core.FirstRun", false))
            {
                isInitialRun = true;
                PropertyService.Set("MonoDevelop.Core.FirstRun", false);
                PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildVariables.PackageVersion);
                PropertyService.Set("MonoDevelop.Core.LastRunVersion", CurrentRevision);
                PropertyService.SaveProperties();
            }

            string lastVersion  = PropertyService.Get("MonoDevelop.Core.LastRunVersion", "1.9.1");
            int    lastRevision = PropertyService.Get("MonoDevelop.Core.LastRunRevision", 0);

            if (lastRevision != CurrentRevision && !isInitialRun)
            {
                isInitialRunAfterUpgrade = true;
                if (lastRevision == 0)
                {
                    switch (lastVersion)
                    {
                    case "1.0": lastRevision = 1; break;

                    case "2.0": lastRevision = 2; break;

                    case "2.2": lastRevision = 3; break;

                    case "2.2.1": lastRevision = 4; break;
                    }
                }
                upgradedFromRevision = lastRevision;
                PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildVariables.PackageVersion);
                PropertyService.Set("MonoDevelop.Core.LastRunRevision", CurrentRevision);
                PropertyService.SaveProperties();
            }

            // The ide is now initialized

            isInitialized = true;

            if (isInitialRun)
            {
                try {
                    OnInitialRun();
                } catch (Exception e) {
                    LoggingService.LogError("Error found while initializing the IDE", e);
                }
            }

            if (isInitialRunAfterUpgrade)
            {
                try {
                    OnUpgraded(upgradedFromRevision);
                } catch (Exception e) {
                    LoggingService.LogError("Error found while initializing the IDE", e);
                }
            }

            if (initializedEvent != null)
            {
                initializedEvent(null, EventArgs.Empty);
            }

            // load previous combine
            if ((bool)PropertyService.Get("SharpDevelop.LoadPrevProjectOnStartup", true))
            {
                RecentOpen recentOpen = Workbench.RecentOpen;

                if (recentOpen.RecentProjectsCount > 0)
                {
                    IdeApp.Workspace.OpenWorkspaceItem(recentOpen.RecentProjects.First().ToString()).WaitForCompleted();
                }
            }

            commandService.CommandSelected   += OnCommandSelected;
            commandService.CommandDeselected += OnCommandDeselected;

            //FIXME: we should really make this on-demand. consumers can display a "loading help cache" message like VS
            MonoDevelop.Projects.HelpService.AsyncInitialize();

            UpdateInstrumentationIcon();
            IdeApp.Preferences.EnableInstrumentationChanged += delegate {
                UpdateInstrumentationIcon();
            };
            AutoTestService.NotifyEvent("MonoDevelop.Ide.IdeStart");
        }
Ejemplo n.º 9
0
        protected override void Update(CommandInfo info)
        {
            RecentOpen recentOpen = IdeApp.Workbench.RecentOpen;

            info.Enabled = recentOpen.RecentProjectsCount > 0;
        }
Ejemplo n.º 10
0
        void RealOpenFile(FileOpenInformation openFileInfo)
        {
            FilePath         fileName;
            IProgressMonitor monitor = openFileInfo.ProgressMonitor;

            using (monitor)
            {
                Counters.OpenDocumentTimer.Trace("Checking file");

                string origName = openFileInfo.FileName;

                if (origName == null)
                {
                    monitor.ReportError(GettextCatalog.GetString("Invalid file name"), null);
                    return;
                }

                if (origName.StartsWith("file://"))
                {
                    fileName = new Uri(origName).LocalPath;
                }
                else
                {
                    fileName = origName;
                }

                if (!origName.StartsWith("http://"))
                {
                    fileName = fileName.FullPath;
                }

                //Debug.Assert(FileService.IsValidPath(fileName));
                if (FileService.IsDirectory(fileName))
                {
                    monitor.ReportError(GettextCatalog.GetString("{0} is a directory", fileName), null);
                    return;
                }
                // test, if file fileName exists
                if (!origName.StartsWith("http://"))
                {
                    // test, if an untitled file should be opened
                    if (!System.IO.Path.IsPathRooted(origName))
                    {
                        foreach (Document doc in Documents)
                        {
                            if (doc.Window.ViewContent.IsUntitled && doc.Window.ViewContent.UntitledName == origName)
                            {
                                doc.Select();
                                openFileInfo.NewContent = doc.Window.ViewContent;
                                return;
                            }
                        }
                    }
                    if (!File.Exists(fileName))
                    {
                        monitor.ReportError(GettextCatalog.GetString("File not found: {0}", fileName), null);
                        return;
                    }
                }

                foreach (Document doc in Documents)
                {
                    if (doc.FileName == fileName)
                    {
                        if (openFileInfo.BringToFront)
                        {
                            doc.Select();
                            IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> ();
                            if (openFileInfo.Line != -1 && ipos != null)
                            {
                                ipos.SetCaretTo(openFileInfo.Line, openFileInfo.Column != -1 ? openFileInfo.Column : 0, openFileInfo.HighlightCaretLine);
                            }
                        }
                        openFileInfo.NewContent = doc.Window.ViewContent;
                        return;
                    }
                }

                Counters.OpenDocumentTimer.Trace("Looking for binding");

                IDisplayBinding binding;

                if (openFileInfo.DisplayBinding != null)
                {
                    binding = openFileInfo.DisplayBinding;
                }
                else
                {
                    binding = DisplayBindingService.GetDefaultBinding(fileName, DesktopService.GetMimeTypeForUri(fileName));
                }

                if (binding != null)
                {
                    // When looking for the project to which the file belongs, look first
                    // in the active project, then the active solution, and so on
                    Project project = null;
                    if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
                    {
                        if (IdeApp.ProjectOperations.CurrentSelectedProject.Files.GetFile(fileName) != null)
                        {
                            project = IdeApp.ProjectOperations.CurrentSelectedProject;
                        }
                    }
                    if (project == null && IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null)
                    {
                        project = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetProjectContainingFile(fileName);
                        if (project == null)
                        {
                            WorkspaceItem it = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.ParentWorkspace;
                            while (it != null && project == null)
                            {
                                project = it.GetProjectContainingFile(fileName);
                                it      = it.ParentWorkspace;
                            }
                        }
                    }
                    if (project == null)
                    {
                        project = IdeApp.Workspace.GetProjectContainingFile(fileName);
                    }

                    LoadFileWrapper fw = new LoadFileWrapper(workbench, binding, project, openFileInfo);
                    fw.Invoke(fileName);

                    Counters.OpenDocumentTimer.Trace("Adding to recent files");
                    RecentOpen.AddLastFile(fileName, project != null ? project.Name : null);
                }
                else
                {
                    try {
                        Counters.OpenDocumentTimer.Trace("Showing in browser");
                        // FIXME: this doesn't seem finished yet in Gtk#
                        //MimeType mimetype = new MimeType (new Uri ("file://" + fileName));
                        //if (mimetype != null) {
                        //	mimetype.DefaultAction.Launch ();
                        //} else {
                        DesktopService.ShowUrl("file://" + fileName);
                        //}
                    } catch (Exception ex) {
                        LoggingService.LogError("Error opening file: " + fileName, ex);
                        MessageService.ShowError(GettextCatalog.GetString("File '{0}' could not be opened", fileName));
                    }
                }
            }
        }