[latexila/structure] Structure: right-click: UI stuff
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/structure] Structure: right-click: UI stuff
- Date: Sun, 12 Jun 2011 17:14:33 +0000 (UTC)
commit e32a80c4f058ec9eee3032eea35d81dfed44b920
Author: Sébastien Wilmet <swilmet src gnome org>
Date: Sun Jun 12 19:11:26 2011 +0200
Structure: right-click: UI stuff
TODO | 16 +++++++-
src/main_window.vala | 23 ++++++++++-
src/structure.vala | 111 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/ui/ui.xml | 26 ++++++++++++
4 files changed, 171 insertions(+), 5 deletions(-)
---
diff --git a/TODO b/TODO
index 5857377..8d7b5e6 100644
--- a/TODO
+++ b/TODO
@@ -7,7 +7,21 @@ LaTeXila 2.2
============
- Structure (list of chapters, sections, etc. to easily navigate in a document):
- - Right click: cut, copy, paste below, select, delete, comment, shift left/right.
+ - Figures and Tables:
+ - the TextMark should point to the \begin{env} line
+ - a second TextMark for the \end{env}
+ - contents of the item: first caption (max N characters)
+ - contents of the tooltip: all the caption
+
+ - New item type: graphic file (\includegraphics)
+
+ - Right click:
+ - cut, copy, delete, select
+ - comment
+ - shift left
+ - shift right:
+ - display a warning if a subparagraph already exists
+
Shift left/right is new comparated to Kile. For example we have a big section (with
subsections, etc.) and we want to shift it to the left so it becomes a chapter (the
subsections becomes sections, etc.).
diff --git a/src/main_window.vala b/src/main_window.vala
index a68b79d..208b1f0 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -131,6 +131,26 @@ public class MainWindow : Window
{ "ProjectsManage", Stock.PREFERENCES, N_("_Manage Projects"), null,
N_("Manage Projects"), on_projects_manage },
+ // Structure
+ { "Structure", null, N_("S_tructure") },
+ { "StructureCut", Stock.CUT, null, "",
+ N_("Cut the selected structure item"), Structure.on_cut },
+ { "StructureCopy", Stock.COPY, null, "",
+ N_("Copy the selected structure item"), Structure.on_copy },
+ { "StructureDelete", Stock.DELETE, null, "",
+ N_("Delete the selected structure item"), Structure.on_delete },
+ { "StructureSelect", Stock.SELECT_ALL, N_("_Select"), "",
+ N_("Select the contents of the selected structure item"),
+ Structure.on_select },
+ { "StructureComment", null, N_("_Comment"), null,
+ N_("Comment the selected structure item"), Structure.on_comment },
+ { "StructureShiftLeft", Stock.GO_BACK, N_("Shift _Left"), "",
+ N_("Shift the selected structure item to the left (e.g. section â?? chapter"),
+ Structure.on_shift_left },
+ { "StructureShiftRight", Stock.GO_FORWARD, N_("Shift _Right"), "",
+ N_("Shift the selected structure item to the right (e.g. chapter â?? section"),
+ Structure.on_shift_right },
+
// Help
{ "Help", null, N_("_Help") },
{ "HelpLatexReference", Stock.HELP, N_("_LaTeX Reference"), "<Release>F1",
@@ -290,8 +310,9 @@ public class MainWindow : Window
file_browser = new FileBrowser (this);
side_panel.add_component (_("File Browser"), Stock.OPEN, file_browser);
- _structure = new Structure (this);
+ _structure = new Structure (this, ui_manager);
side_panel.add_component (_("Structure"), Stock.INDEX, _structure);
+
side_panel.restore_state ();
/* signal handlers */
diff --git a/src/structure.vala b/src/structure.vala
index 0773e15..30ab649 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -40,6 +40,15 @@ public enum StructType
public class Structure : VBox
{
private unowned MainWindow _main_window;
+ private Menu _popup_menu;
+ private Gtk.Action _action_all_menu;
+ private Gtk.Action _action_cut;
+ private Gtk.Action _action_copy;
+ private Gtk.Action _action_delete;
+ private Gtk.Action _action_select;
+ private Gtk.Action _action_comment;
+ private Gtk.Action _action_shift_left;
+ private Gtk.Action _action_shift_right;
private ToggleButton[] _simple_list_buttons = {};
private VPaned _vpaned;
@@ -58,11 +67,22 @@ public class Structure : VBox
private static string[] _icons = null;
private static string[] _names = null;
- public Structure (MainWindow main_window)
+ public Structure (MainWindow main_window, UIManager ui_manager)
{
GLib.Object (spacing: 3);
_main_window = main_window;
+ _popup_menu = (Menu) ui_manager.get_widget ("/StructurePopup");
+ _action_all_menu = ui_manager.get_action ("/MainMenu/Structure");
+ _action_cut = ui_manager.get_action ("/StructurePopup/StructureCut");
+ _action_copy = ui_manager.get_action ("/StructurePopup/StructureCopy");
+ _action_delete = ui_manager.get_action ("/StructurePopup/StructureDelete");
+ _action_select = ui_manager.get_action ("/StructurePopup/StructureSelect");
+ _action_comment = ui_manager.get_action ("/StructurePopup/StructureComment");
+ _action_shift_left = ui_manager.get_action ("/StructurePopup/StructureShiftLeft");
+ _action_shift_right =
+ ui_manager.get_action ("/StructurePopup/StructureShiftRight");
+
init_toolbar ();
init_vpaned ();
init_list_view ();
@@ -71,7 +91,11 @@ public class Structure : VBox
_list_view_sw.hide ();
show.connect (connect_parsing);
- hide.connect (disconnect_parsing);
+ hide.connect (() =>
+ {
+ disconnect_parsing ();
+ _action_all_menu.set_sensitive (false);
+ });
}
private void init_toolbar ()
@@ -264,6 +288,25 @@ public class Structure : VBox
// double-click
_tree_view.row_activated.connect ((path) => select_tree_row (path));
+ // right click
+ _popup_menu.attach_to_widget (_tree_view, null);
+
+ _tree_view.button_press_event.connect ((event) =>
+ {
+ // right click
+ if (event.button == 3 && event.type == Gdk.EventType.BUTTON_PRESS)
+ show_popup_menu (event);
+
+ // propagate the event further so the row is also selected
+ return false;
+ });
+
+ _tree_view.popup_menu.connect (() =>
+ {
+ show_popup_menu (null);
+ return true;
+ });
+
// with a scrollbar
Widget sw = Utils.add_scrollbar (_tree_view);
_vpaned.add2 (sw);
@@ -341,7 +384,11 @@ public class Structure : VBox
return_val_if_reached (false);
TextMark mark;
- _model.get (tree_iter, StructColumn.MARK, out mark, -1);
+ StructType type;
+ _model.get (tree_iter,
+ StructColumn.MARK, out mark,
+ StructColumn.TYPE, out type,
+ -1);
/* go to the location in the document */
TextBuffer doc = mark.get_buffer ();
@@ -356,6 +403,8 @@ public class Structure : VBox
_main_window.active_view.scroll_to_mark (doc.get_insert (), 0, true, 0, 0);
/* select the corresponding item in the simple list */
+ set_actions_sensitivity (type);
+
if (! first_select)
return true;
@@ -449,6 +498,62 @@ public class Structure : VBox
return type <= StructType.SUBPARAGRAPH;
}
+
+ /*************************************************************************/
+ // Right-click: actions callbacks
+
+ private void show_popup_menu (Gdk.EventButton? event)
+ {
+ if (event != null)
+ _popup_menu.popup (null, null, null, event.button, event.time);
+ else
+ _popup_menu.popup (null, null, null, 0, get_current_event_time ());
+ }
+
+ private void set_actions_sensitivity (StructType type)
+ {
+ _action_all_menu.sensitive = true;
+
+ _action_cut.sensitive = true;
+ _action_copy.sensitive = true;
+ _action_delete.sensitive = true;
+ _action_select.sensitive = true;
+ _action_comment.sensitive = type != StructType.TODO && type != StructType.FIXME;
+
+ _action_shift_left.sensitive =
+ StructType.PART < type && type <= StructType.SUBPARAGRAPH;
+
+ _action_shift_right.sensitive = type < StructType.SUBPARAGRAPH;
+ }
+
+ public static void on_cut ()
+ {
+ }
+
+ public static void on_copy ()
+ {
+ }
+
+ public static void on_delete ()
+ {
+ }
+
+ public static void on_select ()
+ {
+ }
+
+ public static void on_comment ()
+ {
+ }
+
+ public static void on_shift_left ()
+ {
+ }
+
+ public static void on_shift_right ()
+ {
+ }
+
public static string get_icon_from_type (StructType type)
{
if (_icons == null)
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index e357a70..a5db2ed 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -356,6 +356,19 @@ along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
<menuitem action="ProjectsManage" />
</menu>
+ <menu action="Structure">
+ <menuitem action="StructureCut" />
+ <menuitem action="StructureCopy" />
+ <menuitem action="StructureDelete" />
+ <separator />
+ <menuitem action="StructureSelect" />
+ <separator />
+ <menuitem action="StructureComment" />
+ <separator />
+ <menuitem action="StructureShiftLeft" />
+ <menuitem action="StructureShiftRight" />
+ </menu>
+
<menu action="Help">
<menuitem action="HelpLatexReference" />
<menuitem action="HelpAbout" />
@@ -499,4 +512,17 @@ along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
<separator />
<menuitem action="FileClose" />
</popup>
+
+ <popup action="StructurePopup">
+ <menuitem action="StructureCut" />
+ <menuitem action="StructureCopy" />
+ <menuitem action="StructureDelete" />
+ <separator />
+ <menuitem action="StructureSelect" />
+ <separator />
+ <menuitem action="StructureComment" />
+ <separator />
+ <menuitem action="StructureShiftLeft" />
+ <menuitem action="StructureShiftRight" />
+ </popup>
</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]