public bool Do()
            {
                _con.View.BeginTreeUpdate();

                foreach (var item in _items)
                {
                    if (item is ContentItem)
                    {
                        _con._project.ContentItems.Remove(item as ContentItem);
                    }
                    _con.View.RemoveTreeItem(item);

                    if (_delete)
                    {
                        // Only delete if the item is in the project folder, otherwise we may (and have done!) delete files/folders outside of the project
                        if (!item.OriginalPath.Contains(".."))
                        {
                            var fullItemPath = _con.GetFullPath(item.OriginalPath);
                            try
                            {
                                if (item is DirectoryItem)
                                {
                                    Directory.Delete(_con.GetFullPath(item.OriginalPath), true);
                                }
                                else
                                {
                                    File.Delete(_con.GetFullPath(item.OriginalPath));
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                // No error needed in case file is not found
                            }
                            catch (Exception ex)
                            {
                                _con.View.ShowError("Error while trying to delete the file", ex.Message);
                            }
                        }
                    }
                }

                foreach (var sitem in _subitems)
                {
                    _con._project.ContentItems.Remove(sitem);
                }

                //Since these items are removed from the project, manually clear the selection
                _con.SelectedItems.Clear();
                _con.SelectionChanged(_con.SelectedItems);

                _con.View.EndTreeUpdate();
                _con.ProjectDirty = true;

                return(true);
            }
            private void ExistsThread()
            {
                while (true)
                {
                    // Can't lock without major code modifications
                    try
                    {
                        var items = _controller._project.ContentItems.ToArray();

                        foreach (var item in items)
                        {
                            Thread.Sleep(100);

                            if (item.Exists == File.Exists(_controller.GetFullPath(item.OriginalPath)))
                            {
                                continue;
                            }

                            item.Exists = !item.Exists;
                            _view.ItemExistanceChanged(item);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            private void ExistsThread()
            {
                while (true)
                {
                    // Can't lock without major code modifications
                    try
                    {
                        var items = _controller._project.ContentItems.ToArray();

                        foreach (var item in items)
                        {
                            Thread.Sleep(100);

                            if (item.Exists == File.Exists(_controller.GetFullPath(item.OriginalPath)))
                            {
                                continue;
                            }

                            item.Exists = !item.Exists;
                            _view.Invoke(() => _view.UpdateTreeItem(item));
                        }
                    }
                    catch (ThreadAbortException ex)
                    {
                        return;
                    }
                    catch
                    {
                    }
                }
            }
            public void Do()
            {
                var ext      = Path.GetExtension(_template.TemplateFile);
                var filename = Path.ChangeExtension(_name, ext);
                var fullpath = _con.GetFullPath(Path.Combine(_location, filename));

                if (File.Exists(fullpath))
                {
                    _con.View.ShowError("Error", string.Format("File already exists: '{0}'.", fullpath));
                    return;
                }

                File.Copy(_template.TemplateFile, fullpath);

                var parser = new PipelineProjectParser(_con, _con._project);

                _con.View.BeginTreeUpdate();

                _con.Selection.Clear(_con);

                if (parser.AddContent(fullpath, true))
                {
                    var item = _con._project.ContentItems.Last();
                    item.Observer      = _con;
                    item.ImporterName  = _template.ImporterName;
                    item.ProcessorName = _template.ProcessorName;
                    item.ResolveTypes();

                    _con.View.AddTreeItem(item);
                    _con.Selection.Add(item, _con);
                }

                _con.View.EndTreeUpdate();
                _con.ProjectDirty = true;
            }
Example #5
0
            public bool Do()
            {
                _con.View.BeginTreeUpdate();

                foreach (var item in _items)
                {
                    if (item is ContentItem)
                    {
                        _con._project.ContentItems.Remove(item as ContentItem);
                    }
                    _con.View.RemoveTreeItem(item);

                    if (_delete)
                    {
                        try
                        {
                            if (item is DirectoryItem)
                            {
                                Directory.Delete(_con.GetFullPath(item.OriginalPath), true);
                            }
                            else
                            {
                                File.Delete(_con.GetFullPath(item.OriginalPath));
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            // No error needed in case file is not found
                        }
                        catch (Exception ex)
                        {
                            _con.View.ShowError("Error while trying to delete the file", ex.Message);
                        }
                    }
                }

                foreach (var sitem in _subitems)
                {
                    _con._project.ContentItems.Remove(sitem);
                }

                _con.View.EndTreeUpdate();
                _con.ProjectDirty = true;

                return(true);
            }
            private bool Move(string path, string newpath, FileType type)
            {
                _con.View.BeginTreeUpdate();

                if (type == FileType.File)
                {
                    var    item        = _con.GetItem(path) as ContentItem;
                    string fullpath    = _con.GetFullPath(path);
                    string fullnewpath = _con.GetFullPath(newpath);

                    if (item == null)
                    {
                        _con.View.ShowError("Error", "An internal error has occured.");
                        return(false);
                    }

                    try
                    {
                        if (File.Exists(fullnewpath))
                        {
                            _con.View.ShowError("Error", "File: \"" + fullnewpath + "\" already exists.");
                            return(false);
                        }

                        File.Move(fullpath, fullnewpath);
                    }
                    catch
                    {
                        _con.View.ShowError("Error", "An error has occurred while trying to move a file.");
                        return(false);
                    }

                    MoveFile(item, newpath);
                }
                else if (type == FileType.Folder)
                {
                    string fullpath    = _con.GetFullPath(path);
                    string fullnewpath = _con.GetFullPath(newpath);

                    try
                    {
                        if (Directory.Exists(fullnewpath))
                        {
                            _con.View.ShowError("Error", "Directory: \"" + fullnewpath + "\" already exists.");
                            return(false);
                        }

                        Directory.Move(fullpath, fullnewpath);
                    }
                    catch
                    {
                        _con.View.ShowError("Error", "An error has occurred while trying to move the directory.");
                        return(false);
                    }

                    var cis = new List <ContentItem>();
                    var nps = new List <string>();

                    for (var i = 0; i < _con._project.ContentItems.Count; i++)
                    {
                        var item = _con._project.ContentItems[i];
                        if (item.OriginalPath.StartsWith(path))
                        {
                            cis.Add(item);
                            nps.Add(newpath + item.OriginalPath.Substring(path.Length));
                        }
                    }

                    for (int i = 0; i < nps.Count; i++)
                    {
                        MoveFile(cis[i], newpath + cis[i].OriginalPath.Substring(path.Length));
                    }

                    _con.View.RemoveTreeItem(new DirectoryItem(path));
                }
                else
                {
                    _con.MoveProject(newpath);
                }

                _con.View.EndTreeUpdate();
                _con.ProjectDirty = true;

                return(true);
            }
 private void AddValue(string floc)
 {
     listStore.AppendValues("<b>" + System.IO.Path.GetFileNameWithoutExtension(floc) + "</b>\r\n" + controller.GetFullPath(floc), floc);
 }