better TextDisplay = better MessageBox on linux

This commit is contained in:
Adam D. Ruppe 2023-12-11 20:59:52 -05:00
parent 84c1e8162d
commit fcc840df4e
1 changed files with 37 additions and 10 deletions

View File

@ -7624,8 +7624,8 @@ class ScrollMessageWidget : Widget {
auto _this = this; auto _this = this;
container.addEventListener((scope ClickEvent ce) { container.addEventListener((scope ClickEvent ce) {
if(ce.target && ce.target.tabStop) //if(ce.target && ce.target.tabStop)
ce.target.focus(); //ce.target.focus();
// ctrl is reserved for the application // ctrl is reserved for the application
if(ce.ctrlKey) if(ce.ctrlKey)
@ -8232,9 +8232,11 @@ class Window : Widget {
version(custom_widgets) version(custom_widgets)
override void defaultEventHandler_click(ClickEvent event) { override void defaultEventHandler_click(ClickEvent event) {
if(event.button != MouseButton.wheelDown && event.button != MouseButton.wheelUp) {
if(event.target && event.target.tabStop) if(event.target && event.target.tabStop)
event.target.focus(); event.target.focus();
} }
}
private static void delegate(Window) newWindowCreated; private static void delegate(Window) newWindowCreated;
@ -12072,12 +12074,17 @@ class TextDisplayHelper : Widget {
override Menu contextMenu(int x, int y) { override Menu contextMenu(int x, int y) {
if(ctx is null) { if(ctx is null) {
ctx = new Menu("Actions", this); ctx = new Menu("Actions", this);
if(!readonly) {
ctx.addItem(new MenuItem(new Action("&Undo", GenericIcons.Undo, &undo))); ctx.addItem(new MenuItem(new Action("&Undo", GenericIcons.Undo, &undo)));
ctx.addItem(new MenuItem(new Action("&Redo", GenericIcons.Redo, &redo))); ctx.addItem(new MenuItem(new Action("&Redo", GenericIcons.Redo, &redo)));
ctx.addSeparator(); ctx.addSeparator();
}
if(!readonly)
ctx.addItem(new MenuItem(new Action("Cu&t", GenericIcons.Cut, &cut))); ctx.addItem(new MenuItem(new Action("Cu&t", GenericIcons.Cut, &cut)));
ctx.addItem(new MenuItem(new Action("&Copy", GenericIcons.Copy, &copy))); ctx.addItem(new MenuItem(new Action("&Copy", GenericIcons.Copy, &copy)));
if(!readonly)
ctx.addItem(new MenuItem(new Action("&Paste", GenericIcons.Paste, &paste))); ctx.addItem(new MenuItem(new Action("&Paste", GenericIcons.Paste, &paste)));
if(!readonly)
ctx.addItem(new MenuItem(new Action("&Delete", 0, &deleteContentOfSelection))); ctx.addItem(new MenuItem(new Action("&Delete", 0, &deleteContentOfSelection)));
ctx.addSeparator(); ctx.addSeparator();
ctx.addItem(new MenuItem(new Action("Select &All", 0, &selectAll))); ctx.addItem(new MenuItem(new Action("Select &All", 0, &selectAll)));
@ -12099,6 +12106,7 @@ class TextDisplayHelper : Widget {
} }
void undo() { void undo() {
if(readonly) return;
if(undoStack.length) { if(undoStack.length) {
auto state = undoStack[$-1]; auto state = undoStack[$-1];
undoStack = undoStack[0 .. $-1]; undoStack = undoStack[0 .. $-1];
@ -12113,6 +12121,7 @@ class TextDisplayHelper : Widget {
} }
void redo() { void redo() {
if(readonly) return;
if(redoStack.length) { if(redoStack.length) {
doStateCheckpoint(); doStateCheckpoint();
auto state = redoStack[$-1]; auto state = redoStack[$-1];
@ -12127,6 +12136,7 @@ class TextDisplayHelper : Widget {
} }
void cut() { void cut() {
if(readonly) return;
with(l.selection()) { with(l.selection()) {
if(!isEmpty()) { if(!isEmpty()) {
setClipboardText(parentWindow.win, getContentString()); setClipboardText(parentWindow.win, getContentString());
@ -12150,6 +12160,7 @@ class TextDisplayHelper : Widget {
} }
void paste() { void paste() {
if(readonly) return;
getClipboardText(parentWindow.win, (txt) { getClipboardText(parentWindow.win, (txt) {
doStateCheckpoint(); doStateCheckpoint();
l.selection.replaceContent(txt); l.selection.replaceContent(txt);
@ -12160,6 +12171,7 @@ class TextDisplayHelper : Widget {
} }
void deleteContentOfSelection() { void deleteContentOfSelection() {
if(readonly) return;
doStateCheckpoint(); doStateCheckpoint();
l.selection.replaceContent(""); l.selection.replaceContent("");
l.selection.setUserXCoordinate(); l.selection.setUserXCoordinate();
@ -13255,6 +13267,21 @@ class TextDisplay : EditableTextWidget {
this.readonly = true; this.readonly = true;
} }
override void registerMovement() {
super.registerMovement();
// FIXME: do the horizontal one too as needed and make sure that it does
// wordwrapping again
if(l.height + smw.horizontalScrollBar.height > this.height)
smw.verticalScrollBar.show();
else
smw.verticalScrollBar.hide();
l.wordWrapWidth = this.width;
smw.verticalScrollBar.setPosition = 0;
}
class Style : Widget.Style { class Style : Widget.Style {
// just want the generic look for these // just want the generic look for these
} }