Skip to content

Commit f655ff8

Browse files
committed
add Duplicate command to Edit menu
1 parent 2591b2a commit f655ff8

8 files changed

Lines changed: 59 additions & 2 deletions

QtSLiM/QtSLiMAppDelegate.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ void QtSLiMAppDelegate::addActionsForGlobalMenuItems(QWidget *window)
10081008
}
10091009
{
10101010
QAction *actionShowDebuggingOutput = new QAction("Show Debugging Output", this);
1011-
actionShowDebuggingOutput->setShortcut(flagsAndKey(Qt::ControlModifier, Qt::Key_D));
1011+
actionShowDebuggingOutput->setShortcut(flagsAndKey(Qt::ControlModifier | Qt::ShiftModifier, Qt::Key_D));
10121012
connect(actionShowDebuggingOutput, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_showDebuggingOutput);
10131013
window->addAction(actionShowDebuggingOutput);
10141014
}
@@ -1080,6 +1080,12 @@ void QtSLiMAppDelegate::addActionsForGlobalMenuItems(QWidget *window)
10801080
connect(actionPaste, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_paste);
10811081
window->addAction(actionPaste);
10821082
}
1083+
{
1084+
QAction *actionDuplicate = new QAction("Duplicate", this);
1085+
actionDuplicate->setShortcut(flagsAndKey(Qt::ControlModifier, Qt::Key_D));
1086+
connect(actionDuplicate, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_duplicate);
1087+
window->addAction(actionDuplicate);
1088+
}
10831089
{
10841090
QAction *actionDelete = new QAction("Delete", this);
10851091
//actionDelete->setShortcut(flagsAndKey(Qt::ControlModifier, Qt::Key_V));
@@ -1495,6 +1501,15 @@ void QtSLiMAppDelegate::dispatch_paste(void)
14951501
plainTextEdit->paste();
14961502
}
14971503

1504+
void QtSLiMAppDelegate::dispatch_duplicate(void)
1505+
{
1506+
QWidget *focusWidget = QApplication::focusWidget();
1507+
QtSLiMScriptTextEdit *scriptEdit = dynamic_cast<QtSLiMScriptTextEdit*>(focusWidget);
1508+
1509+
if (scriptEdit && scriptEdit->isEnabled() && !scriptEdit->isReadOnly())
1510+
scriptEdit->duplicateSelection();
1511+
}
1512+
14981513
void QtSLiMAppDelegate::dispatch_delete(void)
14991514
{
15001515
QWidget *focusWidget = QApplication::focusWidget();

QtSLiM/QtSLiMAppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public slots:
137137
void dispatch_cut(void);
138138
void dispatch_copy(void);
139139
void dispatch_paste(void);
140+
void dispatch_duplicate(void);
140141
void dispatch_delete(void);
141142
void dispatch_selectAll(void);
142143

QtSLiM/QtSLiMScriptTextEdit.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,34 @@ void QtSLiMScriptTextEdit::copyAsHTML(void)
26752675
}
26762676
}
26772677

2678+
void QtSLiMScriptTextEdit::duplicateSelection(void)
2679+
{
2680+
if (isEnabled() && !isReadOnly())
2681+
{
2682+
QTextCursor &&edit_cursor = textCursor();
2683+
QString selectedString = edit_cursor.selectedText();
2684+
int pasteStart = edit_cursor.selectionEnd();
2685+
2686+
edit_cursor.beginEditBlock();
2687+
2688+
edit_cursor.setPosition(pasteStart, QTextCursor::MoveAnchor);
2689+
edit_cursor.insertText(selectedString);
2690+
2691+
int pasteEnd = edit_cursor.position();
2692+
2693+
edit_cursor.setPosition(pasteStart, QTextCursor::MoveAnchor);
2694+
edit_cursor.setPosition(pasteEnd, QTextCursor::KeepAnchor);
2695+
2696+
// end the editing block, producing one undo-able operation
2697+
edit_cursor.endEditBlock();
2698+
setTextCursor(edit_cursor);
2699+
}
2700+
else
2701+
{
2702+
qApp->beep();
2703+
}
2704+
}
2705+
26782706
void QtSLiMScriptTextEdit::shiftSelectionLeft(void)
26792707
{
26802708
if (isEnabled() && !isReadOnly())

QtSLiM/QtSLiMScriptTextEdit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class QtSLiMScriptTextEdit : public QtSLiMTextEdit
201201

202202
public slots:
203203
void copyAsHTML(void);
204+
void duplicateSelection(void);
204205
void shiftSelectionLeft(void);
205206
void shiftSelectionRight(void);
206207
void commentUncommentSelection(void);

QtSLiM/QtSLiMWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,7 @@ void QtSLiMWindow::updateMenuEnablingSHARED(QWidget *p_focusWidget)
33253325
bool isScriptTextEdit = (!!scriptEdit);
33263326
bool isModifiableScriptTextEdit = (isScriptTextEdit && !scriptEdit->isReadOnly());
33273327

3328+
ui->actionDuplicate->setEnabled(isModifiableScriptTextEdit);
33283329
ui->actionCopyAsHTML->setEnabled(isScriptTextEdit);
33293330
ui->actionShiftLeft->setEnabled(isModifiableScriptTextEdit);
33303331
ui->actionShiftRight->setEnabled(isModifiableScriptTextEdit);

QtSLiM/QtSLiMWindow.ui

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ QSlider::handle:horizontal:disabled {
13831383
<addaction name="actionCopy"/>
13841384
<addaction name="actionCopyAsHTML"/>
13851385
<addaction name="actionPaste"/>
1386+
<addaction name="actionDuplicate"/>
13861387
<addaction name="actionDelete"/>
13871388
<addaction name="actionSelectAll"/>
13881389
<addaction name="separator"/>
@@ -1918,7 +1919,7 @@ QSlider::handle:horizontal:disabled {
19181919
<string>Show Debugging Output</string>
19191920
</property>
19201921
<property name="shortcut">
1921-
<string>Ctrl+D</string>
1922+
<string>Ctrl+Shift+D</string>
19221923
</property>
19231924
</action>
19241925
<action name="actionClearDebug">
@@ -2102,6 +2103,14 @@ QSlider::handle:horizontal:disabled {
21022103
<string>Show a chart depicting the plot symbols used by Plot's points() method</string>
21032104
</property>
21042105
</action>
2106+
<action name="actionDuplicate">
2107+
<property name="text">
2108+
<string>Duplicate</string>
2109+
</property>
2110+
<property name="shortcut">
2111+
<string>Ctrl+D</string>
2112+
</property>
2113+
</action>
21052114
</widget>
21062115
<layoutdefault spacing="6" margin="11"/>
21072116
<customwidgets>

QtSLiM/QtSLiMWindow_glue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void QtSLiMWindow::glueUI(void)
229229
connect(ui->actionCut, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_cut);
230230
connect(ui->actionCopy, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_copy);
231231
connect(ui->actionPaste, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_paste);
232+
connect(ui->actionDuplicate, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_duplicate);
232233
connect(ui->actionDelete, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_delete);
233234
connect(ui->actionSelectAll, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_selectAll);
234235

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ development head (in the master branch):
3535
partial fix for #530, extend cor() and cov() to support correlation/covariance between the columns of a matrix (or matrices), as in R
3636
policy change: cov(x, y), cor(x, y), var(x), and sd(x) with x and/or y of length 1 now returns NAN (used to return NULL);
3737
this is because you can't make a matrix containing NULLs, and Eidos doesn't have NA (which is what R uses in this case)
38+
add Duplicate command to the Edit command, command-D, useful for code editing; change Show Debugging Output to shift-command-D
3839

3940

4041
version 5.0 (Eidos version 4.0):

0 commit comments

Comments
 (0)