예제 #1
0
 public TestServices With(
     IAssetLoader assetLoader                      = null,
     IFocusManager focusManager                    = null,
     IInputManager inputManager                    = null,
     Func <IKeyboardDevice> keyboardDevice         = null,
     IKeyboardNavigationHandler keyboardNavigation = null,
     Func <IMouseDevice> mouseDevice               = null,
     IRuntimePlatform platform                     = null,
     IPlatformRenderInterface renderInterface      = null,
     IRenderLoop renderLoop = null,
     IScheduler scheduler   = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     return(new TestServices(
                assetLoader: assetLoader ?? AssetLoader,
                focusManager: focusManager ?? FocusManager,
                inputManager: inputManager ?? InputManager,
                keyboardDevice: keyboardDevice ?? KeyboardDevice,
                keyboardNavigation: keyboardNavigation ?? KeyboardNavigation,
                mouseDevice: mouseDevice ?? MouseDevice,
                platform: platform ?? Platform,
                renderInterface: renderInterface ?? RenderInterface,
                scheduler: scheduler ?? Scheduler,
                standardCursorFactory: standardCursorFactory ?? StandardCursorFactory,
                styler: styler ?? Styler,
                theme: theme ?? Theme,
                threadingInterface: threadingInterface ?? ThreadingInterface,
                windowingPlatform: windowingPlatform ?? WindowingPlatform,
                windowImpl: windowImpl ?? WindowImpl));
 }
예제 #2
0
 public TestServices(
     IAssetLoader assetLoader                     = null,
     IInputManager inputManager                   = null,
     ILayoutManager layoutManager                 = null,
     IPclPlatformWrapper platformWrapper          = null,
     IPlatformRenderInterface renderInterface     = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     AssetLoader           = assetLoader;
     InputManager          = inputManager;
     LayoutManager         = layoutManager;
     PlatformWrapper       = platformWrapper;
     RenderInterface       = renderInterface;
     StandardCursorFactory = standardCursorFactory;
     Styler             = styler;
     Theme              = theme;
     ThreadingInterface = threadingInterface;
     WindowImpl         = windowImpl;
     WindowingPlatform  = windowingPlatform;
 }
예제 #3
0
 public TestServices(
     IAssetLoader assetLoader = null,
     IFocusManager focusManager = null,
     IInputManager inputManager = null,
     Func<IKeyboardDevice> keyboardDevice = null,
     ILayoutManager layoutManager = null,
     IPclPlatformWrapper platformWrapper = null,
     IPlatformRenderInterface renderInterface = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler = null,
     Func<Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     AssetLoader = assetLoader;
     FocusManager = focusManager;
     InputManager = inputManager;
     KeyboardDevice = keyboardDevice;
     LayoutManager = layoutManager;
     PlatformWrapper = platformWrapper;
     RenderInterface = renderInterface;
     StandardCursorFactory = standardCursorFactory;
     Styler = styler;
     Theme = theme;
     ThreadingInterface = threadingInterface;
     WindowImpl = windowImpl;
     WindowingPlatform = windowingPlatform;
 }
예제 #4
0
        public Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
        {
            var events = new SystemDialogEvents();

            if (dialog is OpenFileDialog ofd)
            {
                _native.OpenFileDialog((parent as WindowImpl).Native,
                                       events, ofd.AllowMultiple,
                                       ofd.Title,
                                       ofd.InitialDirectory,
                                       ofd.InitialFileName,
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }
            else
            {
                _native.SaveFileDialog((parent as WindowImpl).Native,
                                       events,
                                       dialog.Title,
                                       dialog.InitialDirectory,
                                       dialog.InitialFileName,
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result; }));
        }
예제 #5
0
        public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            var tcs = new TaskCompletionSource<string>();
            var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent),
                FileChooserAction.SelectFolder,
                "Cancel", ResponseType.Cancel,
                "Select Folder", ResponseType.Accept)
            {

            };

            dlg.Modal = true;

            dlg.Response += (_, args) =>
            {
                if (args.ResponseId == ResponseType.Accept)
                    tcs.TrySetResult(dlg.Filename);

                dlg.Hide();
                dlg.Dispose();
            };

            dlg.Close += delegate
            {
                tcs.TrySetResult(null);
                dlg.Dispose();
            };
            dlg.Show();
            return tcs.Task;
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Window"/> class.
 /// </summary>
 /// <param name="impl">The window implementation.</param>
 public Window(IWindowImpl impl)
     : base(impl)
 {
     impl.Closing            = HandleClosing;
     impl.WindowStateChanged = HandleWindowStateChanged;
     _maxPlatformClientSize  = PlatformImpl?.MaxClientSize ?? default(Size);
 }
예제 #7
0
 public TestServices(
     IAssetLoader assetLoader                     = null,
     IFocusManager focusManager                   = null,
     IInputManager inputManager                   = null,
     Func <IKeyboardDevice> keyboardDevice        = null,
     ILayoutManager layoutManager                 = null,
     IRuntimePlatform platform                    = null,
     IPlatformRenderInterface renderInterface     = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     AssetLoader           = assetLoader;
     FocusManager          = focusManager;
     InputManager          = inputManager;
     KeyboardDevice        = keyboardDevice;
     LayoutManager         = layoutManager;
     Platform              = platform;
     RenderInterface       = renderInterface;
     StandardCursorFactory = standardCursorFactory;
     Styler             = styler;
     Theme              = theme;
     ThreadingInterface = threadingInterface;
     WindowImpl         = windowImpl;
     WindowingPlatform  = windowingPlatform;
 }
예제 #8
0
        public async Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            var res = await ShowDialog(dialog.Title, ((WindowBaseImpl)parent)?.GtkWidget,
                                       GtkFileChooserAction.SelectFolder, false, dialog.InitialDirectory);

            return(res?.FirstOrDefault());
        }
예제 #9
0
 public TestServices(
     IAssetLoader assetLoader                      = null,
     IFocusManager focusManager                    = null,
     IInputManager inputManager                    = null,
     Func <IKeyboardDevice> keyboardDevice         = null,
     IKeyboardNavigationHandler keyboardNavigation = null,
     Func <IMouseDevice> mouseDevice               = null,
     IRuntimePlatform platform                     = null,
     IPlatformRenderInterface renderInterface      = null,
     IRenderLoop renderLoop = null,
     IScheduler scheduler   = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     AssetLoader           = assetLoader;
     FocusManager          = focusManager;
     InputManager          = inputManager;
     KeyboardDevice        = keyboardDevice;
     KeyboardNavigation    = keyboardNavigation;
     MouseDevice           = mouseDevice;
     Platform              = platform;
     RenderInterface       = renderInterface;
     Scheduler             = scheduler;
     StandardCursorFactory = standardCursorFactory;
     Styler             = styler;
     Theme              = theme;
     ThreadingInterface = threadingInterface;
     WindowImpl         = windowImpl;
     WindowingPlatform  = windowingPlatform;
 }
예제 #10
0
 public TestServices With(
     IAssetLoader assetLoader                     = null,
     IInputManager inputManager                   = null,
     ILayoutManager layoutManager                 = null,
     IPclPlatformWrapper platformWrapper          = null,
     IPlatformRenderInterface renderInterface     = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     return(new TestServices(
                assetLoader: assetLoader ?? AssetLoader,
                inputManager: inputManager ?? InputManager,
                layoutManager: layoutManager ?? LayoutManager,
                platformWrapper: platformWrapper ?? PlatformWrapper,
                renderInterface: renderInterface ?? RenderInterface,
                standardCursorFactory: standardCursorFactory ?? StandardCursorFactory,
                styler: styler ?? Styler,
                theme: theme ?? Theme,
                threadingInterface: threadingInterface ?? ThreadingInterface,
                windowImpl: windowImpl ?? WindowImpl,
                windowingPlatform: windowingPlatform ?? WindowingPlatform));
 }
예제 #11
0
 public TestServices With(
     IAssetLoader assetLoader              = null,
     IFocusManager focusManager            = null,
     IInputManager inputManager            = null,
     Func <IKeyboardDevice> keyboardDevice = null,
     ILayoutManager layoutManager          = null,
     IRuntimePlatform platform             = null,
     IRenderer renderer = null,
     IPlatformRenderInterface renderInterface = null,
     IRenderLoop renderLoop = null,
     IScheduler scheduler   = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler      = null,
     Func <Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     return(new TestServices(
                assetLoader: assetLoader ?? AssetLoader,
                focusManager: focusManager ?? FocusManager,
                inputManager: inputManager ?? InputManager,
                keyboardDevice: keyboardDevice ?? KeyboardDevice,
                layoutManager: layoutManager ?? LayoutManager,
                platform: platform ?? Platform,
                renderer: renderer ?? Renderer,
                renderInterface: renderInterface ?? RenderInterface,
                renderLoop: renderLoop ?? RenderLoop,
                scheduler: scheduler ?? Scheduler,
                standardCursorFactory: standardCursorFactory ?? StandardCursorFactory,
                styler: styler ?? Styler,
                theme: theme ?? Theme,
                threadingInterface: threadingInterface ?? ThreadingInterface,
                windowingPlatform: windowingPlatform ?? WindowingPlatform));
 }
            async Task <string[]> Show(SystemDialog d, IWindowImpl parent)
            {
                var model = new ManagedFileChooserViewModel((FileSystemDialog)d);

                var dialog = new T
                {
                    Content     = new ManagedFileChooser(),
                    DataContext = model
                };

                dialog.Closed += delegate { model.Cancel(); };

                string[] result = null;

                model.CompleteRequested += items =>
                {
                    result = items;
                    dialog.Close();
                };

                model.CancelRequested += dialog.Close;

                await dialog.ShowDialog <object>(parent);

                return(result);
            }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Window"/> class.
 /// </summary>
 /// <param name="impl">The window implementation.</param>
 public Window(IWindowImpl impl)
     : base(impl)
 {
     impl.Closing           = HandleClosing;
     _maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size);
     Screens = new Screens(PlatformImpl?.Screen);
 }
예제 #14
0
        public Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            var tcs = new TaskCompletionSource <string>();
            var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImplBase)parent)?.Widget.Toplevel as Window,
                                                        FileChooserAction.SelectFolder,
                                                        "Cancel", ResponseType.Cancel,
                                                        "Select Folder", ResponseType.Accept)
            {
            };

            dlg.Modal = true;

            dlg.Response += (_, args) =>
            {
                if (args.ResponseId == ResponseType.Accept)
                {
                    tcs.TrySetResult(dlg.Filename);
                }

                dlg.Hide();
                dlg.Dispose();
            };

            dlg.Close += delegate
            {
                tcs.TrySetResult(null);
                dlg.Dispose();
            };
            dlg.Show();
            return(tcs.Task);
        }
예제 #15
0
        public Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            return(Task.Factory.StartNew(() =>
            {
                string result = string.Empty;

                var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero;
                var frm = (IFileDialog)(new UnmanagedMethods.FileOpenDialogRCW());
                uint options;
                frm.GetOptions(out options);
                options |= (uint)(UnmanagedMethods.FOS.FOS_PICKFOLDERS | UnmanagedMethods.FOS.FOS_FORCEFILESYSTEM | UnmanagedMethods.FOS.FOS_NOVALIDATE | UnmanagedMethods.FOS.FOS_NOTESTFILECREATE | UnmanagedMethods.FOS.FOS_DONTADDTORECENT);
                frm.SetOptions(options);

                if (dialog.InitialDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.InitialDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetFolder(directoryShellItem);
                    }
                }

                if (dialog.DefaultDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.DefaultDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetDefaultFolder(directoryShellItem);
                    }
                }

                if (frm.Show(hWnd) == (uint)UnmanagedMethods.HRESULT.S_OK)
                {
                    IShellItem shellItem;
                    if (frm.GetResult(out shellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        IntPtr pszString;
                        if (shellItem.GetDisplayName(UnmanagedMethods.SIGDN_FILESYSPATH, out pszString) == (uint)UnmanagedMethods.HRESULT.S_OK)
                        {
                            if (pszString != IntPtr.Zero)
                            {
                                try
                                {
                                    result = Marshal.PtrToStringAuto(pszString);
                                }
                                finally
                                {
                                    Marshal.FreeCoTaskMem(pszString);
                                }
                            }
                        }
                    }
                }

                return result;
            }));
        }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Window"/> class.
 /// </summary>
 /// <param name="impl">The window implementation.</param>
 public Window(IWindowImpl impl)
     : base(impl)
 {
     impl.Closing            = HandleClosing;
     impl.WindowStateChanged = HandleWindowStateChanged;
     _maxPlatformClientSize  = PlatformImpl?.MaxClientSize ?? default(Size);
     this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl?.Resize(x));
 }
예제 #17
0
        public Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            var events = new SystemDialogEvents();

            _native.SelectFolderDialog((parent as WindowImpl).Native, events, dialog.Title, dialog.InitialDirectory);

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result.FirstOrDefault(); }));
        }
예제 #18
0
 public static IWindowImpl Unwrap(IWindowImpl impl)
 {
     if (impl is ValidatingWindowImpl v)
     {
         return(v.Inner);
     }
     return(impl);
 }
예제 #19
0
 public Window()
 {
     Icon = Properties.Resources.WindowIcon;
     js_window_callback_         = new IWindowImpl(this);
     form_closing_event_handler_ = new FormClosingEventHandler(this.Window_FormClosing);
     this.FormClosed            += new FormClosedEventHandler(Window_FormClosed);
     this.FormClosing           += form_closing_event_handler_;
 }
예제 #20
0
 public Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
 {
     return(ShowDialog(dialog.Title, ((WindowBaseImpl)parent)?.GtkWidget,
                       dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save,
                       (dialog as OpenFileDialog)?.AllowMultiple ?? false,
                       Path.Combine(string.IsNullOrEmpty(dialog.InitialDirectory) ? "" : dialog.InitialDirectory,
                                    string.IsNullOrEmpty(dialog.InitialFileName) ? "" : dialog.InitialFileName)));
 }
예제 #21
0
 public void ShowDialog(IWindowImpl parent)
 {
     _parent = (WindowImpl)parent;
     _parent._disabledBy.Add(this);
     _parent.UpdateEnabled();
     SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, ((WindowImpl)parent)._hwnd);
     ShowWindow(_showWindowState);
 }
예제 #22
0
        public async Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            await EnsureInitialized();

            var xid = parent.Handle.Handle;

            return(await await RunOnGtkThread(
                       () => _inner.ShowFolderDialogAsync(dialog, GtkWindow.Null, chooser => UpdateParent(chooser, xid))));
        }
예제 #23
0
 public WindowDecorator(ITopLevelImpl tl)
 {
     _tl = tl;
     _window = tl as IWindowImpl;
     _popup = tl as IPopupImpl;
     _tl.Input = OnInput;
     _tl.Paint = OnPaint;
     _tl.Resized = OnResized;
 }
예제 #24
0
 public Window()
 {
     InitializeComponent();
     iwindow_ = new IWindowImpl(this);
     Icon     = Properties.Resources.WindowIcon;
     form_closing_event_handler = new FormClosingEventHandler(this.Window_FormClosing);
     this.FormClosed           += new FormClosedEventHandler(Window_FormClosed);
     this.FormClosing          += form_closing_event_handler;
 }
예제 #25
0
 public WindowDecorator(ITopLevelImpl tl)
 {
     _tl         = tl;
     _window     = tl as IWindowImpl;
     _popup      = tl as IPopupImpl;
     _tl.Input   = OnInput;
     _tl.Paint   = OnPaint;
     _tl.Resized = OnResized;
 }
예제 #26
0
        public MainWindow(IWindowImpl impl) : base(impl)
        {
            AvaloniaXamlLoader.Load(this);
            this.AttachDevTools();

            Pager = this.FindControl <PageContainer>("Container");

            Pager.RegisterPages(HomePage, new AmbientSoundPage(), new FindMyGearPage(), new FactoryResetPage(),
                                new CreditsPage(), new TouchpadPage(), new EqualizerPage(), new AdvancedPage(), new NoiseProPage(),
                                new SystemPage(), new SelfTestPage(), new SettingsPage(), new PopupSettingsPage(),
                                ConnectionLostPage, CustomTouchActionPage, DeviceSelectionPage, new SystemInfoPage(),
                                new WelcomePage(), UnsupportedFeaturePage, UpdatePage, UpdateProgressPage, new SystemCoredumpPage(),
                                new HotkeyPage());

            _titleBar = this.FindControl <CustomTitleBar>("TitleBar");
            _titleBar.PointerPressed += (i, e) => PlatformImpl?.BeginMoveDrag(e);
            _titleBar.OptionsPressed += (i, e) => _titleBar.OptionsButton.ContextMenu.Open(_titleBar.OptionsButton);

            _popup = new BudsPopup();

            BluetoothImpl.Instance.BluetoothError += OnBluetoothError;
            BluetoothImpl.Instance.Disconnected   += OnDisconnected;
            BluetoothImpl.Instance.Connected      += OnConnected;

            SPPMessageHandler.Instance.ExtendedStatusUpdate += OnExtendedStatusUpdate;
            SPPMessageHandler.Instance.StatusUpdate         += OnStatusUpdate;
            SPPMessageHandler.Instance.OtherOption          += HandleOtherTouchOption;

            EventDispatcher.Instance.EventReceived += OnEventReceived;
            NotifyIconImpl.Instance.LeftClicked    += TrayIcon_OnLeftClicked;
            TrayManager.Instance.Rebuild();

            Pager.PageSwitched  += (sender, pages) => BuildOptionsMenu();
            Loc.LanguageUpdated += BuildOptionsMenu;
            BuildOptionsMenu();

            if (BluetoothImpl.Instance.RegisteredDeviceValid)
            {
                Task.Factory.StartNew(() => BluetoothImpl.Instance.ConnectAsync());
                Pager.SwitchPage(AbstractPage.Pages.Home);
            }
            else
            {
                Pager.SwitchPage(AbstractPage.Pages.Welcome);
            }

            if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                if (desktop.Args.Contains("/StartMinimized") && PlatformUtils.SupportsTrayIcon)
                {
                    WindowState = WindowState.Minimized;
                }
            }
        }
예제 #27
0
파일: Stubs.cs 프로젝트: xllance/Avalonia
 public WindowStub(IWindowImpl parent = null)
 {
     if (parent != null)
     {
         PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent,
                                                                                                (_, size, __) =>
         {
             Resize(size);
         }));
     }
 }
        /// <summary>
        /// show folder dialog as an asynchronous operation.
        /// </summary>
        /// <param name="dialog">The dialog.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>System.String.</returns>
        public async Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            await EnsureInitialized();

            return(await await RunOnGlibThread(async() =>
            {
                var res = await ShowDialog(dialog.Title, parent,
                                           GtkFileChooserAction.SelectFolder, false, dialog.Directory, null, null);
                return res?.FirstOrDefault();
            }));
        }
예제 #29
0
 public WindowStub(IWindowImpl parent = null)
 {
     if (parent != null)
     {
         PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent,
                                                                                                (_, size, __) =>
         {
             Resize(size, PlatformResizeReason.Unspecified);
         }));
     }
 }
예제 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Window"/> class.
        /// </summary>
        /// <param name="impl">The window implementation.</param>
        public Window(IWindowImpl impl)
            : base(impl)
        {
            impl.Closing = HandleClosing;
            impl.GotInputWhenDisabled = OnGotInputWhenDisabled;
            impl.WindowStateChanged   = HandleWindowStateChanged;
            _maxPlatformClientSize    = PlatformImpl?.MaxClientSize ?? default(Size);
            this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl?.Resize(x));

            PlatformImpl?.ShowTaskbarIcon(ShowInTaskbar);
        }
예제 #31
0
        public async Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
        {
            await EnsureInitialized();

            return(await await RunOnGlibThread(
                       () => ShowDialog(dialog.Title, parent,
                                        dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save,
                                        (dialog as OpenFileDialog)?.AllowMultiple ?? false,
                                        Path.Combine(string.IsNullOrEmpty(dialog.InitialDirectory) ? "" : dialog.InitialDirectory,
                                                     string.IsNullOrEmpty(dialog.InitialFileName) ? "" : dialog.InitialFileName), dialog.Filters)));
        }
예제 #32
0
파일: Window.cs 프로젝트: xuezs/Avalonia
        /// <summary>
        /// Initializes a new instance of the <see cref="Window"/> class.
        /// </summary>
        /// <param name="impl">The window implementation.</param>
        public Window(IWindowImpl impl)
            : base(impl)
        {
            impl.Closing           = HandleClosing;
            _maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size);
            Screens = new Screens(PlatformImpl?.Screen);

            if (PlatformImpl != null)
            {
                PlatformImpl.WindowStateChanged = s => WindowState = s;
            }
        }
예제 #33
0
    public static IWindowImpl Wrap(IWindowImpl impl)
    {
#if DEBUG
        if (impl is ValidatingToplevelImpl)
        {
            return(impl);
        }
        return(new ValidatingWindowImpl(impl));
#else
        return(impl);
#endif
    }
예제 #34
0
        public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
        {
            var tcs = new TaskCompletionSource<string[]>();
            var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent),
                dialog is OpenFileDialog
                    ? FileChooserAction.Open
                    : FileChooserAction.Save,
                "Cancel", ResponseType.Cancel,
                "Open", ResponseType.Accept)
            {
                SelectMultiple = (dialog as OpenFileDialog)?.AllowMultiple ?? false,
            };
            foreach (var filter in dialog.Filters)
            {
                var ffilter = new FileFilter()
                {
                    Name = filter.Name + " (" + string.Join(";", filter.Extensions.Select(e => "*." + e)) + ")"
                };
                foreach (var ext in filter.Extensions)
                    ffilter.AddPattern("*." + ext);
                dlg.AddFilter(ffilter);
            }
            dlg.SetFilename(dialog.InitialFileName);
            dlg.Modal = true;

            dlg.Response += (_, args) =>
            {
                if (args.ResponseId == ResponseType.Accept)
                    tcs.TrySetResult(dlg.Filenames);
                dlg.Hide();
                dlg.Dispose();
            };

            dlg.Close += delegate
            {
                tcs.TrySetResult(null);
                dlg.Dispose();
            };
            dlg.Show();
            return tcs.Task;
        }
예제 #35
0
 public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
 {
     throw new NotImplementedException();
 }
예제 #36
0
 public TestServices With(
     IAssetLoader assetLoader = null,
     IFocusManager focusManager = null,
     IInputManager inputManager = null,
     Func<IKeyboardDevice> keyboardDevice = null,
     ILayoutManager layoutManager = null,
     IPclPlatformWrapper platformWrapper = null,
     IPlatformRenderInterface renderInterface = null,
     IStandardCursorFactory standardCursorFactory = null,
     IStyler styler = null,
     Func<Styles> theme = null,
     IPlatformThreadingInterface threadingInterface = null,
     IWindowImpl windowImpl = null,
     IWindowingPlatform windowingPlatform = null)
 {
     return new TestServices(
         assetLoader: assetLoader ?? AssetLoader,
         focusManager: focusManager ?? FocusManager,
         inputManager: inputManager ?? InputManager,
         keyboardDevice: keyboardDevice ?? KeyboardDevice,
         layoutManager: layoutManager ?? LayoutManager,
         platformWrapper: platformWrapper ?? PlatformWrapper,
         renderInterface: renderInterface ?? RenderInterface,
         standardCursorFactory: standardCursorFactory ?? StandardCursorFactory,
         styler: styler ?? Styler,
         theme: theme ?? Theme,
         threadingInterface: threadingInterface ?? ThreadingInterface,
         windowImpl: windowImpl ?? WindowImpl,
         windowingPlatform: windowingPlatform ?? WindowingPlatform);
 }
예제 #37
0
 public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
 {
     throw new NotImplementedException();
 }
예제 #38
0
 public WindowingPlatformImpl(IWindowImpl window)
 {
     _window = window;
 }
예제 #39
0
        public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            return Task.Factory.StartNew(() =>
            {
                string result = string.Empty;

                var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero;
                var frm = (IFileDialog)(new UnmanagedMethods.FileOpenDialogRCW());
                uint options;
                frm.GetOptions(out options);
                options |= (uint)(UnmanagedMethods.FOS.FOS_PICKFOLDERS | UnmanagedMethods.FOS.FOS_FORCEFILESYSTEM | UnmanagedMethods.FOS.FOS_NOVALIDATE | UnmanagedMethods.FOS.FOS_NOTESTFILECREATE | UnmanagedMethods.FOS.FOS_DONTADDTORECENT);
                frm.SetOptions(options);

                if (dialog.InitialDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.InitialDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetFolder(directoryShellItem);
                    }
                }

                if (dialog.DefaultDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.DefaultDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetDefaultFolder(directoryShellItem);
                    }
                }

                if (frm.Show(hWnd) == (uint)UnmanagedMethods.HRESULT.S_OK)
                {
                    IShellItem shellItem;
                    if (frm.GetResult(out shellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        IntPtr pszString;
                        if (shellItem.GetDisplayName(UnmanagedMethods.SIGDN_FILESYSPATH, out pszString) == (uint)UnmanagedMethods.HRESULT.S_OK)
                        {
                            if (pszString != IntPtr.Zero)
                            {
                                try
                                {
                                    result = Marshal.PtrToStringAuto(pszString);
                                }
                                finally
                                {
                                    Marshal.FreeCoTaskMem(pszString);
                                }
                            }
                        }
                    }
                }

                return result;
            });
        }
예제 #40
0
        public unsafe Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
        {
            var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero;
            return Task.Factory.StartNew(() =>
            {
                var filters = new StringBuilder();
                foreach (var filter in dialog.Filters)
                {
                    var extMask = string.Join(";", filter.Extensions.Select(e => "*." + e));
                    filters.Append(filter.Name);
                    filters.Append(" (");
                    filters.Append(extMask);
                    filters.Append(")");
                    filters.Append('\0');
                    filters.Append(extMask);
                    filters.Append('\0');
                }
                if (filters.Length == 0)
                    filters.Append("All files\0*.*\0");
                filters.Append('\0');

                var filterBuffer = new char[filters.Length];
                filters.CopyTo(0, filterBuffer, 0, filterBuffer.Length);

                var defExt = (dialog as SaveFileDialog)?.DefaultExtension;
                var fileBuffer = new char[256];
                dialog.InitialFileName?.CopyTo(0, fileBuffer, 0, dialog.InitialFileName.Length);

                string userSelectedExt = null;

                fixed (char* pFileBuffer = fileBuffer)
                fixed (char* pFilterBuffer = filterBuffer)
                fixed (char* pDefExt = defExt)
                fixed (char* pInitDir = dialog.InitialDirectory)
                fixed (char* pTitle = dialog.Title)
                {

                    var ofn = new UnmanagedMethods.OpenFileName()
                    {
                        hwndOwner = hWnd,
                        hInstance = IntPtr.Zero,
                        lCustData = IntPtr.Zero,
                        nFilterIndex = 0,
                        Flags =
                            UnmanagedMethods.OpenFileNameFlags.OFN_EXPLORER |
                            UnmanagedMethods.OpenFileNameFlags.OFN_HIDEREADONLY,
                        nMaxCustFilter = 0,
                        nMaxFile = fileBuffer.Length - 1,
                        nMaxFileTitle = 0,
                        lpTemplateName = IntPtr.Zero,
                        lpfnHook = IntPtr.Zero,
                        lpstrCustomFilter = IntPtr.Zero,
                        lpstrDefExt = new IntPtr(pDefExt),
                        lpstrFile = new IntPtr(pFileBuffer),
                        lpstrFileTitle = IntPtr.Zero,
                        lpstrFilter = new IntPtr(pFilterBuffer),
                        lpstrInitialDir = new IntPtr(pInitDir),
                        lpstrTitle = new IntPtr(pTitle),

                    };
                    ofn.lStructSize = Marshal.SizeOf(ofn);
                    if ((dialog as OpenFileDialog)?.AllowMultiple == true)
                        ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_ALLOWMULTISELECT;

                    if (dialog is SaveFileDialog)
                        ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_NOREADONLYRETURN |
                                     UnmanagedMethods.OpenFileNameFlags.OFN_OVERWRITEPROMPT;

                    var pofn = &ofn;

                    var res = dialog is OpenFileDialog
                        ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn))
                        : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn));
                    if (!res)
                        return null;
                    if (dialog?.Filters.Count > 0)
                        userSelectedExt = dialog.Filters[ofn.nFilterIndex - 1].Extensions.FirstOrDefault();
                }
                var cStart = 0;
                string dir = null;
                var files = new List<string>();
                for (var c = 0; c < fileBuffer.Length; c++)
                {
                    if (fileBuffer[c] == 0)
                    {
                        //Encountered double zero char
                        if (cStart == c)
                            break;

                        var s = new string(fileBuffer, cStart, c - cStart);
                        if (dir == null)
                            dir = s;
                        else
                            files.Add(s);
                        cStart = c + 1;
                    }
                }
                if (files.Count == 0)
                {
                    if (dialog is SaveFileDialog)
                    {
                        if (string.IsNullOrWhiteSpace(Path.GetExtension(dir)) &&
                            !string.IsNullOrWhiteSpace(userSelectedExt) &&
                            !userSelectedExt.Contains("*"))
                            dir = Path.ChangeExtension(dir, userSelectedExt);
                    }
                    
                    return new[] {dir};
                }

                return files.Select(f => Path.Combine(dir, f)).ToArray();
            });
        }
예제 #41
0
파일: Window.cs 프로젝트: cyyt/Lesktop
 public Window()
 {
     Icon = Properties.Resources.WindowIcon;
     js_window_callback_ = new IWindowImpl(this);
     form_closing_event_handler_ = new FormClosingEventHandler(this.Window_FormClosing);
     this.FormClosed += new FormClosedEventHandler(Window_FormClosed);
     this.FormClosing += form_closing_event_handler_;
 }