Skip to content

Commit

Permalink
More declarative copy paste state
Browse files Browse the repository at this point in the history
  • Loading branch information
pvuorela committed Jun 8, 2016
1 parent 84de8a7 commit 0a5b02d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
14 changes: 2 additions & 12 deletions qml/MenuFingerterm.qml
Expand Up @@ -24,8 +24,6 @@ Item {
id: menuWin

property bool showing
property bool enableCopy
property bool enablePaste
property string currentShowMethod: util.settingsValue("ui/vkbShowMethod")
property string currentDragMode: util.settingsValue("ui/dragMode")
property string currentOrientationLockMode: util.settingsValue("ui/orientationLockMode")
Expand Down Expand Up @@ -137,7 +135,7 @@ Item {
}
width: window.buttonWidthHalf
height: window.buttonHeightLarge
enabled: menuWin.enableCopy
enabled: util.terminalHasSelection
}
Button {
text: "Paste"
Expand All @@ -147,7 +145,7 @@ Item {
}
width: window.buttonWidthHalf
height: window.buttonHeightLarge
enabled: menuWin.enablePaste
enabled: util.canPaste
}
}
Button {
Expand Down Expand Up @@ -462,12 +460,4 @@ Item {
}
}
}

Connections {
target: util
onClipboardOrSelectionChanged: {
enableCopy = util.terminalHasSelection();
enablePaste = util.canPaste();
}
}
}
4 changes: 3 additions & 1 deletion util.cpp
Expand Up @@ -266,12 +266,14 @@ void Util::copyTextToClipboard(QString str)

bool Util::terminalHasSelection()
{
if (!iTerm) {
return false;
}
return !iTerm->selection().isNull();
}

bool Util::canPaste()
{

QClipboard *cb = QGuiApplication::clipboard();

return !cb->text().isEmpty();
Expand Down
7 changes: 5 additions & 2 deletions util.h
Expand Up @@ -31,6 +31,8 @@ class Util : public QObject
Q_OBJECT
Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged)
Q_PROPERTY(QString windowTitle READ windowTitle NOTIFY windowTitleChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY clipboardOrSelectionChanged)
Q_PROPERTY(bool terminalHasSelection READ terminalHasSelection NOTIFY clipboardOrSelectionChanged)

public:
explicit Util(QSettings* settings, QObject *parent = 0);
Expand All @@ -56,8 +58,9 @@ class Util : public QObject
Q_INVOKABLE void notifyText(QString text);

Q_INVOKABLE void copyTextToClipboard(QString str);
Q_INVOKABLE bool canPaste();
Q_INVOKABLE bool terminalHasSelection();

bool canPaste();
bool terminalHasSelection();

void bellAlert();
void selectionFinished();
Expand Down

0 comments on commit 0a5b02d

Please sign in to comment.