예제 #1
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();
            }
        }
예제 #2
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;
                }
            }
        }