public static void GetInput(NativeOSWindow parent, Browser browser, bool modal, SendResult <BrowseType> sendResult, Action <String, Action <String> > importCallback, String prompt, String wildcard, String extension)
        {
            BrowserWindow <BrowseType> inputBox = createInputBox(browser, modal, sendResult);

            inputBox.importButton.MouseButtonClick += (source, e) =>
            {
                FileOpenDialog openDialog = new FileOpenDialog(parent, prompt, wildcard: wildcard);
                openDialog.showModal((result, paths) =>
                {
                    if (result == NativeDialogResult.OK)
                    {
                        String path = paths.First();
                        String ext  = Path.GetExtension(path);
                        if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase))
                        {
                            importCallback(path, previewPath =>
                            {
                                ThreadManager.invoke(new Action(() =>
                                {
                                    BrowserNode node = new BrowserNode(Path.GetFileName(previewPath), previewPath);
                                    inputBox.browserTree.Nodes.First().Children.add(inputBox.addNodes(node, node));
                                    inputBox.browserTree.layout();
                                }));
                            });
                        }
                        else
                        {
                            MessageBox.show(String.Format("Cannot open a file with extension '{0}'.", extension), "Can't Load File", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok);
                        }
                    }
                });
            };
        }
        public void showOpenFileDialog(string filterString, SendResult <string> resultCallback)
        {
            FileOpenDialog dlg = new FileOpenDialog(wildcard: filterString, selectMultiple: false);

            dlg.showModal((mResult, mFiles) =>
            {
                fileOpenResults(mResult, mFiles, resultCallback, dlg);
            });
        }
        void browseDestination_MouseButtonClick(Widget source, EventArgs e)
        {
            FileOpenDialog open = new FileOpenDialog(parentWindow, wildcard: Filter, selectMultiple: false);

            open.showModal((result, path) =>
            {
                if (result == NativeDialogResult.OK)
                {
                    destTextBox.OnlyText = path.FirstOrDefault();
                }
            });
        }
        /// <summary>
        /// Show the open file dialog and return the chosen file.
        /// <param name="fileChosenCb">A function that is called when a file is chosen with the name of the chosen file.</param>
        /// </summary>
        public void openFile(FileChosen fileChosenCb)
        {
            FileOpenDialog fileOpen = new FileOpenDialog(ParentWindow, "", DefaultDirectory, "", Filter, false);

            fileOpen.showModal((result, files) =>
            {
                String file = files.FirstOrDefault();
                if (result == NativeDialogResult.OK && !String.IsNullOrEmpty(file))
                {
                    currentFile = file;
                    fileChosenCb(currentFile);
                }
            });
        }
Exemple #5
0
        void showOpenProjectDialog()
        {
            editorController.stopPlayingTimelines();
            FileOpenDialog fileDialog = new FileOpenDialog(MainWindow.Instance, "Open a project.", "", "", "", false);

            fileDialog.showModal((result, paths) =>
            {
                if (result == NativeDialogResult.OK)
                {
                    String path = paths.First();
                    editorController.openProject(Path.GetDirectoryName(path));
                }
            });
        }
 private void fileOpenResults(NativeDialogResult result, IEnumerable <String> files, SendResult <String> resultCallback, FileOpenDialog dlg)
 {
     if (result == NativeDialogResult.OK)
     {
         String errorPrompt = null;
         if (!resultCallback(files.FirstOrDefault(), ref errorPrompt))
         {
             dlg.showModal((mResult, mFiles) =>
             {
                 fileOpenResults(mResult, mFiles, resultCallback, dlg);
             });
         }
     }
 }
Exemple #7
0
        void browseButton_MouseButtonClick(Widget source, EventArgs e)
        {
            FileOpenDialog openDialog = new FileOpenDialog(MainWindow.Instance, "Choose an image", wildcard: "Images|*.jpg;*.jpeg;*.png");

            openDialog.showModal((result, paths) =>
            {
                if (result == NativeDialogResult.OK)
                {
                    if (imageAtlas.containsImage(Key))
                    {
                        imagePreview.setItemResource(null);
                        imageAtlas.removeImage(Key);
                    }
                    String path      = paths.First();
                    String extension = Path.GetExtension(path);
                    if (extension.Equals(".png", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        imageName       = Guid.NewGuid().ToString("D") + extension;
                        String filename = Path.Combine(subdirectory, imageName);

                        System.Threading.ThreadPool.QueueUserWorkItem((stateInfo) =>
                        {
                            try
                            {
                                using (Stream writeStream = resourceProvider.openWriteStream(filename))
                                {
                                    using (Stream readStream = File.Open(path, FileMode.Open, FileAccess.Read))
                                    {
                                        readStream.CopyTo(writeStream);
                                    }
                                }
                                openImageBGThread(filename, true);
                            }
                            catch (Exception ex)
                            {
                                ThreadManager.invoke(() =>
                                {
                                    MessageBox.show(String.Format("Error copying file {0} to your project.\nReason: {1}", path, ex.Message), "Image Copy Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
                                });
                            }
                        });
                    }
                    else
                    {
                        MessageBox.show(String.Format("Cannot open a file with extension '{0}'. Please choose a file that is a Png Image (.png) or a Jpeg (.jpg or .jpeg).", extension), "Can't Load Image", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok);
                    }
                }
            });
        }
        public static void GetInput(Browser browser, bool modal, SendResult <BrowseType> sendResult, ResourceProvider resourceProvider, Action <String, Action <String> > importCallback = null)
        {
            ImageBrowserWindow <BrowseType> inputBox = new ImageBrowserWindow <BrowseType>(browser.Prompt, resourceProvider);

            inputBox.setBrowser(browser);
            if (importCallback != null)
            {
                inputBox.importButton.MouseButtonClick += (source, e) =>
                {
                    FileOpenDialog openDialog = new FileOpenDialog(MainWindow.Instance, "Choose Image", "Images|*.jpg;*.jpeg;*.png");
                    openDialog.showModal((result, paths) =>
                    {
                        if (result == NativeDialogResult.OK)
                        {
                            String path      = paths.First();
                            String extension = Path.GetExtension(path);
                            if (extension.Equals(".png", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase))
                            {
                                importCallback(path, previewPath =>
                                {
                                    ThreadManager.invoke(new Action(() =>
                                    {
                                        BrowserNode node = new BrowserNode("", previewPath);
                                        inputBox.addNodes(node, node);
                                    }));
                                });
                            }
                            else
                            {
                                MessageBox.show(String.Format("Cannot open a file with extension '{0}'. Please choose a file that is a Png Image (.png) or a Jpeg (.jpg or .jpeg).", extension), "Can't Load Image", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok);
                            }
                        }
                    });
                };
            }
            else
            {
                inputBox.importButton.Visible = false;
            }
            inputBox.SendResult = sendResult;
            inputBox.Closing   += new EventHandler <DialogCancelEventArgs>(inputBox_Closing);
            inputBox.Closed    += new EventHandler(inputBox_Closed);
            inputBox.center();
            inputBox.open(modal);
        }
Exemple #9
0
 void showOpenProjectDialog()
 {
     try
     {
         slideEditController.stopPlayingTimelines();
         FileOpenDialog fileDialog = new FileOpenDialog(MainWindow.Instance, "Open a project.", "", "", openWildcard, false);
         fileDialog.showModal((result, paths) =>
         {
             if (result == NativeDialogResult.OK)
             {
                 String path = paths.First();
                 slideEditController.openProject(path);
             }
         });
     }
     catch (Exception ex)
     {
         MessageBox.show(String.Format("{0} loading the project. Message {1}.", ex.GetType().Name, ex.Message), "Project Load Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
     }
 }
Exemple #10
0
        void fileBrowser_NodeContextEvent(FileBrowserTree tree, string path, bool isDirectory, bool isTopLevel)
        {
            ContextMenu contextMenu = new ContextMenu();

            if (isDirectory)
            {
                contextMenu.add(new ContextMenuItem("Create Directory", path, delegate(ContextMenuItem item)
                {
                    InputBox.GetInput("Directory Name", "Please enter a name for the directory.", true, delegate(String result, ref String errorPrompt)
                    {
                        editorController.ResourceProvider.createDirectory(item.UserObject.ToString(), result);
                        return(true);
                    });
                }));

                contextMenu.add(new ContextMenuItem("Add Item", path, delegate(ContextMenuItem item)
                {
                    AddItemDialog.AddItem(editorController.ItemTemplates, (itemTemplate) =>
                    {
                        try
                        {
                            ((ProjectItemTemplate)itemTemplate).createItem(path, editorController);
                        }
                        catch (Exception e)
                        {
                            MessageBox.show(String.Format("Error creating item.\n{0}", e.Message), "Error Creating Item", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
                        }
                    });
                }));

                contextMenu.add(new ContextMenuItem("Import Files", path, delegate(ContextMenuItem item)
                {
                    FileOpenDialog fileDialog = new FileOpenDialog(MainWindow.Instance, "Choose files to import.", "", "", "", true);
                    fileDialog.showModal((result, paths) =>
                    {
                        if (result == NativeDialogResult.OK)
                        {
                            editorController.importFiles(paths, item.UserObject.ToString());
                        }
                    });
                }));

                contextMenu.add(new ContextMenuItem("Explore To", path, item =>
                {
                    OtherProcessManager.openLocalURL(editorController.ResourceProvider.getFullFilePath(item.UserObject.ToString()));
                }));
            }
            if (!isTopLevel)
            {
                contextMenu.add(new ContextMenuItem("Rename", path, delegate(ContextMenuItem item)
                {
                    InputBox.GetInput("Rename", String.Format("Please enter a new name for {0}.", item.UserObject.ToString()), true, delegate(String result, ref String errorPrompt)
                    {
                        String originalExtension = Path.GetExtension(item.UserObject.ToString());
                        String targetName        = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(item.UserObject.ToString()), result), originalExtension);
                        if (editorController.ResourceProvider.exists(targetName))
                        {
                            errorPrompt = String.Format("A file named {0} already exists. Please enter another name.", targetName);
                            return(false);
                        }

                        editorController.ResourceProvider.move(path, targetName);
                        return(true);
                    });
                }));
                contextMenu.add(new ContextMenuItem("Delete", path, delegate(ContextMenuItem item)
                {
                    MessageBox.show(String.Format("Are you sure you want to delete {0}?", item.UserObject.ToString()), "Delete?", MessageBoxStyle.IconQuest | MessageBoxStyle.Yes | MessageBoxStyle.No, delegate(MessageBoxStyle result)
                    {
                        if (result == MessageBoxStyle.Yes)
                        {
                            editorController.ResourceProvider.delete(item.UserObject.ToString());
                        }
                    });
                }));
            }
            tree.showContextMenu(contextMenu);
        }