Exemple #1
0
        private void getSamples()
        {
            int xx, yy, w, h, d = 0;
            this.ParentWindow.GetGeometry(out xx, out yy, out w, out h, out d);

            Console.WriteLine("w X h: {0}; {1} ",w,h);
            w = this.Allocation.Width;

            int count = w/140;
            Console.WriteLine("count "+count);
            Console.WriteLine("this.Allocation.Width "+this.Allocation.Width);

            string defaultIcon =  System.IO.Path.Combine(MainClass.Paths.ResDir,"logo96.png");
            DirectoryInfo dir = new DirectoryInfo(MainClass.Paths.SampleDir);

            LinkImageButton lbGM = new LinkImageButton();

            lbGM.Icon = defaultIcon;
            lbGM.Label =MainClass.Languages.Translate("more_sample_label");
            lbGM.LinkUrl =MainClass.Settings.SamplesBaseUrl;
            lbGM.WidthRequest = 140;

            WebButton lbOS = new WebButton();
            lbOS.Label =MainClass.Languages.Translate("open_sample_label");
            lbOS.LinkUrl =MainClass.Paths.SampleDir;

            if (!dir.Exists ){
                tblSamples.Attach(lbGM,(uint)0,(uint)1,(uint)(1),(uint)(2),AttachOptions.Fill,AttachOptions.Fill,0,0);
                tblSamples.ShowAll();
                return;
            }

            DirectoryInfo[] listdi = dir.GetDirectories("*",SearchOption.TopDirectoryOnly);

            IComparer fileComparer = new CompareDirByDate();
            Array.Sort(listdi, fileComparer);

            int no =0;
            int x = 0;
            int y = 0;

            for(int i =listdi.Length-1 ; i>-1 ; i-- ){

                DirectoryInfo di =listdi[i];

                string  zipFile = System.IO.Path.Combine(di.FullName,di.Name+".zip");
                if(!File.Exists(zipFile)) continue;

                string  pngFile = System.IO.Path.Combine(di.FullName,di.Name+".png");
                //if(!File.Exists(zipFile)) continue;
                string  txtFile = System.IO.Path.Combine(di.FullName,di.Name+".txt");

                LinkImageButton lb = new LinkImageButton();
                lb.Label = System.IO.Path.GetFileName(di.Name);

                //if (txtFile.Length > 0){
                if(File.Exists(txtFile)){
                    string descr = "";

                    try{
                        using (StreamReader file = new StreamReader(txtFile)) {
                            descr = file.ReadToEnd();
                            file.Close();
                            file.Dispose();
                        }
                    } catch (Exception ex){
                        Tool.Logger.Error(ex.Message);
                        descr = di.Name;
                    }

                    if (!String.IsNullOrEmpty(descr)){
                        descr = System.Text.RegularExpressions.Regex.Replace(descr, "<[^>]*>", string.Empty);
                        descr = descr.Replace("\r","").Replace("\n","");
                        descr = descr.Replace("&","");
                        string hover =descr;
                        if(descr.Length> 75)
                            descr = descr.Substring(0,75)+"...";
                        //lb.Description =descr;
                        lb.HoverMessage =hover;
                    }
                }

                if (pngFile.Length > 0){

                    if(File.Exists(pngFile))
                        lb.Icon =pngFile;
                    else
                        lb.Icon = defaultIcon;
                }else {
                    lb.Icon = defaultIcon;
                }

                lb.WidthRequest = 140;
                string fileName = zipFile;
                lb.Clicked+= delegate(object sender, EventArgs e) {

                    string prj = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, prj, MainClass.Languages.Translate("do_you_want_import",prj),  Gtk.MessageType.Question);
                    int result = md.ShowDialog();

                    if (result != (int)Gtk.ResponseType.Yes)
                        return ;

                    MainClass.MainWindow.ImportProject(fileName,true);
                };

                tblSamples.Attach(lb,(uint)x,(uint)(x+1),(uint)(y+1),(uint)(y+2),AttachOptions.Fill,AttachOptions.Shrink,0,0);

                no++;
                x++;
                //if(x>4){
                if(x>=count-1){
                    break;
                }

                //if (no>8) break;
            }
            tblSamples.Attach(lbGM,(uint)x,(uint)(x+1),(uint)(y+1),(uint)(y+2),AttachOptions.Fill,AttachOptions.Shrink,0,0);
            tblSamples.ShowAll();
        }
Exemple #2
0
        private void getSamples()
        {
            int xx, yy, w, h, d = 0;

            this.ParentWindow.GetGeometry(out xx, out yy, out w, out h, out d);

            Console.WriteLine("w X h: {0}; {1} ", w, h);
            w = this.Allocation.Width;

            int count = w / 140;

            Console.WriteLine("count " + count);
            Console.WriteLine("this.Allocation.Width " + this.Allocation.Width);

            string        defaultIcon = System.IO.Path.Combine(MainClass.Paths.ResDir, "logo96.png");
            DirectoryInfo dir         = new DirectoryInfo(MainClass.Paths.SampleDir);

            LinkImageButton lbGM = new LinkImageButton();

            lbGM.Icon         = defaultIcon;
            lbGM.Label        = MainClass.Languages.Translate("more_sample_label");
            lbGM.LinkUrl      = MainClass.Settings.SamplesBaseUrl;
            lbGM.WidthRequest = 140;

            WebButton lbOS = new WebButton();

            lbOS.Label   = MainClass.Languages.Translate("open_sample_label");
            lbOS.LinkUrl = MainClass.Paths.SampleDir;

            if (!dir.Exists)
            {
                tblSamples.Attach(lbGM, (uint)0, (uint)1, (uint)(1), (uint)(2), AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                tblSamples.ShowAll();
                return;
            }

            DirectoryInfo[] listdi = dir.GetDirectories("*", SearchOption.TopDirectoryOnly);

            IComparer fileComparer = new CompareDirByDate();

            Array.Sort(listdi, fileComparer);

            int no = 0;
            int x  = 0;
            int y  = 0;

            for (int i = listdi.Length - 1; i > -1; i--)
            {
                DirectoryInfo di = listdi[i];

                string zipFile = System.IO.Path.Combine(di.FullName, di.Name + ".zip");
                if (!File.Exists(zipFile))
                {
                    continue;
                }

                string pngFile = System.IO.Path.Combine(di.FullName, di.Name + ".png");
                //if(!File.Exists(zipFile)) continue;
                string txtFile = System.IO.Path.Combine(di.FullName, di.Name + ".txt");


                LinkImageButton lb = new LinkImageButton();
                lb.Label = System.IO.Path.GetFileName(di.Name);

                //if (txtFile.Length > 0){
                if (File.Exists(txtFile))
                {
                    string descr = "";

                    try{
                        using (StreamReader file = new StreamReader(txtFile)) {
                            descr = file.ReadToEnd();
                            file.Close();
                            file.Dispose();
                        }
                    } catch (Exception ex) {
                        Tool.Logger.Error(ex.Message);
                        descr = di.Name;
                    }

                    if (!String.IsNullOrEmpty(descr))
                    {
                        descr = System.Text.RegularExpressions.Regex.Replace(descr, "<[^>]*>", string.Empty);
                        descr = descr.Replace("\r", "").Replace("\n", "");
                        descr = descr.Replace("&", "");
                        string hover = descr;
                        if (descr.Length > 75)
                        {
                            descr = descr.Substring(0, 75) + "...";
                        }
                        //lb.Description =descr;
                        lb.HoverMessage = hover;
                    }
                }

                if (pngFile.Length > 0)
                {
                    if (File.Exists(pngFile))
                    {
                        lb.Icon = pngFile;
                    }
                    else
                    {
                        lb.Icon = defaultIcon;
                    }
                }
                else
                {
                    lb.Icon = defaultIcon;
                }

                lb.WidthRequest = 140;
                string fileName = zipFile;
                lb.Clicked += delegate(object sender, EventArgs e) {
                    string         prj    = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    MessageDialogs md     = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, prj, MainClass.Languages.Translate("do_you_want_import", prj), Gtk.MessageType.Question);
                    int            result = md.ShowDialog();

                    if (result != (int)Gtk.ResponseType.Yes)
                    {
                        return;
                    }

                    MainClass.MainWindow.ImportProject(fileName, true);
                };

                tblSamples.Attach(lb, (uint)x, (uint)(x + 1), (uint)(y + 1), (uint)(y + 2), AttachOptions.Fill, AttachOptions.Shrink, 0, 0);

                no++;
                x++;
                //if(x>4){
                if (x >= count - 1)
                {
                    break;
                }

                //if (no>8) break;
            }
            tblSamples.Attach(lbGM, (uint)x, (uint)(x + 1), (uint)(y + 1), (uint)(y + 2), AttachOptions.Fill, AttachOptions.Shrink, 0, 0);
            tblSamples.ShowAll();
        }