Exemplo n.º 1
0
        static void OnDisplayItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ScriptletItem me  = sender as ScriptletItem;
            string        wrk = me.DisplayItem;

            if (!me.DisplayItem.Contains('.'))
            {
                wrk = wrk + ".xml";
            }

            FileInfo source = new FileInfo(me.Filename);
            FileInfo target = new FileInfo(Path.Combine(source.DirectoryName, wrk));

            if (e.OldValue != null)
            {
                source.CopyTo(target.FullName);
            }
            if (!me.IsUpdating)
            {
                me.IsUpdating = true;
                me.Filename   = target.FullName;
                me.IsUpdating = false;
            }
            me.EnableEdit = false;
        }
        static void OnSelectedScriptChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ScriptletItem item = e.OldValue as ScriptletItem;

            if (item != null)
            {
                item.FirstClick = false;
                item.EnableEdit = false;
            }
        }
        private void Rename_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            if (mnu != null)
            {
                ScriptletItem item = mnu.CommandParameter as ScriptletItem;
                item.EnableEdit = true;
            }
        }
        //void LoadCommandBindings()
        //{

        //    CommandBinding cmd = new CommandBinding(EditingCommands.ToggleInsert, new ExecutedRoutedEventHandler(DoInsert));
        //    cmd.CanExecute += new CanExecuteRoutedEventHandler(cmd_CanExecute);

        //    this.CommandBindings.Add(cmd);


        //    cmd = new CommandBinding(EditingCommands.CorrectSpellingError, new ExecutedRoutedEventHandler(DoEdit));
        //    cmd.CanExecute += new CanExecuteRoutedEventHandler(cmd_CanExecute);

        //    this.CommandBindings.Add(cmd);



        //    cmd = new CommandBinding(EditingCommands.Delete, new ExecutedRoutedEventHandler(DoDelete));
        //    cmd.CanExecute += new CanExecuteRoutedEventHandler(cmd_CanExecute);

        //    this.CommandBindings.Add(cmd);



        //    cmd = new CommandBinding(EditingCommands.ToggleUnderline, new ExecutedRoutedEventHandler(DoRename));
        //    cmd.CanExecute += new CanExecuteRoutedEventHandler(cmd_CanExecute);

        //    this.CommandBindings.Add(cmd);
        //}


        private void Insert_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            if (mnu != null)
            {
                ScriptletItem item = mnu.CommandParameter as ScriptletItem;
                Editor.InsertFile(item.Filename);
            }
        }
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            if (mnu != null)
            {
                ScriptletItem item = mnu.CommandParameter as ScriptletItem;
                File.Delete(item.Filename);
                Scripts.Remove(item);
            }
        }
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            if (mnu != null)
            {
                ScriptletItem item = mnu.CommandParameter as ScriptletItem;
                if (item != null)
                {
                    ScriptControl.Show(item.Filename);
                }
            }
        }
        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox t = sender as TextBox;

            if (t != null)
            {
                ScriptletItem item = t.Tag as ScriptletItem;
                if (item != null)
                {
                    item.EnableEdit = false;
                }
            }
        }
 private void TextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         TextBox t = sender as TextBox;
         if (t != null)
         {
             ScriptletItem item = t.Tag as ScriptletItem;
             if (item != null)
             {
                 item.EnableEdit = false;
             }
         }
     }
 }
        private void TextBlock_MouseMove(object sender, MouseEventArgs e)
        {
            Point  mousePos = e.GetPosition(null);
            Vector diff     = startPoint - mousePos;

            TextBlock t = sender as TextBlock;

            if (t != null)
            {
                if (e.LeftButton == MouseButtonState.Pressed &&
                    (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                     Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
                {
                    List <string> files = new List <string>();
                    ScriptletItem f     = t.Tag as ScriptletItem;
                    if (f != null)
                    {
                        string data = null;
                        using (StreamReader sr = new StreamReader(f.Filename))
                        {
                            data = sr.ReadToEnd();
                            if (data.Contains("<event"))
                            {
                                data = null;
                            }
                        }
                        f.EnableEdit = false;
                        IsDragging   = true;
                        if (!string.IsNullOrEmpty(data))
                        {
                            DragDrop.DoDragDrop(t, new DataObject(DataFormats.StringFormat, data), DragDropEffects.Copy);
                        }
                        else
                        {
                            files.Add(f.Filename);
                            DragDrop.DoDragDrop(t, new DataObject(DataFormats.FileDrop, files.ToArray()), DragDropEffects.Copy);
                        }
                        IsDragging = false;
                    }
                }
            }
        }
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();

            diag.Title        = "Select file to import";
            diag.Filter       = "Xml Files (*.xml)|*.xml|All Files (*.*)|*.*";
            diag.DefaultExt   = ".xml";
            diag.AddExtension = true;
            if (diag.ShowDialog() == true)
            {
                foreach (string f in diag.FileNames)
                {
                    FileInfo fle    = new FileInfo(f);
                    string   target = System.IO.Path.Combine(Locations.MissionPath, fle.Name);
                    FileHelper.Copy(fle.FullName, target);
                    ScriptletItem itm = new ScriptletItem(fle);
                    Scripts.Add(itm);
                }
            }
        }
        private void Export_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            if (mnu != null)
            {
                ScriptletItem si = mnu.CommandParameter as ScriptletItem;
                if (si != null)
                {
                    SaveFileDialog diag = new SaveFileDialog();
                    diag.Title  = "Select filename to save scriptlet to.";
                    diag.Filter = "Xml Files (*.xml)|*.xml|All Files (*.*)|*.*";

                    diag.DefaultExt = ".xml";
                    if (diag.ShowDialog() == true)
                    {
                        FileHelper.Copy(si.Filename, diag.FileName);
                    }
                }
            }
        }
Exemplo n.º 12
0
        static void OnFilenameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ScriptletItem me = sender as ScriptletItem;

            if (me != null)
            {
                if (!me.IsUpdating)
                {
                    me.IsUpdating = true;
                    FileInfo f = new FileInfo(me.Filename);
                    if (f.Extension.ToUpperInvariant() == ".XML")
                    {
                        me.DisplayItem = f.Name.Substring(0, f.Name.Length - f.Extension.Length);
                    }
                    else
                    {
                        me.DisplayItem = f.Name;
                    }
                    me.IsUpdating = false;
                }
            }
        }