Add search/replace support to the Query Tool, including regexp matching. Fixes #1765

This commit is contained in:
Dave Page 2016-11-24 15:38:30 +00:00
parent 89ed2a7deb
commit 394381bf75
5 changed files with 166 additions and 14 deletions

View File

@ -58,16 +58,28 @@ When using the syntax-highlighting SQL editors, the following shortcuts are avai
When using the Query Tool, the following shortcuts are available:
+--------------------------+------------------+-------------------------------------+
| Shortcut (Windows/Linux) | Shortcut (Mac) | Function |
+==========================+==================+=====================================+
| F5 | F5 | Execute query |
+--------------------------+------------------+-------------------------------------+
| F7 | F7 | EXPLAIN query |
+--------------------------+------------------+-------------------------------------+
| Shift+F7 | Shift+F7 | EXPLAIN ANALYZE query |
+--------------------------+------------------+-------------------------------------+
| F8 | F8 | Execute query to CSV file |
+--------------------------+------------------+-------------------------------------+
| Ctrl+Space | Ctrl+Space | Auto-complete |
+--------------------------+------------------+-------------------------------------+
+--------------------------+--------------------+-----------------------------------+
| Shortcut (Windows/Linux) | Shortcut (Mac) | Function |
+==========================+====================+===================================+
| F5 | F5 | Execute query |
+--------------------------+--------------------+-----------------------------------+
| F7 | F7 | EXPLAIN query |
+--------------------------+--------------------+-----------------------------------+
| Shift+F7 | Shift+F7 | EXPLAIN ANALYZE query |
+--------------------------+--------------------+-----------------------------------+
| F8 | F8 | Execute query to CSV file |
+--------------------------+--------------------+-----------------------------------+
| Alt+G | Alt+G | Jump (to line:column) |
+--------------------------+--------------------+-----------------------------------+
| Ctrl+Space | Ctrl+Space | Auto-complete |
+--------------------------+--------------------+-----------------------------------+
| Ctrl+F | Cmd+F | Find |
+--------------------------+--------------------+-----------------------------------+
| Ctrl+G | Cmd+G | Find next |
+--------------------------+--------------------+-----------------------------------+
| Shift+Ctrl+G | Shift+Cmd+G | Find previous |
+--------------------------+--------------------+-----------------------------------+
| Shift+Ctrl+F | Shift+Cmd+F | Replace |
+--------------------------+--------------------+-----------------------------------+
| Shift+Ctrl+R | Shift+Cmd+Option+F | Replace all |
+--------------------------+--------------------+-----------------------------------+

View File

@ -40,6 +40,7 @@ class BrowserModule(PgAdminModule):
# Add browser stylesheets
for (endpoint, filename) in [
('static', 'css/codemirror/codemirror.css'),
('static', 'js/codemirror/addon/dialog/dialog.css'),
('static', 'css/jQuery-contextMenu/jquery.contextMenu.css' if current_app.debug
else 'css/jQuery-contextMenu/jquery.contextMenu.min.css'),
('static', 'css/wcDocker/wcDocker.css' if current_app.debug

View File

@ -1465,3 +1465,19 @@ body {
-ms-user-select: text;
user-select: text;
}
/* Codemirror buttons */
.CodeMirror-dialog button {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: white;
font-size: 70%;
background-image: -webkit-linear-gradient(top, #337ab7 0%, #265a88 100%);
background-image: -o-linear-gradient(top, #337ab7 0%, #265a88 100%);
background-image: -webkit-gradient(linear, left top, left bottom, from(#337ab7), to(#265a88));
background-image: linear-gradient(to bottom, #337ab7 0%, #265a88 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff265a88', GradientType=0);
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
background-repeat: repeat-x;
border-color: #245580;
border-radius: 4px;
}

View File

@ -47,6 +47,54 @@
</li>
</ul>
</div>
<div class="btn-group" role="group" aria-label="">
<button id="btn-find" type="button" class="btn btn-default" title="{{ _('Find (Ctrl/Cmd+F)') }}">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
<button id="btn-find-menu-dropdown" type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span> <span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li>
<a id="btn-find-menu-find" href="#">
<span>{{ _('Find (Ctrl/Cmd+F)') }}</span>
</a>
</li>
<li>
<a id="btn-find-menu-find-next" href="#">
<span>{{ _('Find next (Ctrl/Cmd+G)') }}</span>
</a>
</li>
<li>
<a id="btn-find-menu-find-previous" href="#">
<span>{{ _('Find previous (Shift+Ctrl/Cmd+G)') }}</span>
</a>
</li>
<li>
<a id="btn-find-menu-find-persistent" href="#">
<span>{{ _('Persistent find') }}</span>
</a>
</li>
<li class="divider"></li>
<li>
<a id="btn-find-menu-replace" href="#">
<span>{{ _('Replace (Shift+Ctrl/Cmd+F)') }}</span>
</a>
</li>
<li>
<a id="btn-find-menu-replace-all" href="#">
<span>{{ _('Replace all') }}</span>
</a>
</li>
<li class="divider"></li>
<li>
<a id="btn-find-menu-jump" href="#">
<span>{{ _('Jump (Alt+G)') }}</span>
</a>
</li>
</ul>
</div>
<div class="btn-group" role="group" aria-label="">
<button id="btn-copy-row" type="button" class="btn btn-default" title="{{ _('Copy Row') }}" disabled>
<i class="fa fa-files-o" aria-hidden="true"></i>

View File

@ -9,6 +9,10 @@ define(
'codemirror/addon/hint/sql-hint', 'pgadmin.file_manager',
'codemirror/addon/fold/pgadmin-sqlfoldcode',
'codemirror/addon/scroll/simplescrollbars',
'codemirror/addon/dialog/dialog',
'codemirror/addon/search/search',
'codemirror/addon/search/searchcursor',
'codemirror/addon/search/jump-to-line',
'backgrid.sizeable.columns', 'slickgrid/slick.formatters',
'slickgrid/slick.pgadmin.formatters', 'slickgrid/slick.editors',
'slickgrid/slick.pgadmin.editors', 'slickgrid/plugins/slick.autotooltips',
@ -126,6 +130,14 @@ define(
"click #btn-save": "on_save",
"click #btn-file-menu-save": "on_save",
"click #btn-file-menu-save-as": "on_save_as",
"click #btn-find": "on_find",
"click #btn-find-menu-find": "on_find",
"click #btn-find-menu-find-next": "on_find_next",
"click #btn-find-menu-find-previous": "on_find_previous",
"click #btn-find-menu-replace": "on_replace",
"click #btn-find-menu-replace-all": "on_replace_all",
"click #btn-find-menu-find-persistent": "on_find_persistent",
"click #btn-find-menu-jump": "on_jump",
"click #btn-delete-row": "on_delete",
"click #btn-filter": "on_show_filter",
"click #btn-filter-menu": "on_show_filter",
@ -1049,6 +1061,69 @@ define(
);
},
// Callback function for the find button click.
on_find: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("find");
},
// Callback function for the find next button click.
on_find_next: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("findNext");
},
// Callback function for the find previous button click.
on_find_previous: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("findPrev");
},
// Callback function for the replace button click.
on_replace: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("replace");
},
// Callback function for the replace all button click.
on_replace_all: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("replaceAll");
},
// Callback function for the find persistent button click.
on_find_persistent: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("findPersistent");
},
// Callback function for the jump button click.
on_jump: function(ev) {
var self = this, sql;
this._stopEventPropogation(ev);
this._closeDropDown(ev);
self.query_tool_obj.execCommand("jumpToLine");
},
// Callback function for filter button click.
on_show_filter: function() {
var self = this;