lokdocview: fix not updated part selector when search changes part

Change-Id: I337eed47c56dbbbebda4d7fe716eab6177936dc0
This commit is contained in:
Miklos Vajna 2015-05-27 11:30:04 +02:00
parent adce9bf3ad
commit c7ecbbbb6a
3 changed files with 34 additions and 2 deletions

View File

@ -40,6 +40,7 @@ struct _LOKDocViewClass
void (* edit_changed) (LOKDocView* pView, gboolean was_edit); void (* edit_changed) (LOKDocView* pView, gboolean was_edit);
void (* command_changed) (LOKDocView* pView, char* new_state); void (* command_changed) (LOKDocView* pView, char* new_state);
void (* search_not_found) (LOKDocView* pView, char* new_state); void (* search_not_found) (LOKDocView* pView, char* new_state);
void (* part_changed) (LOKDocView* pView, int new_part);
}; };
guint lok_docview_get_type (void); guint lok_docview_get_type (void);

View File

@ -45,6 +45,8 @@ static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later // GtkComboBox requires gtk 2.24 or later
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
static GtkComboBoxText* pPartSelector; static GtkComboBoxText* pPartSelector;
/// Should the part selector avoid calling lok::Document::setPart()?
static bool g_bPartSelectorBroadcast = true;
#endif #endif
GtkWidget* pFindbar; GtkWidget* pFindbar;
GtkWidget* pFindbarEntry; GtkWidget* pFindbarEntry;
@ -238,6 +240,15 @@ static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpoint
gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found"); gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found");
} }
static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*/)
{
#if GTK_CHECK_VERSION(2,24,0)
g_bPartSelectorBroadcast = false;
gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), nPart);
g_bPartSelectorBroadcast = true;
#endif
}
/// User clicked on a cmmand button -> inform LOKDocView. /// User clicked on a cmmand button -> inform LOKDocView.
static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/) static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{ {
@ -285,7 +296,7 @@ static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
{ {
int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ); int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
if ( pDocView ) if (g_bPartSelectorBroadcast && pDocView)
{ {
lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart ); lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart );
} }
@ -436,6 +447,7 @@ int main( int argc, char* argv[] )
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL); g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL); g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL); g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
// Input handling. // Input handling.
g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView); g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView);

View File

@ -194,6 +194,8 @@ struct LOKDocView_Impl
void commandChanged(const std::string& rPayload); void commandChanged(const std::string& rPayload);
/// Search did not find any matches. /// Search did not find any matches.
void searchNotFound(const std::string& rPayload); void searchNotFound(const std::string& rPayload);
/// LOK decided to change parts, need to update UI.
void setPart(const std::string& rPayload);
}; };
namespace { namespace {
@ -1019,7 +1021,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
break; break;
case LOK_CALLBACK_SET_PART: case LOK_CALLBACK_SET_PART:
{ {
renderDocument(0); setPart(pCallback->m_aPayload);
} }
break; break;
default: default:
@ -1066,6 +1068,7 @@ enum
EDIT_CHANGED, EDIT_CHANGED,
COMMAND_CHANGED, COMMAND_CHANGED,
SEARCH_NOT_FOUND, SEARCH_NOT_FOUND,
PART_CHANGED,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -1081,6 +1084,12 @@ void LOKDocView_Impl::searchNotFound(const std::string& rString)
g_signal_emit(m_pDocView, docview_signals[SEARCH_NOT_FOUND], 0, rString.c_str()); g_signal_emit(m_pDocView, docview_signals[SEARCH_NOT_FOUND], 0, rString.c_str());
} }
void LOKDocView_Impl::setPart(const std::string& rString)
{
g_signal_emit(m_pDocView, docview_signals[PART_CHANGED], 0, std::stoi(rString));
renderDocument(0);
}
static void lok_docview_class_init( gpointer ptr ) static void lok_docview_class_init( gpointer ptr )
{ {
LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr); LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr);
@ -1115,6 +1124,16 @@ static void lok_docview_class_init( gpointer ptr )
g_cclosure_marshal_VOID__STRING, g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_STRING); G_TYPE_STRING);
pClass->part_changed = 0;
docview_signals[PART_CHANGED] =
g_signal_new("part-changed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(LOKDocViewClass, part_changed),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
} }
static void lok_docview_init( GTypeInstance* pInstance, gpointer ) static void lok_docview_init( GTypeInstance* pInstance, gpointer )