Author: mhutch
Date: 2007-12-06 20:25:49 -0500 (Thu, 06 Dec 2007)
New Revision: 90880

Added:
   
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/DesktopApplication.cs
   
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/PlatformService.cs
Modified:
   trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog
   trunk/monodevelop/main/src/core/MonoDevelop.Core/Makefile.am
   trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml
   trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs
Log:
2007-12-06  Geoff Norton  <[EMAIL PROTECTED]>

        * MonoDevelop.Core/PlatformService.cs: New service to hand off the
          platform specific operations to platform-specific addins.  Operations
          such as Mime, Font, DefaultApplication and Icons (anything that
          touches Gnome) is abstracted for now.
        * MonoDevelop.Core/Runtime.cs: Expose a static PlatformService to the
          system.
        * MonoDevelop.Core/DesktopApplication.cs: Move this from
          MonoDevelop.Core.Gui as it needs to be available from
          PlatformService.cs.  Refactor the actual commands that get the
          applications into the PlatformService
        * Makefile.am: Add PlatformService.cs and DesktopApplication.cs to 
          the build.
        * MonoDevelop.Core.addin.xml: Register a new ExtensoinPoint for the
          PlatformService



Modified: trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog  2007-12-07 
01:17:33 UTC (rev 90879)
+++ trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog  2007-12-07 
01:25:49 UTC (rev 90880)
@@ -1,3 +1,20 @@
+2007-12-06  Geoff Norton  <[EMAIL PROTECTED]>
+
+       * MonoDevelop.Core/PlatformService.cs: New service to hand off the
+         platform specific operations to platform-specific addins.  Operations
+         such as Mime, Font, DefaultApplication and Icons (anything that
+         touches Gnome) is abstracted for now.
+       * MonoDevelop.Core/Runtime.cs: Expose a static PlatformService to the
+         system.
+       * MonoDevelop.Core/DesktopApplication.cs: Move this from
+         MonoDevelop.Core.Gui as it needs to be available from
+         PlatformService.cs.  Refactor the actual commands that get the
+         applications into the PlatformService
+       * Makefile.am: Add PlatformService.cs and DesktopApplication.cs to 
+         the build.
+       * MonoDevelop.Core.addin.xml: Register a new ExtensoinPoint for the
+         PlatformService
+
 2007-12-04  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
 
        * Makefile.am, MonoDevelop.Core.mdp: Directory reorganization.

Modified: trunk/monodevelop/main/src/core/MonoDevelop.Core/Makefile.am
===================================================================
--- trunk/monodevelop/main/src/core/MonoDevelop.Core/Makefile.am        
2007-12-07 01:17:33 UTC (rev 90879)
+++ trunk/monodevelop/main/src/core/MonoDevelop.Core/Makefile.am        
2007-12-07 01:25:49 UTC (rev 90880)
@@ -46,6 +46,7 @@
        MonoDevelop.Core/AbstractService.cs \
        MonoDevelop.Core/ClrVersion.cs \
        MonoDevelop.Core/DefaultAddinLocalizer.cs \
+       MonoDevelop.Core/DesktopApplication.cs \
        MonoDevelop.Core/FileEventArgs.cs \
        MonoDevelop.Core/FileService.cs \
        MonoDevelop.Core/IAsyncOperation.cs \
@@ -53,6 +54,7 @@
        MonoDevelop.Core/IProgressMonitor.cs \
        MonoDevelop.Core/IService.cs \
        MonoDevelop.Core/LoggingService.cs \
+       MonoDevelop.Core/PlatformService.cs \
        MonoDevelop.Core/Properties.cs \
        MonoDevelop.Core/PropertyChangedEventArgs.cs \
        MonoDevelop.Core/PropertyService.cs \

Added: 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/DesktopApplication.cs
===================================================================
--- 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/DesktopApplication.cs
     2007-12-07 01:17:33 UTC (rev 90879)
+++ 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/DesktopApplication.cs
     2007-12-07 01:25:49 UTC (rev 90880)
@@ -0,0 +1,85 @@
+//
+// DesktopApplication.cs
+//
+// Author:
+//   Lluis Sanchez Gual
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+
+namespace MonoDevelop.Core
+{
+       public struct DesktopApplication
+       {
+               internal string id;
+               string displayName;
+               string command;
+               
+               public string DisplayName {
+                       get { return displayName; }
+               }
+               
+               public string Command {
+                       get { return command; }
+               }
+               
+               public void Launch (params string[] files)
+               {
+                       // TODO: implement all other cases
+                       if (command.IndexOf ("%f") != -1) {
+                               foreach (string s in files) {
+                                       string cmd = command.Replace ("%f", s);
+                                       Process.Start (cmd);
+                               }
+                       }
+                       else if (command.IndexOf ("%F") != -1) {
+                               string[] fs = new string [files.Length];
+                               for (int n=0; n<files.Length; n++) {
+                                       fs [n] = files [n].Replace (" ", "\\ ");
+                               }
+                               string cmd = command.Replace ("%F", string.Join 
(" ", fs));
+                               Process.Start (cmd);
+                       } else {
+                               foreach (string s in files) {
+                                       Process.Start (command + " " + s);
+                               }
+                       }
+               }
+               
+               public static DesktopApplication GetDefaultApplication (string 
mimeType)
+               {
+                       return Runtime.PlatformService.GetDefaultApplication 
(mimeType);
+               }
+               
+               public static DesktopApplication[] GetApplications (string 
mimeType)
+               {
+                       return Runtime.PlatformService.GetAllApplications 
(mimeType);
+               }
+       }
+}

Added: 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/PlatformService.cs
===================================================================
--- 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/PlatformService.cs
        2007-12-07 01:17:33 UTC (rev 90879)
+++ 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/PlatformService.cs
        2007-12-07 01:25:49 UTC (rev 90880)
@@ -0,0 +1,63 @@
+//
+// PlatformService.cs
+//
+// Author:
+//   Geoff Norton  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Diagnostics;
+using System.Text.RegularExpressions;
+
+using Mono.Addins;
+using MonoDevelop.Core;
+
+namespace MonoDevelop.Core
+{
+       public abstract class PlatformService : AbstractService
+       {
+               public abstract DesktopApplication GetDefaultApplication 
(string mimetype);
+               public abstract DesktopApplication [] GetAllApplications 
(string mimetype);
+               public abstract string GetDescription (string mt);
+               public abstract string DefaultMonospaceFont { get; }
+               public abstract string IconForFile (string filename);
+               
+               public virtual string GetMimeTypeForUri (string uri) {
+                       FileInfo file = new FileInfo (uri);
+
+                       switch (file.Extension) {
+                               case ".cs":
+                                       return "text/x-csharp";
+                       }
+                       return "text/plain";
+               }
+
+               public virtual void ShowUrl (string url)
+               {
+                       Process.Start (url);
+               }
+       }
+}

Modified: 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs
===================================================================
--- 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs    
    2007-12-07 01:17:33 UTC (rev 90879)
+++ 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs    
    2007-12-07 01:25:49 UTC (rev 90880)
@@ -41,6 +41,7 @@
 {
        public class Runtime
        {
+               static PlatformService platformService;
                static ProcessService processService;
                static SystemAssemblyService systemAssemblyService;
                static SetupService setupService;
@@ -100,6 +101,14 @@
                        ServiceManager.UnloadAllServices ();
                        PropertyService.SaveProperties ();
                }
+               
+               public static PlatformService PlatformService {
+                       get {
+                               if (platformService == null)
+                                       platformService = (PlatformService) 
AddinManager.GetExtensionObjects ("/MonoDevelop/Core/PlatformService") [0];
+                               return platformService;
+                       }
+               }
        
                public static ProcessService ProcessService {
                        get {
@@ -154,7 +163,10 @@
                                        throw new ApplicationException ("Error 
setting process name: " + Mono.Unix.Native.Stdlib.GetLastError ());
                                }
                        } catch (EntryPointNotFoundException) {
-                               setproctitle (Encoding.ASCII.GetBytes ("%s\0"), 
Encoding.ASCII.GetBytes (name + "\0"));
+                               // Not every BSD has setproctitle
+                               try {
+                                       setproctitle (Encoding.ASCII.GetBytes 
("%s\0"), Encoding.ASCII.GetBytes (name + "\0"));
+                               } catch (EntryPointNotFoundException) {}
                        }
                }
        }

Modified: 
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml
===================================================================
--- trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml 
2007-12-07 01:17:33 UTC (rev 90879)
+++ trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml 
2007-12-07 01:25:49 UTC (rev 90880)
@@ -5,8 +5,8 @@
        copyright   = "GPL"
        url         = "http://www.monodevelop.com";
        description = "Provides the core services of the MonoDevelop platform"
-          category    = "MonoDevelop Core"
-          isroot      = "true"
+       category    = "MonoDevelop Core"
+       isroot      = "true"
        version     = "0.17.0"
        compatVersion = "0.17.0">
 
@@ -18,6 +18,11 @@
                <Description>Services to be initialized by the runtime. 
Specified classes must implement MonoDevelop.Core.IService</Description>
                <ExtensionNode name="Class" 
type="MonoDevelop.Core.Addins.ServiceExtensionNode" />
        </ExtensionPoint>
+       
+       <ExtensionPoint path = "/MonoDevelop/Core/PlatformService" name = 
"Platform Service">
+               <Description>Implementations of platform-dependent code wrapped 
in a platform-agnostic API. Specified classes must inherit from 
MonoDevelop.Core.PlatformService.</Description>
+               <ExtensionNode name="Class" />
+       </ExtensionPoint>
 
        <ExtensionPoint path = "/MonoDevelop/Core/ExecutionHandlers" name = 
"Execution handlers">
                <Description>Default execution handlers.</Description>
@@ -47,13 +52,13 @@
        
        <Extension path = "/MonoDevelop/Core/ExecutionHandlers">
                <ExecutionHandler id="Mono"
-                                       platform = "Mono"
-                           class = 
"MonoDevelop.Core.Execution.MonoPlatformExecutionHandler"/>
+                                 platform = "Mono"
+                                 class = 
"MonoDevelop.Core.Execution.MonoPlatformExecutionHandler"/>
                <ExecutionHandler id="Mint"
-                                       platform = "Mint"
-                           class = 
"MonoDevelop.Core.Execution.MintPlatformExecutionHandler"/>
+                                 platform = "Mint"
+                                 class = 
"MonoDevelop.Core.Execution.MintPlatformExecutionHandler"/>
                <ExecutionHandler id="Native"
-                                       platform = "Native"
-                           class = 
"MonoDevelop.Core.Execution.NativePlatformExecutionHandler"/>
+                                 platform = "Native"
+                                 class = 
"MonoDevelop.Core.Execution.NativePlatformExecutionHandler"/>
        </Extension>
 </Addin>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to