Page 1 of 1

[Solved]Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 8:23 pm
by samsam598
I would like the common dialogs for example,MessageBox has the ability to change the button text if wanted.When I use MessageBox in Chinese version windows,the MessageBox buttons are ok|cancel|no etc,however I like it be 确定|取消|否etc.So I suggest add some properties for this case:
Code: Select all
 
MessageBox{type=yesNo,yesButton.text="确定"; noButton.text="否"}.Modal();
 

something the like.

Regards,
Sam

Re: Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 9:36 pm
by jerome
Sam,

The best way would probably be to use the internationalized version of the SDK, with the Chinese translation :D We are working on this with liqi, I hope it will be ready in 1 or 2 weeks.

The MessageBox code is also quite simple. You could copy/adapt it to your own needs.

Also, you could find the children by looping through the MessageBox's child windows (i.e. a for loop using Window::firstChild and Window::next), and checking the id (they will be equal to DialogResult::cancel, yes, no, ok), and then setting their text property.

It would not be a bad idea though to export each button through properties :) Thanks! maybe you could add a Mantis feature request?

-Jerome

Re: Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 10:21 pm
by samsam598
Could you please provide a couple of lines of code to demonstrate how to iterate through child windows?I tried below code but it does not make sense to change the button's text.

Thanks for the help in advance.
Code: Select all
 
 Button button1
   {
      this, text = "button1", size = { 90, 29 }, position = { 208, 40 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Window win{};
         DialogResult result;
         MessageBox msgbox;
         msgbox=MessageBox{type=yesNo,text="caption",contents="Here is the msg"};
 
 
 
            win=msgbox.firstChild;
 
            while(win)
            {
               result=win.id;
               switch(result)
               {
                  case yes:
                     win.SetText("确定");
 
                  case no:
                     win.SetText("取消");
                     break;
                  default:break;
 
               }
               win=msgbox.next;
            }
            msgbox.Modal();
         return true;
      }
   };                           
 

Re: Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 10:50 pm
by jerome
Sam,

First be careful with using { }:

Code: Select all
Win win { }; // This is an instantiation, it creates a new window!
 
Window win; // This is a handle, it can used to point to something that exists already

The following code works. You have to be careful because the buttons get created during the creation process of the MessageBox, so I added a Create() call before going through the children. Your code was probably not compiling because you have to explicitly use the enumeration name (DialogResult) in front of the values, outside of the context yes and no have no meaning.

The extra checks for nonClient and eClass_IsDerived is to ignore the non client child windows (scrollbars, close, minimize, maximize, ...) and anything else in the dialog that is not a button (e.g. the label). We don't want to be changing the text for those, and the id might be the same our DialogResult, especially DialogResult::cancel which happens to be 0 (the default id).

Code: Select all
   Button button1
   {
      this, text = "button1", size = { 90, 29 }, position = { 208, 40 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Window win;
         DialogResult result;
         MessageBox msgBox {type=yesNo,text="caption",contents="Here is the msg"};
         msgBox.Create();
         for(win = msgBox.firstChild; win; win = win.next)
         {
            if(win.nonClient || !eClass_IsDerived(win._class, class(Button))) continue;
            switch(win.id)
            {
               case DialogResult::yes: win.text = "确定"; break;
               case DialogResult::no:  win.text = "取消"; break;
               default: break;
            }
         }
         msgBox.Modal();
         return true;
      }
   };

Cheers,

Jerome

Re: Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 11:19 pm
by samsam598
Thanks Jerome,it works now.

Things are getting more and more interesting in eC now.If I set the button text to '(Y)确定' and '(N)取消',the original hot key of button 'Yes' and 'No' still valid. :D

And just a moment ago I want to ask you how to iterate thourgh child controls in a form.I think I got a bonus :D

Re: [Solved]Dialog buttons suggestion

PostPosted: Thu Sep 08, 2011 11:41 pm
by jerome
Hi Sam,

Yes, that is how liqi did it in the internationalization! The Documentor should already have the Chinese translation activated.

Checkout the other threads, you can try it:

viewtopic.php?f=30&t=172
viewtopic.php?f=30&t=145

I still have to integrate that with the new gettext functionality. Perhaps you could help us with this?

We need to use $ in front of all strings that need to be internationalized, e.g. $"Yes" .

I've attached the latest version of the .po files that liqi gave me.
Once the strings to be internationalized are identified with the $ in front, we can use Poedit update the Po file from the generated .pot file and it will keep only those strings and discard all other strings that don't need to be translated.

There are still some issues that I want to fix by writing our own gettext implementation however, such as embedding the translation inside the executable resources, and handling multiple text domains in an application (i.e. a separate text domain for dlls than the application).

Hmm, I just learned now about 'dgettext', we could use that in the meantime until we get our own implementation! It lets you specify the domain, I'll have to tweak the compiler to support that :)

Regards,

Jerome

Re: [Solved]Dialog buttons suggestion

PostPosted: Fri Sep 09, 2011 12:04 am
by jerome
Sam,

Just for fun (because really, you should be using the proper i18n support for this kind of stuff!), here is how you could encapsulate that Chinese message box inside a class:
Code: Select all
import "ecere"
 
class CnMessageBox : MessageBox
{
   bool OnPostCreate()
   {
      if(MessageBox::OnPostCreate())
      {
         Window win;
         for(win = firstChild; win; win = win.next)
         {
            if(win.nonClient || !eClass_IsDerived(win._class, class(Button))) continue;
            switch(win.id)
            {
               case DialogResult::yes: win.text = "确定"; break;
               case DialogResult::no:  win.text = "取消"; break;
               default: break;
            }
         }
         return true;
      }
      return false;
   }
}
 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 640, 480 };
 
   Button button1
   {
      this, text = "button1", size = { 90, 29 }, position = { 208, 40 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         DialogResult result;
         CnMessageBox msgBox {type=yesNo,text="caption",contents="Here is the msg"};
         result = msgBox.Modal();
         return true;
      }
   };                           
 }
 
Form1 form1 {};

Re: [Solved]Dialog buttons suggestion

PostPosted: Fri Sep 09, 2011 12:52 am
by samsam598
That's beautiful!I once tried to do the same in other OOP GUI,it was a desaster.So this has already proved the strong flexibility of eC.Thank you!

Re: [Solved]Dialog buttons suggestion

PostPosted: Mon Sep 12, 2011 8:22 pm
by samsam598
jerome wrote:Hi Sam,

Yes, that is how liqi did it in the internationalization! The Documentor should already have the Chinese translation activated.

Checkout the other threads, you can try it:

viewtopic.php?f=30&t=172
viewtopic.php?f=30&t=145

I still have to integrate that with the new gettext functionality. Perhaps you could help us with this?


Hi Jerome,

I would like to.But don't quit understand what should I do first.Could you please clarify?Thanks a lot.

Regards,
Sam

Re: [Solved]Dialog buttons suggestion

PostPosted: Mon Sep 12, 2011 9:48 pm
by jerome
Sam,

First you could get ahold of a copy of Poedit.

You will be able to open liqi's translation (.po) files with this, and see all the strings that are translated.

Then we have to identify in the SDK every string that requires internationalization, and add a dollar sign ($) in front. You could start with sdk/ecere for example. When you build Ecere (You will need to add intl to the Linker tab's Additional Libraries for now, until we implement our own gettext support), this will then generate a ecere.pot (.po template) file in the object building directory, which you will be able to use in Poedit to update the .po file. It will delete all strings that are 'not' marked as internationalizable (No $ in front) from the .po file.

Let me know if you have any question :D You could also come on our IRC channel to chat if you need more assistance.

Thank you!

Jerome