Beispiel #1
0
        public static void SelectPath(NSWindow window, NSTextField field)
        {
            NSOpenPanel openPanel = new NSOpenPanel();

            openPanel.CanChooseFiles          = false;
            openPanel.CanChooseDirectories    = true;
            openPanel.AllowsMultipleSelection = false;
            openPanel.ResolvesAliases         = true;
            openPanel.BeginSheet(window, (i) =>
            {
                try
                {
                    if (openPanel.Url != null)
                    {
                        string path = openPanel.Url.Path;

                        if (!string.IsNullOrEmpty(path))
                        {
                            field.StringValue = path;
                        }
                    }
                }
                finally
                {
                    openPanel.Dispose();
                }
            });
        }
Beispiel #2
0
        public string OpenFileDialog(NSWindow window, string[] FileTypes, string title, bool canchoosedirectories = false, bool canchoosefiles = true)
        {
            string path = string.Empty;

            try {
                NSOpenPanel dlg = NSOpenPanel.OpenPanel;
                //dlg.Prompt = "Selecione um Arquivo";
                dlg.Title                   = title;
                dlg.CanChooseFiles          = canchoosefiles;
                dlg.CanChooseDirectories    = canchoosedirectories;
                dlg.AllowedFileTypes        = FileTypes;
                dlg.AllowsMultipleSelection = false;
                dlg.ResolvesAliases         = true;
                dlg.ReleasedWhenClosed      = true;

//				dlg.BeginSheet(window, (i) => {
//					try
//					{
//						if(dlg.Url != null)
//						{
//
//
//							var urlString = dlg.Url.Path;
//
//							if(!string.IsNullOrEmpty(urlString))
//							{
//								Console.WriteLine(urlString);
//							}
//						}
//					}
//					finally
//					{
//						dlg.Dispose();
//					}
//				});
//



                nint retDlg = dlg.RunModal();
                if (retDlg == 1)
                {
                    NSUrl url = dlg.Urls [0];
                    if (url != null)
                    {
                        path = url.Path;
                    }
                }
                NSDate DateLoop = new NSDate();
                DateLoop = DateLoop.AddSeconds(0.1);
                NSRunLoop.Current.RunUntil(DateLoop);
                dlg.Dispose();
                dlg = null;
            } catch (Exception) {
                //
            }
            return(path);
        }
Beispiel #3
0
 public override void Dispose()
 {
     if (ofdlg != null)
     {
         ofdlg.Dispose();
     }
     if (sfdlg != null)
     {
         sfdlg.Dispose();
     }
 }
Beispiel #4
0
        public static string OpenFilePanel()
        {
            // Open file prompt
            // Credit user: rjm
            // http://forums.xamarin.com/discussion/3876/regression-in-nsopenpanel
            NSOpenPanel openPanel = new NSOpenPanel();
            string      s         = "";

            openPanel.Begin(((int result) => {
                try {
                    if (openPanel.Url != null)
                    {
                        s = openPanel.Url.Path;
                    }
                } finally {
                    openPanel.Dispose();
                }
            }));
            return(s);
        }
        public static void SelectFile(NSWindow window, NSTextField field)
        {
            NSOpenPanel openPanel = new NSOpenPanel();

            openPanel.BeginSheet(window, (i) => {
                try {
                    if (openPanel.Url != null)
                    {
                        string path = openPanel.Url.Path;

                        if (!string.IsNullOrEmpty(path))
                        {
                            field.StringValue = path;
                        }
                    }
                } finally {
                    openPanel.Dispose();
                }
            });
        }
Beispiel #6
0
        /// <inheritdoc />
        public override FileBrowserDialogResult ShowDialog()
        {
            _fileDialog.Title = Title;
            _fileDialog.CanChooseDirectories    = IsFolderBrowser;
            _fileDialog.CanChooseFiles          = !IsFolderBrowser;
            _fileDialog.AllowsMultipleSelection = Multiselect;
            var dialogResult = FileBrowserDialogResult.None;
            var result       = (NSPanelButtonType)(int)_fileDialog.RunModal();

            if (result == NSPanelButtonType.Cancel)
            {
                dialogResult = FileBrowserDialogResult.Cancel;
                _files       = new List <string>();
            }
            else if (result == NSPanelButtonType.Ok)
            {
                dialogResult = FileBrowserDialogResult.Ok;
                _files       = _fileDialog.Urls.Select(f => f.Path).ToList();
            }
            _fileDialog.Close();
            _fileDialog.Dispose();
            _fileDialog = null;
            return(dialogResult);
        }
Beispiel #7
0
        public override void FinishedLaunching(NSObject notification)
        {
            ///////
            /// Glorified Event "Handler"
            ///  for Menu Items (like File, edit and so forth)
            ///////
            ///

            // *************************** //
            // TODO
            // - Reimplement SaveAs (command-S)


            mainWindowController = new MainWindowController();
            mainWindowController.Window.MakeKeyAndOrderFront(this);

            MainWindow winMain = mainWindowController.Window;

            /////
            /// SaveAs File Menu Item
            /////
            miSaveAs.Activated += (object sender, EventArgs e) => {
                SharedWindowMethods.SaveCurrentSetFilePanel();
            };

            /////
            /// Open File Menu Item
            /////
            miOpen.Activated += (object sender, EventArgs e) => {
                // Call for openPanel
                // Credit user: rjm
                // http://forums.xamarin.com/discussion/3876/regression-in-nsopenpanel
                NSOpenPanel openPanel = new NSOpenPanel();
                openPanel.Begin(((int result) => {
                    try {
                        if (openPanel.Url != null)
                        {
                            // get path
                            var file = openPanel.Url.Path;

                            // open file
                            m_at.OpenFile(System.IO.Path.GetFileName(file), System.IO.Path.GetDirectoryName(file));

                            // parse open file
                            m_at.InitSet();

                            // init SetRunner
                            m_sr.Init(m_at.GetSetList());

                            // update table
                            winMain.tbvSetList.DataSource = new TableViewHandler(m_at.GetSetListTable());
                        }
                    } finally {
                        openPanel.Dispose();
                    }
                }));

                // refresh window gui
                winMain.updateGUI();
            };
        }
Beispiel #8
0
        private bool MacOpenFile()
        {
            NSOpenPanel nsOpenPanel = new NSOpenPanel();

            nsOpenPanel.Title = this.Title;
            switch (this.FileChooserAction)
            {
            case FileAction.Open:
                nsOpenPanel.CanChooseFiles       = true;
                nsOpenPanel.CanChooseDirectories = false;
                if (this.AllowedFileTypes != null)
                {
                    nsOpenPanel.AllowedFileTypes = this.AllowedFileTypes;
                    break;
                }
                break;

            case FileAction.Save:
                NSSavePanel savePanel = NSSavePanel.SavePanel;
                savePanel.AllowedFileTypes     = this.AllowedFileTypes;
                savePanel.CanCreateDirectories = true;
                savePanel.DirectoryUrl         = new NSUrl(this.InitialDirectory);
                // ISSUE: reference to a compiler-generated method
                if (savePanel.RunModal() == 1)
                {
                    this.Path = savePanel.Url.Path;
                    savePanel.Dispose();
                    return(true);
                }
                savePanel.Dispose();
                return(false);

            case FileAction.SelectFolder:
                nsOpenPanel.CanChooseDirectories = true;
                nsOpenPanel.CanChooseFiles       = false;
                break;

            case FileAction.SelectFiles:
                nsOpenPanel.CanChooseDirectories = true;
                nsOpenPanel.CanChooseFiles       = true;
                break;
            }
            nsOpenPanel.CanCreateDirectories    = false;
            nsOpenPanel.AllowsMultipleSelection = this.AllowMultipleSelect;
            nsOpenPanel.DirectoryUrl            = new NSUrl(this.InitialDirectory);
            // ISSUE: reference to a compiler-generated method
            if (nsOpenPanel.RunModal() == 1)
            {
                int      length   = nsOpenPanel.Urls.Length;
                string[] strArray = new string[length];
                for (int index = 0; index < length; ++index)
                {
                    strArray[index] = nsOpenPanel.Urls[index].Path.ToString();
                }
                this.Paths = strArray;
                this.Path  = this.Paths[0];
                nsOpenPanel.Dispose();
                return(true);
            }
            nsOpenPanel.Dispose();
            return(false);
        }
Beispiel #9
0
        private void procBtn(int state = 1)
        {
            if (state == 4)
            {
                string[]    filetypes = { "rar" };
                NSOpenPanel dlg       = NSOpenPanel.OpenPanel;
                dlg.Title                   = "Selecione";
                dlg.CanChooseFiles          = true;
                dlg.CanChooseDirectories    = false;
                dlg.AllowedFileTypes        = filetypes;
                dlg.AllowsMultipleSelection = false;
                dlg.ResolvesAliases         = true;
                dlg.ReleasedWhenClosed      = true;
                dlg.BeginSheet(this, (i) => {
                    try
                    {
                        if (dlg.Url != null)
                        {
                            var urlString = dlg.Url.Path;
                            if (!string.IsNullOrEmpty(urlString))
                            {
                                //NSDate DateLoop = new NSDate ();
                                //DateLoop = DateLoop.AddSeconds (0.1);
                                //NSRunLoop.Current.RunUntil(DateLoop );

                                NSThread.Start(() => {
                                    clsRAR orar = new clsRAR();
                                    rarFile     = orar.OpenRAR(urlString, this, this.tbv_Arquivos);
                                    orar        = null;
                                });
                            }
                        }
                    }
                    finally
                    {
                        dlg.Dispose();
                        dlg = null;
                    }
                });
            }
            else
            {
                NSIndexSet nSelRows = this.tbv_Arquivos.SelectedRows;
                if (nSelRows.Count > 0)
                {
                    nuint[] nRows = nSelRows.ToArray();
                    if (nRows.Length > 0)
                    {
                        ViewArquivosDataSource datasource = (ViewArquivosDataSource)this.tbv_Arquivos.DataSource;
                        clsViewArquivos        cvarqs     = new clsViewArquivos();
                        string aState = string.Empty;
                        foreach (nint lRow in nRows)
                        {
                            switch (state)
                            {
                            case 1:
                                aState = "1";
                                break;

                            case 2:
                                aState = cvarqs.GetTagsArquivo(datasource, (int)lRow, 1);
                                break;

                            case 3:
                                NSOpenPanel dlg = NSOpenPanel.OpenPanel;
                                dlg.Title                   = "Salvar em";
                                dlg.CanChooseFiles          = false;
                                dlg.CanChooseDirectories    = true;
                                dlg.AllowsMultipleSelection = false;
                                dlg.ResolvesAliases         = true;
                                dlg.ReleasedWhenClosed      = true;
                                dlg.BeginSheet(this, (i) => {
                                    try {
                                        string urlString = dlg.Url.Path;
                                        if (!string.IsNullOrEmpty(urlString))
                                        {
                                            nSelRows = this.tbv_Arquivos.SelectedRows;
                                            NSThread.Start(() => {
                                                clsRAR exRAR = new clsRAR();
                                                exRAR.ExtractRAR(this, this.tbv_Arquivos, nSelRows, rarFile, urlString);
                                                exRAR = null;
                                            });
                                        }
                                    } finally {
                                        dlg.Dispose();
                                        dlg = null;
                                    }
                                    this.tbv_Arquivos.ReloadData();
                                });
                                break;

                            case 5:

                                break;
                            }
                            if (state != 3)
                            {
                                cvarqs.SetTagsArquivo(datasource, (int)lRow, aState);
                                cvarqs     = null;
                                datasource = null;
                                this.tbv_Arquivos.ReloadData();
                            }
                        }
                    }
                }
                else
                {
                    string mText = string.Empty;
                    string iText = string.Empty;
                    switch (state)
                    {
                    case 1:
                        mText = "Remover Arquivo(s)";
                        iText = "Selecione ao menos um aquivo para Remover !";
                        break;

                    case 2:
                        mText = "Desfazer Ação";
                        iText = "Selecione ao menos um arquivo para\r\n Desfazer a Ação !";
                        break;

                    case 3:
                        mText = "Extrair Arquivos";
                        iText = "Selecione ao menos um arquivo para Extrair !";
                        break;
                    }

                    NSAlert alert = new NSAlert()
                    {
                        AlertStyle      = NSAlertStyle.Warning,
                        InformativeText = iText,
                        MessageText     = mText,
                    };
                    alert.RunSheetModal(this);
                }
            }
        }