Advertisement
thebys

DSDCG - Mainform code-behind beta

Feb 10th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.31 KB | None | 0 0
  1. using DSDCG.Models;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Input;
  6. using System.Windows.Media;
  7. using System.IO;
  8. using System.Threading;
  9. using DSDCG.Workers;
  10. using Ionic.Zip;
  11. using DSDCG.Views;
  12.  
  13.  
  14. namespace DSDCG
  15. {
  16.     /// <summary>
  17.     /// Interaction logic for MainWindow.xaml
  18.     /// </summary>
  19.     public partial class MainWindow : Window
  20.     {
  21.         public MediaItem _activeItem;
  22.         public Container _activeContainer;
  23.         public Container Storyboard;
  24.         public int currentCID = 1; //storyboard má 1, další kontejnery maj 2 a furt nahoru...
  25.         public int currentMID = 1; //není žádný rootitem takže první přidělujeme jedničku...
  26.         public MainWindow()
  27.         {
  28.             InitializeComponent();
  29.             Storyboard = new Container(currentCID, "Storyboard", new TimeSpan(0, 0, 0));
  30.             currentCID++;
  31.             _activeContainer = Storyboard;
  32.             currentCID++;
  33.             LoadActiveContainer(_activeContainer);
  34.             this.Storygrid.Children.Add(DrawSomething(Storyboard)); //vykreslíme /root kontejner
  35.         }
  36.  
  37.         #region obsluha formu
  38.         private void Button_Click_1(object sender, RoutedEventArgs e) //opensinglefiledialog
  39.         {
  40.             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  41.             dlg.Filter = "soubory obrázků |*.jpg;*.jpeg;*.png;*.bmp;*.gif|soubory videa |*.avi;*.mp4;*.mkv;*.wmv"; // Filter files by extension
  42.             Nullable<bool> result = dlg.ShowDialog();
  43.  
  44.             // Process open file dialog box results
  45.             if (result == true)
  46.             {
  47.                 if (System.IO.File.Exists(dlg.FileName))
  48.                 {
  49.                     FileInfo fi = new FileInfo(dlg.FileName);
  50.                     insertNewItem(dlg.FileName, fi.Name, false);
  51.                 }
  52.             }
  53.         }
  54.         private void AddRemoteContentButton_Click(object sender, RoutedEventArgs e) //inser remote content to storyboard button handler...
  55.         {
  56.             Prompt urlprompt = new Prompt();
  57.             string url = urlprompt.ShowDialog("Zadejte URL:", "Vložte URL adresu vzdáleného souboru");
  58.             if (url != string.Empty || url.Length < 6)
  59.             {
  60.                 string[] fullpath = url.Split('/');
  61.                 insertNewItem(url, fullpath[fullpath.Length - 1], true);
  62.             }
  63.             else
  64.             {
  65.                 MessageBox.Show("Zadejte prosím validní adresu souboru");
  66.             }
  67.         }
  68.         private void SaveStoryboardButton_Click(object sender, RoutedEventArgs e)//savefiledialog - pouze ukládá storyboard.xml nekonsoliduje...
  69.         {
  70.             Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  71.             dlg.Filter = "Nekonsolidovaný storyboard |*.sb"; // Filter files by extension
  72.             Nullable<bool> result = dlg.ShowDialog();
  73.             if (result == true)
  74.             {
  75.                 //budeme muset konsolidovat zdroje... řešit složky...
  76.                 //a všechno to správně seserializovat a uložit a zabalit a udělat reverzní operace...
  77.                 Serializer serializer1 = new Serializer();
  78.                 //ask about saving changes maybe?
  79.                 serializer1.SerializeStoryboard(Storyboard, dlg.FileName, false, dlg.SafeFileName);
  80.             }
  81.  
  82.         }
  83.         private void LoadStoryboardButton_Click(object sender, RoutedEventArgs e)//openfiledialog - načítá pouze nekonsolidované kampaně
  84.         {
  85.             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  86.             dlg.Filter = "Nekonsolidovaný storyboard |*.sb"; // Filter files by extension
  87.             Nullable<bool> result = dlg.ShowDialog();
  88.             if (result == true)
  89.             {
  90.                 Serializer serializer1 = new Serializer();
  91.                 //ask about saving changes maybe?
  92.                 Storyboard = serializer1.DeserializeStoryboard(dlg.FileName);
  93.                 //a překreslíme:
  94.                 redraw();
  95.             }
  96.         }
  97.         private void ExportButton_Click_1(object sender, RoutedEventArgs e)//konsoliduje soubory a tím finalizuje storyboard k přehrávání.
  98.         {
  99.             string boardroot;
  100.             Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  101.             dlg.Filter = "Konsolidovaný storyboard |*.ksb"; // Filter files by extension
  102.             Nullable<bool> result = dlg.ShowDialog();
  103.             if (result == true)
  104.             {
  105.                 boardroot = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dlg.FileName));
  106.                 //budeme muset konsolidovat zdroje... řešit složky...
  107.                 //a všechno to správně seserializovat a uložit a zabalit a udělat reverzní operace...
  108.                 Konsolidator konsolidator1 = new Konsolidator();
  109.                 Serializer serializer1 = new Serializer();
  110.                 //ask about saving changes maybe?
  111.                 konsolidator1.ConsolidateStoryboard(Storyboard, boardroot);
  112.                 serializer1.SerializeStoryboard(Storyboard, boardroot, true, dlg.SafeFileName);
  113.                 //zazipovat do jednoho souboru, abychom to pak mohli odeslat
  114.                 try
  115.                 {
  116.                     using (ZipFile zip = new ZipFile())
  117.                     {
  118.                         zip.AddDirectory(System.IO.Path.Combine(boardroot, Storyboard.name));
  119.                         zip.Comment = "Tohle je konsolidovaný a zazipovaný storyboard určený k přenosu do přehrávače. Vytvořeno: " + System.DateTime.Now.ToString("G");
  120.                         zip.Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dlg.FileName), Storyboard.name) + ".ksb");
  121.                     }
  122.                 }
  123.                 catch (Exception)
  124.                 {
  125.                     MessageBox.Show("Nastala chyba při exportu storyboardu");
  126.                 }
  127.  
  128.             }
  129.         }
  130.         private void saveitembutton_Click(object sender, RoutedEventArgs e)
  131.         {
  132.             SaveActiveItem();
  133.             redraw();
  134.         } //uloží změny z formu do activeitemu
  135.         private void discarditemchangesbutton_Click(object sender, RoutedEventArgs e)
  136.         {
  137.             LoadActiveItem(_activeItem);
  138.         } //odmaže změny - vrátí co je v _activeitemu
  139.         private void discardcontainerchanges_Click(object sender, RoutedEventArgs e)
  140.         {
  141.             LoadActiveContainer(_activeContainer);
  142.         } //odmaže změny - vrátí co je v activecontaineru
  143.         private void DeleteActiveItemButton_Click(object sender, RoutedEventArgs e)//smaže aktivní item
  144.         {
  145.             DeleteItem(_activeItem);
  146.             redraw();
  147.         }
  148.         private void savecontainer_Click(object sender, RoutedEventArgs e)//uloží změny z formuláře do aktivního kontejneru
  149.         {
  150.             SaveActiveContainer();
  151.             redraw();
  152.         }
  153.         private void addtocontainer_Click(object sender, RoutedEventArgs e)
  154.         {
  155.             //changedvalues keep/discard dialog here...
  156.             _activeContainer.mediaItems.Add(new MediaItem(_activeItem.MID, _activeItem.name, _activeItem.filepath, _activeItem.type.Value, _activeItem.title, _activeItem.text, _activeItem.duration, _activeItem.absolutepath));
  157.             //a překreslíme:
  158.             redraw();
  159.         } //přidá do aktivního kontejneru aktivní media item...
  160.         private void CreateInActiveButton_Click(object sender, RoutedEventArgs e)
  161.         {
  162.             Container newcont = new Container();
  163.             newcont.name = this.containername.Text;
  164.             newcont.cid = currentCID;
  165.             currentCID++;
  166.             newcont.repeatCount = Convert.ToInt32(repeattxtNum.Text);
  167.             newcont.randomToSelect = Convert.ToInt32(randomtxtNum2.Text);
  168.             newcont.random = randomCheckbox.IsChecked.Value;
  169.             try
  170.             {
  171.                 newcont.duration = TimeSpan.Parse(this.containerduration.Text);
  172.                 _activeContainer.containers.Add(newcont);
  173.             }
  174.             catch
  175.             {
  176.                 MessageBox.Show("Čas se nepodařilo rozparsovat, uveďte jej prosím ve správném formátu");
  177.                 LoadActiveContainer(newcont);
  178.             }
  179.             finally { redraw(); }
  180.  
  181.         } //vytvoří z dat ve formu kontejner do aktivního kontejneru
  182.         private void DeleteActiveContainer_Click(object sender, RoutedEventArgs e)
  183.         {
  184.             DeleteContainer(_activeContainer.cid);
  185.             redraw();
  186.         } //odmaže aktivní kontejner a všechny subkontejnery
  187.  
  188.         private void repeatcountUp_Click(object sender, RoutedEventArgs e) //repeatcount +1 button
  189.         {
  190.             repeattxtNum.Text = (Convert.ToInt32(repeattxtNum.Text) + 1).ToString();
  191.         }
  192.         private void repeatcountDown_Click(object sender, RoutedEventArgs e) //repeatcount -1 button
  193.         {
  194.             repeattxtNum.Text = (Convert.ToInt32(repeattxtNum.Text) - 1).ToString();
  195.         }
  196.         private void randomcountUp_Click(object sender, RoutedEventArgs e) //randomcount +1 button
  197.         {
  198.             randomtxtNum2.Text = (Convert.ToInt32(randomtxtNum2.Text) + 1).ToString();
  199.         }
  200.         private void randomcountDown_Click(object sender, RoutedEventArgs e) //randomcount -1 button
  201.         {
  202.             randomtxtNum2.Text = (Convert.ToInt32(randomtxtNum2.Text) - 1).ToString();
  203.         }
  204.  
  205.         private void redrawButton_Click(object sender, RoutedEventArgs e)
  206.         {
  207.             redraw();
  208.         } //znovuvykreslovací tlačítko boardu.
  209.         void itembtn_Click(object sender, RoutedEventArgs e)
  210.         {
  211.             ItemButton clickeditem = sender as ItemButton;
  212.             _activeItem = clickeditem.RelatedMediaItem;
  213.             LoadActiveItem(_activeItem);
  214.         } //co se stane když někdo klikne na mediaitembutton
  215.         void congrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  216.         {
  217.             e.Handled = true;
  218.             BoardGrid contgrid = new BoardGrid();
  219.             contgrid = sender as BoardGrid;
  220.             contgrid.RelatedContainer.contbrush = contgrid.Background;
  221.             _activeContainer = contgrid.RelatedContainer;
  222.             LoadActiveContainer(contgrid.RelatedContainer);
  223.         } //selektor kontejnerů na kliknutí...
  224.  
  225.         private void exit_Click(object sender, RoutedEventArgs e)
  226.         {
  227.             Application.Current.Shutdown();
  228.         } //exitovací tlačítko :)
  229.         #endregion
  230.  
  231.         #region methods
  232.         public void redraw() //znovuvykreslovací metoda storyboardu...
  233.         {
  234.             Storygrid.Children.Clear();
  235.             this.Storygrid.Children.Add(DrawSomething(Storyboard));
  236.         }
  237.  
  238.         public void insertNewItem(string Filepath, string Filename, bool KeepAbsolutePath)
  239.         {
  240.             MediaItemType newitemtype = MediaItemType.text;
  241.             if (!KeepAbsolutePath)
  242.             {
  243.                 FileInfo fi = new FileInfo(Filepath);
  244.                 string ext = fi.Extension;
  245.                 ext = ext.ToLower();
  246.                 if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".gif")
  247.                 {
  248.                     newitemtype = MediaItemType.image;
  249.                     _activeItem = new MediaItem(currentMID, Filename, System.IO.Path.GetDirectoryName(Filepath), newitemtype, string.Empty, string.Empty, new TimeSpan(0, 0, 10), KeepAbsolutePath);
  250.                 }
  251.                 else if (ext == ".avi" || ext == ".mp4" || ext == ".mkv" || ext == ".wmv")
  252.                 {
  253.                     newitemtype = MediaItemType.video;
  254.                     //determine length by using shell32 COM object on videofile... It gets the same value as users can see in windows explorer
  255.  
  256.                     Shell32.Shell shell = new Shell32.Shell();
  257.                     Shell32.Folder objFolder;
  258.                     objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(Filepath));
  259.                     object objFolderItem = objFolder.ParseName(Filename);
  260.                     _activeItem = new MediaItem(currentMID, Filename, System.IO.Path.GetDirectoryName(Filepath), newitemtype, string.Empty, string.Empty, TimeSpan.Parse(objFolder.GetDetailsOf(objFolderItem, 27)), KeepAbsolutePath);
  261.                 }
  262.                 else if (ext == ".swf")
  263.                 {
  264.                     _activeItem = new MediaItem(currentMID, Filename, System.IO.Path.GetDirectoryName(Filepath), MediaItemType.swf, new TimeSpan(0, 0, 0, 0), KeepAbsolutePath);
  265.                 }
  266.                 else
  267.                 {
  268.                     MessageBox.Show("Zadaný parametr: \"" + filepath + "\" Není podporován.");
  269.                 }
  270.             }
  271.             else
  272.             {
  273.                 if (Filename.ToLower().EndsWith(".swf"))
  274.                 {
  275.                     _activeItem = new MediaItem(currentMID, Filename, Filepath, MediaItemType.swf, new TimeSpan(0, 0, 0, 0), KeepAbsolutePath);
  276.                 }
  277.                 else
  278.                 {
  279.                     MessageBox.Show("Zadaný parametr: \"" + Filename + "\" Není podporován.");
  280.                 }
  281.             }
  282.  
  283.  
  284.             currentMID++;
  285.             LoadActiveItem(_activeItem);
  286.             redraw();
  287.  
  288.  
  289.         }
  290.  
  291.  
  292.         private void LoadActiveItem(MediaItem ItemToBeLoaded) //načte _activeitem do formu...
  293.         {
  294.             this.filename.Text = ItemToBeLoaded.name;
  295.             this.filepath.Text = ItemToBeLoaded.filepath;
  296.             this.filepath.ToolTip = ItemToBeLoaded.filepath;
  297.             this.filetype.SelectedItem = ItemToBeLoaded.type;
  298.             try
  299.             {
  300.                 this.title.Text = _activeItem.title;
  301.             }
  302.             catch (Exception)
  303.             {
  304.                 this.title.Text = string.Empty;
  305.             }
  306.             try
  307.             {
  308.                 this.text.Text = _activeItem.text;
  309.             }
  310.             catch (Exception)
  311.             {
  312.                 this.text.Text = string.Empty;
  313.             }
  314.             try
  315.             {
  316.                 if (_activeItem.type == MediaItemType.video)
  317.                 {
  318.                     this.duration.IsEnabled = false;
  319.                     this.duration.Text = _activeItem.duration.ToString();
  320.                 }
  321.                 else
  322.                 {
  323.                     this.duration.IsEnabled = true;
  324.                     this.duration.Text = _activeItem.duration.ToString();
  325.                 }
  326.             }
  327.             catch (Exception)
  328.             {
  329.                 this.duration.Text = new TimeSpan(0, 13, 37).ToString();
  330.             }
  331.         }
  332.         private void SaveActiveItem() //savne data z formu do _activeitem
  333.         {
  334.             _activeItem.name = this.filename.Text;
  335.             _activeItem.filepath = this.filepath.Text;
  336.             _activeItem.type = (MediaItemType)this.filetype.SelectedItem;
  337.             _activeItem.title = this.title.Text;
  338.             _activeItem.text = this.text.Text;
  339.             try
  340.             {
  341.                 _activeItem.duration = TimeSpan.Parse(this.duration.Text);
  342.             }
  343.             catch
  344.             {
  345.                 MessageBox.Show("Čas se nepodařilo rozparsovat, uveďte jej prosím ve správném formátu");
  346.                 LoadActiveItem(_activeItem);
  347.             }
  348.         }
  349.         private void LoadActiveContainer(Container ContainerToBeLoaded) //načte _activecontainer do formu
  350.         {
  351.             this.containername.Text = ContainerToBeLoaded.name;
  352.             this.ActiveContainerNameLabel.Content = ContainerToBeLoaded.name;
  353.             try
  354.             {
  355.                 this.repeattxtNum.Text = ContainerToBeLoaded.repeatCount.ToString();
  356.                 this.randomtxtNum2.Text = ContainerToBeLoaded.randomToSelect.ToString();
  357.                 if (ContainerToBeLoaded.repeatCount != 1)
  358.                 {
  359.                     randomCheckbox.IsChecked = true;
  360.                 }
  361.                 else
  362.                 {
  363.                     randomCheckbox.IsChecked = false;
  364.                 }
  365.             }
  366.             catch
  367.             {
  368.             }
  369.             if (ContainerToBeLoaded.contbrush != null)
  370.             {
  371.                 ActiveContainerBorder.BorderBrush = ContainerToBeLoaded.contbrush;
  372.             }
  373.             else
  374.             {
  375.                 ActiveContainerBorder.BorderBrush = Brushes.Transparent;
  376.             }
  377.             if (_activeContainer.duration != null)
  378.             {
  379.                 this.containerduration.Text = _activeContainer.duration.ToString();
  380.             }
  381.             if (_activeContainer.duration == null)
  382.             {
  383.                 this.containerduration.Text = new TimeSpan(0, 0, 5).ToString();
  384.             }
  385.         }
  386.         private void SaveActiveContainer() //načte data z formu do _activecontainer
  387.         {
  388.             _activeContainer.name = this.containername.Text;
  389.  
  390.  
  391.             try
  392.             {
  393.                 _activeContainer.repeatCount = Convert.ToInt32(repeattxtNum.Text);
  394.                 _activeContainer.randomToSelect = Convert.ToInt32(randomtxtNum2.Text);
  395.                 _activeContainer.random = randomCheckbox.IsChecked.Value;
  396.                 _activeContainer.duration = TimeSpan.Parse(this.containerduration.Text);
  397.             }
  398.             catch
  399.             {
  400.                 MessageBox.Show("Nastala chyba při interpretaci dat z formuláře, uveďte je prosím ve správném formátu");
  401.                 LoadActiveContainer(_activeContainer);
  402.             }
  403.         }
  404.         private void UpdateContainer(int cid, Container newcont) //první část rekurzivního procházení kontejnerů...
  405.         {
  406.             if (cid == 1)
  407.             {
  408.                 Storyboard = newcont;
  409.             }
  410.             else
  411.             {
  412.                 Container ContainerToUpdate = new Container();
  413.                 ContainerToUpdate = searchContainerByID(cid, Storyboard, false);
  414.                 if (ContainerToUpdate != null || ContainerToUpdate.cid != 0)
  415.                 {
  416.                     ContainerToUpdate = newcont;
  417.                 }
  418.             }
  419.  
  420.  
  421.         }
  422.         private Container searchContainerByID(int cid, Container startcont, bool returnParent) //rekurzivní procházecí funkce kontejnerů, používám ji abych mohl editovat storyboard
  423.         {
  424.             //Storyboard.containers.Find(delegate(Container c) { return c.cid == cid; }); alternativní vyhledávací metoda
  425.             //takhle to nefunguje, nedokáže to smazat některý kontejnery
  426.             Container foundcont = new Container();
  427.             if (!returnParent)
  428.             {
  429.                 if (startcont.cid == cid)
  430.                 {
  431.                     return startcont;
  432.                 }
  433.                 else
  434.                 {
  435.                     foreach (Container cont in startcont.containers)
  436.                     {
  437.                         if (cont.cid == cid)
  438.                         {
  439.                             foundcont = cont;
  440.                         }
  441.                         else
  442.                         {
  443.                             searchContainerByID(cid, cont, returnParent);
  444.                         }
  445.                         return foundcont;
  446.                     }
  447.                     return foundcont;
  448.                 }
  449.             }
  450.             else
  451.             {
  452.                 foreach (Container cont in startcont.containers)
  453.                 {
  454.  
  455.                     if (cont.cid == cid)
  456.                     {
  457.                         return startcont;
  458.                     }
  459.                     else
  460.                     {
  461.                         return (searchContainerByID(cid, cont, true));
  462.                     }
  463.                 }
  464.                 return null;
  465.             }
  466.  
  467.  
  468.         }
  469.         private Container searchContainerByMID(int MID, Container startcont) //najde kontejner obsahující MID
  470.         {
  471.             if (startcont.mediaItems.Find(delegate(MediaItem item)
  472.             {
  473.                 return item.MID == MID;
  474.             }) != null)
  475.             {
  476.                 return startcont;
  477.             }
  478.             else
  479.             {
  480.                 foreach (Container cont in startcont.containers)
  481.                 {
  482.                     return searchContainerByMID(MID, cont);
  483.                 }
  484.             }
  485.             return null;
  486.         }
  487.         public TextBlock GenerateGridTextBlock(string text, int fontsize, Thickness paddingThickness, int row, int col)
  488.         {
  489.             TextBlock newblock = new TextBlock();
  490.             newblock.Text = text;
  491.             newblock.FontSize = fontsize;
  492.             newblock.Padding = paddingThickness;
  493.             Grid.SetRow(newblock, row);
  494.             Grid.SetColumn(newblock, col);
  495.             return newblock;
  496.         } //šikovná věcička, ušetřila mi spoustu řádků textblocků
  497.         private Brush PickRandomBrush()
  498.         {
  499.             Brush[] AcceptableColors = new Brush[4] { Brushes.Wheat, Brushes.LimeGreen, Brushes.LightGray, Brushes.Ivory };
  500.             Brush result = Brushes.Transparent;
  501.             Thread.Sleep(3);
  502.             Random rnd = new Random();
  503.             int random = rnd.Next(AcceptableColors.Length);
  504.             result = AcceptableColors[random];
  505.             return result;
  506.         }//funkce nějakýho toníka ze stackoverflow, mrknout na credits "pickbrush()"
  507.         public Border DrawSomething(Container CTD)
  508.         {
  509.             Border br1 = new Border();
  510.             br1.BorderBrush = Brushes.Black;
  511.             br1.BorderThickness = new Thickness(1);
  512.             br1.Padding = new Thickness(1);
  513.  
  514.             Border br2 = new Border();
  515.             br2.BorderBrush = PickRandomBrush();
  516.             br2.BorderThickness = new Thickness(1);
  517.             br2.Padding = new Thickness(1);
  518.  
  519.             BoardGrid congrid = new BoardGrid();
  520.             congrid.RelatedContainer = CTD;
  521.             congrid.Background = PickRandomBrush();
  522.             congrid.HorizontalAlignment = HorizontalAlignment.Left;
  523.             congrid.VerticalAlignment = VerticalAlignment.Center;
  524.             congrid.HorizontalAlignment = HorizontalAlignment.Right;
  525.             congrid.ShowGridLines = false;
  526.             congrid.MouseLeftButtonDown += congrid_MouseLeftButtonDown;
  527.  
  528.             ColumnDefinition gridCol1 = new ColumnDefinition();
  529.             gridCol1.Width = new GridLength();
  530.             ColumnDefinition gridCol2 = new ColumnDefinition();
  531.             gridCol2.Width = new GridLength();
  532.             RowDefinition gridRow1 = new RowDefinition();
  533.             gridRow1.Height = new GridLength();
  534.             RowDefinition gridRow2 = new RowDefinition();
  535.             gridRow2.Height = new GridLength();
  536.             RowDefinition gridRow3 = new RowDefinition();
  537.             gridRow3.Height = new GridLength();
  538.             RowDefinition gridRow4 = new RowDefinition();
  539.             gridRow4.Height = new GridLength();
  540.  
  541.             for (int z = 0; z < CTD.containers.Count; z++)
  542.             {
  543.                 RowDefinition rowDef1 = new RowDefinition();
  544.                 rowDef1.Height = new GridLength();
  545.                 congrid.RowDefinitions.Add(rowDef1);
  546.             }
  547.  
  548.             WrapPanel mediapanel = new WrapPanel();
  549.             mediapanel.MaxWidth = 600;
  550.             //vyřešit situace kdy je v jednom kontejneru shitloads of items... vypadá to hnusně! TICK = wrappanel
  551.             mediapanel.Orientation = Orientation.Horizontal;
  552.             Grid.SetRow(mediapanel, 3);
  553.             Grid.SetColumn(mediapanel, 1);
  554.             foreach (MediaItem item in CTD.mediaItems)
  555.             {
  556.                 ItemButton itembtn = new ItemButton(item);
  557.                 itembtn.Click += itembtn_Click;
  558.                 mediapanel.Children.Add(itembtn);
  559.             }
  560.  
  561.             WrapPanel contwrap = new WrapPanel();
  562.             contwrap.MaxWidth = this.Width - 80; //this is responsible for "wrapping" the child containers... //tohle ještě snese testování, ten wrapping pořád není úplně dokonalej... chtělo by to nastavit minimální velikost okna //TODO !
  563.             Grid.SetColumn(contwrap, 0);
  564.             Grid.SetRow(contwrap, 4);
  565.             foreach (Container container in CTD.containers)
  566.             {
  567.                 contwrap.Children.Add(DrawSomething(container));
  568.             }
  569.             congrid.Children.Add(contwrap);
  570.  
  571.             congrid.Children.Add(GenerateGridTextBlock("Jméno kontejneru", 14, new Thickness(2), 0, 0));
  572.             congrid.Children.Add(GenerateGridTextBlock("Chování kontejneru", 14, new Thickness(2), 1, 0));
  573.             congrid.Children.Add(GenerateGridTextBlock("Trvání kontejneru", 14, new Thickness(2), 2, 0));
  574.             congrid.Children.Add(GenerateGridTextBlock("Mediální položky", 14, new Thickness(2), 3, 0));
  575.             congrid.Children.Add(GenerateGridTextBlock(CTD.name, 14, new Thickness(2), 0, 1));
  576.             string behaviour = string.Empty;
  577.             try
  578.             {
  579.                 // behaviour = CTD.behaviour.ToString();
  580.                 if (CTD.random == false && CTD.repeatCount == 1)
  581.                 {
  582.                     behaviour = "Sekvence";
  583.                 }
  584.                 else if (CTD.random == true && CTD.randomToSelect == 1)
  585.                 {
  586.                     behaviour = "Náhodná položka";
  587.                 }
  588.                 else if (CTD.random == true && CTD.randomToSelect > 1)
  589.                 {
  590.                     behaviour = "Náhodné položky(" + CTD.randomToSelect.ToString() + ")";
  591.                 }
  592.                 else
  593.                 {
  594.                     behaviour = "Uživatelské...";
  595.                 }
  596.             }
  597.             catch (Exception)
  598.             {
  599.                 behaviour = "######";
  600.             }
  601.             finally
  602.             {
  603.                 congrid.Children.Add(GenerateGridTextBlock(behaviour, 14, new Thickness(2), 1, 1));
  604.             }
  605.             congrid.Children.Add(GenerateGridTextBlock(CTD.duration.ToString(), 14, new Thickness(2), 2, 1));
  606.             congrid.Children.Add(mediapanel);
  607.             congrid.ColumnDefinitions.Add(gridCol1);
  608.             congrid.ColumnDefinitions.Add(gridCol2);
  609.             congrid.RowDefinitions.Add(gridRow1);
  610.             congrid.RowDefinitions.Add(gridRow2);
  611.             congrid.RowDefinitions.Add(gridRow3);
  612.             congrid.RowDefinitions.Add(gridRow4);
  613.             br1.Child = congrid;
  614.             br2.Child = br1;
  615.             br2.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
  616.             br2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  617.  
  618.             return br2;
  619.         } //vykreslovací srdce všeho... rekurzivně vykresluje kontejnery od storyboardu dolu...
  620.         private void DeleteItem(MediaItem ItemToDelete) //smaže item s daným MID
  621.         {
  622.             try
  623.             {
  624.                 Container Parentcont = searchContainerByMID(ItemToDelete.MID, Storyboard);
  625.                 try
  626.                 {
  627.                     Parentcont.mediaItems.Remove(ItemToDelete);
  628.                     Storygrid.Children.Clear();
  629.                     //(re)draw storyboard
  630.                     this.Storygrid.Children.Add(DrawSomething(Storyboard));
  631.                 }
  632.                 catch (NullReferenceException)
  633.                 {
  634.                     MessageBox.Show("Položku se nepodařilo smazat, možná už je smazaná...");
  635.                 }
  636.             }
  637.             catch (NullReferenceException)
  638.             {
  639.  
  640.             }
  641.  
  642.  
  643.  
  644.         }
  645.         private void DeleteContainer(int cid)//odmaže kontejner s daným CID
  646.         {
  647.             if (cid != 1)
  648.             {
  649.                 Container contToDelete = searchContainerByID(cid, Storyboard, false);
  650.                 Container parentcont = searchContainerByID(cid, Storyboard, true);
  651.                 try
  652.                 {
  653.                     parentcont.containers.Remove(contToDelete);
  654.                     Storygrid.Children.Clear();
  655.                     //(re)draw storyboard
  656.                     this.Storygrid.Children.Add(DrawSomething(Storyboard));
  657.                 }
  658.                 catch (NullReferenceException)
  659.                 {
  660.                     MessageBox.Show("kontejner ke samazání se nepodařilo nalézt...");
  661.                 }
  662.             }
  663.             else
  664.             {
  665.                 MessageBox.Show("Storyboard nelze smazat, vytvořte si nový projekt");
  666.             }
  667.         }
  668.         #endregion
  669.  
  670.  
  671.  
  672.     }
  673. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement