├── .gitignore ├── LICENSE ├── README.md ├── dub.json ├── dub.selections.json ├── dub.userprefs ├── extract-strings.sh ├── install.sh ├── pkg ├── createReleaseArchive.sh └── desktop │ ├── com.gexperts.VisualGrep.desktop │ └── com.gexperts.VisualGrep.desktop.in ├── po ├── LINGUAS ├── vgrep.pot └── zh_CN.po └── source ├── app.d ├── gtk ├── color.d ├── threads.d ├── util.d └── widget │ └── tablabel.d ├── util ├── file │ └── search.d └── mixins │ └── singleton.d └── vg ├── application.d ├── appwindow.d ├── configuration.d ├── constants.d ├── finddialog.d └── search.d /.gitignore: -------------------------------------------------------------------------------- 1 | .dub 2 | docs.json 3 | __dummy.html 4 | *.o 5 | *.obj 6 | vgrep 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License, version 2.0 2 | 3 | 1. Definitions 4 | 5 | 1.1. "Contributor" 6 | 7 | means each individual or legal entity that creates, contributes to the 8 | creation of, or owns Covered Software. 9 | 10 | 1.2. "Contributor Version" 11 | 12 | means the combination of the Contributions of others (if any) used by a 13 | Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | 17 | means Covered Software of a particular Contributor. 18 | 19 | 1.4. "Covered Software" 20 | 21 | means Source Code Form to which the initial Contributor has attached the 22 | notice in Exhibit A, the Executable Form of such Source Code Form, and 23 | Modifications of such Source Code Form, in each case including portions 24 | thereof. 25 | 26 | 1.5. "Incompatible With Secondary Licenses" 27 | means 28 | 29 | a. that the initial Contributor has attached the notice described in 30 | Exhibit B to the Covered Software; or 31 | 32 | b. that the Covered Software was made available under the terms of 33 | version 1.1 or earlier of the License, but not also under the terms of 34 | a Secondary License. 35 | 36 | 1.6. "Executable Form" 37 | 38 | means any form of the work other than Source Code Form. 39 | 40 | 1.7. "Larger Work" 41 | 42 | means a work that combines Covered Software with other material, in a 43 | separate file or files, that is not Covered Software. 44 | 45 | 1.8. "License" 46 | 47 | means this document. 48 | 49 | 1.9. "Licensable" 50 | 51 | means having the right to grant, to the maximum extent possible, whether 52 | at the time of the initial grant or subsequently, any and all of the 53 | rights conveyed by this License. 54 | 55 | 1.10. "Modifications" 56 | 57 | means any of the following: 58 | 59 | a. any file in Source Code Form that results from an addition to, 60 | deletion from, or modification of the contents of Covered Software; or 61 | 62 | b. any new file in Source Code Form that contains any Covered Software. 63 | 64 | 1.11. "Patent Claims" of a Contributor 65 | 66 | means any patent claim(s), including without limitation, method, 67 | process, and apparatus claims, in any patent Licensable by such 68 | Contributor that would be infringed, but for the grant of the License, 69 | by the making, using, selling, offering for sale, having made, import, 70 | or transfer of either its Contributions or its Contributor Version. 71 | 72 | 1.12. "Secondary License" 73 | 74 | means either the GNU General Public License, Version 2.0, the GNU Lesser 75 | General Public License, Version 2.1, the GNU Affero General Public 76 | License, Version 3.0, or any later versions of those licenses. 77 | 78 | 1.13. "Source Code Form" 79 | 80 | means the form of the work preferred for making modifications. 81 | 82 | 1.14. "You" (or "Your") 83 | 84 | means an individual or a legal entity exercising rights under this 85 | License. For legal entities, "You" includes any entity that controls, is 86 | controlled by, or is under common control with You. For purposes of this 87 | definition, "control" means (a) the power, direct or indirect, to cause 88 | the direction or management of such entity, whether by contract or 89 | otherwise, or (b) ownership of more than fifty percent (50%) of the 90 | outstanding shares or beneficial ownership of such entity. 91 | 92 | 93 | 2. License Grants and Conditions 94 | 95 | 2.1. Grants 96 | 97 | Each Contributor hereby grants You a world-wide, royalty-free, 98 | non-exclusive license: 99 | 100 | a. under intellectual property rights (other than patent or trademark) 101 | Licensable by such Contributor to use, reproduce, make available, 102 | modify, display, perform, distribute, and otherwise exploit its 103 | Contributions, either on an unmodified basis, with Modifications, or 104 | as part of a Larger Work; and 105 | 106 | b. under Patent Claims of such Contributor to make, use, sell, offer for 107 | sale, have made, import, and otherwise transfer either its 108 | Contributions or its Contributor Version. 109 | 110 | 2.2. Effective Date 111 | 112 | The licenses granted in Section 2.1 with respect to any Contribution 113 | become effective for each Contribution on the date the Contributor first 114 | distributes such Contribution. 115 | 116 | 2.3. Limitations on Grant Scope 117 | 118 | The licenses granted in this Section 2 are the only rights granted under 119 | this License. No additional rights or licenses will be implied from the 120 | distribution or licensing of Covered Software under this License. 121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 122 | Contributor: 123 | 124 | a. for any code that a Contributor has removed from Covered Software; or 125 | 126 | b. for infringements caused by: (i) Your and any other third party's 127 | modifications of Covered Software, or (ii) the combination of its 128 | Contributions with other software (except as part of its Contributor 129 | Version); or 130 | 131 | c. under Patent Claims infringed by Covered Software in the absence of 132 | its Contributions. 133 | 134 | This License does not grant any rights in the trademarks, service marks, 135 | or logos of any Contributor (except as may be necessary to comply with 136 | the notice requirements in Section 3.4). 137 | 138 | 2.4. Subsequent Licenses 139 | 140 | No Contributor makes additional grants as a result of Your choice to 141 | distribute the Covered Software under a subsequent version of this 142 | License (see Section 10.2) or under the terms of a Secondary License (if 143 | permitted under the terms of Section 3.3). 144 | 145 | 2.5. Representation 146 | 147 | Each Contributor represents that the Contributor believes its 148 | Contributions are its original creation(s) or it has sufficient rights to 149 | grant the rights to its Contributions conveyed by this License. 150 | 151 | 2.6. Fair Use 152 | 153 | This License is not intended to limit any rights You have under 154 | applicable copyright doctrines of fair use, fair dealing, or other 155 | equivalents. 156 | 157 | 2.7. Conditions 158 | 159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 160 | Section 2.1. 161 | 162 | 163 | 3. Responsibilities 164 | 165 | 3.1. Distribution of Source Form 166 | 167 | All distribution of Covered Software in Source Code Form, including any 168 | Modifications that You create or to which You contribute, must be under 169 | the terms of this License. You must inform recipients that the Source 170 | Code Form of the Covered Software is governed by the terms of this 171 | License, and how they can obtain a copy of this License. You may not 172 | attempt to alter or restrict the recipients' rights in the Source Code 173 | Form. 174 | 175 | 3.2. Distribution of Executable Form 176 | 177 | If You distribute Covered Software in Executable Form then: 178 | 179 | a. such Covered Software must also be made available in Source Code Form, 180 | as described in Section 3.1, and You must inform recipients of the 181 | Executable Form how they can obtain a copy of such Source Code Form by 182 | reasonable means in a timely manner, at a charge no more than the cost 183 | of distribution to the recipient; and 184 | 185 | b. You may distribute such Executable Form under the terms of this 186 | License, or sublicense it under different terms, provided that the 187 | license for the Executable Form does not attempt to limit or alter the 188 | recipients' rights in the Source Code Form under this License. 189 | 190 | 3.3. Distribution of a Larger Work 191 | 192 | You may create and distribute a Larger Work under terms of Your choice, 193 | provided that You also comply with the requirements of this License for 194 | the Covered Software. If the Larger Work is a combination of Covered 195 | Software with a work governed by one or more Secondary Licenses, and the 196 | Covered Software is not Incompatible With Secondary Licenses, this 197 | License permits You to additionally distribute such Covered Software 198 | under the terms of such Secondary License(s), so that the recipient of 199 | the Larger Work may, at their option, further distribute the Covered 200 | Software under the terms of either this License or such Secondary 201 | License(s). 202 | 203 | 3.4. Notices 204 | 205 | You may not remove or alter the substance of any license notices 206 | (including copyright notices, patent notices, disclaimers of warranty, or 207 | limitations of liability) contained within the Source Code Form of the 208 | Covered Software, except that You may alter any license notices to the 209 | extent required to remedy known factual inaccuracies. 210 | 211 | 3.5. Application of Additional Terms 212 | 213 | You may choose to offer, and to charge a fee for, warranty, support, 214 | indemnity or liability obligations to one or more recipients of Covered 215 | Software. However, You may do so only on Your own behalf, and not on 216 | behalf of any Contributor. You must make it absolutely clear that any 217 | such warranty, support, indemnity, or liability obligation is offered by 218 | You alone, and You hereby agree to indemnify every Contributor for any 219 | liability incurred by such Contributor as a result of warranty, support, 220 | indemnity or liability terms You offer. You may include additional 221 | disclaimers of warranty and limitations of liability specific to any 222 | jurisdiction. 223 | 224 | 4. Inability to Comply Due to Statute or Regulation 225 | 226 | If it is impossible for You to comply with any of the terms of this License 227 | with respect to some or all of the Covered Software due to statute, 228 | judicial order, or regulation then You must: (a) comply with the terms of 229 | this License to the maximum extent possible; and (b) describe the 230 | limitations and the code they affect. Such description must be placed in a 231 | text file included with all distributions of the Covered Software under 232 | this License. Except to the extent prohibited by statute or regulation, 233 | such description must be sufficiently detailed for a recipient of ordinary 234 | skill to be able to understand it. 235 | 236 | 5. Termination 237 | 238 | 5.1. The rights granted under this License will terminate automatically if You 239 | fail to comply with any of its terms. However, if You become compliant, 240 | then the rights granted under this License from a particular Contributor 241 | are reinstated (a) provisionally, unless and until such Contributor 242 | explicitly and finally terminates Your grants, and (b) on an ongoing 243 | basis, if such Contributor fails to notify You of the non-compliance by 244 | some reasonable means prior to 60 days after You have come back into 245 | compliance. Moreover, Your grants from a particular Contributor are 246 | reinstated on an ongoing basis if such Contributor notifies You of the 247 | non-compliance by some reasonable means, this is the first time You have 248 | received notice of non-compliance with this License from such 249 | Contributor, and You become compliant prior to 30 days after Your receipt 250 | of the notice. 251 | 252 | 5.2. If You initiate litigation against any entity by asserting a patent 253 | infringement claim (excluding declaratory judgment actions, 254 | counter-claims, and cross-claims) alleging that a Contributor Version 255 | directly or indirectly infringes any patent, then the rights granted to 256 | You by any and all Contributors for the Covered Software under Section 257 | 2.1 of this License shall terminate. 258 | 259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 260 | license agreements (excluding distributors and resellers) which have been 261 | validly granted by You or Your distributors under this License prior to 262 | termination shall survive termination. 263 | 264 | 6. Disclaimer of Warranty 265 | 266 | Covered Software is provided under this License on an "as is" basis, 267 | without warranty of any kind, either expressed, implied, or statutory, 268 | including, without limitation, warranties that the Covered Software is free 269 | of defects, merchantable, fit for a particular purpose or non-infringing. 270 | The entire risk as to the quality and performance of the Covered Software 271 | is with You. Should any Covered Software prove defective in any respect, 272 | You (not any Contributor) assume the cost of any necessary servicing, 273 | repair, or correction. This disclaimer of warranty constitutes an essential 274 | part of this License. No use of any Covered Software is authorized under 275 | this License except under this disclaimer. 276 | 277 | 7. Limitation of Liability 278 | 279 | Under no circumstances and under no legal theory, whether tort (including 280 | negligence), contract, or otherwise, shall any Contributor, or anyone who 281 | distributes Covered Software as permitted above, be liable to You for any 282 | direct, indirect, special, incidental, or consequential damages of any 283 | character including, without limitation, damages for lost profits, loss of 284 | goodwill, work stoppage, computer failure or malfunction, or any and all 285 | other commercial damages or losses, even if such party shall have been 286 | informed of the possibility of such damages. This limitation of liability 287 | shall not apply to liability for death or personal injury resulting from 288 | such party's negligence to the extent applicable law prohibits such 289 | limitation. Some jurisdictions do not allow the exclusion or limitation of 290 | incidental or consequential damages, so this exclusion and limitation may 291 | not apply to You. 292 | 293 | 8. Litigation 294 | 295 | Any litigation relating to this License may be brought only in the courts 296 | of a jurisdiction where the defendant maintains its principal place of 297 | business and such litigation shall be governed by laws of that 298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing 299 | in this Section shall prevent a party's ability to bring cross-claims or 300 | counter-claims. 301 | 302 | 9. Miscellaneous 303 | 304 | This License represents the complete agreement concerning the subject 305 | matter hereof. If any provision of this License is held to be 306 | unenforceable, such provision shall be reformed only to the extent 307 | necessary to make it enforceable. Any law or regulation which provides that 308 | the language of a contract shall be construed against the drafter shall not 309 | be used to construe this License against a Contributor. 310 | 311 | 312 | 10. Versions of the License 313 | 314 | 10.1. New Versions 315 | 316 | Mozilla Foundation is the license steward. Except as provided in Section 317 | 10.3, no one other than the license steward has the right to modify or 318 | publish new versions of this License. Each version will be given a 319 | distinguishing version number. 320 | 321 | 10.2. Effect of New Versions 322 | 323 | You may distribute the Covered Software under the terms of the version 324 | of the License under which You originally received the Covered Software, 325 | or under the terms of any subsequent version published by the license 326 | steward. 327 | 328 | 10.3. Modified Versions 329 | 330 | If you create software not governed by this License, and you want to 331 | create a new license for such software, you may create and use a 332 | modified version of this License if you rename the license and remove 333 | any references to the name of the license steward (except to note that 334 | such modified license differs from this License). 335 | 336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 337 | Licenses If You choose to distribute Source Code Form that is 338 | Incompatible With Secondary Licenses under the terms of this version of 339 | the License, the notice described in Exhibit B of this License must be 340 | attached. 341 | 342 | Exhibit A - Source Code Form License Notice 343 | 344 | This Source Code Form is subject to the 345 | terms of the Mozilla Public License, v. 346 | 2.0. If a copy of the MPL was not 347 | distributed with this file, You can 348 | obtain one at 349 | http://mozilla.org/MPL/2.0/. 350 | 351 | If it is not possible or desirable to put the notice in a particular file, 352 | then You may include the notice in a location (such as a LICENSE file in a 353 | relevant directory) where a recipient would be likely to look for such a 354 | notice. 355 | 356 | You may add additional accurate notices of copyright ownership. 357 | 358 | Exhibit B - "Incompatible With Secondary Licenses" Notice 359 | 360 | This Source Code Form is "Incompatible 361 | With Secondary Licenses", as defined by 362 | the Mozilla Public License, v. 2.0. 363 | 364 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## This application is deprecated so no support is available, leaving repo here for posterity only ## 2 | 3 | # Visual Grep 4 | A grep graphical user interface written in D and GTK 3 5 | 6 | ###### Main Window 7 | ![Screenshot](http://www.gexperts.com/img/vgrep/main.png) 8 | 9 | ###### Find Dialog 10 | ![Screenshot](http://www.gexperts.com/img/vgrep/options.png) 11 | 12 | ### About 13 | 14 | Visual Grep is a small utility application that provides grep capabilities in a GUI application. While the command line grep is powerful and useful for a variety of tasks, there are times when I prefer using a GUI to persistently hold the results and make them easy to browse. Thus this utility was born to scratch that itch. 15 | 16 | The following features are currently available: 17 | 18 | * Supports tabs for multiple searches 19 | * Multi-threaded application, searches happen in the background 20 | * Supports regular expressions as per the [D documentation](http://dlang.org/phobos/std_regex.html) 21 | 22 | The application was written using GTK 3 and an effort was made to conform to Gnome Human Interface Guidelines (HIG). As a result, it does use CSD (i.e. the GTK HeaderBar) and no allowance has been made for other Desktop Environments (xfce, unity, kde, etc) at this time so your mileage may vary. Consideration for other environments may be given if demand warrants it. 23 | 24 | At this point in time the application should be considered early alpha and has only been tested under Arch Linux using GTK 3.1.8. 25 | 26 | ### Dependencies 27 | 28 | Visual Grep requires the following libraries to be installed in order to run: 29 | * GTK 3.1.6 or later 30 | 31 | ### Todo Items 32 | 33 | Since this is an early alpha release, there are a number of features which have not yet been developed including: 34 | 35 | * Save recent searches 36 | * Support regex for file matching 37 | * Command line parameters 38 | * Support sorting in result and match lists 39 | 40 | Additional feature requests are gladly accepted 41 | 42 | ### Building 43 | 44 | Visual Grep is written in D and GTK 3 using the gtkd framework. This project uses dub to manage the build process including fetching the dependencies, thus there is no need to install dependencies manually. The only thing you need to install to build the application is the D tools (DMD and Phobos) along with dub itself. 45 | 46 | Once you have those installed, building the application is a one line command as follows: 47 | 48 | ``` 49 | dub build --build=release 50 | ``` 51 | #### Build Dependencies 52 | 53 | Visual Grep depends on the following libraries as defined in dub.json: 54 | * [gtkd](http://gtkd.org/) >= 3.1.4 55 | * [sdlang-d](https://github.com/Abscissa/SDLang-D/blob/master/HOWTO.md) >= 0.9.3 56 | 57 | ### Installation 58 | 59 | Visual Grep can be installed on arch by using the *visual-grep* package in AUR. 60 | 61 | For other distros, no installation packages are available at this time. A compiled binary can be downloaded from the releases. 62 | -------------------------------------------------------------------------------- /dub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vgrep", 3 | "description": "Visual Grep", 4 | "copyright": "Copyright © 2015, Gerald Nunn", 5 | "license": "MPL-2.0", 6 | "authors": ["Gerald Nunn"], 7 | "buildRequirements": ["allowWarnings"], 8 | "versions": ["StdLoggerDisableTrace"], 9 | "dependencies": { 10 | "gtk-d": ">=3.2.3", 11 | "sdlang-d": "~>0.9.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dub.selections.json: -------------------------------------------------------------------------------- 1 | { 2 | "fileVersion": 1, 3 | "versions": { 4 | "libinputvisitor": "1.2.0", 5 | "gtk-d": "3.2.3", 6 | "sdlang-d": "0.9.3" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dub.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /extract-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DOMAIN=vgrep 3 | BASEDIR=$(dirname $0) 4 | OUTPUT_FILE=${BASEDIR}/po/${DOMAIN}.pot 5 | 6 | echo "Extracting translatable strings... " 7 | 8 | # Extract the strings from D source code. Since xgettext does not support D 9 | # as a language we use Vala, which works reasonable well. 10 | find ${BASEDIR}/source -name '*.d' | xgettext \ 11 | --join-existing \ 12 | --output $OUTPUT_FILE \ 13 | --files-from=- \ 14 | --directory=$BASEDIR \ 15 | --language=Vala \ 16 | --from-code=utf-8 17 | 18 | xgettext \ 19 | --join-existing \ 20 | --output $OUTPUT_FILE \ 21 | --default-domain=$DOMAIN \ 22 | --package-name=$DOMAIN \ 23 | --directory=$BASEDIR \ 24 | --foreign-user \ 25 | --language=Desktop \ 26 | ${BASEDIR}/pkg/desktop/com.gexperts.VisualGrep.desktop.in 27 | 28 | # Merge the messages with existing po files 29 | echo "Merging with existing translations... " 30 | for file in ${BASEDIR}/po/*.po 31 | do 32 | echo -n $file 33 | msgmerge --update $file $OUTPUT_FILE 34 | done 35 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ -z "$1" ]; then 4 | export PREFIX=/usr 5 | # Make sure only root can run our script 6 | if [ "$(id -u)" != "0" ]; then 7 | echo "This script must be run as root" 1>&2 8 | exit 1 9 | fi 10 | else 11 | export PREFIX=$1 12 | fi 13 | 14 | echo "Installing to prefix ${PREFIX}" 15 | 16 | # Compile po files 17 | echo "Copying and installing localization files" 18 | for f in po/*.po; do 19 | echo "Processing $f" 20 | LOCALE=$(basename "$f" .po) 21 | mkdir -p ${PREFIX}/share/locale/${LOCALE}/LC_MESSAGES 22 | msgfmt $f -o ${PREFIX}/share/locale/${LOCALE}/LC_MESSAGES/vgrep.mo 23 | done 24 | 25 | # Generate desktop file 26 | msgfmt --desktop --template=pkg/desktop/com.gexperts.VisualGrep.desktop.in -d po -o pkg/desktop/com.gexperts.VisualGrep.desktop 27 | 28 | # Copy executable and desktop file 29 | mkdir -p ${PREFIX}/bin 30 | cp vgrep ${PREFIX}/bin/vgrep 31 | mkdir -p ${PREFIX}/share/applications 32 | cp pkg/desktop/com.gexperts.VisualGrep.desktop ${PREFIX}/share/applications 33 | -------------------------------------------------------------------------------- /pkg/createReleaseArchive.sh: -------------------------------------------------------------------------------- 1 | export VGREP_ARCHIVE_PATH="/tmp/vgrep/archive"; 2 | 3 | rm -rf ${VGREP_ARCHIVE_PATH} 4 | 5 | CURRENT_DIR=$(pwd) 6 | 7 | echo "Building application..." 8 | cd .. 9 | dub build --build=release 10 | 11 | ./install.sh ${VGREP_ARCHIVE_PATH}/usr 12 | 13 | echo "Creating archive" 14 | cd ${VGREP_ARCHIVE_PATH} 15 | zip -r vgrep.zip * 16 | 17 | cp vgrep.zip ${CURRENT_DIR}/vgrep.zip 18 | cd ${CURRENT_DIR} 19 | -------------------------------------------------------------------------------- /pkg/desktop/com.gexperts.VisualGrep.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Visual Grep 3 | Comment=A simple GTK3 GUI for grep 4 | Exec=vgrep 5 | Terminal=false 6 | Type=Application 7 | StartupNotify=true 8 | Categories=Utilities 9 | Icon=search 10 | Name[en_US]=com.gexperts.VisualGrep.desktop.in 11 | -------------------------------------------------------------------------------- /pkg/desktop/com.gexperts.VisualGrep.desktop.in: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Visual Grep 3 | Comment=A simple GTK3 GUI for grep 4 | Exec=vgrep 5 | Terminal=false 6 | Type=Application 7 | StartupNotify=true 8 | Categories=Utilities 9 | Icon=search 10 | Name[en_US]=com.gexperts.VisualGrep.desktop.in 11 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | zh_CN 2 | -------------------------------------------------------------------------------- /po/vgrep.pot: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # This file is put in the public domain. 3 | # FIRST AUTHOR , YEAR. 4 | # 5 | #, fuzzy 6 | msgid "" 7 | msgstr "" 8 | "Project-Id-Version: vgrep\n" 9 | "Report-Msgid-Bugs-To: \n" 10 | "POT-Creation-Date: 2016-03-14 19:05-0600\n" 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME \n" 13 | "Language-Team: LANGUAGE \n" 14 | "Language: \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=CHARSET\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | 19 | #: source/vg/application.d:128 20 | msgid "About" 21 | msgstr "" 22 | 23 | #: source/vg/application.d:129 24 | msgid "Quit" 25 | msgstr "" 26 | 27 | #: source/vg/finddialog.d:56 28 | msgid "Search Name" 29 | msgstr "" 30 | 31 | #: source/vg/finddialog.d:63 32 | msgid "Name" 33 | msgstr "" 34 | 35 | #: source/vg/finddialog.d:69 36 | msgid "Search Text" 37 | msgstr "" 38 | 39 | #: source/vg/finddialog.d:77 40 | msgid "Pattern" 41 | msgstr "" 42 | 43 | #: source/vg/finddialog.d:87 44 | msgid "Case Insenstive" 45 | msgstr "" 46 | 47 | #: source/vg/finddialog.d:92 48 | msgid "Search Path" 49 | msgstr "" 50 | 51 | #: source/vg/finddialog.d:100 52 | msgid "Path" 53 | msgstr "" 54 | 55 | #: source/vg/finddialog.d:114 56 | msgid "File Mask" 57 | msgstr "" 58 | 59 | #: source/vg/finddialog.d:124 60 | msgid "Search Subdirectories" 61 | msgstr "" 62 | 63 | #: source/vg/finddialog.d:131 64 | msgid "Follow Symlinks" 65 | msgstr "" 66 | 67 | #: source/vg/finddialog.d:155 68 | msgid "Select Path" 69 | msgstr "" 70 | 71 | #: source/vg/finddialog.d:155 72 | msgid "Open" 73 | msgstr "" 74 | 75 | #: source/vg/finddialog.d:155 76 | msgid "Cancel" 77 | msgstr "" 78 | 79 | #: source/vg/finddialog.d:174 80 | msgid "Find" 81 | msgstr "" 82 | 83 | #: source/vg/appwindow.d:74 source/vg/appwindow.d:241 84 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:3 85 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:3 86 | msgid "Visual Grep" 87 | msgstr "" 88 | 89 | #: source/vg/appwindow.d:81 90 | msgid "Initiate new search" 91 | msgstr "" 92 | 93 | #: source/vg/appwindow.d:89 94 | msgid "Create a new tab" 95 | msgstr "" 96 | 97 | #: source/vg/appwindow.d:115 98 | msgid "Search" 99 | msgstr "" 100 | 101 | #: source/vg/appwindow.d:286 102 | msgid "File" 103 | msgstr "" 104 | 105 | #: source/vg/appwindow.d:289 106 | msgid "Matches" 107 | msgstr "" 108 | 109 | #: source/vg/appwindow.d:308 110 | msgid "Line" 111 | msgstr "" 112 | 113 | #: source/vg/appwindow.d:309 114 | msgid "Match" 115 | msgstr "" 116 | 117 | #: source/vg/appwindow.d:328 118 | msgid "Abort the current search" 119 | msgstr "" 120 | 121 | #: source/vg/appwindow.d:410 122 | msgid "Starting..." 123 | msgstr "" 124 | 125 | #: source/vg/appwindow.d:415 126 | #, c-format 127 | msgid "Search %s" 128 | msgstr "" 129 | 130 | #: source/vg/appwindow.d:428 131 | #, c-format 132 | msgid "%s, total matches found %d" 133 | msgstr "" 134 | 135 | #: source/app.d:34 136 | msgid "Your GTK version is too old, you need at least GTK " 137 | msgstr "" 138 | 139 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:4 140 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:4 141 | msgid "A simple GTK3 GUI for grep" 142 | msgstr "" 143 | 144 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:10 145 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:10 146 | msgid "search" 147 | msgstr "" 148 | -------------------------------------------------------------------------------- /po/zh_CN.po: -------------------------------------------------------------------------------- 1 | # vgrep zh_CN translation 2 | # Jeff Bai , 2016. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: \n" 6 | "POT-Creation-Date: \n" 7 | "PO-Revision-Date: \n" 8 | "Last-Translator: Jeff Bai \n" 9 | "Language-Team: \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "Language: zh_CN\n" 14 | "X-Generator: Poedit 1.8.7.1\n" 15 | 16 | #: source/vg/application.d:128 17 | msgid "About" 18 | msgstr "关于" 19 | 20 | #: source/vg/application.d:129 21 | msgid "Quit" 22 | msgstr "退出" 23 | 24 | #: source/vg/finddialog.d:56 25 | msgid "Search Name" 26 | msgstr "搜索名称" 27 | 28 | #: source/vg/finddialog.d:63 29 | msgid "Name" 30 | msgstr "名称" 31 | 32 | #: source/vg/finddialog.d:69 33 | msgid "Search Text" 34 | msgstr "搜索文本" 35 | 36 | #: source/vg/finddialog.d:77 37 | msgid "Pattern" 38 | msgstr "搜索模式" 39 | 40 | #: source/vg/finddialog.d:87 41 | msgid "Case Insenstive" 42 | msgstr "区分大小写" 43 | 44 | #: source/vg/finddialog.d:92 45 | msgid "Search Path" 46 | msgstr "搜索路径" 47 | 48 | #: source/vg/finddialog.d:100 49 | msgid "Path" 50 | msgstr "路径" 51 | 52 | #: source/vg/finddialog.d:114 53 | msgid "File Mask" 54 | msgstr "屏蔽文件" 55 | 56 | #: source/vg/finddialog.d:124 57 | msgid "Search Subdirectories" 58 | msgstr "搜索子目录" 59 | 60 | #: source/vg/finddialog.d:131 61 | msgid "Follow Symlinks" 62 | msgstr "跟随符号链接" 63 | 64 | #: source/vg/finddialog.d:155 65 | msgid "Select Path" 66 | msgstr "选择路径" 67 | 68 | #: source/vg/finddialog.d:155 69 | msgid "Open" 70 | msgstr "打开" 71 | 72 | #: source/vg/finddialog.d:155 73 | msgid "Cancel" 74 | msgstr "取消" 75 | 76 | #: source/vg/finddialog.d:174 77 | msgid "Find" 78 | msgstr "查找" 79 | 80 | #: source/vg/appwindow.d:74 source/vg/appwindow.d:241 81 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:3 82 | msgid "Visual Grep" 83 | msgstr "图形化 Grep" 84 | 85 | #: source/vg/appwindow.d:81 86 | msgid "Initiate new search" 87 | msgstr "开始新搜索" 88 | 89 | #: source/vg/appwindow.d:89 90 | msgid "Create a new tab" 91 | msgstr "新建标签页" 92 | 93 | #: source/vg/appwindow.d:115 94 | msgid "Search" 95 | msgstr "搜索" 96 | 97 | #: source/vg/appwindow.d:286 98 | msgid "File" 99 | msgstr "文件" 100 | 101 | #: source/vg/appwindow.d:289 102 | msgid "Matches" 103 | msgstr "匹配" 104 | 105 | #: source/vg/appwindow.d:308 106 | msgid "Line" 107 | msgstr "行" 108 | 109 | #: source/vg/appwindow.d:309 110 | msgid "Match" 111 | msgstr "匹配" 112 | 113 | #: source/vg/appwindow.d:328 114 | msgid "Abort the current search" 115 | msgstr "中止当前搜索" 116 | 117 | #: source/vg/appwindow.d:410 118 | msgid "Starting..." 119 | msgstr "正在开始搜索…" 120 | 121 | #: source/vg/appwindow.d:415 122 | #, c-format 123 | msgid "Search %s" 124 | msgstr "搜索 %s" 125 | 126 | #: source/vg/appwindow.d:428 127 | #, c-format 128 | msgid "%s, total matches found %d" 129 | msgstr "%s,总共找到 %d 个匹配项" 130 | 131 | #: source/app.d:34 132 | msgid "Your GTK version is too old, you need at least GTK " 133 | msgstr "你的 GTK 版本太老,需要至少 GTK " 134 | 135 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:4 136 | msgid "A simple GTK3 GUI for grep" 137 | msgstr "基于 GTK3 的简洁 grep 界面" 138 | 139 | #: pkg/desktop/com.gexperts.VisualGrep.desktop.in:10 140 | msgid "search" 141 | msgstr "搜索" 142 | -------------------------------------------------------------------------------- /source/app.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | import core.thread; 6 | 7 | import std.conv; 8 | 9 | import gtk.Main; 10 | import gtk.Version; 11 | import gtk.MessageDialog; 12 | 13 | import i18n.l10n; 14 | 15 | import vg.application; 16 | import vg.constants; 17 | 18 | int main(string[] args) { 19 | 20 | //Version checking cribbed from grestful, thanks! 21 | string error = Version.checkVersion(GTK_VERSION_MAJOR, GTK_VERSION_MINOR, GTK_VERSION_PATCH); 22 | 23 | //textdomain 24 | textdomain("vgrep"); 25 | 26 | if (error !is null) { 27 | Main.init(args); 28 | 29 | MessageDialog dialog = new MessageDialog( 30 | null, 31 | DialogFlags.MODAL, 32 | MessageType.ERROR, 33 | ButtonsType.OK, 34 | _("Your GTK version is too old, you need at least GTK ") ~ 35 | to!string(GTK_VERSION_MAJOR) ~ '.' ~ 36 | to!string(GTK_VERSION_MINOR) ~ '.' ~ 37 | to!string(GTK_VERSION_PATCH) ~ '!', 38 | null 39 | ); 40 | 41 | dialog.setDefaultResponse(ResponseType.OK); 42 | 43 | dialog.run(); 44 | return 1; 45 | } 46 | 47 | 48 | //Required to initialized send/receive capabilities 49 | std.concurrency.thisTid; 50 | 51 | auto vgApp = new VisualGrep(); 52 | return vgApp.run(args); 53 | } -------------------------------------------------------------------------------- /source/gtk/color.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module gtk.color; 6 | 7 | import std.conv; 8 | import std.format; 9 | 10 | import gdk.RGBA; 11 | 12 | string rgbaToHex(RGBA color) { 13 | int red = to!(int)(color.red() * 255); 14 | int green = to!(int)(color.green() * 255); 15 | int blue = to!(int)(color.blue() * 255); 16 | int alpha = to!(int)(color.alpha() * 255); 17 | 18 | return format("%X%X%X%X",red,green,blue,alpha); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /source/gtk/threads.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module gtk.threads; 6 | 7 | import gdk.Threads; 8 | 9 | import std.algorithm; 10 | import std.stdio; 11 | 12 | 13 | /** 14 | * Simple structure that contains a pointer to a delegate. This is necessary because delegates are not directly 15 | * convertable to a simple pointer (which is needed to pass as data to a C callback). 16 | * 17 | * This code from grestful (https://github.com/Gert-dev/grestful) 18 | */ 19 | struct DelegatePointer(S, U...) 20 | { 21 | S delegateInstance; 22 | 23 | U parameters; 24 | 25 | /** 26 | * Constructor. 27 | * 28 | * @param delegateInstance The delegate to invoke. 29 | * @param parameters The parameters to pass to the delegate. 30 | */ 31 | public this(S delegateInstance, U parameters) 32 | { 33 | this.delegateInstance = delegateInstance; 34 | this.parameters = parameters; 35 | } 36 | } 37 | 38 | /** 39 | * Callback that will invoke the passed DelegatePointer's delegate when it is called. This very useful method can be 40 | * used to pass delegates to gdk.Threads.threadsAddIdle instead of having to define a callback with C linkage and a 41 | * different method for every different action. 42 | * 43 | * The return type is the type that should be returned by this function. The invoked delegate should as a best practice 44 | * return the same value. If an exception happens and the value from the delegate can't be returned, the '.init' value 45 | * of the type will be used instead (or nothing in the case of void). 46 | * 47 | * Finally, if doRemoveRoot is set to true, this function will execute a removeRoot on the garbage collector for the 48 | * passed data (which is the delegate). This is useful in situations where you're passing a delegate to a C function 49 | * that will happen asynchronously, in which case you should be adding the newly allocated DelegatePointer using 50 | * addRoot to ensure the garbage collector doesn't attempt to collect the delegate while the callback hasn't been 51 | * invoked yet. 52 | * 53 | * @param data The data that is passed to the method. 54 | * 55 | * @return Whether or not the method should continue executing. 56 | * 57 | * This code from grestful (https://github.com/Gert-dev/grestful) 58 | */ 59 | extern(C) nothrow static ReturnType invokeDelegatePointerFunc(S, ReturnType, bool doRemoveRoot = false)(void* data) 60 | { 61 | auto callbackPointer = cast(S*) data; 62 | 63 | try 64 | { 65 | static if (__traits(compiles, ReturnType.init)) 66 | { 67 | auto returnValue = callbackPointer.delegateInstance(callbackPointer.parameters); 68 | 69 | return returnValue; 70 | } 71 | 72 | else 73 | { 74 | callbackPointer.delegateInstance(callbackPointer.parameters); 75 | } 76 | } 77 | 78 | catch (Exception e) 79 | { 80 | // Just catch it, can't throw D exceptions accross C boundaries. 81 | static if (__traits(compiles, ReturnType.init)) 82 | return ReturnType.init; 83 | } 84 | 85 | // Should only end up here for types that don't have an initial value (such as void). 86 | } 87 | 88 | /** 89 | * Convenience method that allows scheduling a delegate to be executed with gdk.Threads.threadsAddIdle instead of a 90 | * traditional callback with C linkage. 91 | * 92 | * @param theDelegate The delegate to schedule. 93 | * @param parameters A tuple of parameters to pass to the delegate when it is invoked. 94 | * 95 | * @example 96 | * auto myMethod = delegate(string name, string value) { do_something_with_name_and_value(); } 97 | * threadsAddIdleDelegate(myMethod, "thisIsAName", "thisIsAValue"); 98 | * 99 | * This code from grestful (https://github.com/Gert-dev/grestful) 100 | */ 101 | void threadsAddIdleDelegate(T, parameterTuple...)(T theDelegate, parameterTuple parameters) 102 | { 103 | void* delegatePointer = null; 104 | 105 | auto wrapperDelegate = (parameterTuple parameters) { 106 | bool callAgainNextIdleCycle = false; 107 | 108 | try 109 | { 110 | callAgainNextIdleCycle = theDelegate(parameters); 111 | } 112 | 113 | catch (Exception e) 114 | { 115 | // Catch exceptions here as otherwise, memory may never be freed below. 116 | } 117 | 118 | if (!callAgainNextIdleCycle) 119 | core.memory.GC.removeRoot(delegatePointer); 120 | 121 | return callAgainNextIdleCycle; 122 | }; 123 | 124 | delegatePointer = cast(void*) new DelegatePointer!(T, parameterTuple)(wrapperDelegate, parameters); 125 | 126 | // We're going into a separate thread and exiting here, make sure the garbage collector doesn't think the memory 127 | // isn't used anymore and collects it. 128 | core.memory.GC.addRoot(delegatePointer); 129 | 130 | gdk.Threads.threadsAddIdle( 131 | cast(GSourceFunc) &invokeDelegatePointerFunc!(DelegatePointer!(T, parameterTuple), bool), 132 | delegatePointer 133 | ); 134 | } -------------------------------------------------------------------------------- /source/gtk/util.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module gtk.util; 6 | 7 | import gtk.Window; 8 | 9 | enum WindowState {NORMAL, MAXIMIZED}; 10 | 11 | struct WindowDisplayState { 12 | int x; 13 | int y; 14 | int w; 15 | int h; 16 | WindowState s; 17 | } 18 | 19 | void restoreWindowDisplayState(Window window, WindowDisplayState wds) { 20 | window.move(wds.x, wds.y); 21 | window.setDefaultSize(wds.w, wds.h); 22 | if (wds.s == WindowState.MAXIMIZED) window.maximize(); 23 | } 24 | 25 | WindowDisplayState getWindowDisplayState(Window window) { 26 | WindowDisplayState result; 27 | result.s = WindowState.NORMAL; 28 | if (window.isMaximized) { 29 | result.s = WindowState.MAXIMIZED; 30 | } 31 | 32 | window.getPosition(result.x, result.y); 33 | window.getSize(result.w, result.h); 34 | 35 | return result; 36 | } -------------------------------------------------------------------------------- /source/gtk/widget/tablabel.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module gtk.widget.tablabel; 6 | 7 | import gtk.Button; 8 | import gtk.Box; 9 | import gtk.Label; 10 | import gtk.Widget; 11 | 12 | alias OnCloseClickedDelegate = void delegate(TabLabel label, Widget Page); 13 | 14 | class TabLabel: Box { 15 | 16 | private: 17 | Button button; 18 | Label label; 19 | Widget page; 20 | 21 | OnCloseClickedDelegate[] closeClickedHandlers; 22 | 23 | void closeClicked(Button button) { 24 | foreach (OnCloseClickedDelegate handler; closeClickedHandlers) { 25 | handler(this, page); 26 | } 27 | } 28 | 29 | public: 30 | 31 | this(string text, Widget page) { 32 | super(Orientation.HORIZONTAL, 5); 33 | 34 | this.page = page; 35 | 36 | label = new Label(text); 37 | label.setHexpand(true); 38 | add(label); 39 | 40 | button = new Button("window-close-symbolic", IconSize.MENU); 41 | button.setRelief(ReliefStyle.NONE); 42 | button.setFocusOnClick(false); 43 | 44 | button.addOnClicked(&closeClicked); 45 | 46 | add(button); 47 | 48 | showAll(); 49 | } 50 | 51 | void addOnCloseClicked(OnCloseClickedDelegate handler) { 52 | closeClickedHandlers ~= handler; 53 | } 54 | 55 | @property string text() { 56 | return label.getText(); 57 | } 58 | 59 | @property void text(string value) { 60 | label.setText(value); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /source/util/file/search.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module util.file.search; 6 | 7 | import core.time; 8 | 9 | import std.algorithm; 10 | import std.array; 11 | import std.concurrency; 12 | import std.conv; 13 | import std.experimental.logger; 14 | import std.file; 15 | import std.path; 16 | import std.regex; 17 | import std.stdio; 18 | import std.string; 19 | import std.uuid; 20 | 21 | import glib.SimpleXML; 22 | 23 | /** 24 | * The criteria to search 25 | */ 26 | struct Criteria { 27 | 28 | /** 29 | * Unique id used to identify this search 30 | */ 31 | string id; 32 | 33 | /** 34 | * Pattern to search files for 35 | */ 36 | string pattern; 37 | 38 | /** 39 | * Whether the search is case sensitive 40 | */ 41 | bool caseInsensitive = false; 42 | 43 | /** 44 | * Path within to search 45 | */ 46 | string path; 47 | 48 | /** 49 | * Wildcard pattern to optionally match files to 50 | */ 51 | string wildcardPattern; 52 | 53 | /** 54 | * Include subdirectories in search 55 | */ 56 | bool searchSubdirectories; 57 | 58 | /** 59 | * Follow symbolic links 60 | */ 61 | bool followSymbolic; 62 | 63 | /** 64 | * Maximum number of matches to capture. The search routine will still 65 | * count matches over this number but only the number of matches up to 66 | * this number will be returned. 67 | */ 68 | ulong maximumMatches; 69 | } 70 | 71 | struct MarkupTags { 72 | 73 | bool pangoMarkup = false; 74 | 75 | string pre; 76 | 77 | string post; 78 | } 79 | 80 | /** 81 | * Represents a single match within a file 82 | */ 83 | struct Match { 84 | 85 | string line; 86 | ulong lineNo; 87 | ulong startPos; 88 | ulong endPos; 89 | } 90 | 91 | /** 92 | * All matches for a single file 93 | */ 94 | struct Result { 95 | /** 96 | * The file name for which matches were found 97 | */ 98 | string file; 99 | 100 | /** 101 | * An array of matches found up to the maximum number 102 | * specified in the Criteria 103 | */ 104 | Match[] matches; 105 | 106 | /** 107 | * The total number of matches found, this can be greater 108 | * then the number of matches returned in the matches array 109 | * if the maximum number of matches was exceeded. 110 | */ 111 | ulong matchCount; 112 | } 113 | 114 | enum Status {PROGRESS_PATH, PROGRESS_RESULT, COMPLETED, ABORTED}; 115 | 116 | immutable string ABORT_MESSAGE = "abort"; 117 | 118 | void search(Criteria criteria, MarkupTags markup, Tid tid) { 119 | 120 | trace(criteria.id, ": Starting search"); 121 | bool abort = false; 122 | 123 | char[] flags; 124 | if (criteria.caseInsensitive) flags ~='i'; 125 | auto r = regex(criteria.pattern, flags); 126 | 127 | ulong lastProgress = 0; 128 | string lastPath; 129 | string currentPath = null; 130 | 131 | SpanMode mode = (criteria.searchSubdirectories?SpanMode.depth:SpanMode.shallow); 132 | 133 | string wildcard = criteria.wildcardPattern; 134 | if (wildcard.length==0) wildcard = "*"; 135 | 136 | ulong totalMatchCount = 0; 137 | 138 | foreach (DirEntry entry; dirEntries(criteria.path, wildcard, mode, criteria.followSymbolic).filter!(a => a.isFile)) { 139 | trace("Searching file ", entry.name); 140 | char[] buf; 141 | string path = dirName(entry.name); 142 | if (!path.equal(currentPath)) { 143 | currentPath = path; 144 | tid.send(Status.PROGRESS_PATH, criteria.id, currentPath); 145 | } 146 | auto f = File(entry.name,"r"); 147 | ulong lineCount = 1; 148 | ulong matchCount = 0; 149 | shared Match[] matches; 150 | while (f.readln(buf)) { 151 | string line; 152 | foreach (m; matchAll(buf,r)) { 153 | if (matchCount < criteria.maximumMatches) { 154 | if (line.length==0) line ~= chomp(buf); 155 | if (markup.pangoMarkup) { 156 | line = chomp(escapeText(to!string(m.pre())) ~ markup.pre ~ escapeText(to!string(m.hit())) ~ markup.post ~ escapeText(to!string(m.post()))); 157 | } 158 | shared Match match = {line, lineCount, m.pre().length, m.pre().length + m.hit().length}; 159 | //trace("Match at line:",match.lineNo,", start: ",match.startPos,",end: ",match.endPos); 160 | matches = matches ~ match; 161 | } 162 | matchCount++; 163 | } 164 | lineCount++; 165 | if (lineCount % 10000 == 0) { 166 | trace(format("Processed %d lines with %d total matches", lineCount, matches.length)); 167 | abort = isAborted(); 168 | if (abort) break; 169 | } 170 | } 171 | 172 | if (matches.length>0) { 173 | trace(format("Found %d matches in %s", matchCount, entry.name)); 174 | shared Result result = {entry.name, matches, matchCount}; 175 | totalMatchCount = totalMatchCount + matchCount; 176 | tid.send(Status.PROGRESS_RESULT, criteria.id, result); 177 | 178 | } 179 | if (abort || isAborted()) { 180 | break; 181 | } 182 | } 183 | 184 | tid.send(abort?Status.ABORTED:Status.COMPLETED, criteria.id, totalMatchCount); 185 | } 186 | 187 | private bool isAborted() { 188 | bool result = false; 189 | receiveTimeout(dur!("msecs")( 0 ), 190 | (string msg) { 191 | if (ABORT_MESSAGE.equal(msg)) { 192 | result = true; 193 | } 194 | } 195 | ); 196 | 197 | return result; 198 | } 199 | 200 | private string escapeText(string s) { 201 | return SimpleXML.markupEscapeText(s, s.length); 202 | } -------------------------------------------------------------------------------- /source/util/mixins/singleton.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module util.mixins.singleton; 6 | 7 | /** 8 | * Mixin or trait that can be used in classes to inject code typical for singleton classes, such as an 'Instance' 9 | * property that will automatically instantiate the singleton if needed. Making the constructor private is the 10 | * responsibility of the using class. 11 | * 12 | * This code from grestful (https://github.com/Gert-dev/grestful), slight modifications to confirm to D style guid 13 | */ 14 | mixin template Singleton() 15 | { 16 | @property 17 | { 18 | /** 19 | * Retrieves the sole instance of this class. 20 | * 21 | * @return The sole instance. 22 | */ 23 | auto public static instance() 24 | { 25 | static typeof(this) instance = null; 26 | 27 | if (!instance) 28 | instance = new typeof(this)(); 29 | 30 | return instance; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /source/vg/application.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.application; 6 | 7 | import std.experimental.logger; 8 | 9 | import gio.Menu; 10 | import gio.SimpleAction; 11 | 12 | import glib.Variant; 13 | import glib.VariantType; 14 | 15 | import gtk.AboutDialog; 16 | import gtk.Application; 17 | import gtk.Dialog; 18 | 19 | import gtk.util; 20 | 21 | import i18n.l10n; 22 | 23 | import vg.appwindow; 24 | import vg.constants; 25 | import vg.configuration; 26 | 27 | class VisualGrep: Application { 28 | 29 | private: 30 | 31 | private MainWindow window; 32 | 33 | /** 34 | * Maps actions registered to the application by their action name. 35 | * 36 | * This code from grestful (https://github.com/Gert-dev/grestful) 37 | */ 38 | SimpleAction[string] registeredActions; 39 | 40 | /** 41 | * Retrieves the action with the specified name. The action must exist. If an attempt is made to fetch a 42 | * non-existing action, it is a programmatic error and it will be caught by an assert in debug mode. 43 | * 44 | * This code from grestful (https://github.com/Gert-dev/grestful) 45 | * 46 | * @param name The name of the action to retrieve. 47 | * 48 | * @return The action (which must exist or the method will fail). 49 | */ 50 | SimpleAction getAction(string name) 51 | { 52 | assert(name in this.registeredActions); 53 | return this.registeredActions[name]; 54 | } 55 | 56 | /** 57 | * Convenience function to quickly set an action as enabled or disabled. 58 | * 59 | * This code from grestful (https://github.com/Gert-dev/grestful) 60 | * 61 | * @param name The name of the action. 62 | * @param enabled Whether to enable the action or not. 63 | */ 64 | void setActionEnabled(string name, bool enabled) 65 | { 66 | this.getAction(name).setEnabled(enabled); 67 | } 68 | 69 | /** 70 | * Adds a new action to the specified menu. An action is automatically added to the application that invokes the 71 | * specified callback when the actual menu item is activated. 72 | * 73 | * This code from grestful (https://github.com/Gert-dev/grestful) 74 | * 75 | * @param id The ID to give to the action. This can be used in other places to refer to the action 76 | * by a string. Must always start with "app.". 77 | * @param accelerator The (application wide) keyboard accelerator to activate the action. 78 | * @param callback The callback to invoke when the action is invoked. 79 | * @param type The type of data passed as parameter to the action when activated. 80 | * @param acceleratorParameter The parameter to pass to the callback when the action is invoked by its 81 | * accelerator. 82 | * 83 | * @return The registered action. 84 | */ 85 | SimpleAction registerAction( 86 | string id, 87 | string accelerator = null, 88 | void delegate(Variant, SimpleAction) callback = null, 89 | VariantType type = null, 90 | Variant acceleratorParameter = null 91 | ) { 92 | // Application registered actions expect a prefix of app. and we need to specify the name 93 | // without 'app' here. 94 | SimpleAction action = new SimpleAction(id[4 .. $], type); 95 | this.registeredActions[id] = action; 96 | 97 | if (callback !is null) 98 | action.addOnActivate(callback); 99 | 100 | this.addAction(action); 101 | 102 | if (accelerator) 103 | this.addAccelerator(accelerator, id, acceleratorParameter); 104 | 105 | return action; 106 | } 107 | 108 | /** 109 | * Installs the application menu. This is the menu that drops down in gnome-shell when you click the application 110 | * name next to Activities. 111 | * 112 | * This code adapted from grestful (https://github.com/Gert-dev/grestful) 113 | */ 114 | void installAppMenu() 115 | { 116 | Menu menu; 117 | 118 | this.registerAction("app.about", null, delegate(Variant, SimpleAction) { 119 | this.showAboutDialog(); 120 | }); 121 | 122 | this.registerAction("app.quit", null, delegate(Variant, SimpleAction) { 123 | this.window.close(); 124 | }); 125 | 126 | with (menu = new Menu()) 127 | { 128 | append(_("About"), "app.about"); 129 | append(_("Quit"), "app.quit"); 130 | } 131 | 132 | this.setAppMenu(menu); 133 | } 134 | 135 | /** 136 | * Shows the about dialog. 137 | * 138 | * This code adapted from grestful (https://github.com/Gert-dev/grestful) 139 | */ 140 | void showAboutDialog() 141 | { 142 | AboutDialog dialog; 143 | 144 | with (dialog = new AboutDialog()) 145 | { 146 | setDestroyWithParent(true); 147 | setTransientFor(this.window); 148 | setModal(true); 149 | 150 | setWrapLicense(true); 151 | setLogoIconName(null); 152 | setName(APPLICATION_NAME); 153 | setComments(APPLICATION_COMMENTS); 154 | setVersion(APPLICATION_VERSION); 155 | setCopyright(APPLICATION_COPYRIGHT); 156 | setAuthors(APPLICATION_AUTHORS.dup); 157 | setArtists(APPLICATION_ARTISTS.dup); 158 | setDocumenters(APPLICATION_DOCUMENTERS.dup); 159 | setTranslatorCredits(APPLICATION_TRANSLATORS); 160 | setLicense(APPLICATION_LICENSE); 161 | //addCreditSection(_("Credits"), []) 162 | 163 | addOnResponse(delegate(int responseId, Dialog sender) { 164 | if (responseId == ResponseType.CANCEL || responseId == ResponseType.DELETE_EVENT) 165 | sender.hideOnDelete(); // Needed to make the window closable (and hide instead of be deleted). 166 | }); 167 | 168 | present(); 169 | } 170 | } 171 | 172 | void appActivate(GioApplication app) { 173 | window = new MainWindow(this); 174 | restoreWindowDisplayState(window, Configuration.instance.mainWindow); 175 | window.showAll(); 176 | } 177 | 178 | void appStartup(GioApplication app) { 179 | trace("Startup Signal"); 180 | Configuration.instance.loadConfig(); 181 | installAppMenu(); 182 | } 183 | 184 | void appShutdown(GioApplication app) { 185 | trace("Quit Signal"); 186 | Configuration.instance.saveConfig(); 187 | } 188 | 189 | public: 190 | 191 | this() { 192 | super(APPLICATION_ID, ApplicationFlags.FLAGS_NONE); 193 | 194 | this.addOnActivate(&appActivate); 195 | this.addOnStartup(&appStartup); 196 | this.addOnShutdown(&appShutdown); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /source/vg/appwindow.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.appwindow; 6 | 7 | import std.concurrency; 8 | import std.experimental.logger; 9 | import std.format; 10 | import std.process; 11 | import std.uuid; 12 | 13 | import gdk.RGBA; 14 | import gdk.Threads; 15 | 16 | import gtk.Application: Application; 17 | import gio.Application: GioApplication = Application; 18 | import gtk.ApplicationWindow: ApplicationWindow; 19 | import gtkc.giotypes: GApplicationFlags; 20 | 21 | import gtk.Box; 22 | import gtk.Button; 23 | import gtk.CellRendererText; 24 | import gdk.Event; 25 | import gtk.HeaderBar; 26 | import gtk.Label; 27 | import gtk.ListStore; 28 | import gtk.Notebook; 29 | import gtk.Paned; 30 | import gtk.ScrolledWindow; 31 | import gtk.Statusbar; 32 | import gtk.StyleContext; 33 | import gtk.TreeIter; 34 | import gtk.TreePath; 35 | import gtk.TreeStore; 36 | import gtk.TreeView; 37 | import gtk.TreeViewColumn; 38 | import gtk.Widget; 39 | 40 | import gtk.color; 41 | import gtk.widget.tablabel; 42 | import gtk.util; 43 | import gtk.threads; 44 | import util.file.search; 45 | 46 | import i18n.l10n; 47 | 48 | import vg.configuration; 49 | import vg.finddialog; 50 | import vg.search; 51 | 52 | /** 53 | * The main window of the application 54 | */ 55 | class MainWindow: ApplicationWindow { 56 | 57 | private: 58 | 59 | Button btnFind; 60 | HeaderBar hb; 61 | Notebook nb; 62 | SearchManager manager; 63 | ResultPage[string] pages; 64 | 65 | bool idleHandlerEnabled = false; 66 | 67 | private bool delegate() cbThreadIdle; 68 | 69 | 70 | void createUI() { 71 | //Create header bar 72 | hb = new HeaderBar(); 73 | hb.setShowCloseButton(true); 74 | hb.setTitle(_("Visual Grep")); 75 | this.setTitlebar(hb); 76 | 77 | //Create Find button 78 | btnFind = new Button(StockID.FIND); 79 | btnFind.setAlwaysShowImage(true); 80 | btnFind.addOnClicked(&showFindDialog); 81 | btnFind.setTooltipText(_("Initiate new search")); 82 | 83 | hb.packStart(btnFind); 84 | 85 | //Create New Button 86 | Button btnNew = new Button("tab-new-symbolic", IconSize.BUTTON); 87 | btnNew.setAlwaysShowImage(true); 88 | btnNew.addOnClicked(&createNewTab); 89 | btnNew.setTooltipText(_("Create a new tab")); 90 | 91 | hb.packStart(btnNew); 92 | 93 | //Create Notebook 94 | nb = new Notebook(); 95 | nb.addOnSwitchPage(&pageChanged); 96 | this.add(nb); 97 | 98 | createNewSearchPage(); 99 | 100 | this.setDefaultSize(1024,640); 101 | } 102 | 103 | void createNewTab(Button button) { 104 | createNewSearchPage(); 105 | } 106 | 107 | void pageChanged(Widget page, uint pageNum, Notebook notebook) { 108 | updateUIState(); 109 | } 110 | 111 | void createNewSearchPage() { 112 | string id = randomUUID.toString(); 113 | ResultPage page = new ResultPage(manager, id); 114 | pages[id] = page; 115 | TabLabel label = new TabLabel(_("Search"), page); 116 | label.addOnCloseClicked(&closePage); 117 | nb.appendPage(page, label); 118 | nb.showAll(); 119 | nb.setCurrentPage(nb.getNPages()-1); 120 | 121 | updateUIState(); 122 | } 123 | 124 | void closePage(TabLabel label, Widget widget) { 125 | ResultPage page = cast(ResultPage) widget; 126 | manager.stop(page.id); 127 | if (page.id in pages) { 128 | pages.remove(page.id); 129 | } 130 | nb.remove(page); 131 | 132 | updateUIState(); 133 | } 134 | 135 | void showFindDialog(Button button) { 136 | ResultPage page = cast(ResultPage)nb.getNthPage(nb.getCurrentPage()); 137 | if (!page) return; 138 | 139 | TabLabel label = cast(TabLabel) nb.getTabLabel(page); 140 | 141 | FindDialog dialog = new FindDialog(this, label.text, page.criteria); 142 | scope(exit) dialog.destroy; 143 | 144 | dialog.showAll(); 145 | if (dialog.run()==ResponseType.OK) { 146 | Criteria criteria = dialog.criteria(); 147 | label.text = dialog.searchName; 148 | Configuration.instance().addPath(criteria.path); 149 | Configuration.instance().addPattern(criteria.pattern); 150 | page.searchStart(criteria); 151 | MarkupTags markup = page.getMarkupTags(); 152 | doSearch(criteria, markup); 153 | } 154 | 155 | updateUIState(); 156 | } 157 | 158 | /** 159 | * Updates the UI state in terms of enabling/disabling elements, etc. 160 | */ 161 | void updateUIState() { 162 | // Only show tabs when more then one tab is present, emulate gedit and files behavior in gnome 163 | nb.setShowTabs((nb.getNPages()>1)); 164 | 165 | // Check if any search is in progress for the current page and disable find button if it 166 | if (nb.getCurrentPage()>=0) { 167 | ResultPage page = cast(ResultPage)nb.getNthPage(nb.getCurrentPage()); 168 | btnFind.setSensitive(!manager.isSearchInProgress(page.id)); 169 | } 170 | } 171 | 172 | bool progress(string id, string currentPath) { 173 | ResultPage page; 174 | try { 175 | page = pages[id]; 176 | } catch (Throwable t) { 177 | error(id,": Failed to find page for id"); 178 | return true; 179 | } 180 | page.searchProgress(currentPath); 181 | 182 | updateUIState(); 183 | return false; 184 | } 185 | 186 | bool result(string id, Result result) { 187 | ResultPage page = pages[id]; 188 | if (page is null) { 189 | return true; 190 | } else { 191 | page.searchResult(result); 192 | } 193 | updateUIState(); 194 | return false; 195 | } 196 | 197 | void finished(string id, bool aborted, ulong total) { 198 | info(id, ": Finished"); 199 | ResultPage page; 200 | try { 201 | page = pages[id]; 202 | } catch (Throwable t) { 203 | error(id,": Failed to find page for id"); 204 | return; 205 | } 206 | //Todo - Should show the total matches found 207 | page.searchCompleted(aborted, total); 208 | updateUIState(); 209 | } 210 | 211 | void doSearch(Criteria criteria, MarkupTags markup) { 212 | trace("Calling manager to do search..."); 213 | manager.search(criteria, markup); 214 | if (!idleHandlerEnabled) { 215 | trace("Adding idle handler..."); 216 | threadsAddIdleDelegate(cbThreadIdle); 217 | } 218 | } 219 | 220 | bool checkPendingSearches() { 221 | //writeln("Checking pending messages...", thisTid); 222 | if (!manager.checkPending(1)) { 223 | idleHandlerEnabled = false; 224 | trace("Stopping idle handler..."); 225 | return false; 226 | } 227 | return true; 228 | } 229 | 230 | bool windowClosed(Event event, Widget widget) { 231 | Configuration.instance.mainWindow = getWindowDisplayState(this); 232 | manager.stopAll(); 233 | return false; 234 | } 235 | 236 | public: 237 | 238 | this(Application application) { 239 | super(application); 240 | cbThreadIdle = &this.checkPendingSearches; 241 | setTitle(_("Visual Grep")); 242 | setIconName("search"); 243 | 244 | manager = new SearchManager(); 245 | manager.onResult = &result; 246 | manager.onProgress = &progress; 247 | manager.onFinished = &finished; 248 | createUI(); 249 | 250 | this.addOnDelete(&windowClosed); 251 | } 252 | } 253 | 254 | /** 255 | * The individual pages of the notebook where the search results are displayed 256 | */ 257 | class ResultPage: Box { 258 | 259 | private: 260 | SearchManager manager; 261 | 262 | TreeView tvResults; 263 | TreeView tvMatches; 264 | Statusbar sbStatus; 265 | Button btnAbort; 266 | 267 | Criteria _criteria; 268 | 269 | ListStore lsResults; 270 | ListStore lsMatches; 271 | 272 | Result[] results; 273 | 274 | void createUI() { 275 | Paned paned = new Paned(GtkOrientation.VERTICAL); 276 | 277 | //Results View 278 | tvResults = new TreeView(); 279 | tvResults.setHexpand(true); 280 | tvResults.setVexpand(true); 281 | tvResults.setActivateOnSingleClick(false); 282 | 283 | ScrolledWindow scrollResults = new ScrolledWindow(); 284 | scrollResults.add(tvResults); 285 | 286 | TreeViewColumn column = new TreeViewColumn(_("File"), new CellRendererText(), "text", 0); 287 | column.setExpand(true); 288 | tvResults.appendColumn(column); 289 | tvResults.appendColumn(new TreeViewColumn(_("Matches"), new CellRendererText(), "text", 1)); 290 | lsResults = new ListStore([GType.STRING, GType.LONG]); 291 | tvResults.setModel(lsResults); 292 | 293 | tvResults.addOnRowActivated(&rowActivatedResults); 294 | tvResults.addOnCursorChanged(&rowSelectedResults); 295 | 296 | //Matches View 297 | tvMatches = new TreeView(); 298 | tvMatches.setHexpand(true); 299 | tvMatches.setVexpand(true); 300 | tvMatches.setActivateOnSingleClick(false); 301 | 302 | lsMatches = new ListStore([GType.LONG, GType.STRING]); 303 | tvMatches.setModel(lsMatches); 304 | 305 | ScrolledWindow scrollMatches = new ScrolledWindow(); 306 | scrollMatches.add(tvMatches); 307 | 308 | tvMatches.appendColumn(new TreeViewColumn(_("Line"), new CellRendererText(), "text", 0)); 309 | column = new TreeViewColumn(_("Match"), new CellRendererText(), "markup", 1); 310 | column.setExpand(true); 311 | tvMatches.appendColumn(column); 312 | 313 | paned.add(scrollResults,scrollMatches); 314 | add(paned); 315 | paned.setPosition(300); 316 | 317 | //Status button and abort button 318 | Box b = new Box(Orientation.HORIZONTAL, 0); 319 | 320 | sbStatus = new Statusbar(); 321 | sbStatus.setHexpand(true); 322 | b.add(sbStatus); 323 | 324 | btnAbort = new Button("window-close-symbolic", IconSize.MENU); 325 | btnAbort.setRelief(ReliefStyle.NONE); 326 | btnAbort.setFocusOnClick(false); 327 | btnAbort.setSensitive(false); 328 | btnAbort.setTooltipText(_("Abort the current search")); 329 | btnAbort.addOnClicked(&abortSearch); 330 | b.add(btnAbort); 331 | 332 | add(b); 333 | 334 | } 335 | 336 | void rowSelectedResults(TreeView tv) { 337 | lsMatches.clear(); 338 | TreeIter selected = tv.getSelectedIter(); 339 | if (selected !is null) { 340 | TreePath path = lsResults.getPath(selected); 341 | auto index = path.getIndices()[0]; 342 | foreach(Match match; results[index].matches) { 343 | TreeIter iter = lsMatches.createIter(); 344 | lsMatches.setValue(iter, 0, cast(int)match.lineNo); 345 | lsMatches.setValue(iter, 1, match.line ); 346 | } 347 | } 348 | } 349 | 350 | void rowActivatedResults(TreePath path, TreeViewColumn column, TreeView tv) { 351 | if (path.getIndices().length>0) { 352 | TreeIter selectedIter = new TreeIter(); 353 | if (tv.getModel().getIter(selectedIter, path)) { 354 | auto index = path.getIndices()[0]; 355 | trace("Launching application for file ", results[index].file); 356 | executeShell(format("xdg-open \"%s\"", results[index].file)); 357 | } 358 | } 359 | } 360 | 361 | void abortSearch(Button button) { 362 | manager.stop(_criteria.id); 363 | button.setSensitive(false); 364 | } 365 | 366 | package: 367 | 368 | /** 369 | * Gets the Pango markup tags to highlight search results, uses the 370 | * selection colors of the treeview for the highlight. 371 | */ 372 | MarkupTags getMarkupTags() { 373 | RGBA bg; 374 | RGBA fg; 375 | StyleContext context = tvMatches.getStyleContext(); 376 | context.getBackgroundColor(StateFlags.SELECTED, bg); 377 | context.getColor(StateFlags.SELECTED, fg); 378 | 379 | MarkupTags result = {true, format("",rgbaToHex(bg), rgbaToHex(fg)), ""}; 380 | return result; 381 | } 382 | 383 | void clear() { 384 | lsMatches.clear(); 385 | lsResults.clear(); 386 | results = []; 387 | sbStatus.removeAll(0); 388 | } 389 | 390 | public: 391 | 392 | this(SearchManager manager, string id) { 393 | super(GtkOrientation.VERTICAL,0); 394 | this.manager = manager; 395 | _criteria.id = id; 396 | createUI(); 397 | } 398 | 399 | @property string id() { 400 | return _criteria.id; 401 | }; 402 | 403 | @property Criteria criteria() { 404 | return _criteria; 405 | } 406 | 407 | void searchStart(Criteria value) { 408 | this._criteria = value; 409 | clear(); 410 | sbStatus.push(1, _("Starting...")); 411 | btnAbort.setSensitive(true); 412 | } 413 | 414 | void searchProgress(string currentPath) { 415 | sbStatus.push(1, format(_("Search %s"), currentPath)); 416 | } 417 | 418 | void searchResult(Result result) { 419 | TreeIter iter = lsResults.createIter(); 420 | lsResults.setValue(iter, 0, result.file); 421 | lsResults.setValue(iter, 1, cast(int)result.matchCount); 422 | results ~= result; 423 | trace("Results length: ", results.length); 424 | } 425 | 426 | void searchCompleted(bool aborted, ulong total) { 427 | sbStatus.removeAll(1); 428 | sbStatus.push(0, format(_("%s, total matches found %d"), aborted?"Aborted":"Completed", total)); 429 | btnAbort.setSensitive(false); 430 | } 431 | } -------------------------------------------------------------------------------- /source/vg/configuration.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.configuration; 6 | 7 | import std.algorithm; 8 | import std.array; 9 | import std.container; 10 | import std.conv; 11 | import std.file; 12 | import std.path; 13 | import std.stdio; 14 | 15 | import glib.Util; 16 | 17 | import sdlang; 18 | 19 | import gtk.util; 20 | 21 | import util.mixins.singleton; 22 | 23 | /** 24 | * This class saves and loads configuration data for 25 | * the app to an SDL file. The code here is pretty horrific, 26 | * in Java I'd probably use automated class serialization driven 27 | * by annotations approach. Need to figure out the besy way to do 28 | * this in D. 29 | */ 30 | class Configuration { 31 | 32 | mixin Singleton; 33 | 34 | private: 35 | 36 | immutable int MAXIMUM_ENTRIES = 20; 37 | 38 | immutable string CONFIG_FILE_NAME = "vgrep.sdl"; 39 | immutable string CONFIG_PATH = "vgrep"; 40 | 41 | immutable string TAG_ELEMENT = "Element"; 42 | immutable string TAG_MAX_MATCHES = "MaxMatches"; 43 | immutable string TAG_PATTERNS = "Patterns"; 44 | immutable string TAG_PATHS = "Paths"; 45 | immutable string TAG_MASKS = "Masks"; 46 | immutable string TAG_VGREP = "VGrep"; 47 | immutable string TAG_WDS = "Window"; 48 | 49 | immutable string TAG_X = "x"; 50 | immutable string TAG_Y = "y"; 51 | immutable string TAG_H = "h"; 52 | immutable string TAG_W = "w"; 53 | immutable string TAG_S = "s"; 54 | 55 | Array!string paths; 56 | Array!string patterns; 57 | Array!string masks; 58 | 59 | long maxMatches = 1000; 60 | 61 | WindowDisplayState wds; 62 | 63 | string getConfig() { 64 | //Note root tag cannot have namespace 65 | Tag config = new Tag(null, TAG_VGREP); 66 | 67 | saveArray(config, TAG_PATTERNS, patterns); 68 | saveArray(config, TAG_PATHS, paths); 69 | saveArray(config, TAG_MASKS, masks); 70 | 71 | //Save Max Matches 72 | new Tag(config, null, TAG_MAX_MATCHES, [Value(maxMatches)]); 73 | 74 | Tag mainWindow = new Tag(config, null, TAG_WDS); 75 | saveWindow(mainWindow, wds); 76 | 77 | return config.toSDLDocument(); 78 | } 79 | 80 | void saveWindow(Tag main, WindowDisplayState value) { 81 | new Tag(main, null, TAG_X, [Value(value.x)]); 82 | new Tag(main, null, TAG_Y, [Value(value.y)]); 83 | new Tag(main, null, TAG_W, [Value(value.w)]); 84 | new Tag(main, null, TAG_H, [Value(value.h)]); 85 | new Tag(main, null, TAG_S, [Value(cast(int)(value.s))]); 86 | } 87 | 88 | void loadWindow(Tag main) { 89 | wds.x = main.tags[TAG_X][0].values[0].get!int(); 90 | wds.y = main.tags[TAG_Y][0].values[0].get!int(); 91 | wds.w = main.tags[TAG_W][0].values[0].get!int(); 92 | wds.h = main.tags[TAG_H][0].values[0].get!int(); 93 | wds.s = cast(WindowState) main.tags[TAG_S][0].values[0].get!int(); 94 | } 95 | 96 | Tag saveArray(Tag parent, string name, Array!string values) { 97 | Tag result = new Tag(parent, null, name); 98 | //new Tag(result, null, "Length", [Value(to!int(values.length))]); 99 | int count = 0; 100 | foreach(string value; values) { 101 | count++; 102 | new Tag(result, null, TAG_ELEMENT, [Value(value)]); 103 | } 104 | return result; 105 | } 106 | 107 | Array!string loadArray(Tag tag) { 108 | Array!string result; 109 | if (TAG_ELEMENT in tag.tags) { 110 | foreach(Tag child; tag.tags[TAG_ELEMENT]) { 111 | string value = child.values[0].get!string(); 112 | result.insertBack(value); 113 | } 114 | } 115 | return result; 116 | } 117 | 118 | 119 | void setConfig(string sdl) { 120 | Tag root = parseSource(sdl); 121 | if (TAG_PATTERNS in root.tags) { 122 | patterns = loadArray(root.tags[TAG_PATTERNS][0]); 123 | } 124 | if (TAG_PATHS in root.tags) { 125 | paths = loadArray(root.tags[TAG_PATHS][0]); 126 | } 127 | if (TAG_MASKS in root.tags) { 128 | masks = loadArray(root.tags[TAG_MASKS][0]); 129 | } 130 | if (TAG_MAX_MATCHES in root.tags) { 131 | maxMatches = root.tags[TAG_MAX_MATCHES][0].values[0].get!long(); 132 | } 133 | if (TAG_WDS in root.tags) { 134 | loadWindow(root.tags[TAG_WDS][0]); 135 | } 136 | 137 | } 138 | 139 | void addValue(ref Array!string values, string value) { 140 | if (values[].find(value).length>0) { 141 | values.linearRemove(values[].find(value)[0..1]); 142 | values.insertBefore(values[0..0], value); 143 | } else { 144 | values.insertBefore(values[0..0], value); 145 | if (values.length > MAXIMUM_ENTRIES) { 146 | values.removeBack(); 147 | } 148 | } 149 | } 150 | 151 | public: 152 | 153 | @property string config() { 154 | return getConfig(); 155 | } 156 | 157 | @property void config(string sdl) { 158 | setConfig(sdl); 159 | } 160 | 161 | @property ulong maximumMatches() { 162 | return maxMatches; 163 | } 164 | 165 | @property void maximumMatches(ulong value) { 166 | maxMatches = value; 167 | } 168 | 169 | @property WindowDisplayState mainWindow() { 170 | return wds; 171 | } 172 | 173 | @property void mainWindow(WindowDisplayState value) { 174 | wds = value; 175 | } 176 | 177 | void addPath(string path) { 178 | addValue(paths, path); 179 | } 180 | 181 | Array!string getPaths() { 182 | return paths; 183 | } 184 | 185 | void addPattern(string pattern) { 186 | addValue(patterns, pattern); 187 | } 188 | 189 | Array!string getPatterns() { 190 | return patterns; 191 | } 192 | 193 | void addMasks(string mask) { 194 | addValue(masks, mask); 195 | } 196 | 197 | Array!string getMasks() { 198 | return masks; 199 | } 200 | 201 | void saveConfig() { 202 | string path = chainPath(Util.getUserConfigDir, CONFIG_PATH).array; 203 | mkdirRecurse(path); 204 | File f = File(chainPath(path, CONFIG_FILE_NAME),"w"); 205 | f.write(Configuration.instance.config); 206 | f.close(); 207 | } 208 | 209 | void loadConfig() { 210 | auto filename = chainPath(Util.getUserConfigDir,CONFIG_PATH,CONFIG_FILE_NAME); 211 | if (exists(filename)) { 212 | Configuration.instance.config = readText(filename); 213 | } 214 | } 215 | } -------------------------------------------------------------------------------- /source/vg/constants.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.constants; 6 | 7 | immutable uint GTK_VERSION_MAJOR = 3; 8 | immutable uint GTK_VERSION_MINOR = 16; 9 | immutable uint GTK_VERSION_PATCH = 0; 10 | 11 | immutable string APPLICATION_ID = "com.gexperts.VisualGrep"; 12 | 13 | immutable string APPLICATION_NAME = "Visual Grep"; 14 | immutable string APPLICATION_VERSION = "0.3.0"; 15 | immutable string APPLICATION_AUTHOR = "Gerald Nunn"; 16 | immutable string APPLICATION_COPYRIGHT = "Copyright \xc2\xa9 2015 " ~ APPLICATION_AUTHOR; 17 | immutable string APPLICATION_COMMENTS = "A GTK+ gui for the grep utility"; 18 | immutable string APPLICATION_LICENSE = "This Source Code Form is subject to the terms of the Mozilla Public " 19 | "License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at " 20 | "http://mozilla.org/MPL/2.0/."; 21 | 22 | immutable string[] APPLICATION_AUTHORS = ["Gerald Nunn"]; 23 | immutable string[] APPLICATION_ARTISTS = []; 24 | immutable string[] APPLICATION_DOCUMENTERS = [""]; 25 | immutable string APPLICATION_TRANSLATORS = ""; 26 | 27 | -------------------------------------------------------------------------------- /source/vg/finddialog.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.finddialog; 6 | 7 | import std.container; 8 | import std.format; 9 | 10 | import gtk.Box; 11 | import gtk.Button; 12 | import gtk.Dialog; 13 | import gtk.Entry; 14 | import gtk.Grid; 15 | import gtk.ComboBoxText; 16 | import gtk.FileChooserDialog; 17 | import gtk.Label; 18 | import gtk.Switch; 19 | import gtk.Widget; 20 | import gtk.Window; 21 | 22 | import util.file.search; 23 | 24 | import i18n.l10n; 25 | 26 | import vg.configuration; 27 | 28 | class FindDialog: Dialog { 29 | 30 | private: 31 | ComboBoxText cbPattern; 32 | ComboBoxText cbPath; 33 | ComboBoxText cbMask; 34 | Entry eSearchName; 35 | Switch swCaseInsensitive; 36 | Switch swSearchSubdirectories; 37 | Switch swFollowSymbolic; 38 | 39 | string id; 40 | 41 | void createUI() { 42 | setDefaultSize(800,300); 43 | 44 | //Create Grid Layout 45 | Grid grid = new Grid(); 46 | 47 | grid.setColumnSpacing(12); 48 | grid.setRowSpacing(6); 49 | grid.setMarginTop(18); 50 | grid.setMarginBottom(18); 51 | grid.setMarginLeft(18); 52 | grid.setMarginRight(18); 53 | 54 | int row = 0; 55 | //Search Label Title Text 56 | Label label = new Label(format("%s", _("Search Name"))); 57 | label.setUseMarkup(true); 58 | label.setHalign(Align.START); 59 | grid.attach(label,0,row,2,1); 60 | row++; 61 | 62 | //Search Label 63 | grid.attach(createLabel(_("Name")),0,row,1,1); 64 | eSearchName = new Entry(); 65 | grid.attach(eSearchName, 1,row,1,1); 66 | row++; 67 | 68 | //Search Text Title Label 69 | label = new Label(format("%s", _("Search Text"))); 70 | label.setUseMarkup(true); 71 | label.setHalign(Align.START); 72 | label.setMarginTop(18); 73 | grid.attach(label,0,row,2,1); 74 | row++; 75 | 76 | //Search Pattern 77 | grid.attach(createLabel(_("Pattern")),0,row,1,1); 78 | cbPattern = new ComboBoxText(true); 79 | cbPattern.setHexpand(true); 80 | cbPattern.addOnChanged(&changeListener); 81 | grid.attach(cbPattern,1,row,1,1); 82 | row++; 83 | 84 | //Case Insensitive 85 | swCaseInsensitive = new Switch(); 86 | swCaseInsensitive.setHalign(GtkAlign.START); 87 | grid.attach(createLabel(_("Case Insenstive")),0,row,1,1); 88 | grid.attach(swCaseInsensitive,1,row,1,1); 89 | row++; 90 | 91 | //Search Path Ttitle Label 92 | label = new Label(format("%s", _("Search Path"))); 93 | label.setUseMarkup(true); 94 | label.setHalign(Align.START); 95 | label.setMarginTop(18); 96 | grid.attach(label,0,row,2,1); 97 | row++; 98 | 99 | //Search Path 100 | grid.attach(createLabel(_("Path")),0,row,1,1); 101 | cbPath = new ComboBoxText(true); 102 | cbPath.setHexpand(true); 103 | cbPath.addOnChanged(&changeListener); 104 | Box box = new Box(Orientation.HORIZONTAL, 0); 105 | box.add(cbPath); 106 | //Select Directory 107 | Button button = new Button("folder-symbolic", IconSize.MENU); 108 | box.add(button); 109 | button.addOnClicked(&selectPath); 110 | grid.attach(box,1,row,1,1); 111 | row++; 112 | 113 | //Mask 114 | grid.attach(createLabel(_("File Mask")),0,row,1,1); 115 | cbMask = new ComboBoxText(true); 116 | cbMask.setHexpand(true); 117 | cbMask.addOnChanged(&changeListener); 118 | grid.attach(cbMask,1,row,1,1); 119 | row++; 120 | 121 | //Create Search Subdirectories 122 | swSearchSubdirectories = new Switch(); 123 | swSearchSubdirectories.setHalign(GtkAlign.START); 124 | grid.attach(createLabel(_("Search Subdirectories")),0,row,1,1); 125 | grid.attach(swSearchSubdirectories,1,row,1,1); 126 | row++; 127 | 128 | //Create Follow Symlinks Row 129 | swFollowSymbolic = new Switch(); 130 | swFollowSymbolic.setHalign(GtkAlign.START); 131 | grid.attach(createLabel(_("Follow Symlinks")),0,row,1,1); 132 | grid.attach(swFollowSymbolic,1,row,1,1); 133 | row++; 134 | 135 | getContentArea().add(grid); 136 | } 137 | 138 | Label createLabel(string text) { 139 | Label label = new Label(text); 140 | label.setHalign(GtkAlign.END); 141 | label.setMarginLeft(12); 142 | return label; 143 | } 144 | 145 | void updateUIState() { 146 | bool okEnabled = (cbPattern.getActiveText().length>0 && cbPath.getActiveText().length>0); 147 | setResponseSensitive(ResponseType.OK, okEnabled); 148 | } 149 | 150 | void changeListener(ComboBoxText cbt) { 151 | updateUIState(); 152 | } 153 | 154 | void selectPath(Button button) { 155 | FileChooserDialog dialog = new FileChooserDialog(_("Select Path"), this, FileChooserAction.SELECT_FOLDER, [_("Open"), _("Cancel")], [ResponseType.OK, ResponseType.CANCEL]); 156 | scope(exit) dialog.destroy(); 157 | dialog.setDefaultResponse(ResponseType.OK); 158 | 159 | if (cbPath.getActiveText().length>0) { 160 | dialog.setFilename(cbPath.getActiveText()); 161 | } 162 | if (dialog.run()) { 163 | Widget widget = cbPath.getChild(); 164 | if (widget !is null) { 165 | Entry entry = new Entry(cast(GtkEntry*)widget.getWidgetStruct()); 166 | entry.setText(dialog.getFilename()); 167 | } 168 | } 169 | } 170 | 171 | 172 | public: 173 | this(Window parent, string id) { 174 | super(_("Find"),parent,GtkDialogFlags.MODAL+GtkDialogFlags.USE_HEADER_BAR,[StockID.CANCEL,StockID.OK],[ResponseType.CANCEL,ResponseType.OK]); 175 | setDefaultResponse(ResponseType.OK); 176 | this.id = id; 177 | createUI(); 178 | } 179 | 180 | this(Window parent, string searchName, Criteria criteria) { 181 | this(parent, criteria.id); 182 | 183 | eSearchName.setText(searchName); 184 | 185 | foreach(pattern; Configuration.instance.getPatterns()) cbPattern.appendText(pattern); 186 | foreach(path; Configuration.instance.getPaths()) cbPath.appendText(path); 187 | foreach(mask; Configuration.instance.getMasks()) cbMask.appendText(mask); 188 | 189 | if (criteria.pattern.length>0) { 190 | cbPattern.setActiveText(criteria.pattern); 191 | } else { 192 | cbPattern.setActive(-1); 193 | } 194 | 195 | if (criteria.path.length>0) { 196 | cbPath.setActiveText(criteria.path); 197 | } else { 198 | cbPath.setActive(-1); 199 | } 200 | 201 | if (criteria.wildcardPattern.length>0) { 202 | cbMask.setActiveText(criteria.wildcardPattern); 203 | } else { 204 | cbMask.setActive(-1); 205 | } 206 | 207 | swCaseInsensitive.setActive(criteria.caseInsensitive); 208 | swFollowSymbolic.setActive(criteria.followSymbolic); 209 | swSearchSubdirectories.setActive(criteria.searchSubdirectories); 210 | updateUIState(); 211 | } 212 | 213 | Criteria criteria() { 214 | Criteria criteria = {id, 215 | cbPattern.getActiveText(), 216 | swCaseInsensitive.getActive(), 217 | cbPath.getActiveText(), 218 | cbMask.getActiveText(), 219 | swSearchSubdirectories.getActive(), 220 | swFollowSymbolic.getActive(), 221 | Configuration.instance.maximumMatches}; 222 | return criteria; 223 | } 224 | 225 | @property string searchName() { 226 | return eSearchName.getText(); 227 | } 228 | 229 | @property void setSearchName(string name) { 230 | eSearchName.setText(name); 231 | } 232 | } 233 | 234 | -------------------------------------------------------------------------------- /source/vg/search.d: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not 3 | * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | */ 5 | module vg.search; 6 | 7 | import core.time; 8 | import core.thread; 9 | 10 | import std.concurrency; 11 | import std.experimental.logger; 12 | import std.parallelism; 13 | 14 | import util.file.search; 15 | 16 | alias ResultDelegate = bool delegate(string id, Result result); 17 | alias ProgressDelegate = bool delegate(string id, string path); 18 | alias FinishedDelegate = void delegate(string id, bool aborted, ulong total); 19 | 20 | /** 21 | * SearchManager manages a set of individual search requests, it basically 22 | * allows multiple file searches to happen concurrently in individual threads 23 | */ 24 | class SearchManager { 25 | 26 | private: 27 | 28 | SearchRequest[string] requests; 29 | ProgressDelegate cbProgress; 30 | ResultDelegate cbResult; 31 | FinishedDelegate cbFinished; 32 | 33 | public: 34 | 35 | this() { 36 | } 37 | 38 | void search(Criteria criteria, MarkupTags markup) { 39 | SearchRequest request = new SearchRequest(criteria, markup); 40 | requests[criteria.id] = request; 41 | request.search(); 42 | } 43 | 44 | @property ulong count() { 45 | return requests.length; 46 | } 47 | 48 | void stopAll() { 49 | foreach(SearchRequest request; requests) { 50 | request.stopSearch(); 51 | } 52 | } 53 | 54 | void stop(string id) { 55 | if (id in requests) { 56 | SearchRequest request = requests[id]; 57 | request.stopSearch(); 58 | } 59 | } 60 | 61 | bool checkPending(ulong wait) { 62 | //writeln("Checking messages..."); 63 | try { 64 | receiveTimeout(dur!("msecs")( wait ), 65 | (Status s, string id, ulong total) { 66 | trace(id, ": Received completed message"); 67 | if (id in requests) { 68 | SearchRequest request = requests[id]; 69 | if (request !is null && cbFinished !is null) { 70 | requests.remove(id); 71 | cbFinished(id, (s==Status.ABORTED), total); 72 | } 73 | } else { 74 | error(id, " :Failed to get request for id"); 75 | } 76 | }, 77 | 78 | (Status s, string id, shared Result result) { 79 | if (cbResult !is null) { 80 | //Have to cast here otherwise the delegate must be shared and it just leaks everywhere 81 | //not optimal solution, works around D's annoying limitation of not being able to 82 | //pass immutable via send/receive 83 | cbResult(id, cast(Result) result); 84 | } 85 | trace(id, ": Received result ", result.file); 86 | }, 87 | (Status s, string id, string path) { 88 | trace(id, ": Received progress ", path); 89 | if (cbProgress !is null) { 90 | cbProgress(id, path); 91 | } 92 | } 93 | ); 94 | } catch (Throwable t) { 95 | error("Unexpected exception ", t.msg); 96 | } 97 | 98 | return requests.length>0; 99 | 100 | } 101 | 102 | @property void onProgress(ProgressDelegate progress) { 103 | this.cbProgress = progress; 104 | }; 105 | 106 | @property void onFinished(FinishedDelegate finished) { 107 | this.cbFinished = finished; 108 | } 109 | 110 | @property void onResult(ResultDelegate result) { 111 | this.cbResult = result; 112 | } 113 | 114 | bool isSearchInProgress(string id) { 115 | if (id in requests) return true; 116 | else return false; 117 | } 118 | } 119 | 120 | /** 121 | * Represents an individual search request 122 | */ 123 | class SearchRequest { 124 | 125 | private: 126 | Criteria criteria; 127 | MarkupTags markup; 128 | Tid tid; 129 | 130 | public: 131 | 132 | this(Criteria criteria, MarkupTags markup) { 133 | this.criteria = criteria; 134 | this.markup = markup; 135 | } 136 | 137 | public: 138 | 139 | void search() { 140 | trace("Putting search task in taskPool"); 141 | tid = spawn(&util.file.search.search, criteria, markup, thisTid); 142 | } 143 | 144 | void stopSearch() { 145 | tid.send(ABORT_MESSAGE); 146 | } 147 | } 148 | 149 | --------------------------------------------------------------------------------