Merge lp:~tai271828/ubuntu/precise/pcmanx-gtk2/fix-for-1284447 into lp:ubuntu/precise/pcmanx-gtk2

Proposed by Taihsiang Ho
Status: Needs review
Proposed branch: lp:~tai271828/ubuntu/precise/pcmanx-gtk2/fix-for-1284447
Merge into: lp:ubuntu/precise/pcmanx-gtk2
Diff against target: 149 lines (+82/-6)
2 files modified
src/mainframe.cpp (+79/-6)
src/mainframe.h (+3/-0)
To merge this branch: bzr merge lp:~tai271828/ubuntu/precise/pcmanx-gtk2/fix-for-1284447
Reviewer Review Type Date Requested Status
Sebastien Bacher Needs Fixing
Review via email: mp+211676@code.launchpad.net

Description of the change

This is a function enhancement for LP: #1284447 and backport from upstream.
Please see the upstream bug report
https://code.google.com/p/pcmanx-gtk2/issues/detail?id=67&can=1

[Test Case]
open few connection windows, and then
* middle click to close what your middle button select - verify the new feature
* alt+w button to close the current window - verify the OnCloseCon behavior is the same after refactoring
* ctrl+d button to close the current window - verify the OnCloseCon behavior is the same after refactoring

[Regression Potential]
No, this is a userspace application to connect a telnet message window.
The most risk is the user could not close the exact telnet message window launched by the pcmanx-gtk2 application.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your work. Could you include a changelog entry to your update? Before fixing that in precise you also need the fix uploaded to the current serie (trusty), could you work on that?

review: Needs Fixing

Unmerged revisions

18. By Taihsiang Ho

Refactoring to modulize query dialogue on closing connection (LP: #1284447)

17. By Taihsiang Ho

Close tabs selected by middle clicks. (LP: #1284447)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mainframe.cpp'
2--- src/mainframe.cpp 2012-02-02 22:53:10 +0000
3+++ src/mainframe.cpp 2014-03-19 07:54:51 +0000
4@@ -799,21 +799,86 @@
5 t_pView->PasteFromClipboard(true);
6 }
7
8+void CMainFrame::OnCloseSelectCon(GtkWidget *notebook, GtkMenuItem* mitem, CMainFrame* _this)
9+{
10+ /**
11+ * Close pages selected by middle click of tabs.
12+ *
13+ * At first choose which tab is the closet tab to the click location.
14+ * Then switch to the selected page.
15+ * Finally close it, and then switch back to the original page.
16+ *
17+ * TODO:
18+ * The most right hand tab will be selected
19+ * even the click location is not exactly on the tab.
20+ */
21+ int window_w = 0;
22+ int window_h = 0;
23+ gtk_window_get_size(GTK_WINDOW(gtk_widget_get_toplevel(notebook)), &window_w, &window_h);
24+
25+ GtkWidget *closet_tab;
26+
27+ int closet_tab_x = window_w;
28+ int number_of_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
29+ int nth_page_number = 0;
30+ int number_of_closet_tab = 0;
31+ /* pick up the tab which is closet to the click location. */
32+ for(nth_page_number = 0; nth_page_number < number_of_pages; nth_page_number++)
33+ {
34+ GtkWidget *tab_label;
35+ tab_label = gtk_notebook_get_tab_label( GTK_NOTEBOOK(notebook),
36+ gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
37+ nth_page_number));
38+ int lx, ly;
39+ gtk_widget_get_pointer(tab_label, &lx, &ly);
40+ if(lx > 0 && lx < closet_tab_x)
41+ {
42+ closet_tab_x = lx;
43+ closet_tab = tab_label;
44+ number_of_closet_tab = nth_page_number;
45+ }
46+ }
47+
48+ /* switch to the page which is clicked. */
49+ int page_idx_before_close = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
50+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), number_of_closet_tab);
51+ _this->SetCurView( _this->m_Views[number_of_closet_tab] );
52+
53+ if ( !(_this->QueryOnCloseCon(_this)) ) return;
54+
55+ int page_idx_after_close = 0;
56+ page_idx_before_close < number_of_closet_tab ? page_idx_after_close = page_idx_before_close : page_idx_after_close = page_idx_before_close - 1;
57+ /* close the current page and then switch page back to the original one. */
58+ _this->CloseConAndPageSwitch(_this->m_pNotebook->GetCurPage(), true, notebook, page_idx_after_close);
59+}
60+
61 void CMainFrame::OnCloseCon(GtkMenuItem* mitem UNUSED, CMainFrame* _this)
62 {
63+ if ( !(_this->QueryOnCloseCon(_this)) ) return;
64+ _this->CloseCon(_this->m_pNotebook->GetCurPage(), true);
65+}
66+
67+bool CMainFrame::QueryOnCloseCon(CMainFrame* _this)
68+{
69+
70 CTelnetCon* con = _this->GetCurCon();
71 if( !con )
72- return;
73+ return false;
74 if( AppConfig.QueryOnCloseCon && !con->IsClosed() )
75 {
76- GtkWidget* dlg = gtk_message_dialog_new(GTK_WINDOW(_this->m_Widget), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, _("Close Connection?"));
77+ GtkWidget* dlg = gtk_message_dialog_new(GTK_WINDOW(_this->m_Widget),
78+ GTK_DIALOG_MODAL,
79+ GTK_MESSAGE_QUESTION,
80+ GTK_BUTTONS_OK_CANCEL,
81+ _("Close Connection?"));
82 bool can_close = ( gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK );
83 gtk_widget_destroy(dlg);
84 if( !can_close )
85- return;
86+ return false;
87 }
88
89- _this->CloseCon(_this->m_pNotebook->GetCurPage(), true);
90+ return true;
91+
92 }
93
94
95@@ -1015,7 +1080,7 @@
96 _this->SetCurView( _this->m_Views[page_num] );
97 }
98
99-gboolean CMainFrame::OnNotebookPopupMenu(GtkWidget *widget UNUSED,
100+gboolean CMainFrame::OnNotebookPopupMenu(GtkWidget *widget,
101 GdkEventButton *event,
102 CMainFrame* _this)
103 {
104@@ -1075,7 +1140,7 @@
105 // similar to the behavior under Firefox
106 if (AppConfig.MidClickAsClose &&
107 event->type == GDK_BUTTON_PRESS && event->button == 2) {
108- _this->OnCloseCon(GTK_MENU_ITEM(menu_item_close), _this);
109+ _this->OnCloseSelectCon(widget, GTK_MENU_ITEM(menu_item_close), _this);
110 return TRUE;
111 }
112
113@@ -1089,6 +1154,14 @@
114 return TRUE;
115 }
116
117+void CMainFrame::CloseConAndPageSwitch(int idx, bool confirm UNUSED, GtkWidget *notebook, int page_idx)
118+{
119+ m_pNotebook->RemovePage(idx);
120+ m_Views.erase( m_Views.begin() + idx );
121+
122+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), page_idx);
123+ SetCurView( page_idx >= 0 ? m_Views[page_idx] : NULL );
124+}
125
126 void CMainFrame::CloseCon(int idx, bool confirm UNUSED)
127 {
128
129=== modified file 'src/mainframe.h'
130--- src/mainframe.h 2012-02-02 22:53:10 +0000
131+++ src/mainframe.h 2014-03-19 07:54:51 +0000
132@@ -63,6 +63,7 @@
133 static void OnFont(GtkMenuItem* mitem, CMainFrame* _this);
134 static void OnAbout(GtkMenuItem* mitem, CMainFrame* _this);
135 static void pasteFromClipboard(GtkMenuItem* mitem, CMainFrame* _this);
136+ static void OnCloseSelectCon(GtkWidget* notebook, GtkMenuItem* mitem, CMainFrame* _this);
137 static void OnCloseCon(GtkMenuItem* mitem, CMainFrame* _this);
138 static void OnCopy(GtkMenuItem* mitem, CMainFrame* _this);
139 static void OnCopyWithColor(GtkMenuItem* mitem, CMainFrame* _this);
140@@ -136,7 +137,9 @@
141 void LoadIcons();
142 void LoadStartupSites();
143 static void OnJumpToPage(GObject* obj, CMainFrame* _this);
144+ void CloseConAndPageSwitch(int idx, bool confirm UNUSED, GtkWidget *notebook, int page_idx);
145 void CloseCon(int idx, bool confirm = false);
146+ static bool QueryOnCloseCon(CMainFrame* _this);
147 static void OnAddToFavorites(GtkMenuItem* widget, CMainFrame* _this);
148 void CreateFavoritesMenu();
149 void CreateTrayIcon();

Subscribers

People subscribed via source and target branches

to all changes: