private void fiche_WebPageImageChanged(Fiche _sender) { if (InvokeRequired) { BeginInvoke(new fiche_WebPageImageChangedDelegate(fiche_WebPageImageChanged), _sender); return; } //System.Diagnostics.Debug.WriteLine( "New web page images need to be displayed!" ); // panelWebPage.BackgroundImage = _sender.WebPageImage.AsBitmap; PanelMultiBitmaps.BitmapWithRectangle[] bitmaps = this.Bitmaps; if (bitmaps == null) { return; } panelWebPage.Bitmaps = bitmaps; panelWebPage.ClearRectangles(); // Make sure the panel is at least as large as the host // It can be much bigger but can't be smaller Rectangle pageRectangle = panelWebPage.TotalRectangle; panelWebPage.Width = Math.Max(panelHost.Width, pageRectangle.Right); panelWebPage.Height = Math.Max(panelHost.Height, pageRectangle.Bottom); panelWebPage.Invalidate(); }
public Fiche CreateFiche(FichesDB _database, string _title, Uri _URL) { // Patch any empty title if (_title == null) { _title = ""; } // Extract any tags from the title and fetch or create the tags ourselves string[] tags = WebHelpers.ExtractTags(_title); List <Fiche> tagFiches = new List <Fiche>(); foreach (string tag in tags) { Fiche tagFiche = _database.Sync_FindOrCreateTagFiche(tag); tagFiches.Add(tagFiche); } // Create the descriptor Fiche F = _database.Sync_CreateFicheDescriptor(Fiche.TYPE.REMOTE_ANNOTABLE_WEBPAGE, _title, _URL, tagFiches.ToArray(), null); // Load the web page and save the fiche when ready uint maxScrollsCount = Fiche.ChunkWebPageSnapshot.ms_maxWebPagePieces; // @TODO: make that depend on the domain, like tweets shouldn't have any comments and a single screen should suffice, for example... _database.Async_LoadContentAndSaveFiche(F, maxScrollsCount, true); return(F); }
public void AddReference(Fiche _reference) { if (m_references.Contains(_reference)) { return; // Already got it! } m_references.Add(_reference); }
public void RemoveReference(Fiche _reference) { if (!m_references.Contains(_reference)) { return; // Don't have it! } m_references.Remove(_reference); }
public void AddTag(Fiche _tag) { if (m_tags.Contains(_tag)) { return; // Already got it! } m_tags.Add(_tag); _tag.AddReference(this); }
public void RemoveTag(Fiche _tag) { if (!m_tags.Contains(_tag)) { return; // Don't have it! } m_tags.Remove(_tag); _tag.RemoveReference(this); }
private void fiche_TitleChanged(Fiche _sender) { if (InvokeRequired) { BeginInvoke(new fiche_TitleChangedDelegate(fiche_TitleChanged), _sender); return; } this.richTextBoxTitle.Text = _sender.Title; }
int ImportBookmarksChrome(FileInfo _fileName, List <Fiche> _createdTags, List <Fiche> _complexNameTags) { // Attempt to parse JSON file WebServices.JSON parser = new WebServices.JSON(); WebServices.JSON.JSONObject root = null; try { using (StreamReader R = _fileName.OpenText()) { root = parser.ReadJSON(R); } } catch (Exception _e) { throw new Exception("Failed to parse JSON file!", _e); } // Read bookmarks Bookmark.ms_tags = _createdTags; Bookmark.ms_complexNameTags = _complexNameTags; List <Bookmark> bookmarks = new List <Bookmark>(); try { root = root["root"]["roots"]; // Fetch the actual root foreach (object value in root.AsDictionary.Values) { WebServices.JSON.JSONObject rootFolder = value as WebServices.JSON.JSONObject; if (rootFolder != null) { // Add a new root folder containing bookmarks bookmarks.Add(new Bookmark(m_owner.Database, null, rootFolder, bookmarks)); } } } catch (Exception _e) { throw new Exception("Failed to parse bookmarks!", _e); } // Now convert bookmarks into fiches int successfullyImportedBookmarksCounter = 0; foreach (Bookmark bookmark in bookmarks) { try { if (bookmark.m_parent == null) { continue; // Don't create root folders... } // Reading the fiche property will create it and create its parent tags as well... Fiche F = bookmark.Fiche; successfullyImportedBookmarksCounter++; } catch (Exception _e) { throw new Exception("Failed to parse bookmarks!", _e); } } return(successfullyImportedBookmarksCounter); }
public ChunkBase(Fiche _owner, ulong _offset, uint _size) { m_owner = _owner; if (m_owner != null) { m_owner.m_chunks.Add(this); } m_offset = _offset; m_size = _size; }
// /// <summary> // /// Called as a post-process to finally resolve actual tag links after read // /// </summary> // /// <param name="_ID2Fiche"></param> // public void ResolveTags( Dictionary< Guid, Fiche > _ID2Fiche ) { // foreach ( Guid parentID in m_tagGUIDs ) { // Fiche parent = null; // if ( _ID2Fiche.TryGetValue( parentID, out parent ) ) // AddTag( parent ); // } // } /// <summary> /// Resolve one of our missing tags /// </summary> /// <param name="_fiche"></param> public void ResolveTag(Fiche _fiche) { foreach (Guid tagGUIID in m_tagGUIDs) { if (tagGUIID == _fiche.GUID) { // Found it! AddTag(_fiche); return; } } throw new Exception("Fiche is not one of our tags!"); }
protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (DialogResult != DialogResult.OK) { return; } // Create fiches for each selected tag foreach (string tag in checkedListBox.CheckedItems) { Fiche F = m_database.Sync_FindOrCreateTagFiche(tag); m_database.Async_NotifyFicheModifiedAndNeedsAsyncSaving(F); } }
public Fiche CreateFiche(FichesDB _database, string _format, object _data) { string text = _data.ToString(); // Check if it's not a URL in disguise, in which case we'll create a webpage instead... if (URLHandler.CanHandleURLScheme(text)) { return(URLHandler.CreateURLFiche(_database, null, WebHelpers.CreateCanonicalURL(text))); } string title = text; // Do better? string HTML = WebHelpers.BuildHTMLDocument(title, text); Fiche F = _database.Sync_CreateFicheDescriptor(Fiche.TYPE.LOCAL_EDITABLE_WEBPAGE, text, null, null, HTML); _database.Async_SaveFiche(F, true, true); return(F); }
protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); // Save fiches that changed foreach (ListViewItem item in listViewTagNames.Items) { Fiche fiche = item.Tag as Fiche; if (item.Text == fiche.Title) { continue; // No change... } // Update title & request saving fiche.Title = item.Text; fiche.Database.Async_NotifyFicheModifiedAndNeedsAsyncSaving(fiche); } }
public void NotifyFiche(Fiche _fiche, NOTIFICATION_TYPE _type) { // Register notification m_lastNotificationTime = DateTime.Now; int panelsCount = 0; switch (_type) { case NOTIFICATION_TYPE.SUCCESS: m_successCounter++; panelsCount++; break; case NOTIFICATION_TYPE.WARNING: m_warningCounter++; panelsCount++; break; case NOTIFICATION_TYPE.ERROR: m_errorCounter++; panelsCount++; break; } // Resize depending on amount of panels we need this.Size = new Size(panelsCount * ICON_PANEL_SIZE, ICON_PANEL_SIZE); // Center form on screen Point sourcePosition; if (Visible) { sourcePosition = this.Location; // Next, simply use the screen where the form already is } else { sourcePosition = Control.MousePosition; // First popup on the screen where the mouse is } Screen containingScreen; IntPtr hMonitor; Interop.GetMonitorFromPosition(sourcePosition, out containingScreen, out hMonitor); this.Location = new Point((containingScreen.Bounds.Width - this.Width) / 2, (containingScreen.Bounds.Height - this.Height) / 2); // Ask for a repaint Invalidate(); // Show if not already visible if (!Visible) { Show(m_owner); } }
public IFicheEditor GetEditorForFiche(Fiche _fiche) { if (_fiche == null) { return(null); // No fiche = no editor } switch (_fiche.Type) { case Fiche.TYPE.REMOTE_ANNOTABLE_WEBPAGE: return(m_ficheWebPageAnnotatorForm); case Fiche.TYPE.LOCAL_EDITABLE_WEBPAGE: case Fiche.TYPE.LOCAL_FILE: return(m_ficheWebPageEditorForm); } throw new Exception("No editor for fiche type!"); }
private void fiche_DOMElementsChanged(Fiche _sender) { panelWebPage.SuspendLayout(); panelWebPage.ClearRectangles(); if (_sender.DOMElements != null) { foreach (DOMElement element in _sender.DOMElements.m_children) { Color color = Color.Magenta; switch (element.m_type) { case DOMElement.ELEMENT_TYPE.TEXT: color = Color.ForestGreen; break; case DOMElement.ELEMENT_TYPE.LINK: color = Color.CornflowerBlue; break; case DOMElement.ELEMENT_TYPE.IMAGE: color = Color.IndianRed; break; } panelWebPage.AddRectangle(element.m_rectangle, color); } } panelWebPage.ResumeLayout(); panelWebPage.PerformLayout(); }
public EditedTag(Fiche _fiche, EditedTag _nextTag) { InsertBefore(_nextTag); Fiche = _fiche; }
// From https://stackoverflow.com/questions/2450373/set-global-hotkeys-using-c-sharp /// <summary> /// Overridden to get the notifications. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { switch (m.Msg) { case Interop.WM_HOTKEY: Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); Interop.NativeModifierKeys modifiers = (Interop.NativeModifierKeys)((int)m.LParam & 0xFFFF); PreferencesForm.Shortcut shortcut = m_preferenceForm.HandleHotKey(modifiers, key); if (shortcut == null) { break; } switch (shortcut.m_type) { case PreferencesForm.Shortcut.SHORTCUT.TOGGLE: // Toggle visibility if (Visible) { Hide(); } else { Show(); } break; case PreferencesForm.Shortcut.SHORTCUT.PASTE: // Create a quick fiche & ask for tags in a very light way try { IDataObject clipboardData = Clipboard.GetDataObject(); Fiche fiche = m_database.Sync_CreateFicheFromClipboard(clipboardData); SelectedFiche = fiche; if (!SelectedFicheEditor.EditorForm.Visible) { m_fastTaggerForm.Fiches = new Fiche[] { fiche }; // m_fastTaggerFormF.Location = this.Location + this.Size - F.Size; // Bottom-right of the screen m_fastTaggerForm.CenterOnPoint(Control.MousePosition); // Center on mouse if (!m_fastTaggerForm.Visible) { m_fastTaggerForm.Show(this); } } } catch (Exception _e) { // @TODO => Show an error dialog! LogError(_e); } break; case PreferencesForm.Shortcut.SHORTCUT.NEW: // Show and create a new empty editable fiche try { Fiche fiche = m_database.Sync_CreateFicheDescriptor(Fiche.TYPE.LOCAL_EDITABLE_WEBPAGE, "New Fiche", null, null, null); // Make it the last edited fiche m_ficheWebPageEditorForm.EditedFiche = fiche; // Show both the application & the fiche editor m_showEditorFormOnShowMain = true; Show(); } catch (Exception _e) { // @TODO => Show an error dialog! LogError(_e); } break; } break; case Interop.WM_KEYDOWN: // if ( m.HWnd == m_ficheEditorForm.Handle ) { // System.Diagnostics.Debug.WriteLine( "Bisou!" ); // } break; default: // Log every message! //System.Diagnostics.Debug.WriteLine( "Message: " + m ); break; } if (!m_fishing) { base.WndProc(ref m); // Process messages normally } else { // In "fishing mode", dispatch messages to background windows switch (m.Msg) { case 0x7f: case 0x84: // (WM_NCHITTEST) hwnd=0xaa1b64 wparam=0x0 lparam=0x34c040e result=0x0 case 0x20: // (WM_SETCURSOR) break; default: System.Diagnostics.Debug.WriteLine("Message: " + m); break; } // if ( m.Msg == Interop.WM_KEYUP || m.Msg == Interop.WM_KEYDOWN || m.Msg == Interop.WM_SYSKEYUP || m.Msg == Interop.WM_SYSKEYDOWN ) { if (m.Msg == Interop.WM_KEYUP || m.Msg == Interop.WM_SYSKEYUP) { if (((Keys)m.WParam.ToInt32()) == Keys.Menu) { System.Diagnostics.Debug.WriteLine("========================= EXIT FISHING! ========================="); ExitFishing(); } } DispatchMessageToBackgroundWindows(m); } }
private void database_FicheErrorOccurred(Fiche _fiche, string _error) { m_notificationForm.NotifyFiche(_fiche, NotificationForm.NOTIFICATION_TYPE.ERROR); database_Log(FichesDB.LOG_TYPE.ERROR, _error); }
private void database_FicheWarningOccurred(Fiche _fiche, string _errorOrWarning) { m_notificationForm.NotifyFiche(_fiche, NotificationForm.NOTIFICATION_TYPE.WARNING); database_Log(FichesDB.LOG_TYPE.WARNING, _errorOrWarning); }
public ChunkThumbnail(Fiche _owner, ImageFile _imagesWebPage) : base(_owner, ~0UL, 0) { UpdateFromWebPageImage(_imagesWebPage); }
public ChunkWebPageSnapshot(Fiche _owner, uint _imageStartIndex, Rectangle[] _contentRectangles, ImageFile[] _images, ImageFile.FILE_FORMAT _targetFormat) : base(_owner, ~0UL, 0) { UpdateImages(_imageStartIndex, _contentRectangles, _images, _targetFormat); }
public ChunkWebPageSnapshot(Fiche _owner, ulong _offset, uint _size) : base(_owner, _offset, _size) { }
public ChunkThumbnail(Fiche _owner, ulong _offset, uint _size) : base(_owner, _offset, _size) { }
private void database_FicheSuccessOccurred(Fiche _fiche) { m_notificationForm.NotifyFiche(_fiche, NotificationForm.NOTIFICATION_TYPE.SUCCESS); database_Log(FichesDB.LOG_TYPE.INFO, "SUCCESS on fiche \"" + _fiche.Title + "\"!"); }