com.intellij.ui.mac.foundation.MacUtil Java Examples

The following examples show how to use com.intellij.ui.mac.foundation.MacUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiSelectDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 6 votes vote down vote up
protected void _init(Project project,
                     String title,
                     String message,
                     @Nullable String checkboxText,
                     boolean checkboxStatus,
                     @Nullable DoNotAskOption doNotAskOption) {
    setTitle(title);
    if (Messages.isMacSheetEmulation()) {
        setUndecorated(true);
    }
    propertiesComponent = PropertiesComponent.getInstance(project);
    myMessage = message;
    myCheckboxText = checkboxText;
    myChecked = checkboxStatus;
    setButtonsAlignment(SwingConstants.RIGHT);
    setDoNotAskOption(doNotAskOption);
    init();
    if (Messages.isMacSheetEmulation()) {
        MacUtil.adjustFocusTraversal(myDisposable);
    }
}
 
Example #2
Source File: Messages.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void _init(String title,
                     String message,
                     @Nonnull String[] options,
                     int defaultOptionIndex,
                     int focusedOptionIndex,
                     @Nullable Icon icon,
                     @Nullable DoNotAskOption doNotAskOption) {
  setTitle(title);
  if (isMacSheetEmulation()) {
    setUndecorated(true);
  }
  myMessage = message;
  myOptions = options;
  myDefaultOptionIndex = defaultOptionIndex;
  myFocusedOptionIndex = focusedOptionIndex;
  myIcon = icon;
  setButtonsAlignment(SwingConstants.CENTER);
  setDoNotAskOption(doNotAskOption);
  init();
  if (isMacSheetEmulation()) {
    MacUtil.adjustFocusTraversal(myDisposable);
  }
}
 
Example #3
Source File: GoogleAlertDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 5 votes vote down vote up
protected void _init(String title, String message) {
    setTitle(title);
    mMessage = message;
    if (Messages.isMacSheetEmulation()) {
        setUndecorated(true);
    }

    setButtonsAlignment(SwingConstants.RIGHT);
    setDoNotAskOption(null);
    init();
    if (Messages.isMacSheetEmulation()) {
        MacUtil.adjustFocusTraversal(myDisposable);
    }
}
 
Example #4
Source File: AddFilterRuleDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 5 votes vote down vote up
protected void _init(String title,
                     @Nullable DoNotAskOption doNotAskOption) {
    setTitle(title);
    if (Messages.isMacSheetEmulation()) {
        setUndecorated(true);
    }

    setButtonsAlignment(SwingConstants.RIGHT);
    setDoNotAskOption(doNotAskOption);
    init();
    if (Messages.isMacSheetEmulation()) {
        MacUtil.adjustFocusTraversal(myDisposable);
    }
}
 
Example #5
Source File: UnityOpenFilePostHandler.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private void activateFrame(@Nullable Project openedProject, @Nonnull UnityOpenFilePostHandlerRequest body)
{
	if(openedProject == null)
	{
		return;
	}

	IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(openedProject);
	if(ideFrame == null || !ideFrame.getWindow().isVisible())
	{
		return;
	}

	if(SystemInfo.isMac)
	{
		RequestFocusHttpRequestHandler.activateFrame(ideFrame);
		ID id = MacUtil.findWindowFromJavaWindow(TargetAWT.to(ideFrame.getWindow()));
		if(id != null)
		{
			Foundation.invoke(id, "makeKeyAndOrderFront:", ID.NIL);
		}
	}
	else if(SystemInfo.isWindows)
	{
		Pointer windowPointer = Native.getWindowPointer(TargetAWT.to(ideFrame.getWindow()));
		User32.INSTANCE.SetForegroundWindow(new WinDef.HWND(windowPointer));
	}
	else
	{
		RequestFocusHttpRequestHandler.activateFrame(ideFrame);
	}
}
 
Example #6
Source File: AbstractProgressIndicatorBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
void stopSystemActivity() {
  MacUtil.Activity macActivity = myMacActivity;
  if (macActivity != null) {
    macActivity.matrixHasYou();
    myMacActivity = null;
  }
}
 
Example #7
Source File: AbstractProgressIndicatorBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void startSystemActivity() {
  myMacActivity = myShouldStartActivity ? MacUtil.wakeUpNeo(this) : null;
}
 
Example #8
Source File: JBMacMessages.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static consulo.ui.Window getForemostWindow(final Window window) {
  Window _window = null;
  IdeFocusManager ideFocusManager = IdeFocusManager.getGlobalInstance();

  Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
  // Let's ask for a focused component first
  if (focusOwner != null) {
    _window = SwingUtilities.getWindowAncestor(focusOwner);
  }

  if (_window == null) {
    // Looks like ide lost focus, let's ask about the last focused component
    focusOwner = ideFocusManager.getLastFocusedFor(ideFocusManager.getLastFocusedFrame());
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window == null) {
    _window = WindowManager.getInstance().findVisibleFrame();
  }

  if (_window == null && window != null) {
    // It might be we just has not opened a frame yet.
    // So let's ask AWT
    focusOwner = window.getMostRecentFocusOwner();
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window != null) {
    // We have successfully found the window
    // Let's check that we have not missed a blocker
    if (ModalityHelper.isModalBlocked(_window)) {
      _window = ModalityHelper.getModalBlockerFor(_window);
    }
  }

  if (SystemInfo.isAppleJvm && MacUtil.getWindowTitle(_window) == null) {
    // With Apple JDK we cannot find a window if it does not have a title
    // Let's show a dialog instead of the message.
    throw new MacMessageException("MacMessage parent does not have a title.");
  }
  while (_window != null && MacUtil.getWindowTitle(_window) == null) {
    _window = _window.getOwner();
    //At least our frame should have a title
  }

  while (Registry.is("skip.untitled.windows.for.mac.messages") && _window != null && _window instanceof JDialog && !((JDialog)_window).isModal()) {
    _window = _window.getOwner();
  }

  return TargetAWT.from(_window);
}
 
Example #9
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Window showDialog(@Nullable consulo.ui.Window uiWindow, final String methodName, final DialogParamsWrapper paramsWrapper) {

    Window awtWindow = TargetAWT.to(uiWindow);

    final Window foremostWindow = getForemostWindow(awtWindow);

    final Window documentRoot = getDocumentRootFromWindow(foremostWindow);

    final ID nativeFocusedWindow = MacUtil.findWindowFromJavaWindow(foremostWindow);

    paramsWrapper.setNativeWindow(nativeFocusedWindow);

    final ID paramsArray = paramsWrapper.getParamsAsID();

    foremostWindow.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosed(WindowEvent e) {
        super.windowClosed(e);
        //if (blockedDocumentRoots.get(documentRoot) != null) {
        //   LOG.assertTrue(blockedDocumentRoots.get(documentRoot) < 2);
        //}
        queuesFromDocumentRoot.remove(documentRoot);
        if (blockedDocumentRoots.remove(documentRoot) != null) {
          throw new MacMessageException("Owner window has been removed");
        }
      }
    });

    final ID delegate = invoke(invoke(getObjcClass("NSAlertDelegate_"), "alloc"), "init");

    IdeFocusManager.getGlobalInstance().setTypeaheadEnabled(false);

    runOrPostponeForWindow(documentRoot, new Runnable() {
      @Override
      public void run() {
        invoke(delegate, "performSelectorOnMainThread:withObject:waitUntilDone:",
               createSelector(methodName), paramsArray, false);
      }
    });

    startModal(documentRoot, nativeFocusedWindow);

    IdeFocusManager.getGlobalInstance().setTypeaheadEnabled(true);
    return documentRoot;
  }
 
Example #10
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Window getForemostWindow(final Window window) {
  Window _window = null;
  IdeFocusManager ideFocusManager = IdeFocusManager.getGlobalInstance();

  Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
  // Let's ask for a focused component first
  if (focusOwner != null) {
    _window = SwingUtilities.getWindowAncestor(focusOwner);
  }

  if (_window == null) {
    // Looks like ide lost focus, let's ask about the last focused component
    focusOwner = ideFocusManager.getLastFocusedFor(ideFocusManager.getLastFocusedFrame());
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window == null) {
    _window = WindowManager.getInstance().findVisibleFrame();
  }

  if (_window == null && window != null) {
    // It might be we just has not opened a frame yet.
    // So let's ask AWT
    focusOwner = window.getMostRecentFocusOwner();
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window != null) {
    // We have successfully found the window
    // Let's check that we have not missed a blocker
    if (ModalityHelper.isModalBlocked(_window)) {
      _window = ModalityHelper.getModalBlockerFor(_window);
    }
  }

  if (SystemInfo.isAppleJvm && MacUtil.getWindowTitle(_window) == null) {
    // With Apple JDK we cannot find a window if it does not have a title
    // Let's show a dialog instead of the message.
    throw new MacMessageException("MacMessage parent does not have a title.");
  }
  while (_window != null && MacUtil.getWindowTitle(_window) == null) {
    _window = _window.getOwner();
    //At least our frame should have a title
  }

  while (Registry.is("skip.untitled.windows.for.mac.messages") && _window != null && _window instanceof JDialog && !((JDialog)_window).isModal()) {
    _window = _window.getOwner();
  }

  return _window;
}