示例#1
0
        //==========================================================================================
        // Constructors
        //==========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="PackageContext"/> class.
        /// </summary>
        /// <param name="serviceProvider">
        /// The <see cref="ServiceProvider"/> instance to use for getting services from the environment.
        /// </param>
        public PackageContext(ServiceProvider serviceProvider)
        {
            Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider");
            this.serviceProvider = serviceProvider;

            // Get an IUIHostLocale instance and Visual Studio's locale
            IUIHostLocale hostLocale = this.GetService(typeof(SUIHostLocale)) as IUIHostLocale;

            Tracer.Assert(hostLocale != null, "Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
            int lcid = Thread.CurrentThread.CurrentUICulture.LCID;

            if (hostLocale != null)
            {
                uint lcidUnsigned;
                int  hr = hostLocale.GetUILocale(out lcidUnsigned);
                if (NativeMethods.Succeeded(hr))
                {
                    lcid = (int)lcidUnsigned;
                }
                else
                {
                    Tracer.Fail("Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
                }
            }

            // Initialize our helpers
            this.managedResources = this.CreateManagedResourceManager();
            this.nativeResources  = new NativeResourceManager(lcid);
            this.settings         = this.CreatePackageSettings(this.ServiceProvider);
        }
示例#2
0
        /// <summary>
        /// Deletes the file or folder from the disk. Folders will be recursively deleted.
        /// </summary>
        public virtual void Delete()
        {
            // Don't delete if we're not supposed to.
            if (!this.CanDelete)
            {
                return;
            }

            // First ask the user if he really wants to delete the item.
            PackageContext        context   = Package.Instance.Context;
            NativeResourceManager resources = context.NativeResources;
            string             title        = resources.GetString(ResourceId.IDS_DELETECONFIRMATION_TITLE, this.Caption);
            string             message      = resources.GetString(ResourceId.IDS_DELETECONFIRMATION, this.Caption);
            VsMessageBoxResult result       = context.ShowMessageBox(title, message, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_WARNING);

            if (result == VsMessageBoxResult.No)
            {
                return;
            }

            // Close the node first.
            this.Close();

            // Remove the node from the project.
            this.RemoveFromProject();

            // Attempt the delete the node from disk.
            try
            {
                if (this.IsFolder && Directory.Exists(this.AbsolutePath))
                {
                    Directory.Delete(this.AbsolutePath, true);
                }
                else if (this.IsFile && File.Exists(this.AbsolutePath))
                {
                    // Make sure the file is not read only, hidden, etc.
                    File.SetAttributes(this.AbsolutePath, FileAttributes.Normal);
                    File.Delete(this.AbsolutePath);
                }
            }
            catch (Exception e)
            {
                title   = resources.GetString(ResourceId.IDS_E_DELETEFROMPROJECT_TITLE);
                message = resources.GetString(ResourceId.IDS_E_DELETEFROMPROJECT, e.Message);
                context.ShowErrorMessageBox(title, message);
            }
        }
示例#3
0
        //==========================================================================================
        // Constructors
        //==========================================================================================
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageContext"/> class.
        /// </summary>
        /// <param name="serviceProvider">
        /// The <see cref="ServiceProvider"/> instance to use for getting services from the environment.
        /// </param>
        public PackageContext(ServiceProvider serviceProvider)
        {
            Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider");
            this.serviceProvider = serviceProvider;

            // Get an IUIHostLocale instance and Visual Studio's locale
            IUIHostLocale hostLocale = this.GetService(typeof(SUIHostLocale)) as IUIHostLocale;
            Tracer.Assert(hostLocale != null, "Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
            int lcid = Thread.CurrentThread.CurrentUICulture.LCID;
            if (hostLocale != null)
            {
                uint lcidUnsigned;
                int hr = hostLocale.GetUILocale(out lcidUnsigned);
                if (NativeMethods.Succeeded(hr))
                {
                    lcid = (int)lcidUnsigned;
                }
                else
                {
                    Tracer.Fail("Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
                }
            }

            // Initialize our helpers
            this.managedResources = this.CreateManagedResourceManager();
            this.nativeResources = new NativeResourceManager(lcid);
            this.settings = this.CreatePackageSettings(this.ServiceProvider);
        }