Ejemplo n.º 1
0
 /// <summary>
 /// Most controls are data bound, however, this is not (directly) possible for the AvalonEditors.
 /// (Text is not a dependency property). Hence we need this eventhandler here to update them manually.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lstSnippets_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     lProgrammatic = true;
     if (lstSnippets.SelectedItem == null)
     {
         txtSnippetCode.Clear();
         //txtSnippetCode.IsEnabled = false;
     }
     else
     {
         SnippetsDataSet.SnippetsTableRow r = ((DataRowView)lstSnippets.SelectedItem).Row as SnippetsDataSet.SnippetsTableRow;
         if (r.IsNull(snippetsTable.SnippetCodeColumn))
         {
             txtSnippetCode.Clear();
         }
         else
         {
             txtSnippetCode.Text = r.SnippetCode;
         }
         if (r.IsNull(snippetsTable.SampleCodeColumn))
         {
             txtSampleCode.Clear();
         }
         else
         {
             txtSampleCode.Text = r.SampleCode;
         }
     }
     lProgrammatic = false;
 }
Ejemplo n.º 2
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("This will import the selected styles. There is no going back. Are you sure?", "Import", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                // step 1: import changed items
                foreach (CodeSnippet s in snippetList)
                {
                    if (s.IsSelected && s.IsAlreadyThere && s.IsChanged)
                    {
                        s.FillRow(s.tag);
                    }
                }

                // step 2: add new items
                foreach (CodeSnippet s in snippetList)
                {
                    if (s.IsSelected && !s.IsAlreadyThere)
                    {
                        SnippetsDataSet.SnippetsTableRow r = SnippTable.NewSnippetsTableRow();
                        s.FillRow(r);
                        SnippTable.Rows.Add(r);
                    }
                }

                DialogResult = true;
                Close();
            }
        }
Ejemplo n.º 3
0
 private void InsertDependenciesClick(object sender, RoutedEventArgs e)
 {
     if (lstSnippets.SelectedItem != null)
     {
         SnippetsDataSet.SnippetsTableRow r = ((DataRowView)lstSnippets.SelectedItem).Row as SnippetsDataSet.SnippetsTableRow;
         TheModel.HandleInsertDependenciesClick(r);
     }
 }
Ejemplo n.º 4
0
 private void lstSnippets_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (lstSnippets.SelectedItem != null)
     {
         SnippetsDataSet.SnippetsTableRow r = ((DataRowView)lstSnippets.SelectedItem).Row as SnippetsDataSet.SnippetsTableRow;
         TheModel.HandleMouseDoubleClick(r);
     }
 }
Ejemplo n.º 5
0
        private void cmdAddClick(object sender, RoutedEventArgs e)
        {
            SnippetsDataSet.SnippetsTableRow r = snippetsTable.NewSnippetsTableRow();
            r.Name         = "New Snippet";
            r.Category     = "Styles";
            r.Description  = "Add descriptive text here \r\nWill be displayed as tooltip";
            r.SampleCode   = "\\begin{tikzpicture}\r\n  \\draw (1,1)--(3,3);\r\n\\end{tikzpicture}";
            r.SnippetCode  = "draw";
            r.Dependencies = "";
            if (lstSnippets.SelectedItem != null)
            {
                SnippetsDataSet.SnippetsTableRow curr = ((DataRowView)(lstSnippets.SelectedItem)).Row as SnippetsDataSet.SnippetsTableRow;
                r.Category = curr.Category;

                if (sender == cmdAddClone)
                {
                    // copy settings from current snippet
                    r.Name        = curr.Name; r.Description = curr.Description; r.SampleCode = curr.SampleCode;
                    r.SnippetCode = curr.SnippetCode; r.Dependencies = curr.Dependencies;
                    if (!curr.IsEdgeStyleNull())
                    {
                        r.EdgeStyle = curr.EdgeStyle;
                    }
                    if (!curr.IsNodeStyleNull())
                    {
                        r.NodeStyle = curr.NodeStyle;
                    }
                }
            }

            snippetsTable.Rows.Add(r);
            //make sure lstsnippets is update to date (i.e. just added r is shown)
            lstSnippets.UpdateLayout();
            //now find entry in lstsnippets that corresponds to the just added row r
            foreach (DataRowView lstEntry in lstSnippets.Items)
            {
                if (lstEntry.Row == r)
                {
                    //get the expander of this entry in order to expand it.
                    Expander eee = GetExpander(lstEntry);
                    if (eee != null)
                    {
                        eee.IsExpanded = true;
                    }
                    else
                    {
                        eee = GetExpander(lstEntry);
                    }
                    //also select the just added entey.
                    lstSnippets.SelectedItem = lstEntry;
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void UseStyleButton_Click(object sender, RoutedEventArgs e)
        {
            // find row corresponding to clicked button
            object curItem = ((ListBoxItem)lstSnippets.ContainerFromElement((Button)sender)).Content;

            if (curItem != null)
            {
                SnippetsDataSet.SnippetsTableRow r = (curItem as DataRowView).Row as SnippetsDataSet.SnippetsTableRow;
                TheModel.HandleUseStyleButtonClick(r);
            }
        }
Ejemplo n.º 7
0
 public void FillRow(SnippetsDataSet.SnippetsTableRow r)
 {
     r.Name         = Name;
     r.Category     = Category;
     r.Description  = Description;
     r.SampleCode   = SampleCode;
     r.SnippetCode  = SnippetCode;
     r.EdgeStyle    = EdgeStyle;
     r.NodeStyle    = NodeStyle;
     r.Dependencies = Dependencies;
 }
Ejemplo n.º 8
0
 private void cmdDeleteClick(object sender, RoutedEventArgs e)
 {
     if (lstSnippets.SelectedIndex >= 0)
     {
         SnippetsDataSet.SnippetsTableRow curr = ((DataRowView)(lstSnippets.SelectedItem)).Row as SnippetsDataSet.SnippetsTableRow;
         if (MessageBox.Show("Do you really want to delete entry \"" + curr.Name + "\" from category \"" + curr.Category + "\"?", "Delete \"" + curr.Name + "\" from \"" + curr.Category + "\"?", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
         {
             ((DataRowView)(lstSnippets.SelectedItem)).Delete();
         }
         //snippetsDataSet.Tables["SnippetsTable"].Rows.Remove(lstSnippets.SelectedIndex);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// This method is called (in a different thread) when the Bitmap Factory has succesfully compiled a Thumbnail
 /// </summary>
 void fact_BitmapGenerated(object sender, EventArgs e)
 {
     //Dispatcher.Invoke(new Action(
     //                delegate()
     //                {
     // refresh currently selected item
     if (lstSnippets.SelectedItem != null)
     {
         SnippetsDataSet.SnippetsTableRow curr = ((DataRowView)(lstSnippets.SelectedItem)).Row as SnippetsDataSet.SnippetsTableRow;
         curr.ID = curr.ID;
     }
     //                }
     //                ));
 }
Ejemplo n.º 10
0
        public void HandleInsertDependenciesClick(SnippetsDataSet.SnippetsTableRow r)
        {
            string d = "";

            if (!r.IsNull(snippetsTable.DependenciesColumn))
            {
                d = r.Dependencies;
            }

            TheView.RaiseOnInsert(new InsertEventArgs()
            {
                code = @"\usetikzlibrary{" + d + "}" + Environment.NewLine, dependencies = d
            });
        }
Ejemplo n.º 11
0
        private void cmdCompile_Click(object sender, RoutedEventArgs e)
        {
            if (lstSnippets.SelectedItem == null)
            {
                MessageBox.Show("Select an item from snippet table on the left!");
                return;
            }

            SnippetsDataSet.SnippetsTableRow r = ((DataRowView)lstSnippets.SelectedItem).Row as SnippetsDataSet.SnippetsTableRow;
            if (!r.IsNull(snippetsTable.SampleCodeColumn))
            {
                fact.AddJob(r.SampleCode, Helper.GetSnippetsPath() + r.ID + Consts.SnippetsExtension, new Rect(0, 0, 0, 0), r.Name, true);
            }
        }
Ejemplo n.º 12
0
 private void txtSnippetCode_TextChanged(object sender, EventArgs e)
 {
     if (lstSnippets.SelectedItem != null && !lProgrammatic)
     {
         SnippetsDataSet.SnippetsTableRow r = ((DataRowView)lstSnippets.SelectedItem).Row as SnippetsDataSet.SnippetsTableRow;
         if (sender == txtSampleCode)
         {
             r.SampleCode = txtSampleCode.Text;
         }
         else if (sender == txtSnippetCode)
         {
             r.SnippetCode = txtSnippetCode.Text;
         }
     }
 }
Ejemplo n.º 13
0
        public SnippetsDataSet.SnippetsTableRow tag; // used to remember the datatable row to be changed, if applicable

        public CodeSnippet(SnippetsDataSet.SnippetsTableRow r)
        {
            Name         = r.Name;
            Category     = r.Category;
            Description  = r.Description;
            SampleCode   = r.SampleCode;
            SnippetCode  = r.SnippetCode;
            EdgeStyle    = r.IsEdgeStyleNull()?"":r.EdgeStyle;
            NodeStyle    = r.IsNodeStyleNull() ? "" : r.NodeStyle;
            Dependencies = r.Dependencies;

            IsSelected     = false;
            IsAlreadyThere = false;
            IsChanged      = false;
        }
Ejemplo n.º 14
0
        public void HandleInsertFullCodeClick(SnippetsDataSet.SnippetsTableRow r)
        {
            string c = "", d = "";

            if (!r.IsNull(snippetsTable.SampleCodeColumn))
            {
                c = r.SampleCode;
            }
            if (!r.IsNull(snippetsTable.DependenciesColumn))
            {
                d = r.Dependencies;
            }

            TheView.RaiseOnInsert(new InsertEventArgs()
            {
                code = c, dependencies = d
            });
        }
Ejemplo n.º 15
0
        public void HandleUseStyleButtonClick(SnippetsDataSet.SnippetsTableRow r)
        {
            UseStylesEventArgs args = new UseStylesEventArgs();

            if (!r.IsNull(snippetsTable.NodeStyleColumn))
            {
                args.nodestyle = r.NodeStyle;
            }
            if (!r.IsNull(snippetsTable.EdgeStyleColumn))
            {
                args.edgestyle = r.EdgeStyle;
            }
            if (!r.IsNull(snippetsTable.DependenciesColumn))
            {
                args.dependencies = r.Dependencies;
            }
            args.InAddition = System.Windows.Forms.Control.ModifierKeys.HasFlag(Keys.Control);

            TheView.RaiseOnUseStyle(args);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Finds items in the current snippet list that are already there in the
        /// current snippet database and marks them as such.
        /// Note: duplicates based on category+name
        /// </summary>
        void FindDuplicates()
        {
            foreach (CodeSnippet s in snippetList)
            {
                SnippetsDataSet.SnippetsTableRow r = SnippTable.Cast <SnippetsDataSet.SnippetsTableRow>().FirstOrDefault(rr => rr.Category == s.Category && rr.Name == s.Name);
                if (r != null)
                {
                    s.IsAlreadyThere = true;
                    s.tag            = r;

                    // Check if changed
                    s.IsChanged = !(
                        StrCompare(s.Description, (r.IsNull(SnippTable.DescriptionColumn) ? null : r.Description)) &&
                        StrCompare(s.SnippetCode, (r.IsNull(SnippTable.SnippetCodeColumn) ? null : r.SnippetCode)) &&
                        StrCompare(s.SampleCode, (r.IsNull(SnippTable.SampleCodeColumn) ? null : r.SampleCode)) &&
                        StrCompare(s.NodeStyle, (r.IsNull(SnippTable.NodeStyleColumn) ? null : r.NodeStyle)) &&
                        StrCompare(s.EdgeStyle, (r.IsNull(SnippTable.EdgeStyleColumn) ? null : r.EdgeStyle)) &&
                        StrCompare(s.Dependencies, (r.IsNull(SnippTable.DependenciesColumn) ? null : r.Dependencies)));
                }
            }
        }
Ejemplo n.º 17
0
        public void HandleInsertAsTikzStyleClick(SnippetsDataSet.SnippetsTableRow r)
        {
            string toinsert = "", dependencies = "";

            if (!r.IsNull(snippetsTable.NodeStyleColumn) && !(r.NodeStyle.Trim() == ""))
            {
                toinsert += "\\tikzstyle{mynodestyle} = [" + r.NodeStyle + "]" + Environment.NewLine;
            }
            if (!r.IsNull(snippetsTable.EdgeStyleColumn) && !(r.EdgeStyle.Trim() == ""))
            {
                toinsert += "\\tikzstyle{myedgestyle} = [" + r.EdgeStyle + "]" + Environment.NewLine;
            }
            if (!r.IsNull(snippetsTable.DependenciesColumn))
            {
                dependencies = r.Dependencies;
            }

            TheView.RaiseOnInsert(new InsertEventArgs()
            {
                code = toinsert, dependencies = dependencies
            });
        }