Skip to content

Commit

Permalink
add delete to input context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed May 14, 2023
1 parent 5903cc7 commit 1464098
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/scripts/controllers/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,18 @@
};
};

$scope.isSupportForceDeleteEmpty = function (option) {
if ($scope.context.options[option.key] || $scope.context.options[option.key] === '') {
return false;
}

if (option.overrideMode === 'append' || aria2SettingService.isOptionKeyRequired(option.key)) {
return false;
}

return !!($scope.context.globalOptions[option.key] && $scope.context.globalOptions[option.key].trim());
};

$scope.setOption = function (key, value, optionStatus) {
if (value !== '' || !aria2SettingService.isOptionKeyRequired(key)) {
$scope.context.options[key] = value;
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/core/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@
context.editable = false;
}

if (angular.element(event.target).attr('data-support-force-delete-empty') === 'true'
&& angular.element(event.target).val() === '') {
context.forceDeleteEmpty = true;
}

if (event.target.nodeName.match(/^(input|textarea)$/i) || event.target.isContentEditable) {
ariaNgNativeElectronService.showTextboxContextMenu(context);
}
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
ngModel: '=',
defaultValue: '=?',
fixedValue: '=?',
supportForceDeleteEmpty: '=?',
onChangeValue: '&'
},
link: function (scope, element, attrs, ngModel) {
var pendingSaveRequest = null;
var options = {
showPlaceholderCount: false,
deleteKeyAlwaysChangeValue: false,
lazySaveTimeout: ariaNgConstants.lazySaveTimeout,
errorTooltipPlacement: 'top',
errorTooltipDelay: ariaNgConstants.errorTooltipDelay
Expand Down
2 changes: 1 addition & 1 deletion app/views/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
</div>
</div>
<ng-setting ng-repeat="option in context.availableOptions" ng-if="context.optionFilter[option.category]"
option="option" show-placeholder-count="true"
option="option" show-placeholder-count="true" support-force-delete-empty="isSupportForceDeleteEmpty(option)"
lazy-save-timeout="0" delete-key-always-change-value="true"
default-value="(option.overrideMode !== 'append' && !context.options[option.key] && context.options[option.key] !== '') ? context.globalOptions[option.key] : ''"
fixed-value="option.overrideMode === 'append' ? context.globalOptions[option.key] : ''"
Expand Down
7 changes: 5 additions & 2 deletions app/views/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
<div ng-class="{'input-group': !!option.suffix}">
<div class="form-group has-feedback" ng-class="[optionStatus.getStatusFeedbackStyle()]">
<pre ng-if="fixedValue && fixedValue.trim()" ng-bind="fixedValue"></pre>
<input class="form-control" type="text" placeholder="{{placeholder}}" ng-disabled="!!option.readonly"
<input class="form-control" type="text" placeholder="{{placeholder}}"
data-support-force-delete-empty="{{supportForceDeleteEmpty}}" ng-disabled="!!option.readonly"
ng-if="(option.type === 'string' && !option.showHistory) || option.type === 'integer' || option.type === 'float'"
ng-model="optionValue" ng-change="changeValue(optionValue, true)" ng-keyup="inputKeyUp($event, true)"/>
<input-dropdown input-class-name="form-control" style="width: 100%;" input-placeholder="{{placeholder}}"
data-support-force-delete-empty="{{supportForceDeleteEmpty}}"
ng-if="option.type === 'string' && option.showHistory" disabled="!!option.readonly"
ng-model="optionValue" ng-keyup="inputKeyUp($event, from === 'input')"
selected-item="optionValue" allow-custom-input="true"
only-show-non-empty-dropdown="true" default-dropdown-items="history"
filter-list-method="filterHistory(userInput)"
value-changed-method="changeValue(value, from === 'input')"></input-dropdown>
<textarea class="form-control" rows="6" placeholder="{{placeholder}}" ng-disabled="!!option.readonly"
<textarea class="form-control" rows="6" placeholder="{{placeholder}}"
data-support-force-delete-empty="{{supportForceDeleteEmpty}}" ng-disabled="!!option.readonly"
ng-if="option.type === 'text'"
ng-model="optionValue"
ng-change="changeValue(optionValue, true)" ng-keyup="inputKeyUp($event, true)"></textarea>
Expand Down
18 changes: 18 additions & 0 deletions main/components/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ let buildTextboxContextMenu = function(context) {
}
}

if (item.role === 'delete') {
if (context.forceDeleteEmpty) {
item.role = '';
item.click = function () {
core.mainWindow.webContents.sendInputEvent({
type: 'keyUp',
keyCode: 'Delete'
});
}
} else if (context.selected === false) {
item.enabled = false;
}
}

if (item.role === 'undo' || item.role === 'redo' || item.role === 'cut' || item.role === 'paste') {
if (context.editable === false) {
item.enabled = false;
Expand Down Expand Up @@ -195,6 +209,10 @@ let setTextboxContextMenuTemplate = function (context) {
label: getMenuTitle(context, 'Paste', 'Paste'),
role: 'paste'
},
{
label: getMenuTitle(context, 'Delete', 'Delete'),
role: 'delete'
},
{
type: 'separator'
},
Expand Down

0 comments on commit 1464098

Please sign in to comment.