Exemplo n.º 1
0
	def __init__(self):
		GObject.Object.__init__(self)

		self.uri = ""
		self.window = None
		self.id_name = 'OpenURIContextMenuPluginID'
		self.encoding = Gedit.encoding_get_from_charset("UTF-8")
Exemplo n.º 2
0
	def find_all_in_dir(self, parent_it, dir_path, file_pattern, search_pattern, find_options, replace_flg = False):
		#start_time = time.time()
		if search_pattern == "":
			return
			
		#d_list = []
		file_list = []
		grep_cmd = ['grep', '-l', '-I']
		if find_options['MATCH_WHOLE_WORD'] == True:
			grep_cmd.append('-w')
		if find_options['MATCH_CASE'] == False:
			grep_cmd.append('-i')
		if find_options['INCLUDE_SUBFOLDER'] == True:
			grep_cmd.append('-R')

		if not file_pattern == '': 
			pattern_list = re.split('\s*\|\s*', file_pattern)
			for f_pattern in pattern_list:
				if f_pattern.startswith('-'):
					grep_cmd.append('--exclude=' + f_pattern[1:])
				else:
					grep_cmd.append('--include=' + f_pattern)

		if find_options['REGEX_SEARCH'] == True:
			grep_cmd = grep_cmd + ['-E', '-e', search_pattern, dir_path]
		else:
			grep_cmd = grep_cmd + ['-F', '-e', search_pattern, dir_path]
		#print(grep_cmd)

		p = subprocess.Popen(grep_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		for e in p.stderr:
			print(e)

		for f in p.stdout:
			file_list.append(f[:-1])
			
		
		'''
		for root, dirs, files in os.walk(unicode(dir_path, 'utf-8')):
			for d in dirs:
				d_list.append(os.path.join(root, d))	
			for f in files:
				if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')):
					if find_options['INCLUDE_SUBFOLDER'] == True:
						file_list.append(os.path.join(root, f))
					else:
						if os.path.dirname(f) not in d_list:
							file_list.append(os.path.join(root, f))
				self.find_ui.do_events()
		#'''
					
		#mid_time = time.time()
		#print('Use ' + str(mid_time-start_time) + ' seconds to find files.')
		
		self._results_view.is_busy(True)
		self._results_view.do_events()
					
		for file_path in file_list:
			if os.path.isfile(file_path):
				temp_doc = Gedit.Document()
				#file_uri = 'file://' + file_path
				#temp_doc.load(Gio.file_new_for_uri(file_uri), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False)
				temp_doc.load(Gio.file_new_for_path(bytes.decode(file_path)), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False)
				f_temp = open(file_path, 'r')
				try:
					text = str(f_temp.read())
				except:
					text = f_temp.read()
				f_temp.close()
				temp_doc.set_text(text)
				
				self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, find_options, replace_flg)
				self.find_ui.do_events()
				if self._results_view.stopButton.get_sensitive() == False:
					break
				
		self._results_view.is_busy(False)
Exemplo n.º 3
0
# fix document_loaded: assertion `(tab->priv->state == GEDIT_TAB_STATE_LOADING) || (tab->priv->state == GEDIT_TAB_STATE_REVERTING)' failed

from gettext import gettext as _

from gi.repository import GObject, Gtk, Gio, Gedit
import functools

# All encodings names
enclist_func = lambda i=0: [Gedit.encoding_get_from_index(i)] + enclist_func(
    i + 1) if Gedit.encoding_get_from_index(i) else []

shown_enc = Gio.Settings.new("org.gnome.gedit.preferences.encodings").get_strv(
    "shown-in-menu")
# show the full list of encodings if not they not configured in the Open/Save Dialog
enclist = sorted(
    ([Gedit.encoding_get_from_charset(encname)
      for encname in shown_enc] if shown_enc else enclist_func()) +
    [Gedit.encoding_get_utf8()],
    key=lambda enc: enc.to_string())

ui_str = """<ui>
          <menubar name="MenuBar">
            <menu name="FileMenu" action="File">
              <placeholder name="FileOps_2">
                <menu name="FileEncodingMenu" action="FileEncoding">
                  <placeholder name="EncodingListHolder"/>
                  <separator/>
%s
                </menu>
              </placeholder>
            </menu>
Exemplo n.º 4
0
#  Boston, MA 02111-1307, USA.

# TODO:
# fix document_loaded: assertion `(tab->priv->state == GEDIT_TAB_STATE_LOADING) || (tab->priv->state == GEDIT_TAB_STATE_REVERTING)' failed

from gettext import gettext as _

from gi.repository import GObject, Gtk, Gio, Gedit
import functools

# All encodings names
enclist_func = lambda i=0: [Gedit.encoding_get_from_index(i)] + enclist_func(i+1) if Gedit.encoding_get_from_index(i) else []

shown_enc = Gio.Settings.new("org.gnome.gedit.preferences.encodings").get_strv("shown-in-menu")
# show the full list of encodings if not they not configured in the Open/Save Dialog
enclist = sorted(([Gedit.encoding_get_from_charset(encname) for encname in shown_enc]
                 if shown_enc else enclist_func())
                  + [Gedit.encoding_get_utf8()], key=lambda enc: enc.to_string())

ui_str = """<ui>
          <menubar name="MenuBar">
            <menu name="FileMenu" action="File">
              <placeholder name="FileOps_2">
                <menu name="FileEncodingMenu" action="FileEncoding">
                  <placeholder name="EncodingListHolder"/>
                  <separator/>
%s
                </menu>
              </placeholder>
            </menu>
          </menubar>