Bläddra i källkod

add delete to input context menu

MaysWind 2 år sedan
förälder
incheckning
1464098b59

+ 12 - 0
app/scripts/controllers/new.js

@@ -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;

+ 5 - 0
app/scripts/core/root.js

@@ -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);
             }

+ 1 - 1
app/scripts/directives/setting.js

@@ -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

+ 1 - 1
app/views/new.html

@@ -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] : ''"

+ 5 - 2
app/views/setting.html

@@ -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>

+ 18 - 0
main/components/menu.js

@@ -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;
@@ -195,6 +209,10 @@ let setTextboxContextMenuTemplate = function (context) {
             label: getMenuTitle(context, 'Paste', 'Paste'),
             role: 'paste'
         },
+        {
+            label: getMenuTitle(context, 'Delete', 'Delete'),
+            role: 'delete'
+        },
         {
             type: 'separator'
         },