Improve font selection with keyboard in PasteTextCommand

This commit is contained in:
David Capello 2015-10-19 15:32:44 -03:00
parent 02ef2268fe
commit 62a16d0525
5 changed files with 33 additions and 11 deletions

View File

@ -6,7 +6,7 @@
<view id="view" expansive="true" />
<hbox>
<boxfiller />
<button id="load_font" text="Load" width="80" />
<button id="load_font" text="Load" magnet="true" width="80" />
</hbox>
</vbox>
</gui>

View File

@ -109,6 +109,7 @@ private:
try {
m_fontPopup.reset(new FontPopup());
m_fontPopup->Load.connect(&PasteTextWindow::setFontFace, this);
m_fontPopup->Close.connect(Bind<void>(&PasteTextWindow::onCloseFontPopup, this));
}
catch (const std::exception& ex) {
Console::showException(ex);
@ -127,6 +128,10 @@ private:
}
}
void onCloseFontPopup() {
fontFace()->dropDown()->requestFocus();
}
std::string m_face;
base::UniquePtr<FontPopup> m_fontPopup;
};

View File

@ -118,7 +118,9 @@ private:
};
FontPopup::FontPopup()
: PopupWindow("Fonts", kCloseOnClickInOtherWindow)
: PopupWindow("Fonts",
kCloseOnClickInOtherWindow,
kDoNothingOnEnter)
, m_popup(new gen::FontPopup())
{
setAutoRemap(false);
@ -127,6 +129,7 @@ FontPopup::FontPopup()
addChild(m_popup);
m_popup->loadFont()->Click.connect(Bind<void>(&FontPopup::onLoadFont, this));
m_listBox.setFocusMagnet(true);
m_listBox.Change.connect(Bind<void>(&FontPopup::onChangeFont, this));
m_listBox.DoubleClickItem.connect(Bind<void>(&FontPopup::onLoadFont, this));

View File

@ -19,9 +19,12 @@ namespace ui {
using namespace gfx;
PopupWindow::PopupWindow(const std::string& text, ClickBehavior clickBehavior)
PopupWindow::PopupWindow(const std::string& text,
ClickBehavior clickBehavior,
EnterBehavior enterBehavior)
: Window(WithTitleBar, text)
, m_clickBehavior(clickBehavior)
, m_enterBehavior(enterBehavior)
, m_filtering(false)
{
setSizeable(false);
@ -83,7 +86,7 @@ bool PopupWindow::onProcessMessage(Message* msg)
case kMouseLeaveMessage:
if (m_hotRegion.isEmpty() && !isMoveable())
closeWindow(NULL);
closeWindow(nullptr);
break;
case kKeyDownMessage:
@ -91,12 +94,15 @@ bool PopupWindow::onProcessMessage(Message* msg)
KeyMessage* keymsg = static_cast<KeyMessage*>(msg);
KeyScancode scancode = keymsg->scancode();
if (scancode == kKeyEsc ||
scancode == kKeyEnter ||
scancode == kKeyEnterPad) {
closeWindow(NULL);
}
if (scancode == kKeyEsc)
closeWindow(nullptr);
if (m_enterBehavior == kCloseOnEnter &&
(scancode == kKeyEnter ||
scancode == kKeyEnterPad)) {
closeWindow(this);
return true;
}
}
break;

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2013, 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -21,7 +21,14 @@ namespace ui {
kCloseOnClickOutsideHotRegion
};
PopupWindow(const std::string& text, ClickBehavior clickBehavior);
enum EnterBehavior {
kDoNothingOnEnter,
kCloseOnEnter,
};
PopupWindow(const std::string& text,
ClickBehavior clickBehavior,
EnterBehavior enterBehavior = kCloseOnEnter);
~PopupWindow();
void setHotRegion(const gfx::Region& region);
@ -41,6 +48,7 @@ namespace ui {
void stopFilteringMessages();
ClickBehavior m_clickBehavior;
EnterBehavior m_enterBehavior;
gfx::Region m_hotRegion;
bool m_filtering;
};