Permalink
Browse files

Use sub notify if available

  • Loading branch information...
facelessuser committed Jun 15, 2014
1 parent deb318e commit e7367ee4820204018ffe29885e0c6368dfc2af35
Showing with 38 additions and 8 deletions.
  1. +3 −0 reg_replace.sublime-settings
  2. +24 −0 rr_notify.py
  3. +6 −5 rr_replacer.py
  4. +5 −3 rr_sequencer.py
@@ -43,6 +43,9 @@
// region to find and replace all instances of the regex, when regex cannot be formatted
// to find all instances in a greedy fashion. Default is false.
{
+ // Use sub notify if available
+ "use_sub_notify": true,
+
"replacements": {
// Example replacements
"html5_remove_deprecated_type_attr": {
View
@@ -0,0 +1,24 @@
+import sublime
+try:
+ from SubNotify.sub_notify import SubNotifyIsReadyCommand as Notify
+except:
+ class Notify:
+ @classmethod
+ def is_ready(cls):
+ return False
+
+
+def notify(msg):
+ settings = sublime.load_settings("reg_replace.sublime-settings")
+ if settings.get("use_sub_notify", False) and Notify.is_ready():
+ sublime.run_command("sub_notify", {"title": "RegReplace", "msg": msg})
+ else:
+ sublime.status_message(msg)
+
+
+def error(msg):
+ settings = sublime.load_settings("reg_replace.sublime-settings")
+ if settings.get("use_sub_notify", False) and Notify.is_ready():
+ sublime.run_command("sub_notify", {"title": "RegReplace", "msg": msg, "level": "error"})
+ else:
+ sublime.error_message("RegReplace:\n%s" % msg)
View
@@ -3,6 +3,7 @@
from RegReplace.rr_plugin import Plugin
import RegReplace.rr_extended as rr_extended
import traceback
+from RegReplace.rr_notify import error
class FindReplace(object):
@@ -288,7 +289,7 @@ def apply(self, pattern):
regions = self.regex_findall(find, flags, replace, extractions, literal)
except Exception as err:
print(str(traceback.format_exc()))
- sublime.error_message('REGEX ERROR: %s' % str(err))
+ error('REGEX ERROR: %s' % str(err))
return replaced
if self.selection_only and self.full_file:
@@ -478,7 +479,7 @@ def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi)
self.view.replace(self.edit, region, extraction)
except Exception as err:
print(str(traceback.format_exc()))
- sublime.error_message('REGEX ERROR: %s' % str(err))
+ error('REGEX ERROR: %s' % str(err))
return total_replaced
return total_replaced
@@ -512,7 +513,7 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
count += 1
except Exception as err:
print(str(traceback.format_exc()))
- sublime.error_message('REGEX ERROR: %s' % str(err))
+ error('REGEX ERROR: %s' % str(err))
return total_replaced
try:
@@ -534,7 +535,7 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
break
except Exception as err:
print(str(traceback.format_exc()))
- sublime.error_message('REGEX ERROR: %s' % str(err))
+ error('REGEX ERROR: %s' % str(err))
return total_replaced
# Did we find a suitable region?
@@ -642,7 +643,7 @@ def scope_apply(self, pattern):
re_find = re.compile(find, flags)
except Exception as err:
print(str(traceback.format_exc()))
- sublime.error_message('REGEX ERROR: %s' % str(err))
+ error('REGEX ERROR: %s' % str(err))
return replaced
# Greedy Scope?
View
@@ -9,6 +9,8 @@
import re
from fnmatch import fnmatch
from RegReplace.rr_replacer import FindReplace
+from RegReplace.rr_notify import error
+
DEFAULT_SHOW_PANEL = False
DEFAULT_HIGHLIGHT_COLOR = 'invalid'
@@ -109,7 +111,7 @@ def select(self, item):
elif item['action'] == "mark":
self.highlights += item['sequence']
else:
- sublime.error_message("action %s is not a valid action" % item["action"])
+ error("action %s is not a valid action" % item["action"])
elif "highlight" in item and bool(item['highlight']):
sublime.message_dialog(
"RegReplace:\n\"on_save_sequence\" setting option '\"highlight\": true' is deprecated!\nPlease use '\"action\": \"mark\"'."
@@ -346,7 +348,7 @@ def perform_action(self):
try:
self.view.unfold(self.ignore_ending_newlines(self.replace_obj.target_regions))
except:
- sublime.error_message("Cannot unfold! Please upgrade to the latest stable beta build to remove this error.")
+ error("Cannot unfold! Please upgrade to the latest stable beta build to remove this error.")
elif self.action == 'mark':
# Mark targeted regions
if 'key' in self.options:
@@ -425,7 +427,7 @@ def start_sequence(self):
# Perform action
if self.action is not None:
if not self.perform_action():
- results = 'Error: Bad Action!'
+ results = 'Error: %s - Bad Action!' % self.action
# Report results
if self.panel_display:

0 comments on commit e7367ee

Please sign in to comment.