[latexila] Create the MainWindowStructure class
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Create the MainWindowStructure class
- Date: Mon, 23 Jul 2012 22:49:33 +0000 (UTC)
commit b481ca19e2aada24f8acaff1819a0b51454cc5f6
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Tue Jul 24 00:46:26 2012 +0200
Create the MainWindowStructure class
The purpose is to have a smaller MainWindow class.
And the Structure doesn't need the UIManager anymore.
po/POTFILES.in | 1 +
src/main_window.vala | 85 +++--------------------
src/main_window_structure.vala | 149 ++++++++++++++++++++++++++++++++++++++++
src/structure.vala | 64 ++---------------
4 files changed, 169 insertions(+), 130 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4a0eb91..b47fe33 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -29,6 +29,7 @@ src/latex_menu.vala
src/latex_post_processor.vala
src/main.vala
src/main_window_build_tools.vala
+src/main_window_structure.vala
src/main_window.vala
src/menu_in_toolbar.vala
src/most_used_symbols.vala
diff --git a/src/main_window.vala b/src/main_window.vala
index 578be57..6a6391f 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -121,26 +121,6 @@ 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"), on_structure_cut },
- { "StructureCopy", Stock.COPY, null, "",
- N_("Copy the selected structure item"), on_structure_copy },
- { "StructureDelete", Stock.DELETE, null, "",
- N_("Delete the selected structure item"), on_structure_delete },
- { "StructureSelect", Stock.SELECT_ALL, N_("_Select"), "",
- N_("Select the contents of the selected structure item"),
- on_structure_select },
- { "StructureComment", null, N_("_Comment"), null,
- N_("Comment the selected structure item"), on_structure_comment },
- { "StructureShiftLeft", Stock.GO_BACK, N_("Shift _Left"), "",
- N_("Shift the selected structure item to the left (e.g. section â chapter)"),
- on_structure_shift_left },
- { "StructureShiftRight", Stock.GO_FORWARD, N_("Shift _Right"), "",
- N_("Shift the selected structure item to the right (e.g. chapter â section)"),
- on_structure_shift_right },
-
// Help
{ "Help", null, N_("_Help") },
{ "HelpContents", Stock.HELP, N_("_Contents"), "<Release>F1",
@@ -264,17 +244,17 @@ public class MainWindow : Window
goto_line = new GotoLine (this);
search_and_replace = new SearchAndReplace (this);
- // side panel
- _side_panel = new SidePanel ();
+ // File browser
+ FileBrowser file_browser = new FileBrowser (this);
+ // Symbols
_symbols = new SymbolsView (this);
- _side_panel.add_component (_("Symbols"), "symbol_greek", _symbols);
- FileBrowser file_browser = new FileBrowser (this);
- _side_panel.add_component (_("File Browser"), Stock.OPEN, file_browser);
-
- // bottom panel
+ // Structure
+ _structure = new Structure (this);
+ new MainWindowStructure (ui_manager, _structure);
+ // Bottom panel
BuildView build_view = new BuildView (this);
_main_window_build_tools = new MainWindowBuildTools (this, ui_manager,
@@ -293,10 +273,11 @@ public class MainWindow : Window
bottom_panel.bind_property ("visible", action_bottom_panel, "active",
BindingFlags.BIDIRECTIONAL);
- // structure (the UI manager must be initialized)
- _structure = new Structure (this, ui_manager);
+ // Side panel
+ _side_panel = new SidePanel ();
+ _side_panel.add_component (_("Symbols"), "symbol_greek", _symbols);
+ _side_panel.add_component (_("File Browser"), Stock.OPEN, file_browser);
_side_panel.add_component (_("Structure"), Stock.INDEX, _structure);
-
_side_panel.restore_state ();
// menu and toolbars
@@ -1541,50 +1522,6 @@ public class MainWindow : Window
ProjectDialogs.manage_projects (this);
}
- /* Structure */
-
- public void on_structure_cut ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.CUT);
- }
-
- public void on_structure_copy ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.COPY);
- }
-
- public void on_structure_delete ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.DELETE);
- }
-
- public void on_structure_select ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.SELECT);
- }
-
- public void on_structure_comment ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.COMMENT);
- }
-
- public void on_structure_shift_left ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.SHIFT_LEFT);
- }
-
- public void on_structure_shift_right ()
- {
- return_if_fail (_structure != null);
- _structure.do_action (StructAction.SHIFT_RIGHT);
- }
-
/* Help */
public void on_help_contents ()
diff --git a/src/main_window_structure.vala b/src/main_window_structure.vala
new file mode 100644
index 0000000..e2698e6
--- /dev/null
+++ b/src/main_window_structure.vala
@@ -0,0 +1,149 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright  2012 SÃbastien Wilmet
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: SÃbastien Wilmet
+ */
+
+using Gtk;
+
+// MainWindow stuff for the structure (the list of chapters, sections, ... of a document).
+
+public class MainWindowStructure
+{
+ private const Gtk.ActionEntry[] _action_entries =
+ {
+ { "Structure", null, N_("S_tructure") },
+
+ { "StructureCut", Stock.CUT, null, "",
+ N_("Cut the selected structure item"), on_cut },
+
+ { "StructureCopy", Stock.COPY, null, "",
+ N_("Copy the selected structure item"), on_copy },
+
+ { "StructureDelete", Stock.DELETE, null, "",
+ N_("Delete the selected structure item"), on_delete },
+
+ { "StructureSelect", Stock.SELECT_ALL, N_("_Select"), "",
+ N_("Select the contents of the selected structure item"), on_select },
+
+ { "StructureComment", null, N_("_Comment"), null,
+ N_("Comment the selected structure item"), on_comment },
+
+ { "StructureShiftLeft", Stock.GO_BACK, N_("Shift _Left"), "",
+ N_("Shift the selected structure item to the left (e.g. section â chapter)"),
+ on_shift_left },
+
+ { "StructureShiftRight", Stock.GO_FORWARD, N_("Shift _Right"), "",
+ N_("Shift the selected structure item to the right (e.g. chapter â section)"),
+ on_shift_right }
+ };
+
+ private UIManager _ui_manager;
+ private Structure _structure;
+
+ public MainWindowStructure (UIManager ui_manager, Structure structure)
+ {
+ _ui_manager = ui_manager;
+ _structure = structure;
+
+ Gtk.ActionGroup action_group = new Gtk.ActionGroup ("StructureActionGroup");
+ action_group.set_translation_domain (Config.GETTEXT_PACKAGE);
+ action_group.add_actions (_action_entries, this);
+
+ ui_manager.insert_action_group (action_group, 0);
+
+ structure.hide.connect (() =>
+ {
+ Gtk.Action menu = ui_manager.get_action ("/MainMenu/Structure");
+ menu.sensitive = false;
+ });
+
+ structure.show_popup_menu.connect (show_popup_menu);
+ structure.item_selected.connect (set_actions_sensitivity);
+ }
+
+ private void show_popup_menu (Gdk.EventButton? event)
+ {
+ Gtk.Menu popup_menu = _ui_manager.get_widget ("/StructurePopup") as Gtk.Menu;
+
+ 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)
+ {
+ Gtk.Action menu = _ui_manager.get_action ("/MainMenu/Structure");
+ menu.sensitive = true;
+
+ Gtk.Action shift_left =
+ _ui_manager.get_action ("/StructurePopup/StructureShiftLeft");
+
+ shift_left.sensitive = StructType.PART < type && type <= StructType.SUBPARAGRAPH;
+
+ Gtk.Action shift_right =
+ _ui_manager.get_action ("/StructurePopup/StructureShiftRight");
+
+ shift_right.sensitive = StructType.PART <= type && type < StructType.SUBPARAGRAPH;
+ }
+
+ /* Gtk.Action callbacks */
+
+ public void on_cut ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.CUT);
+ }
+
+ public void on_copy ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.COPY);
+ }
+
+ public void on_delete ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.DELETE);
+ }
+
+ public void on_select ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.SELECT);
+ }
+
+ public void on_comment ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.COMMENT);
+ }
+
+ public void on_shift_left ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.SHIFT_LEFT);
+ }
+
+ public void on_shift_right ()
+ {
+ return_if_fail (_structure != null);
+ _structure.do_action (StructAction.SHIFT_RIGHT);
+ }
+}
diff --git a/src/structure.vala b/src/structure.vala
index 391d615..b8a3ad3 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -91,15 +91,6 @@ public enum StructAction
public class Structure : Grid
{
private unowned MainWindow _main_window;
- private Gtk.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 Paned _vpaned;
@@ -122,23 +113,15 @@ public class Structure : Grid
private static string[] _names = null;
private static string[] _action_names = null;
- public Structure (MainWindow main_window, UIManager ui_manager)
+ public signal void item_selected (StructType type);
+ public signal void show_popup_menu (Gdk.EventButton? event);
+
+ public Structure (MainWindow main_window)
{
orientation = Orientation.VERTICAL;
row_spacing = 3;
_main_window = main_window;
- _popup_menu = ui_manager.get_widget ("/StructurePopup") as Gtk.Menu;
- _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 ();
@@ -147,11 +130,7 @@ public class Structure : Grid
_list_view_sw.hide ();
show.connect (connect_parsing);
- hide.connect (() =>
- {
- disconnect_parsing ();
- _action_all_menu.set_sensitive (false);
- });
+ hide.connect (disconnect_parsing);
}
private void init_toolbar ()
@@ -338,8 +317,6 @@ public class Structure : Grid
_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
@@ -436,8 +413,8 @@ public class Structure : Grid
StructType type;
_model.get (tree_iter,
StructColumn.START_MARK, out mark,
- StructColumn.TYPE, out type,
- -1);
+ StructColumn.TYPE, out type
+ );
/* go to the location in the document */
TextBuffer doc = mark.get_buffer ();
@@ -452,14 +429,13 @@ public class Structure : Grid
_main_window.active_view.scroll_to_mark (doc.get_insert (), 0, true, 1, 0);
/* select the corresponding item in the simple list */
- set_actions_sensitivity (type);
-
if (! first_select)
return true;
select_simple_list_item (tree_iter);
// the row is selected
+ item_selected (type);
return true;
}
@@ -606,30 +582,6 @@ public class Structure : Grid
/*************************************************************************/
// Right-click: actions
- 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 = true;
-
- _action_shift_left.sensitive =
- StructType.PART < type && type <= StructType.SUBPARAGRAPH;
-
- _action_shift_right.sensitive = type < StructType.SUBPARAGRAPH;
- }
-
public void do_action (StructAction action_type)
{
TreeIter selected_iter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]