IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Implémenter Couper,Copier,Coller, Redo, Undo (MenuCommandService)


Sujet :

C#

  1. #1
    Membre confirmé Avatar de New World
    Homme Profil pro
    Commandant croisière
    Inscrit en
    Juillet 2015
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Commandant croisière
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juillet 2015
    Messages : 132
    Par défaut Implémenter Couper,Copier,Coller, Redo, Undo (MenuCommandService)
    Bonjour,

    Nous avons besoin d'implémenter les fonctions citées dans le titre de la discussion pour notre concepteur de fenêtre.
    Les services "delete" , "centervertically" et "centerhorizontally" fonctionnent très bien.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     MenuCommandService = new Host.MenuCommandServiceImpl(_hostSurfaceManager);
                 System.ComponentModel.Design.IMenuCommandService ims = HostC.HostSurface.GetService(typeof(System.ComponentModel.Design.IMenuCommandService)) as        System.ComponentModel.Design.IMenuCommandService;
                var a = System.ComponentModel.Design.StandardCommands.Delete;
                  ims.GlobalInvoke(a);
                MenuCommandService.GlobalInvoke(a);
    Néanmoins si l'on veut utiliser les services Couper,Copier,Coller,Annuler,Rétablir : aucune réaction. BasicDesignerLoader ne semble pas prêt pour cela.

    Voici le fichier concerné directement : https://github.com/MaximLeroy/OSMake...iteurCCplus.cs

    je vais partir sur ces explications concises, je reste disponible pour toutes explications complémentaires.
    Merci

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    Citation Envoyé par New World Voir le message
    Bonjour,

    Nous avons besoin d'implémenter les fonctions citées dans le titre de la discussion pour notre concepteur de fenêtre.

    Néanmoins si l'on veut utiliser les services Couper,Copier,Coller,Annuler,Rétablir : aucune réaction. BasicDesignerLoader ne semble pas prêt pour cela.

    je vais partir sur ces explications concises, je reste disponible pour toutes explications complémentaires.
    Merci
    Ainsi "BasicDesignerLoader ne semble pas prêt pour cela". Qu'à cela ne tienne , il existe toujours un moyen de l'amener à faire amende honorable.
    Pour cela faire ceci:
    1/ Ajouter le Class suivant au projet (dossier Host) qui fait de la "serialization" à la CODEDOM:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
     
     
    using System;
    using System.Collections;
    using System.ComponentModel.Design.Serialization;
    using System.Windows.Forms;
     
    namespace Host
    {
        public class DesignerSerializationService : IDesignerSerializationService
        {
     
            IServiceProvider serviceProvider;
     
            public DesignerSerializationService(IServiceProvider serviceProvider)
            {
     
                this.serviceProvider = serviceProvider;
     
     
            }
     
            #region IDesignerSerializationService Members
     
            public System.Collections.ICollection Deserialize(object serializationData)
            {
     
                SerializationStore serializationStore = serializationData as SerializationStore;
     
                if (serializationStore != null)
                {
                    ComponentSerializationService componentSerializationService = serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
                    ICollection collection = componentSerializationService.Deserialize(serializationStore);
                    return collection;
                }
     
                return new object[0];
     
            }
     
            public object Serialize(System.Collections.ICollection objects)
            {
     
                ComponentSerializationService componentSerializationService = serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
                SerializationStore returnObject = null;
     
                using (SerializationStore serializationStore = componentSerializationService.CreateStore())
                {
                    foreach (object obj in objects)
                    {
                        if (obj is Control)
                        {
                            componentSerializationService.Serialize(serializationStore, obj);
                        }
                    }
     
                    returnObject = serializationStore;
                }
     
                return returnObject;
     
            }
     
            #endregion
        }
    }
    2/ Modifier les 2 ctors du class HostSurface (dossier Host) :
    but de l'opération : 2 services sont ajoutés à ce class HostSurface
    - le nouveau Class ci-avant et
    - class CodeDomComponentSerializationService
    comme services.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
     
    public HostSurface() : base()
            {
     
                this.AddService(typeof(IMenuCommandService), new MenuCommandService(this.ServiceContainer ));
                //You only need to do your own implementation if you want to do something special. 
                this.AddService(typeof(IDesignerSerializationService),
                    new DesignerSerializationService(this.ServiceContainer));
                this.AddService(typeof(ComponentSerializationService),
                    new CodeDomComponentSerializationService(this.ServiceContainer));
     
            }
    public HostSurface(IServiceProvider parentProvider) : base(parentProvider)
    		{
                // idem  correction
                this.AddService(typeof(IMenuCommandService), new MenuCommandService(this.ServiceContainer ));
                // Ajout : les 2 lignes de code suivantes. 
                this.AddService(typeof(IDesignerSerializationService),
                    new DesignerSerializationService(this.ServiceContainer));
                this.AddService(typeof(ComponentSerializationService),
                    new CodeDomComponentSerializationService(this.ServiceContainer));
            }
    Et tout devrait marcher sur des roulettes !!!
    bon code...

  3. #3
    Membre confirmé Avatar de New World
    Homme Profil pro
    Commandant croisière
    Inscrit en
    Juillet 2015
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Commandant croisière
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juillet 2015
    Messages : 132
    Par défaut
    Bonjour merci,
    J'ai essayé d'implémenter UndoEngine pour annuler/rétablir mais sans succès pour l'instant

    [/CODE]

    Pour la classe UndoEngineImpl
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
     
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ComponentModel.Design;
     
    namespace OSMaker.Host
    {
        public class UndoEngineImpl : UndoEngine
        {
            List<UndoEngine.UndoUnit> undoUnitList = new List<UndoUnit>();
     
            // points to the command that should be executed for Redo
            int currentPos = 0;
     
            public UndoEngineImpl(IServiceProvider provider)
                : base(provider)
            {
            }
     
            public void DoUndo()
            {
                if (currentPos > 0)
                {
                    UndoEngine.UndoUnit undoUnit = undoUnitList[currentPos - 1];
                    undoUnit.Undo();
                    currentPos--;
                }
                UpdateUndoRedoMenuCommandsStatus();
            }
     
            public void DoRedo()
            {
                if (currentPos < undoUnitList.Count)
                {
                    UndoEngine.UndoUnit undoUnit = undoUnitList[currentPos];
                    undoUnit.Undo();
                    currentPos++;
                }
                UpdateUndoRedoMenuCommandsStatus();
            }
     
            private void UpdateUndoRedoMenuCommandsStatus()
            {
                // this components maybe cached.
                MenuCommandService menuCommandService = GetService(typeof(MenuCommandService)) as MenuCommandService;
                MenuCommand undoMenuCommand = menuCommandService.FindCommand(StandardCommands.Undo);
                MenuCommand redoMenuCommand = menuCommandService.FindCommand(StandardCommands.Redo);
     
                if (undoMenuCommand != null)
                    undoMenuCommand.Enabled = currentPos > 0;
                if (redoMenuCommand != null)
                    redoMenuCommand.Enabled = currentPos < this.undoUnitList.Count;
            }
     
            protected override void AddUndoUnit(UndoEngine.UndoUnit unit)
            {
                undoUnitList.RemoveRange(currentPos, undoUnitList.Count - currentPos);
                undoUnitList.Add(unit);
                currentPos = undoUnitList.Count;
            }
     
            protected override UndoEngine.UndoUnit CreateUndoUnit(string name, bool primary)
            {
                return base.CreateUndoUnit(name, primary);
            }
     
            protected override void DiscardUndoUnit(UndoEngine.UndoUnit unit)
            {
                undoUnitList.Remove(unit);
                base.DiscardUndoUnit(unit);
            }
     
            protected override void OnUndoing(EventArgs e)
            {
                base.OnUndoing(e);
            }
     
            protected override void OnUndone(EventArgs e)
            {
                base.OnUndone(e);
            }
        }
    }

  4. #4
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    Ton implementation est bonne !! mais....mais la galere dans un Designer n'est pas finie ...
    Voici le code qui sauve ,code à rajouter, dans toujours ce diabolique class HostSurface:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    public HostSurface() : base()
            {
     
                // le bon code, mais modifie pour ajouter les event handlers suivants: 
                IMenuCommandService ims = new MenuCommandService(this.ServiceContainer);
                ims.AddCommand(new MenuCommand(new EventHandler(this.ExecuteUndo), StandardCommands.Undo));
                ims.AddCommand(new MenuCommand(new EventHandler(this.ExecuteRedo), StandardCommands.Redo));
     
                this.AddService(typeof(IMenuCommandService), ims );
     
                // Ajout : les 2 lignes de code suivantes. 
                this.AddService(typeof(IDesignerSerializationService),
                    new DesignerSerializationService(this.ServiceContainer));
                this.AddService(typeof(ComponentSerializationService),
                    new CodeDomComponentSerializationService(this.ServiceContainer));
     
                // AJOUT : UndoEngine
                UndoEngine undoEngine = new UndoEngineImpl(this.ServiceContainer);
     
                //- enable the UndoEngine
                undoEngine.Enabled =true;
                if (undoEngine != null)
                {
                    //- the UndoEngine is ready to be replaced
                    this.ServiceContainer.RemoveService(typeof(UndoEngine), false);
                    this.ServiceContainer.AddService(typeof(UndoEngine), undoEngine);
                }
     
            }
    		public HostSurface(IServiceProvider parentProvider) : base(parentProvider)
    		{
     
                IMenuCommandService ims = new MenuCommandService(this.ServiceContainer);
                ims.AddCommand(new MenuCommand(new EventHandler(this.ExecuteUndo), StandardCommands.Undo));
                ims.AddCommand(new MenuCommand(new EventHandler(this.ExecuteRedo), StandardCommands.Redo));
                this.AddService(typeof(IMenuCommandService), ims);
     
     
                this.AddService(typeof(IDesignerSerializationService),
                    new DesignerSerializationService(this.ServiceContainer));
                this.AddService(typeof(ComponentSerializationService),
                    new CodeDomComponentSerializationService(this.ServiceContainer));
                this.AddService(typeof(UndoEngine),new UndoEngineImpl(this.ServiceContainer));
     
                // AJOUT  : UndoEngine
                UndoEngine undoEngine = new UndoEngineImpl(this.ServiceContainer);
     
                //- enable the UndoEngine
                undoEngine.Enabled = true;
                if (undoEngine != null)
                {
                    //- the UndoEngine is ready to be replaced
                    this.ServiceContainer.RemoveService(typeof(UndoEngine), false);
                    this.ServiceContainer.AddService(typeof(UndoEngine), undoEngine);
                }
            }
     
     
     
            ....
            // ICI les EVENT HANDLERS
            private void ExecuteUndo(object sender, EventArgs e)
            {
     
                UndoEngineImpl undoEngine = this.GetService(typeof(UndoEngine)) as UndoEngineImpl;
     
                if (undoEngine != null)
     
                    undoEngine.DoUndo();
     
            }
     
            private void ExecuteRedo(object sender, EventArgs e)
            {
     
                UndoEngineImpl undoEngine = this.GetService(typeof(UndoEngine)) as UndoEngineImpl;
     
                if (undoEngine != null)
     
                    undoEngine.DoRedo();
     
            }
    Tu observeras que en plus de l'ajout du service UndoEngine ,il faut ajouter les commandes au Class MenuCommandService ,ce qui indique que ces 2 commandes ne sont une implementation standard dans les Designers ,sauf dans l'environnement VS.
    bon code...

  5. #5
    Membre confirmé Avatar de New World
    Homme Profil pro
    Commandant croisière
    Inscrit en
    Juillet 2015
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Commandant croisière
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juillet 2015
    Messages : 132
    Par défaut
    Je reste dans la continuité de ce sujet
    l'implémentation fonctionne maintenant merci
    Nous nous demandons comment ajouter un évènement double click à la hostsurface(?) quand il y a un double click sur un objet sélectionné dans le designer , afin d'afficher un onglet avec le code et enfin de générer dans le fichier code un évènement click SI il n'a pas déjà été généré au quel cas on se contentera de mettre le curseur en dessous la borne de début de l'évènement MouseClick de l'objet sélectionné dans le designer (même principe que le designer de visual studio).
    voici à quoi ressemble un évènement MouseClick dans notre language.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Function/ MyButton.MouseClick()
     
    // Code à executer
     
    End/ Function
    Merci

Discussions similaires

  1. Implémenter Couper,Copier et Coller
    Par momjunior dans le forum NetBeans
    Réponses: 0
    Dernier message: 15/03/2014, 22h46
  2. couper copier coller
    Par matinz dans le forum Débuter
    Réponses: 1
    Dernier message: 07/07/2009, 16h54
  3. [JTree] Couper / Copier / Coller
    Par jojodu31 dans le forum Composants
    Réponses: 5
    Dernier message: 11/06/2008, 16h15
  4. Couper, Copier, Coller d'un textarea dans IE et Firefox?
    Par Prosis dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 13/01/2008, 00h35
  5. Protéger Couper/Copier/Coller dans un Objet en développement
    Par tibi666 dans le forum Composants VCL
    Réponses: 14
    Dernier message: 06/12/2004, 14h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo