Commit 739b3569 authored by Steve Frécinaux's avatar Steve Frécinaux Committed by Paolo Borelli

implement applicability (gray unusable tools, allow to run a command on

2006-01-21  Steve Frécinaux  <steve@istique.net>

	* plugins/externaltools/tools/functions.py: implement applicability
	(gray unusable tools, allow to run a command on unsaved document)
	* plugins/externaltools/tools/__init__.py: adapt for applicability;
	remove debug message
	* plugins/externaltools/tools/manager.py: correct a bug related to
	keyboard navigation; allow reordering the tools in the tree and in the
	main window menu; update the right pane title when a tool is renamed
	* plugins/externaltools/tools/tools.glade: name the hpaned
	* plugins/externaltools/tools/outputpanel.py: show the panel when a
	tool is ran

2006-01-21  Steve Frécinaux  <steve@istique.net>

	* plugins/snippets/snippets/SnippetsDialog.py: remove the gconf stuff
parent e9f41d0a
2006-01-21 Steve Frécinaux <steve@istique.net>
* plugins/externaltools/tools/functions.py: implement applicability
(gray unusable tools, allow to run a command on unsaved document)
* plugins/externaltools/tools/__init__.py: adapt for applicability;
remove debug message
* plugins/externaltools/tools/manager.py: correct a bug related to
keyboard navigation; allow reordering the tools in the tree and in the
main window menu; update the right pane title when a tool is renamed
* plugins/externaltools/tools/tools.glade: name the hpaned
* plugins/externaltools/tools/outputpanel.py: show the panel when a
tool is ran
2006-01-21 Steve Frécinaux <steve@istique.net>
* plugins/snippets/snippets/SnippetsDialog.py: remove the gconf stuff
=== gedit 2.13.4 ===
2006-01-20 Paolo Borelli <pborelli@katamail.com>
......
......@@ -47,6 +47,7 @@ class ToolsPlugin(gedit.Plugin):
'ToolsManager', 'ToolsManager',
gtk.UI_MANAGER_MENUITEM, False)
insert_tools_menu(window)
filter_tools_menu(window)
manager.ensure_update()
# Create output console
......@@ -67,7 +68,10 @@ class ToolsPlugin(gedit.Plugin):
bottom = window.get_bottom_panel()
bottom.remove_item(window_data["output_buffer"].panel)
window.set_data("ToolsPluginWindowData", None)
print "deactivate on window %s" % window
def update_ui(self, window):
filter_tools_menu(window)
window.get_ui_manager().ensure_update()
def create_configure_dialog(self):
return self.open_dialog()
......
......@@ -55,6 +55,9 @@ class Capture(gobject.GObject):
def set_input(self, text):
self.input_text = text
def set_cwd(self, cwd):
self.cwd = cwd
def execute(self):
if self.command is None:
return
......
......@@ -73,7 +73,7 @@ class ToolsTree:
for tool in self.root:
if tool != ignore:
skey, smod = gtk.accelerator_parse(tool.get('accelerator'))
skey, smod = gtk.accelerator_parse(default(tool.get('accelerator'), ''))
if skey == keyval and smod & mod == smod:
return tool
return None
......@@ -86,8 +86,10 @@ def default(val, d):
return d
# ==== UI related functions ====
APPLICABILITIES = ('all', 'titled', 'local', 'remote', 'untitled')
def insert_tools_menu(window, tools = None):
window_data = dict()
window_data = dict()
window.set_data("ToolsPluginCommandsData", window_data)
if tools is None:
......@@ -95,20 +97,24 @@ def insert_tools_menu(window, tools = None):
manager = window.get_ui_manager()
window_data['action_group'] = gtk.ActionGroup("GeditToolsPluginCommandsActions")
window_data['action_group'].set_translation_domain('gedit')
window_data['action_groups'] = dict()
window_data['ui_id'] = manager.new_merge_id()
i = 0;
for tool in tools:
menu_id = "ToolCommand%06d" % i
window_data['action_group'].add_actions([(menu_id,
None,
tool.get('label'),
tool.get('accelerator'),
tool.get('description'),
capture_menu_action)],
(window, tool))
ap = tool.get('applicability')
if ap not in window_data['action_groups']:
window_data['action_groups'][ap] = \
gtk.ActionGroup("GeditToolsPluginCommandsActions%s" % ap.capitalize())
window_data['action_groups'][ap].set_translation_domain('gedit')
window_data['action_groups'][ap].add_actions(
[(menu_id, None, tool.get('label'),
tool.get('accelerator'), tool.get('description'),
capture_menu_action)],
(window, tool))
manager.add_ui(window_data['ui_id'],
'/MenuBar/ToolsMenu/ToolsOps_4',
menu_id,
......@@ -117,63 +123,89 @@ def insert_tools_menu(window, tools = None):
False)
i = i + 1
manager.insert_action_group(window_data['action_group'], -1)
for applic in APPLICABILITIES:
if applic in window_data['action_groups']:
manager.insert_action_group(window_data['action_groups'][applic], -1)
def remove_tools_menu(window):
window_data = window.get_data("ToolsPluginCommandsData")
manager = window.get_ui_manager()
manager.remove_ui(window_data['ui_id'])
manager.remove_action_group(window_data['action_group'])
for action_group in window_data['action_groups'].itervalues():
manager.remove_action_group(action_group)
window.set_data("ToolsPluginCommandsData", None)
def update_tools_menu(tools = None):
for window in gedit.gedit_app_get_default().get_windows():
remove_tools_menu(window)
insert_tools_menu(window, tools)
filter_tools_menu(window)
window.get_ui_manager().ensure_update()
def filter_tools_menu(window):
action_groups = window.get_data("ToolsPluginCommandsData")['action_groups']
document = window.get_active_document()
if document is not None:
active_groups = ['all']
uri = document.get_uri()
if uri is not None:
active_groups.append('titled')
if gnomevfs.get_uri_scheme(uri) == 'file':
active_groups.append('local')
else:
active_groups.append('remote')
else:
active_groups.append('untitled')
else:
active_groups = []
for name, group in action_groups.iteritems():
group.set_sensitive(name in active_groups)
# ==== Capture related functions ====
def capture_menu_action(action, window, node):
# Get the panel
panel = window.get_data("ToolsPluginWindowData")["output_buffer"]
panel.show()
panel.clear()
view = window.get_active_view()
document = view.get_buffer()
if document is None:
# :TODO: Allow command on no document
panel.write("No document\n", panel.command_tag)
return
uri = document.get_uri()
if uri is None:
# :TODO: Allow command on unnamed documents
panel.write("Current document has no file name\n", panel.command_tag)
return
# Configure capture environment
path = gnomevfs.get_local_path_from_uri(uri)
cwd = os.path.dirname(path)
capture = Capture(node.text, os.getcwd())
capture.env = os.environ.copy()
capture.set_env(GEDIT_CWD = os.getcwd())
capture = Capture(node.text, cwd)
capture.set_flags(capture.CAPTURE_BOTH)
view = window.get_active_view()
if view is not None:
# Environment vars relative to current document
document = view.get_buffer()
uri = document.get_uri()
if uri is not None:
scheme = gnomevfs.get_uri_scheme(uri)
name = os.path.basename(uri)
capture.set_env(GEDIT_CURRENT_DOCUMENT_URI = uri,
GEDIT_CURRENT_DOCUMENT_NAME = name,
GEDIT_CURRENT_DOCUMENT_SCHEME = scheme)
if scheme == 'file':
path = gnomevfs.get_local_path_from_uri(uri)
cwd = os.path.dirname(path)
capture.set_cwd(cwd)
capture.set_env(GEDIT_CURRENT_DOCUMENT_PATH = path,
GEDIT_CURRENT_DOCUMENT_DIR = cwd)
documents_uri = [document.get_uri()
for document in window.get_documents()
if document.get_uri() is not None]
documents_path = [gnomevfs.get_local_path_from_uri(uri)
for uri in documents_uri
if gnomevfs.get_uri_scheme(uri) == 'file']
capture.set_env(GEDIT_DOCUMENTS_URI = ' '.join(documents_uri),
GEDIT_DOCUMENTS_PATH = ' '.join(documents_path))
documents_uri = [document.get_uri()
for document in window.get_documents()
if document.get_uri() is not None]
documents_path = [gnomevfs.get_local_path_from_uri(uri)
for uri in documents_uri]
capture.set_flags(capture.CAPTURE_BOTH)
capture.env = os.environ.copy()
capture.set_env(GEDIT_CURRENT_DOCUMENT_URI = uri,
GEDIT_CURRENT_DOCUMENT_PATH = path,
GEDIT_CURRENT_DOCUMENT_NAME = os.path.basename(path),
GEDIT_CURRENT_DOCUMENT_DIR = cwd,
GEDIT_DOCUMENTS_URI = ' '.join(documents_uri),
GEDIT_DOCUMENTS_PATH = ' '.join(documents_path))
# Assign the error output to the output panel
panel.process = capture
......@@ -185,7 +217,7 @@ def capture_menu_action(action, window, node):
input_type = default(node.get('input'), 'nothing')
output_type = default(node.get('output'), 'output-panel')
if input_type != 'nothing':
if input_type != 'nothing' and view is not None:
if input_type == 'document':
start, end = document.get_bounds()
elif input_type == 'selection':
......@@ -218,10 +250,7 @@ def capture_menu_action(action, window, node):
capture.set_input(input_text)
# Assign the standard output to the chosen "file"
if output_type == 'output-panel':
capture.connect('stdout-line', capture_stdout_line_panel, panel)
document.begin_user_action()
elif output_type == 'new-document':
if output_type == 'new-document':
tab = window.create_tab(True)
view = tab.get_view()
document = tab.get_document()
......@@ -230,7 +259,7 @@ def capture_menu_action(action, window, node):
document.begin_user_action()
view.set_editable(False)
view.set_cursor_visible(False)
else:
elif output_type != 'output-panel' and view is not None:
document.begin_user_action()
view.set_editable(False)
view.set_cursor_visible(False)
......@@ -246,6 +275,10 @@ def capture_menu_action(action, window, node):
else:
pos = document.get_end_iter()
capture.connect('stdout-line', capture_stdout_line_document, document, pos)
else:
capture.connect('stdout-line', capture_stdout_line_panel, panel)
document.begin_user_action()
# Run the command
view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gdk.Cursor(gdk.WATCH))
......
......@@ -26,9 +26,11 @@ from gettext import gettext as _
from functions import *
import ElementTree as et
GLADE_FILE = os.path.join(os.path.dirname(__file__), "tools.glade")
class Manager:
GLADE_FILE = os.path.join(os.path.dirname(__file__), "tools.glade")
GCONF_DIR = '/apps/gedit-2/plugins/tools'
LABEL_COLUMN = 0 # For Combo and Tree
NODE_COLUMN = 1 # For Tree only
NAME_COLUMN = 1 # For Combo only
......@@ -74,11 +76,11 @@ class Manager:
'on_tool_manager_dialog_response': self.on_tool_manager_dialog_response,
'on_accelerator_key_press' : self.on_accelerator_key_press,
'on_accelerator_focus_in' : self.on_accelerator_focus_in,
'on_entry_accelerator_focus_out' : self.on_entry_accelerator_focus_out
'on_accelerator_focus_out' : self.on_accelerator_focus_out
}
# Load the "main-window" widget from the glade file.
self.ui = glade.XML(GLADE_FILE, 'tool-manager-dialog')
self.ui = glade.XML(self.GLADE_FILE, 'tool-manager-dialog')
self.ui.signal_autoconnect(callbacks)
self.dialog = self.ui.get_widget('tool-manager-dialog')
self.view = self.ui.get_widget('view')
......@@ -93,11 +95,12 @@ class Manager:
self.current_node = None
self.model = gtk.ListStore(str, object)
self.model.set_sort_column_id(self.LABEL_COLUMN, gtk.SORT_ASCENDING)
self.view.set_model(self.model)
for item in self.tools:
self.model.append([item.get('label'), item])
self.model.connect('row-changed', self.on_tools_model_row_changed)
def __init_tools_view(self):
# Tools column
......@@ -110,7 +113,7 @@ class Manager:
renderer.connect('edited', self.on_view_label_cell_edited)
self.view.get_selection().connect('changed', self.on_view_selection_changed, None)
def __init_combobox(self, name):
combo = self[name]
model = gtk.ListStore(str, str)
......@@ -133,8 +136,8 @@ class Manager:
combo.set_active_iter(piter)
return True
piter = model.iter_next(piter)
return False
return False
def get_selected_tool(self):
model, piter = self.view.get_selection().get_selected()
......@@ -203,6 +206,7 @@ class Manager:
node = self.model.get_value(piter, self.NODE_COLUMN)
node.set("label", new_text)
self.model.set(piter, self.LABEL_COLUMN, new_text)
self['title'].set_label(_('Edit tool <i>%s</i>:') % new_text)
def on_view_selection_changed(self, selection, userdata):
self.save_current_tool()
......@@ -217,6 +221,13 @@ class Manager:
# :TODO: Config panel should be grayed
pass
def on_tools_model_row_changed(self, model, path, piter):
tool = model.get_value(piter, self.NODE_COLUMN)
if tool is not self.tools.root[path[0]]:
if tool in self.tools.root.items():
self.tools.root.remove(tool)
self.tools.root.insert(path[0], tool)
def set_accelerator(self, keyval, mod):
# Check whether accelerator already exists
......@@ -229,8 +240,11 @@ class Manager:
self.current_node.get('label'))
return False
self.current_node.set('accelerator',
gtk.accelerator_name(keyval, mod))
name = gtk.accelerator_name(keyval, mod)
if name != '':
self.current_node.set('accelerator', name)
else:
self.current_node.set('accelerator', None)
return True
def on_accelerator_key_press(self, entry, event):
......@@ -242,7 +256,6 @@ class Manager:
return True
elif event.keyval == gtk.keysyms.Delete \
or event.keyval == gtk.keysyms.BackSpace:
self.remove_accelerator()
entry.set_text('')
self.current_node.set('accelerator', '')
self['commands'].grab_focus()
......@@ -273,7 +286,7 @@ class Manager:
else:
entry.set_text('Type a new accelerator')
def on_entry_accelerator_focus_out(self, entry, event):
def on_accelerator_focus_out(self, entry, event):
if self.current_node is not None:
entry.set_text(self.current_node.get('accelerator'))
......@@ -284,9 +297,6 @@ class Manager:
self.save_current_tool()
# :TODO: Save size and pane position
# self.save_metrics()
self.dialog.destroy()
self.dialog = None
......
......@@ -94,5 +94,6 @@ class OutputPanel(UniqueById):
gobject.idle_add(self.scroll_to_end)
def show(self):
# :TODO: Show the good panel
pass
panel = self.window.get_bottom_panel()
panel.show()
panel.activate_item(self.panel)
......@@ -155,7 +155,7 @@
</child>
<child>
<widget class="GtkHPaned" id="hpaned1">
<widget class="GtkHPaned" id="paned">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
......@@ -208,7 +208,7 @@
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="reorderable">True</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
......
......@@ -310,12 +310,11 @@ class SnippetsPluginInstance:
holders = len(self.placeholders)
active_info = s.insert_into(self)
self.active_snippets.append(active_info)
# Put cursor back to beginning of the snippet
piter = buf.get_iter_at_mark(active_info[0])
buf.move_mark(buf.get_insert(), piter)
buf.move_mark(buf.get_selection_bound(), piter)
buf.place_cursor(piter)
# Jump to first placeholder
(current, next) = self.next_placeholder()
......
......@@ -20,7 +20,6 @@ from gtk import glade
from gtk import gdk
import pango
import os
import gconf
from xml.dom import minidom
import xml
import gedit
......@@ -35,7 +34,6 @@ class SnippetsDialog:
EDITABLE_COLUMN = 2
OBJ_COLUMN = 3
GCONF_DIR = '/apps/gedit-2/plugins/snippets'
model = None
def __init__(self, plugin):
......@@ -274,7 +272,6 @@ class SnippetsDialog:
def run(self):
if not self.dlg:
self.build()
self.load_metrics()
self.dlg.show_all()
else:
self.build_model()
......@@ -323,36 +320,6 @@ class SnippetsDialog:
self.tree_view.get_selection().select_iter(piter)
self.tree_view.scroll_to_cell(self.model.get_path(piter), None, \
True, 0.5, 0.5)
def preference_int(self, client, pref):
try:
ret = client.get_int(self.GCONF_DIR + '/' + pref)
except gobject.GError:
ret = 0
return ret
def load_metrics(self):
client = gconf.client_get_default()
width = self.preference_int(client, 'dialog_width')
height = self.preference_int(client, 'dialog_height')
position = self.preference_int(client, 'dialog_paned')
if width > 0 and height > 0:
self.dlg.set_default_size(width, height)
if position > 0:
self['hpaned_paned'].set_position(position)
def save_metrics(self):
client = gconf.client_get_default()
client.set_int(self.GCONF_DIR + '/dialog_width', \
self.dlg.allocation.width)
client.set_int(self.GCONF_DIR + '/dialog_height', \
self.dlg.allocation.height)
client.set_int(self.GCONF_DIR + '/dialog_paned', \
self['hpaned_paned'].get_position())
def new_snippet(self):
if not self.language_path:
......@@ -403,9 +370,6 @@ class SnippetsDialog:
# Show help
return
# Save size and pane position
self.save_metrics()
self.snippet = None
self.dlg.destroy()
self.dlg = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment