Exemple #1
0
        public void New(object sender, object e)
        {
            //IDocumentFactory firstFactory = null;
            //foreach (var item in this.documentFactories.Values)
            //{
            //    firstFactory = item;
            //    break;
            //}

            UIInvoke(() =>
            {
                IDocumentFactory firstFactory            = null;
                ReadOnlyCollection <IDocumentType> types = DocumentTypes;
                if (types.Count == 1)
                {
                    foreach (IDocumentFactory item in documentFactories.Values)
                    {
                        firstFactory = item;
                        break;
                    }
                }
                else
                {
                    firstFactory =
                        new NewFileDialog().SelectDocumentType(DocumentTypes) as IDocumentFactory;
                }
                if (firstFactory == null)
                {
                    return;
                }
                New(firstFactory);
            });
        }
        public virtual string GetDefaultNamespace(string fileName)
        {
            string relPath = FileUtility.GetRelativePath(this.Directory, Path.GetDirectoryName(fileName));

            string[]      subdirs           = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            StringBuilder standardNameSpace = new StringBuilder(this.RootNamespace);

            foreach (string subdir in subdirs)
            {
                if (subdir == "." || subdir == ".." || subdir.Length == 0)
                {
                    continue;
                }
                if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (standardNameSpace.Length > 0)
                {
                    standardNameSpace.Append('.');
                }
                standardNameSpace.Append(NewFileDialog.GenerateValidClassOrNamespaceName(subdir, true));
            }
            return(standardNameSpace.ToString());
        }
Exemple #3
0
        private void NewFile()
        {
            //Create and show
            NewTagViewModel newTagViewModel = new NewTagViewModel();
            NewFileDialog   newFileDialog   = new NewFileDialog()
            {
                Owner = Owner, DataContext = newTagViewModel
            };

            if (newFileDialog.ShowDialog() ?? false)
            {
                //Get tag group
                Group tagGroup = TagLookup.CreateTagGroup(newTagViewModel.SelectedTagDefinition.GroupTag);

                //Create file
                TagFileModel newTagFileModel = new TagFileModel($"new_{tagGroup.GroupName}.{tagGroup.GroupName}", new AbideTagGroupFile()
                {
                    TagGroup = tagGroup
                })
                {
                    IsDirty = true, CloseCallback = File_Close
                };
                newTagFileModel.OpenTagReferenceRequested += OpenTagReferenceRequested;
                Files.Add(newTagFileModel);

                //Set
                SelectedFile = newTagFileModel;
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets the namespace the file should have in the specified project.
        /// </summary>
        public static string GetDefaultNamespace(IProject project, string fileName)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            string relPath = FileUtility.GetRelativePath(project.Directory, Path.GetDirectoryName(fileName));

            string[]      subdirs           = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            StringBuilder standardNameSpace = new StringBuilder(project.RootNamespace);

            foreach (string subdir in subdirs)
            {
                if (subdir == "." || subdir == ".." || subdir.Length == 0)
                {
                    continue;
                }
                if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                standardNameSpace.Append('.');
                standardNameSpace.Append(NewFileDialog.GenerateValidClassName(subdir));
            }
            return(standardNameSpace.ToString());
        }
Exemple #5
0
        public override void Run()
        {
            ProjectNode node = ProjectBrowserPad.Instance.CurrentProject;

            if (node != null)
            {
                if (node.Project.ReadOnly)
                {
                    MessageService.ShowWarningFormatted("${res:Dialog.NewFile.ReadOnlyProjectWarning}", node.Project.FileName);
                }
                else
                {
                    int result = MessageService.ShowCustomDialog("${res:Dialog.NewFile.AddToProjectQuestionTitle}",
                                                                 "${res:Dialog.NewFile.AddToProjectQuestion}",
                                                                 "${res:Dialog.NewFile.AddToProjectQuestionProject}",
                                                                 "${res:Dialog.NewFile.AddToProjectQuestionStandalone}");
                    if (result == 0)
                    {
                        node.AddNewItemsToProject();
                        return;
                    }
                    else if (result == -1)
                    {
                        return;
                    }
                }
            }
            using (NewFileDialog nfd = new NewFileDialog(null)) {
                nfd.Owner = WorkbenchSingleton.MainForm;
                nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm);
            }
        }
Exemple #6
0
        /// <summary>
        ///     新建文件
        /// </summary>
        public async void NewFile()
        {
            NewFileDialog newFileDialog = new NewFileDialog()
            {
                //PrimaryButtonText = "确定",
                //SecondaryButtonText = "取消"
                PrimaryButtonVisibility   = Visibility.Collapsed,
                SecondaryButtonVisibility = Visibility.Collapsed
            };

            var contentDialog = new ContentDialog()
            {
                Title               = "新建文件",
                Content             = newFileDialog,
                PrimaryButtonText   = "确定",
                SecondaryButtonText = "取消"
            };

            contentDialog.PrimaryButtonClick += (sender, e) =>
            {
                string str = AreFileName(newFileDialog);

                if (!string.IsNullOrEmpty(str))
                {
                    newFileDialog.Reminder = str;
                    return;
                }

                VirtualFile newFile = new VirtualFile()
                {
                    Name = newFileDialog.FileName,
                    Size = newFileDialog.Size
                };

                try
                {
                    Folder.NewFile(newFile);
                    //contentDialog.Hide();
                    ListVirtualStorage();
                    newFileDialog.Complete = true;
                }
                catch (Exception)
                {
                    str = "文件存在";
                    newFileDialog.Reminder = str;
                }
            };

            contentDialog.SecondaryButtonClick += (sender, e) =>
            {
                newFileDialog.Complete = true;
            };

            while (!newFileDialog.Complete)
            {
                await contentDialog.ShowAsync();
            }
        }
Exemple #7
0
        public override void Run()
        {
            NewFileDialog nfd = new NewFileDialog();

            if (nfd.ShowDialog() == DialogResult.OK)
            {
                WorkbenchSingleton.Workbench.NewFile((string)nfd.Tag, nfd.Text);
            }
        }
Exemple #8
0
        /// <summary>
        ///     Generates new Layer and sets it as active one.
        /// </summary>
        /// <param name="parameter">CommandParameter.</param>
        public void OpenNewFilePopup(object parameter)
        {
            NewFileDialog newFile = new NewFileDialog();

            if (newFile.ShowDialog())
            {
                NewDocument(newFile.Width, newFile.Height);
            }
        }
Exemple #9
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            using (NewFileDialog nfd = new NewFileDialog())
            {
                Size newDocSize = appWorkspace.GetNewDocumentSize();

                if (Utility.IsClipboardImageAvailable())
                {
                    try
                    {
                        Utility.GCFullCollect();
                        IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject();

                        using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap))
                        {
                            int width2  = clipImage.Width;
                            int height2 = clipImage.Height;
                            newDocSize = new Size(width2, height2);
                        }
                    }

                    catch (Exception ex)
                    {
                        if (ex is OutOfMemoryException ||
                            ex is ExternalException ||
                            ex is NullReferenceException)
                        {
                            // ignore
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                nfd.OriginalSize      = new Size(newDocSize.Width, newDocSize.Height);
                nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false);

                DialogResult dr = nfd.ShowDialog(appWorkspace);

                if (dr == DialogResult.OK)
                {
                    bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), false);

                    if (success)
                    {
                        appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                        Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect);
                    }
                }
            }
        }
Exemple #10
0
 public override void PerformAction(AppWorkspace appWorkspace)
 {
     if (appWorkspace.CanSetActiveWorkspace)
     {
         using (NewFileDialog dialog = new NewFileDialog())
         {
             SizeInt32?clipboardImageSize;
             SizeInt32 newDocumentSize = appWorkspace.GetNewDocumentSize();
             using (new WaitCursorChanger(appWorkspace))
             {
                 CleanupManager.RequestCleanup();
                 try
                 {
                     IPdnDataObject dataObject = PdnClipboard.GetDataObject();
                     clipboardImageSize = ClipboardUtil.GetClipboardImageSize(appWorkspace, dataObject);
                     dataObject         = null;
                 }
                 catch (Exception)
                 {
                     clipboardImageSize = null;
                 }
                 CleanupManager.RequestCleanup();
             }
             if (clipboardImageSize.HasValue)
             {
                 newDocumentSize = clipboardImageSize.Value;
             }
             dialog.OriginalSize      = new Size(newDocumentSize.Width, newDocumentSize.Height);
             dialog.OriginalDpuUnit   = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
             dialog.OriginalDpu       = Document.GetDefaultDpu(dialog.OriginalDpuUnit);
             dialog.Units             = dialog.OriginalDpuUnit;
             dialog.Resolution        = dialog.OriginalDpu;
             dialog.ConstrainToAspect = AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value;
             if ((((dialog.ShowDialog(appWorkspace) == DialogResult.OK) && (dialog.ImageWidth > 0)) && ((dialog.ImageHeight > 0) && dialog.Resolution.IsFinite())) && (dialog.Resolution > 0.0))
             {
                 SizeInt32 size = new SizeInt32(dialog.ImageWidth, dialog.ImageHeight);
                 if (appWorkspace.CreateBlankDocumentInNewWorkspace(size, dialog.Units, dialog.Resolution, false))
                 {
                     appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                     AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value = dialog.ConstrainToAspect;
                     if (dialog.Units != MeasurementUnit.Pixel)
                     {
                         AppSettings.Instance.Workspace.LastNonPixelUnits.Value = dialog.Units;
                     }
                     if (appWorkspace.Units != MeasurementUnit.Pixel)
                     {
                         appWorkspace.Units = dialog.Units;
                     }
                 }
             }
         }
     }
 }
Exemple #11
0
        private async void NewFile_Click(object sender, RoutedEventArgs e)
        {
            ContentDialogResult dialog = await NewFileDialog.ShowAsync();

            if (dialog == ContentDialogResult.Primary)
            {
                StorageFolder localFolder    = KnownFolders.MusicLibrary;
                StorageFolder projectsFolder = await localFolder.CreateFolderAsync("SGBDProjects", CreationCollisionOption.OpenIfExists);

                CurrentFileName.Text = FileNameTextBox.Text + ".dbp";
                App.CurrentProject   = new Project(FileNameTextBox.Text + ".dbp");
                App.SerializeProject();
            }
        }
        //private ElementInsertPanel ElementInsert
        //{
        //    get { return elementInsertPanel.Controls[0] as ElementInsertPanel; }
        //}

        //private ElementChangePanel ElementChange
        //{
        //    get { return elementChangePanel.Controls[0] as ElementChangePanel; }
        //}

        //private QuickFixPanel QuickFix
        //{
        //    get { return quickFixPanel.Controls[0] as QuickFixPanel; }
        //}

        private void ShowNewForm(object sender, EventArgs e)
        {
            NewFileDialog dlg = new NewFileDialog();
            DialogResult  res = dlg.ShowDialog(this);

            if (res == DialogResult.Cancel)
            {
                return;
            }

            XmlDocument doc = dlg.CreateNewDocument();

            OpenNew(doc);
        }
Exemple #13
0
 public FileTemplateResult ShowNewFileDialog(IProject project, DirectoryName directory, IEnumerable <TemplateCategory> templates)
 {
                 #if DEBUG
     SD.Templates.UpdateTemplates();
                 #endif
     using (NewFileDialog nfd = new NewFileDialog(project, directory, templates ?? SD.Templates.TemplateCategories)) {
         if (nfd.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK)
         {
             return(nfd.result);
         }
         else
         {
             return(null);
         }
     }
 }
        public override void Run()
        {
            using (NewFileDialog nfd = new NewFileDialog())
            {
                nfd.Owner = (Form)WorkbenchSingleton.Workbench;
                nfd.ShowDialog();
            }
            IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent;

            if (content != null)
            {
                content.ViewSelected += AlgorithmManager.Algorithms.ClearPadsHandler;
                content.SelectView();
                AlgorithmManager.Algorithms.Timer.Enabled = false;
            }
        }
Exemple #15
0
        protected override void OnActivated()
        {
            Console.WriteLine("newfile - activate");
            base.OnActivated();
            NewFileDialog nfd = new NewFileDialog();

            int result = nfd.Run();

            if (result == (int)ResponseType.Ok)
            {
                string fileName = nfd.FileName;
                string content  = nfd.Content;
                MainClass.MainWindow.CreateFile(fileName, content);
            }
            nfd.Destroy();
            MainClass.MainWindow.SaveWorkspace();
        }
Exemple #16
0
        public override bool Send(SendCommandArgs args)
        {
            base.Send(args);

            NewFileDialog nfd = new NewFileDialog(main.Settings);
            DialogResult  dr  = nfd.ShowModal(main);

            if (dr == DialogResult.Ok)
            {
                if (FileModifiedDialog.Show(main) == DialogResult.Ok)
                {
                    args.Message.Write(nfd.SelectedDocumentType.ID);
                    return(true);
                }
            }

            return(false);
        }
Exemple #17
0
        // return true if we actually created a new level
        private bool NewFile()
        {
            if (DisplayUnsavedDialog())
            {
                return(false);
            }

            var dialog = new NewFileDialog();
            var result = dialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return(false);
            }

            CreateNewLevel(dialog.LevelName, dialog.LevelType);
            return(true);
        }
Exemple #18
0
        void OnAddFileClicked(object sender, EventArgs a)
        {
            TreeIter tiDirectory = new TreeIter();
            string   pathDir     = GetDirectory(ref tiDirectory);

            if (String.IsNullOrEmpty(pathDir))
            {
                return;
            }

            string fileName = "";
            string content  = "";

            NewFileDialog nfd = new NewFileDialog();

            int result = nfd.Run();

            if (result == (int)ResponseType.Ok)
            {
                fileName = nfd.FileName;
                content  = nfd.Content;
            }
            nfd.Destroy();
            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }

            string newFile = System.IO.Path.Combine(pathDir, fileName);

            try {
                FileUtility.CreateFile(newFile, content);
            } catch {
                MessageDialogs md =
                    new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_creating_file"), fileName, Gtk.MessageType.Error);
                md.ShowDialog();
            }
            RefreshDir(pathDir, tiDirectory);

            /*if(MainClass.Workspace != null && !String.IsNullOrEmpty(MainClass.Workspace.FilePath)){
             *      LoadLibs(MainClass.Workspace.RootDirectory);
             * };*/
        }
        public Project AddNewProject(ResourceFolder parentResourceItem, IList <ResourceItem> selectesItem = null)
        {
            IMainTool mainTool = MainWindowPartFactory.GetMainTool();

            if (mainTool == null)
            {
                throw new MissingMethodException("Can not find GetMainTool...");
            }
            FilePath         baseDirectory    = parentResourceItem.BaseDirectory;
            FileDialogResult fileDialogResult = new NewFileDialog((Window)Services.MainWindow, (string)parentResourceItem.BaseDirectory, mainTool.CanvasSize).ShowDialog();

            if (fileDialogResult == null)
            {
                return((Project)null);
            }
            return(this.AddNewProject(parentResourceItem, new ProjectCreateInformation((FilePath)Path.Combine((string)baseDirectory, fileDialogResult.FileName), (IProjectContent)null, selectesItem, (float)fileDialogResult.Size.Width, (float)fileDialogResult.Size.Height)
            {
                ContentType = fileDialogResult.FileType.ToString()
            }));
        }
Exemple #20
0
        protected override void Execute(CommandExecuteArgs args)
        {
            NewFileDialog nfd = new NewFileDialog(main.Settings);
            DialogResult  dr  = nfd.ShowModal(main);

            if (dr == DialogResult.Ok)
            {
                if (FileModifiedDialog.Show(main) == DialogResult.Ok)
                {
                    // create a new document then edit it
                    main.FileList.SelectedIndex = -1;

                    var doc = nfd.SelectedDocumentType.Create(main.Platform);
                    doc.IsNew    = true;
                    doc.EditMode = true;

                    main.SetDocument(doc, true);
                }
            }
        }
Exemple #21
0
        private void CreateNewFileDialog()
        {
            var dialog = new NewFileDialog {
                IsVisible = true
            };

            _imGuiManager.AddElement(dialog);

            dialog.CreateFileRequested += (sender, args) =>
            {
                try
                {
                    _scriptManager.CreateNewScript(dialog.FileName?.Trim(), dialog.SelectedLanguage);
                }
                catch (InvalidOperationException exception)
                {
                    dialog.ErrorText = exception.Message;
                    return;
                }
                catch (Exception exception)
                {
                    dialog.ErrorText = $"Exception: {exception}";
                    return;
                }

                _imGuiManager.RemoveElement(dialog);
                SettingsIo.Save(_appSettings);
                _onScreenLogger.Clear();
            };

            dialog.PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case nameof(NewFileDialog.CloseRequested):
                    _imGuiManager.RemoveElement(dialog);
                    break;
                }
            };
        }
Exemple #22
0
        public EditorUiController(ImGuiManager imGuiManager,
                                  SettingsCommandHandler commandHandler,
                                  AppOperationQueue appOperationQueue,
                                  ApplicationState applicationState,
                                  ITextureFileLoader textureFileLoader,
                                  MonoGameImGuiRenderer monoGameImGuiRenderer)
        {
            _imGuiManager      = imGuiManager;
            _appOperationQueue = appOperationQueue;
            _applicationState  = applicationState;

            _imguiDemoWindow = new DemoWindow {
                IsVisible = false
            };
            _imGuiManager.AddElement(_imguiDemoWindow);

            var appToolbar = new AppToolbar(_appOperationQueue, _applicationState);

            _imGuiManager.AddElement(appToolbar);

            _newFileDialog = new NewFileDialog();
            _newFileDialog.CreateButtonClicked += NewFileDialogOnCreateButtonClicked;
            _newFileDialog.ModalClosed         += NewFileDialogOnModalClosed;
            _imGuiManager.AddElement(_newFileDialog);

            _messagePopup              = new MessagePopup();
            _messagePopup.ModalClosed += MessagePopupOnModalClosed;
            _imGuiManager.AddElement(_messagePopup);

            _emitterSettingsController = new EmitterSettingsController(imGuiManager,
                                                                       commandHandler,
                                                                       applicationState,
                                                                       appOperationQueue,
                                                                       textureFileLoader,
                                                                       monoGameImGuiRenderer);

            appToolbar.NewMenuItemClicked  += AppToolbarOnNewMenuItemClicked;
            appToolbar.OpenMenuItemClicked += AppToolbarOnOpenMenuItemClicked;
            appToolbar.SaveMenuItemClicked += AppToolbarOnSaveMenuItemClicked;
        }
Exemple #23
0
        void c_NewFile(object sender, EventArgs e)
        {
            NewFileDialog newFileDialogWindow = new NewFileDialog();
            var           newFileViewModel    = new NewFileViewModel();

            EventHandler handler = null;

            handler = delegate
            {
                newFileViewModel.RequestClose -= handler;
                newFileDialogWindow.Close();
                if (newFileViewModel.Finished)
                {
                    viewModel.CreateNewFile(newFileViewModel.FileName);
                }
            };

            newFileViewModel.RequestClose += handler;

            newFileDialogWindow.DataContext = newFileViewModel;
            newFileDialogWindow.ShowDialog();
        }
        public override void Run()
        {
            TreeNode      selectedNode = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedNode;
            DirectoryNode node         = null;

            while (selectedNode != null && node == null)
            {
                node         = selectedNode as DirectoryNode;
                selectedNode = selectedNode.Parent;
            }
            if (node == null)
            {
                return;
            }
            node.Expand();
            node.Expanding();

            using (NewFileDialog nfd = new NewFileDialog(node.Directory)) {
                if (nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK)
                {
                    bool additionalProperties = false;
                    foreach (KeyValuePair <string, FileDescriptionTemplate> createdFile in nfd.CreatedFiles)
                    {
                        FileProjectItem item = CreateNewFile(node, createdFile.Key);

                        if (createdFile.Value.SetProjectItemProperties(item))
                        {
                            additionalProperties = true;
                        }
                    }
                    if (additionalProperties)
                    {
                        node.Project.Save();
                        node.RecreateSubNodes();
                    }
                }
            }
        }
Exemple #25
0
 public override void Run()
 {
     if (ProjectBrowserPad.Instance.CurrentProject != null)
     {
         int result = MessageService.ShowCustomDialog("${res:Dialog.NewFile.AddToProjectQuestionTitle}",
                                                      "${res:Dialog.NewFile.AddToProjectQuestion}",
                                                      "${res:Dialog.NewFile.AddToProjectQuestionProject}",
                                                      "${res:Dialog.NewFile.AddToProjectQuestionStandalone}");
         if (result == 0)
         {
             ProjectBrowserPad.Instance.CurrentProject.AddNewItemsToProject();
             return;
         }
         else if (result == -1)
         {
             return;
         }
     }
     using (NewFileDialog nfd = new NewFileDialog(null)) {
         nfd.Owner = (Form)WorkbenchSingleton.Workbench;
         nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm);
     }
 }
        protected IEnumerable <FileProjectItem> AddNewItems()
        {
            DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode;

            if (node == null)
            {
                return(null);
            }
            node.Expand();
            node.Expanding();

            List <FileProjectItem> addedItems = new List <FileProjectItem>();

            using (NewFileDialog nfd = new NewFileDialog(node.Directory)) {
                if (nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK)
                {
                    bool additionalProperties = false;
                    foreach (KeyValuePair <string, FileDescriptionTemplate> createdFile in nfd.CreatedFiles)
                    {
                        FileProjectItem item = node.AddNewFile(createdFile.Key);
                        addedItems.Add(item);

                        if (createdFile.Value.SetProjectItemProperties(item))
                        {
                            additionalProperties = true;
                        }
                    }
                    if (additionalProperties)
                    {
                        node.Project.Save();
                        node.RecreateSubNodes();
                    }
                }
            }

            return(addedItems.AsReadOnly());
        }
Exemple #27
0
        private string AreFileName(NewFileDialog newFileDialog)
        {
            string str = "";
            int    size;

            if (string.IsNullOrEmpty(newFileDialog.FileName))
            {
                str = "文件名为空";
            }
            else if (!VirtualFile.AreFileName(newFileDialog.FileName))
            {
                str = "文件名不能存在\\/*:?\"<>|";
            }
            else if (string.IsNullOrEmpty(newFileDialog.Size))
            {
                str = "文件大小为空";
            }
            else if (!int.TryParse(newFileDialog.Size, out size))
            {
                newFileDialog.Size = "";
                str = "输入文件大小不是数字";
            }
            return(str);
        }
 protected override void Run()
 {
     using (var dlg = new NewFileDialog(null, null))              // new file seems to fail if I pass the project IdeApp.ProjectOperations.CurrentSelectedProject
         MessageService.ShowCustomDialog(dlg, IdeApp.Workbench.RootWindow);
 }
 void FileNewToolStripMenuItemClick(object sender, EventArgs e)
 {
     using (NewFileDialog dialog = new NewFileDialog()) {
         dialog.FileName = GetNewFileName();
         if (dialog.ShowDialog() == DialogResult.OK) {
             string fileName = dialog.FileName;
             using (StreamWriter file = File.CreateText(fileName)) {
                 file.Write(String.Empty);
             }
             LoadFile(fileName);
             AddFileToProject(fileName);
         }
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            LogEntries           = new ObservableCollection <LogEntry>();
            LogPanel.ItemsSource = LogEntries;

            ZerothCompiler compiler = new ZerothCompiler(Logger);

            Debug.WriteLine(compiler.removeComments("Hello world / comment\nNext line ( also a comment ) is here"));

            NewFileButton.Click += (object sender, RoutedEventArgs e) =>
            {
                if (currentProject == null)
                {
                    MessageBox.Show("There is currently no project open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                NewFileDialog dialog = new NewFileDialog();
                dialog.FileName = "NewZerothFile.zth";
                dialog.ShowDialog();
                if (!dialog.cancelled)
                {
                    if (currentProject.fileExists(dialog.FileName))
                    {
                        MessageBox.Show($"{dialog.FileName} already exists in the current project", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    LoadedFile newFile = new LoadedFile {
                        FilePath = currentProject.ProjectPath + System.IO.Path.DirectorySeparatorChar + dialog.FileName, FileContent = ""
                    };
                    currentProject.addFile(newFile);
                    CurrentFile = newFile;
                    currentProject.save();
                    Logger.log($"Imported '{newFile.FileName}'");
                }
            };

            ImportFileButton.Click += (object sender, RoutedEventArgs e) =>
            {
                if (currentProject == null)
                {
                    MessageBox.Show("There is currently no project open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.FileName = Directory.GetCurrentDirectory();
                dialog.Filter   = "Zeroth Source Files (*.zth)|*.zth";
                if (dialog.ShowDialog() == true)
                {
                    LoadedFile imported = currentProject.import(dialog.FileName);
                    if (imported != null)
                    {
                        CurrentFile = imported;
                    }
                    Logger.log($"Imported '{imported.FileName}'");
                }
            };

            BuildLocalButton.Click += (object sender, RoutedEventArgs e) =>
            {
                if (currentProject == null || CurrentFile == null)
                {
                    MessageBox.Show("There is currently no file open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                compiler.BuildFile(CurrentFile);
            };

            BuildProjectButton.Click += (object sender, RoutedEventArgs e) =>
            {
            };

            this.Closing += (object sender, CancelEventArgs e) =>
            {
                if (currentProject != null)
                {
                    currentProject.save();
                }
            };

            Logger.log("Logging started");
        }
Exemple #31
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            using (NewFileDialog nfd = new NewFileDialog())
            {
                Size newDocSize = appWorkspace.GetNewDocumentSize();

                if (Utility.IsClipboardImageAvailable())
                {
                    try
                    {
                        Utility.GCFullCollect();
                        IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject();

                        using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap))
                        {
                            int width2 = clipImage.Width;
                            int height2 = clipImage.Height;
                            newDocSize = new Size(width2, height2);
                        }
                    }

                    catch (Exception ex)
                    {
                        if (ex is OutOfMemoryException ||
                            ex is ExternalException ||
                            ex is NullReferenceException)
                        {
                            // ignore
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                nfd.OriginalSize = new Size(newDocSize.Width, newDocSize.Height);
                nfd.OriginalDpuUnit = SettingNames.GetLastNonPixelUnits();
                nfd.OriginalDpu = Document.GetDefaultDpu(nfd.OriginalDpuUnit);
                nfd.Units = nfd.OriginalDpuUnit;
                nfd.Resolution = nfd.OriginalDpu;
                nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false);

                DialogResult dr = nfd.ShowDialog(appWorkspace);

                if (dr == DialogResult.OK)
                {
                    bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), nfd.Units, nfd.Resolution, false);

                    if (success)
                    {
                        appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                        Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect);

                        if (nfd.Units != MeasurementUnit.Pixel)
                        {
                            Settings.CurrentUser.SetString(SettingNames.LastNonPixelUnits, nfd.Units.ToString());
                        }

                        if (appWorkspace.Units != MeasurementUnit.Pixel)
                        {
                            appWorkspace.Units = nfd.Units;
                        }
                    }
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Shows the add new item dialog and adds a new item
        /// </summary>
        public void AddNewItem()
        {
            if (!IsProjectOpen()) return;
            var nfd = new NewFileDialog();

            if (nfd.ShowDialog() != DialogResult.OK)
                return;

            var pf = new OpenedFile();
            string filePath;

            if (_explorer.tvFiles.SelectedNode == null) // Just do the normal adding to project...
            {
                filePath = Project.Path;
                pf.Folder = null;
            }
            else switch (_explorer.tvFiles.SelectedNode.Tag.GetType().Name)
            {
                case "Project":
                    filePath = Project.Path;
                    pf.Folder = null;
                    break;
                case "Folder":
                    filePath = ((Folder) _explorer.tvFiles.SelectedNode.Tag).FullName();
                    pf.Folder = ((Folder) _explorer.tvFiles.SelectedNode.Tag);
                    break;
                case "OpenedFile":
                    if (((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder == null) // Project File
                    {
                        filePath = Project.Path;
                        pf.Folder = null;
                    }
                    else // File in Folder, so folders parent is cool :D
                    {
                        filePath = ((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder.FullName();
                        pf.Folder = ((OpenedFile) _explorer.tvFiles.SelectedNode.Tag).Folder;
                    }
                    break;
                default:
                    filePath = Project.Path;
                    pf.Folder = null;
                    break;
            }

            if (File.Exists(filePath + @"\" + nfd.FileName))
            {
                Util.ShowError(StringTable.FileAlreadyExists);
                AddNewItem();
                return;
            }
            File.Create(filePath + @"\" + nfd.FileName).Close();
            File.WriteAllText(filePath + @"\" + nfd.FileName, PreprocessCode(nfd.SelectedTemplate.Code));

            pf.Name = nfd.FileName;
            pf.Saved = false;
            pf.FullName = filePath + @"\" + pf.Name;

            Project.Saved = false;

            AddProjectFile(pf);

            SaveProject();

            OpenFile(filePath + @"\" + nfd.FileName);
        }
Exemple #33
0
 protected override void Run()
 {
     using (var dlg = new NewFileDialog(null, null))              // new file seems to fail if I pass the project IdeApp.ProjectOperations.CurrentSelectedProject
         MessageService.ShowCustomDialog(dlg, IdeServices.DesktopService.GetFocusedTopLevelWindow());
 }
		void NewFile()
		{
			using (var dialog = new NewFileDialog()) {
				dialog.FileName = GetNewFileName();
				if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
					string fileName = dialog.FileName;
					using (StreamWriter file = File.CreateText(fileName)) {
						file.Write(String.Empty);
					}
					LoadFile(fileName);
					AddFileToProject(fileName);
				}
			}
		}